V1 folder created For auth Data project, trash, home page based on the token and role based

This commit is contained in:
2025-05-26 12:24:06 +05:30
parent ac8de5d33d
commit 089c6af1b6
20 changed files with 1193 additions and 236 deletions

View File

@@ -0,0 +1,75 @@
import projectModel from "../../V1Models/Project/project-model.ts";
interface IOrg {
organization: string;
role: string;
userId: string;
}
interface IRestore {
projectId: string;
organization: string;
role: string;
userId: string;
}
interface RoleFilter {
isArchive: boolean;
createdBy?: string;
}
export const TrashDatas = async (data: IOrg) => {
try {
const { organization, role, userId } = data;
let filter = { isArchive: true, isDeleted: false } as RoleFilter;
if (role === "User") {
filter.createdBy = userId;
}
const TrashLists = await projectModel(organization).find(filter);
if (!TrashLists) return { staus: "Trash is Empty" };
const TrashDocs: any[] = [];
for (const Trash of TrashLists) {
const now = new Date();
const deletedPlus15 = new Date(
Trash.DeletedAt.getTime() + 15 * 24 * 60 * 60 * 1000
);
if (now > deletedPlus15) {
console.log("now > deletedPlus15: ", now > deletedPlus15);
await projectModel(organization).updateOne(
{ _id: Trash._id },
{ $set: { isDeleted: true } }
);
} else {
TrashDocs.push(Trash);
}
}
const ListDatas = TrashDocs.map((data) => {
return {
projectName: data.projectName,
thumbnail: data.thumbnail,
createdBy: data.createdBy,
_id: data._id,
};
});
return { status: "Success", ListDatas };
} catch (error) {
return { status: error };
}
};
export const RestoreTrashData = async (data: IRestore) => {
try {
const { projectId, organization, role, userId } = data;
let filter = { isArchive: true, _id: projectId } as RoleFilter;
if (role === "User") {
filter.createdBy = userId;
}
const findProject = await projectModel(organization).findOne(filter);
if (!findProject) return { status: "Project not found" };
const restoreData = await projectModel(organization).findOneAndUpdate(
filter,
{ isArchive: false, DeletedAt: null },
{ new: true }
);
if (!restoreData) return { status: "Project Restore unsuccessfull" };
return { status: "Project Restored successfully" };
} catch (error) {
return { status: error };
}
};