Role nd token Based Routing completed for Project,trash,home which is in Controller. Token, Auth Purpose,Rolebased middlewares created. Auth API,Project token Based API, Home Token Based API, Trash Token Based API In v1 AuthRoutes
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import projectModel from "../../model/project/project-model.ts";
|
||||
import userModel from "../../model/user-Model.ts";
|
||||
import UsersDataModel from "../../V1Models/Auth/user.ts";
|
||||
import { existingUser } from "../helpers/ProjecthelperFn.ts";
|
||||
|
||||
interface IRecentData {
|
||||
organization: string;
|
||||
userId: string;
|
||||
role: string;
|
||||
}
|
||||
interface IProject {
|
||||
_id: string;
|
||||
@@ -19,26 +21,31 @@ interface searchProjectInterface {
|
||||
userId: string;
|
||||
organization: string;
|
||||
}
|
||||
interface RoleFilter {
|
||||
isArchive: boolean;
|
||||
createdBy?: string;
|
||||
}
|
||||
export const RecentlyAdded = async (data: IRecentData) => {
|
||||
try {
|
||||
const { userId, organization } = data;
|
||||
const { userId, organization, role } = data;
|
||||
const userExisting = await existingUser(userId, organization);
|
||||
if (!userExisting) return { status: "User not found" };
|
||||
const userRecentData = await userModel(organization)
|
||||
.findOne({ _id: userId })
|
||||
const userRecentData = await UsersDataModel(organization)
|
||||
.findOne({ userId: userId, isArchive: false })
|
||||
.populate({
|
||||
path: "recentlyViewed",
|
||||
model: projectModel(organization),
|
||||
select: "_id",
|
||||
});
|
||||
let filter = { isArchive: false } as RoleFilter;
|
||||
if (role === "User") {
|
||||
filter.createdBy = userId;
|
||||
}
|
||||
const populatedProjects = userRecentData.recentlyViewed as IProject[];
|
||||
const RecentDatas = await Promise.all(
|
||||
populatedProjects.map(async (project) => {
|
||||
const projectExisting = await projectModel(organization)
|
||||
.findOne({
|
||||
_id: project._id,
|
||||
isArchive: false,
|
||||
})
|
||||
.findOne(filter)
|
||||
.select("_id projectName createdBy thumbnail createdAt isViewed");
|
||||
return projectExisting;
|
||||
})
|
||||
@@ -57,26 +64,29 @@ export const searchProject = async (data: searchProjectInterface) => {
|
||||
if (!userExisting) return { status: "User not found" };
|
||||
const findprojectName = await projectModel(organization).find({
|
||||
projectName: { $regex: `${searchName}`, $options: "i" }, // 'i' makes it case-insensitive
|
||||
isArchive: false,
|
||||
})
|
||||
if (!findprojectName||findprojectName.length===0) return { status: "Project not found" }
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findprojectName || findprojectName.length === 0)
|
||||
return { status: "Project not found" };
|
||||
return { status: "Success", data: findprojectName };
|
||||
} catch (error: unknown) {
|
||||
return { status: error };
|
||||
}
|
||||
}
|
||||
};
|
||||
export const searchTrashProject = async (data: searchProjectInterface) => {
|
||||
try {
|
||||
const { userId, organization, searchName } = data;
|
||||
const userExisting = await existingUser(userId, organization);
|
||||
if (!userExisting) return { status: "User not found" };
|
||||
const findprojectName = await projectModel(organization).find({
|
||||
projectName: { $regex: `${searchName}`, $options: "i" },
|
||||
isArchive: true,isDeleted:false
|
||||
})
|
||||
if (!findprojectName||findprojectName.length===0) return { status: "Project not found" }
|
||||
projectName: { $regex: `${searchName}`, $options: "i" },
|
||||
isArchive: true,
|
||||
isDeleted: false,
|
||||
});
|
||||
if (!findprojectName || findprojectName.length === 0)
|
||||
return { status: "Project not found" };
|
||||
return { status: "Success", data: findprojectName };
|
||||
} catch (error: unknown) {
|
||||
return { status: error };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user