RBAC, jwt implemented in Projects,home and collections routing

This commit is contained in:
2025-09-01 16:52:30 +05:30
parent b8950dc42d
commit 322db1911b
17 changed files with 503 additions and 175 deletions

View File

@@ -0,0 +1,51 @@
import ProjectType from "../../shared/model/projectmodel";
import userDataModel from "../model/userDataModel";
import userModel from "../model/userModel";
interface IrecentlyViewed {
organization: string;
userId: string;
}
interface Iresponse {
status: string;
data?: any;
}
export const recentlyViewedServices = async (
data: IrecentlyViewed
): Promise<Iresponse> => {
const { organization, userId } = data;
try {
const ExistingUser = await userModel(organization).findOne({
_id: userId,
isArchive: false,
});
if (!ExistingUser) return { status: "User not found" };
const userDatas = await userDataModel(organization)
.findOne({ userId: userId, isArchive: false })
.select("recentlyViewed userId");
const populatedProjects = userDatas.recentlyViewed;
const RecentDatas = await Promise.all(
populatedProjects.map(async (projectId: any) => {
const projectExisting = await ProjectType(organization)
.findOne({
_id: projectId,
isArchive: false,
})
.select("_id projectName createdBy thumbnail createdAt isViewed");
return projectExisting;
})
);
const filteredProjects = RecentDatas.filter(Boolean);
return { status: "Success", data: filteredProjects };
} catch (error: unknown) {
if (error instanceof Error) {
return {
status: error.message,
};
} else {
return {
status: "An unexpected error occurred",
};
}
}
};