Trash Get, Restore API completed, Project Delete API completed
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
import * as express from "express";
|
import * as express from "express";
|
||||||
import { createProjectController, GetProjects } from "../controller/project/projectController.ts";
|
import {
|
||||||
|
createProjectController,
|
||||||
|
GetProjects,
|
||||||
|
RemoveProject,
|
||||||
|
} from "../controller/project/projectController.ts";
|
||||||
|
|
||||||
const projectRouter = express.Router();
|
const projectRouter = express.Router();
|
||||||
projectRouter.post("/upsertProject",createProjectController)
|
projectRouter.post("/upsertProject", createProjectController);
|
||||||
projectRouter.get("/Projects/:userId/:organization",GetProjects)
|
projectRouter.get("/Projects/:userId/:organization", GetProjects);
|
||||||
export default projectRouter
|
projectRouter.patch("/Project/archive/:projectId", RemoveProject);
|
||||||
|
export default projectRouter;
|
||||||
|
|||||||
8
src/api-server/Routes/trashRoutes.ts
Normal file
8
src/api-server/Routes/trashRoutes.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import * as express from "express";
|
||||||
|
import { GetTrashList, RestoreTrash } from "../controller/trash/trashcontrollers.ts";
|
||||||
|
|
||||||
|
const trashRouter = express.Router();
|
||||||
|
trashRouter.get("/Trash/Lists", GetTrashList);
|
||||||
|
trashRouter.patch("/restore",RestoreTrash)
|
||||||
|
|
||||||
|
export default trashRouter;
|
||||||
@@ -20,6 +20,7 @@ import templateRoutes from "./Routes/templateRoutes.ts";
|
|||||||
import widget3dRoutes from "./Routes/widget3dRoutes.ts";
|
import widget3dRoutes from "./Routes/widget3dRoutes.ts";
|
||||||
import productRouter from "./Routes/productRoutes.ts";
|
import productRouter from "./Routes/productRoutes.ts";
|
||||||
import projectRouter from "./Routes/projectRoutes.ts";
|
import projectRouter from "./Routes/projectRoutes.ts";
|
||||||
|
import trashRouter from "./Routes/trashRoutes.ts";
|
||||||
// import productFlowRoutes from "./Routes/productFlowRouts.ts";
|
// import productFlowRoutes from "./Routes/productFlowRouts.ts";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -87,4 +88,5 @@ app.use("/api/v2", widget3dRoutes);
|
|||||||
app.use("/api/v2", productRouter);
|
app.use("/api/v2", productRouter);
|
||||||
// app.use("/api/v2", productFlowRoutes);
|
// app.use("/api/v2", productFlowRoutes);
|
||||||
app.use("/api/v1",projectRouter)
|
app.use("/api/v1",projectRouter)
|
||||||
|
app.use("/api/v1",trashRouter)
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import { createProject,GetAllProjects } from "../../../shared/services/project/project-Services.ts";
|
import {
|
||||||
|
createProject,
|
||||||
|
DeleteProject,
|
||||||
|
GetAllProjects,
|
||||||
|
} from "../../../shared/services/project/project-Services.ts";
|
||||||
|
|
||||||
export const createProjectController = async (
|
export const createProjectController = async (
|
||||||
req: Request,
|
req: Request,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
|
const { projectName, userId, thumbnail, organization } = req.body;
|
||||||
|
if (!projectName || !userId || !thumbnail || !organization)
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
const result = await createProject(req.body);
|
const result = await createProject(req.body);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "project_exists":
|
case "project_exists":
|
||||||
res.status(409).json({
|
res.status(403).json({
|
||||||
message: "Project already exists",
|
message: "Project already exists",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -21,17 +30,12 @@ export const createProjectController = async (
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "success":
|
case "Success":
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
message: "Project created successfully",
|
message: "Project created Successfully",
|
||||||
projectId: result.project._id,
|
projectId: result.project._id,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "All fields are required":
|
|
||||||
res.status(400).json({
|
|
||||||
message: "All fields are required",
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
message: "Internal server error",
|
message: "Internal server error",
|
||||||
@@ -50,25 +54,23 @@ export const GetProjects = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.params;
|
const { userId, organization } = req.params;
|
||||||
const result = await GetAllProjects({ userId, organization});
|
if (!userId || !organization)
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
const result = await GetAllProjects({ userId, organization });
|
||||||
switch (result?.status) {
|
switch (result?.status) {
|
||||||
|
|
||||||
case "User not found":
|
case "User not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "User not found",
|
message: "User not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "success":
|
case "Success":
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
Projects: result?.Datas,
|
Projects: result?.Datas,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "All fields are required":
|
|
||||||
res.status(400).json({
|
|
||||||
message: "All fields are required",
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
message: "Internal server error",
|
message: "Internal server error",
|
||||||
@@ -80,4 +82,44 @@ export const GetProjects = async (
|
|||||||
message: "Unknown error",
|
message: "Unknown error",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
export const RemoveProject = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { projectId } = req.params;
|
||||||
|
const { organization, userId } = req.body;
|
||||||
|
if (!projectId || !organization || !userId)
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
const result = await DeleteProject({ projectId, organization, userId });
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Project Deleted Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
96
src/api-server/controller/trash/trashcontrollers.ts
Normal file
96
src/api-server/controller/trash/trashcontrollers.ts
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import {
|
||||||
|
TrashDatas,
|
||||||
|
RestoreTrashData,
|
||||||
|
} from "../../../shared/services/trash/trashService.ts";
|
||||||
|
|
||||||
|
export const GetTrashList = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization } = req.query as { organization?: string };
|
||||||
|
console.log("organization: ", organization);
|
||||||
|
if (!organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await TrashDatas({ organization });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "Trash is Empty":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Trash is Empty",
|
||||||
|
TrashDatas: [],
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
// message: "Project created Successfully",
|
||||||
|
TrashDatas: result.ListDatas,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RestoreTrash = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, projectId } = req.query as {
|
||||||
|
organization?: string;
|
||||||
|
projectId?: string;
|
||||||
|
};
|
||||||
|
console.log("organization: ", organization);
|
||||||
|
if (!organization || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await RestoreTrashData({ organization, projectId });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project Restore unsuccessfull":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project Restore unsuccessfull",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project Restored successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project Restored successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -7,6 +7,7 @@ export interface Project extends Document {
|
|||||||
projectName: string;
|
projectName: string;
|
||||||
createdBy: User["_id"];
|
createdBy: User["_id"];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
|
isDeleted: boolean;
|
||||||
thumbnail: string;
|
thumbnail: string;
|
||||||
sharedUsers: [];
|
sharedUsers: [];
|
||||||
DeletedAt: Date;
|
DeletedAt: Date;
|
||||||
@@ -22,6 +23,7 @@ const projectSchema: Schema = new Schema(
|
|||||||
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
|
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
|
||||||
sharedUsers: [{ type: Schema.Types.ObjectId, ref: "user" }],
|
sharedUsers: [{ type: Schema.Types.ObjectId, ref: "user" }],
|
||||||
DeletedAt: { type: Date, default: null },
|
DeletedAt: { type: Date, default: null },
|
||||||
|
isDeleted: { type: Boolean, default: false },
|
||||||
total_versions: { type: String },
|
total_versions: { type: String },
|
||||||
Present_version: { type: String },
|
Present_version: { type: String },
|
||||||
},
|
},
|
||||||
|
|||||||
49
src/shared/services/helpers/ProjecthelperFn.ts
Normal file
49
src/shared/services/helpers/ProjecthelperFn.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import projectModel from "../../model/project/project-model.ts";
|
||||||
|
import userModel from "../../model/user-Model.ts";
|
||||||
|
import { Types } from "mongoose";
|
||||||
|
import versionModel from "../../model/version/versionModel.ts";
|
||||||
|
export const existingProject = async (
|
||||||
|
projectName: string,
|
||||||
|
organization: string,
|
||||||
|
userId: string
|
||||||
|
) => {
|
||||||
|
const projectData = await projectModel(organization).findOne({
|
||||||
|
projectName: projectName,
|
||||||
|
createdBy: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
return projectData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const existingUser = async (userId: string, organization: string) => {
|
||||||
|
if (!Types.ObjectId.isValid(userId)) {
|
||||||
|
console.log("Invalid ObjectId format");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const userData = await userModel(organization).findOne({
|
||||||
|
_id: userId,
|
||||||
|
});
|
||||||
|
return userData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const archiveProject = async (
|
||||||
|
projectId: string,
|
||||||
|
organization: string
|
||||||
|
) => {
|
||||||
|
return await projectModel(organization).findByIdAndUpdate(
|
||||||
|
projectId,
|
||||||
|
{ isArchive: true },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const previousVersion = async (
|
||||||
|
projectId: string,
|
||||||
|
organization: string
|
||||||
|
) => {
|
||||||
|
const result = await versionModel(organization).findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
// .sort({ version: -1 });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
@@ -2,8 +2,12 @@ import projectModel from "../../model/project/project-model.ts";
|
|||||||
import userModel from "../../model/user-Model.ts";
|
import userModel from "../../model/user-Model.ts";
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import versionModel from "../../model/version/versionModel.ts";
|
import versionModel from "../../model/version/versionModel.ts";
|
||||||
import { uploadProjectThumbnail } from "../blob/blobServices.ts";
|
import {
|
||||||
|
existingProject,
|
||||||
|
existingUser,
|
||||||
|
archiveProject,
|
||||||
|
previousVersion,
|
||||||
|
} from "../helpers/ProjecthelperFn.ts";
|
||||||
interface CreateProjectInput {
|
interface CreateProjectInput {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
projectUuid: string;
|
projectUuid: string;
|
||||||
@@ -12,8 +16,13 @@ interface CreateProjectInput {
|
|||||||
sharedUsers?: string[];
|
sharedUsers?: string[];
|
||||||
organization: string;
|
organization: string;
|
||||||
}
|
}
|
||||||
interface GetInterface {
|
interface GetProjectsInterface {
|
||||||
userId: string;
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
}
|
||||||
|
interface DeleteProjectInterface {
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
}
|
}
|
||||||
export const createProject = async (data: CreateProjectInput) => {
|
export const createProject = async (data: CreateProjectInput) => {
|
||||||
@@ -26,22 +35,17 @@ export const createProject = async (data: CreateProjectInput) => {
|
|||||||
sharedUsers,
|
sharedUsers,
|
||||||
organization,
|
organization,
|
||||||
} = data;
|
} = data;
|
||||||
|
|
||||||
if (
|
|
||||||
!projectName ||
|
|
||||||
!userId ||
|
|
||||||
!thumbnail ||
|
|
||||||
// !sharedUsers ||
|
|
||||||
!organization
|
|
||||||
)
|
|
||||||
return { status: "All fields are required" };
|
|
||||||
const userExisting = await existingUser(userId, organization);
|
const userExisting = await existingUser(userId, organization);
|
||||||
if (!userExisting) {
|
if (!userExisting) {
|
||||||
return {
|
return {
|
||||||
status: "user_not_found",
|
status: "user_not_found",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const projectExisting = await existingProject(projectName, organization,userId);
|
const projectExisting = await existingProject(
|
||||||
|
projectName,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
|
||||||
if (projectExisting) {
|
if (projectExisting) {
|
||||||
return {
|
return {
|
||||||
@@ -60,26 +64,29 @@ export const createProject = async (data: CreateProjectInput) => {
|
|||||||
});
|
});
|
||||||
const versionData = await previousVersion(project._id, organization);
|
const versionData = await previousVersion(project._id, organization);
|
||||||
if (!versionData || versionData.length === 0) {
|
if (!versionData || versionData.length === 0) {
|
||||||
const newVersion= await versionModel(organization).create({
|
const newVersion = await versionModel(organization).create({
|
||||||
projectId: project._id,
|
projectId: project._id,
|
||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
version: 0.01,
|
version: 0.01,
|
||||||
});
|
});
|
||||||
await projectModel(organization).findByIdAndUpdate({_id:project._id,isArchive:false},{total_versions:`v-${newVersion.version.toFixed(2)}`})
|
await projectModel(organization).findByIdAndUpdate(
|
||||||
|
{ _id: project._id, isArchive: false },
|
||||||
|
{ total_versions: `v-${newVersion.version.toFixed(2)}` }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
status: "success",
|
status: "Success",
|
||||||
project: project,
|
project: project,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error: ', error);
|
console.log("error: ", error);
|
||||||
return {
|
return {
|
||||||
status: error,
|
status: error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GetAllProjects = async (data: GetInterface) => {
|
export const GetAllProjects = async (data: GetProjectsInterface) => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = data;
|
const { userId, organization } = data;
|
||||||
await existingUser(userId, organization);
|
await existingUser(userId, organization);
|
||||||
@@ -89,53 +96,30 @@ export const GetAllProjects = async (data: GetInterface) => {
|
|||||||
isArchive: false,
|
isArchive: false,
|
||||||
})
|
})
|
||||||
.select("_id projectName createdBy thumbnail");
|
.select("_id projectName createdBy thumbnail");
|
||||||
if (projectDatas) return {status:"success", Datas: projectDatas };
|
if (projectDatas) return { status: "Success", Datas: projectDatas };
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
return { status: error };
|
return { status: error };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const existingProject = async (
|
export const DeleteProject = async (data: DeleteProjectInterface) => {
|
||||||
projectName: string,
|
try {
|
||||||
organization: string,
|
const { projectId, organization, userId } = data;
|
||||||
userId:string
|
const ExistingUser = await existingUser(userId, organization);
|
||||||
) => {
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
const projectData = await projectModel(organization).findOne({
|
const existingProject = await projectModel(organization).findOne({
|
||||||
projectName: projectName,
|
_id: projectId,
|
||||||
createdBy:userId,
|
createdBy: userId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
return projectData;
|
if (!existingProject) return { status: "Project not found" };
|
||||||
};
|
const updateProject = await projectModel(organization).findOneAndUpdate(
|
||||||
|
{ _id: projectId, isArchive: false },
|
||||||
export const existingUser = async (userId: string, organization: string) => {
|
{ isArchive: true, DeletedAt: new Date() },
|
||||||
if (!Types.ObjectId.isValid(userId)) {
|
{ new: true }
|
||||||
console.log("Invalid ObjectId format");
|
);
|
||||||
return null;
|
if (updateProject) return { status: "Success" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
return { status: error };
|
||||||
}
|
}
|
||||||
const userData = await userModel(organization).findOne({
|
|
||||||
_id: userId,
|
|
||||||
});
|
|
||||||
return userData; // ✅ Make sure you return it
|
|
||||||
};
|
|
||||||
|
|
||||||
export const archiveProject = async (
|
|
||||||
projectId: string,
|
|
||||||
organization: string
|
|
||||||
) => {
|
|
||||||
return await projectModel(organization).findByIdAndUpdate(
|
|
||||||
projectId,
|
|
||||||
{ isArchive: true },
|
|
||||||
{ new: true }
|
|
||||||
);
|
|
||||||
};
|
|
||||||
export const previousVersion = async (
|
|
||||||
projectId: string,
|
|
||||||
organization: string
|
|
||||||
)=> {
|
|
||||||
console.log('projectId: ', projectId);
|
|
||||||
const result = await versionModel(organization).findOne({ projectId: projectId, isArchive: false})
|
|
||||||
console.log('result: ', result);
|
|
||||||
// .sort({ version: -1 });
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|||||||
68
src/shared/services/trash/trashService.ts
Normal file
68
src/shared/services/trash/trashService.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import projectModel from "../../model/project/project-model.ts";
|
||||||
|
interface IOrg {
|
||||||
|
organization: string;
|
||||||
|
}
|
||||||
|
interface IRestore {
|
||||||
|
projectId: string;
|
||||||
|
organization: string;
|
||||||
|
}
|
||||||
|
export const TrashDatas = async (data: IOrg) => {
|
||||||
|
try {
|
||||||
|
const { organization } = data;
|
||||||
|
|
||||||
|
const TrashLists = await projectModel(organization).find({
|
||||||
|
isArchive: true,
|
||||||
|
isDeleted: false,
|
||||||
|
});
|
||||||
|
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 } = data;
|
||||||
|
console.log("projectId: ", projectId);
|
||||||
|
const findProject = await projectModel(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
|
isArchive: true,
|
||||||
|
});
|
||||||
|
console.log("findProject: ", findProject);
|
||||||
|
if (!findProject) return { status: "Project not found" };
|
||||||
|
const restoreData = await projectModel(organization).findOneAndUpdate(
|
||||||
|
{ _id: projectId, isArchive: true },
|
||||||
|
{ isArchive: false, DeletedAt: null },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (!restoreData) return { status: "Project Restore unsuccessfull" };
|
||||||
|
return { status: "Project Restored successfully" };
|
||||||
|
} catch (error) {
|
||||||
|
return { status: error };
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -21,10 +21,10 @@ export const projectHandleEvent = async (
|
|||||||
case EVENTS.addProject: {
|
case EVENTS.addProject: {
|
||||||
result = await createProject(data);
|
result = await createProject(data);
|
||||||
console.log('result: ', result);
|
console.log('result: ', result);
|
||||||
const isSuccess = result.status === "success";
|
const isSuccess = result.status === "Success";
|
||||||
// ✅ Build response object
|
// ✅ Build response object
|
||||||
const response = {
|
const response = {
|
||||||
success: result.status === "success",
|
success: result.status === "Success",
|
||||||
message:
|
message:
|
||||||
result.status === "project_exists"
|
result.status === "project_exists"
|
||||||
? "Project already exists"
|
? "Project already exists"
|
||||||
|
|||||||
Reference in New Issue
Block a user