diff --git a/src/api-server/V1/v1Controllers/homeController/v1homeController.ts b/src/api-server/V1/v1Controllers/homeController/v1homeController.ts new file mode 100644 index 0000000..6461f60 --- /dev/null +++ b/src/api-server/V1/v1Controllers/homeController/v1homeController.ts @@ -0,0 +1,151 @@ +import { Request, Response } from "express"; +import { + RecentlyAdded, + searchProject, + searchTrashProject, +} from "../../../../shared/services/v1home/v1homeservice.ts"; +import { AuthenticatedRequest } from "../../../../shared/utils/token.ts"; + +export const recentDataController = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + try { + const { userId, organization, role } = req.user || {}; + if (!userId || !organization || !role) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await RecentlyAdded({ userId, organization, role }); + + switch (result.status) { + case "User not found": + res.status(404).json({ + message: "User not found", + }); + break; + case "Datas were empty": + res.status(200).json({ + RecentlyViewed: [], + }); + break; + case "Success": + res.status(200).json({ + RecentlyViewed: result.data, + }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + return; + } +}; +export const searchProjectController = async ( + req: Request, + res: Response +): Promise => { + try { + const { searchName, organization, userId } = req.query as { + organization: string; + searchName: string; + userId: string; + }; + if (!userId || !organization || !searchName) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await searchProject({ + searchName, + organization, + userId, + }); + switch (result?.status) { + case "Project not found": + res.status(200).json({ + message: "Project not found", + }); + break; + case "User not found": + res.status(404).json({ + message: "User not found", + }); + break; + case "Success": + res.status(200).json({ + projectData: result.data, + }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + return; + } +}; +export const searchTrashProjectController = async ( + req: Request, + res: Response +): Promise => { + try { + const { searchName, organization, userId } = req.query as { + organization: string; + searchName: string; + userId: string; + }; + if (!userId || !organization || !searchName) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await searchTrashProject({ + searchName, + organization, + userId, + }); + switch (result?.status) { + case "Project not found": + res.status(200).json({ + message: "Project not found", + }); + break; + case "User not found": + res.status(404).json({ + message: "User not found", + }); + break; + case "Success": + res.status(200).json({ + projectData: result.data, + }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + return; + } +}; diff --git a/src/api-server/V1/v1Controllers/projectController/v1projectController.ts b/src/api-server/V1/v1Controllers/projectController/v1projectController.ts new file mode 100644 index 0000000..659b186 --- /dev/null +++ b/src/api-server/V1/v1Controllers/projectController/v1projectController.ts @@ -0,0 +1,270 @@ +import { Request, Response } from "express"; +import { + createProject, + DeleteProject, + GetAllProjects, + updateProject, + viewProject, +} from "../../../../shared/services/v1Project/v1projectservice.ts"; +import { AuthenticatedRequest } from "../../../../shared/utils/token.ts"; + +export const createProjectController = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + try { + const { userId, organization } = req.user || {}; + console.log("req.user: ", req.user); + const { projectUuid, thumbnail } = req.body; + if (!req.user || !req.user.userId || !req.user.organization) { + res.status(401).json({ message: "Unauthorized" }); + return; + } + if (!projectUuid || !thumbnail) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await createProject({ ...req.body, userId, organization }); + + switch (result.status) { + case "project_exists": + res.status(403).json({ + message: "Project already exists", + }); + break; + + case "user_not_found": + res.status(404).json({ + message: "User not found", + }); + break; + + case "Success": + res.status(201).json({ + message: "Project created Successfully", + projectId: result.project._id, + }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + return; + } +}; +export const GetProjects = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + try { + const { userId, organization, role } = req.user || {}; + // const { userId, organization } = req.params; + if (!userId || !organization || !role) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await GetAllProjects({ userId, organization, role }); + switch (result?.status) { + case "User not found": + res.status(404).json({ + message: "User not found", + }); + break; + + case "Success": + res.status(201).json({ + Projects: result?.Datas, + }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + return; + } +}; +export const RemoveProject = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + try { + const { projectId } = req.params; + // const { organization, userId } = req.body; + const { organization, userId, role } = req.user || {}; + if ( + !req.user || + !req.user.userId || + !req.user.organization || + !req.user.role + ) { + res.status(401).json({ message: "Unauthorized" }); + return; + } + if (!projectId || !organization || !userId || !role) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await DeleteProject({ + projectId, + organization, + userId, + role, + }); + 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", + }); + return; + } +}; +export const updateProjectController = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + try { + const { userId, organization, role } = req.user || {}; + const { projectId } = req.params; + const { projectName, thumbnail } = req.body; + if (!userId || !organization || !projectId || !role) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await updateProject({ + projectId, + organization, + userId, + projectName, + thumbnail, + role, + }); + 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(200).json({ + message: "Project updated Successfully", + projectData: result.data, + }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + return; + } +}; +export const ViewData = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + try { + const { organization, userId, role } = req.user || {}; + if ( + !req.user || + !req.user.userId || + !req.user.organization || + !req.user.role + ) { + res.status(401).json({ message: "Unauthorized" }); + return; + } + const { projectId } = req.params as { + projectId: string; + }; + if (!userId || !organization || !projectId || !role) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await viewProject({ + projectId, + organization, + userId, + role, + }); + 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(200).json({ + projectData: result.data, + }); + break; + default: + res.status(500).json({ + message: "Internal server error", + }); + break; + } + } catch (error) { + res.status(500).json({ + message: "Unknown error", + }); + return; + } +}; diff --git a/src/api-server/V1/v1Controllers/trashController/v1trashController.ts b/src/api-server/V1/v1Controllers/trashController/v1trashController.ts new file mode 100644 index 0000000..6350ff1 --- /dev/null +++ b/src/api-server/V1/v1Controllers/trashController/v1trashController.ts @@ -0,0 +1,99 @@ +import { Request, Response } from "express"; +import { + TrashDatas, + RestoreTrashData, +} from "../../../../shared/services/v1trash/v1trashservice.ts"; +import { AuthenticatedRequest } from "../../../../shared/utils/token.ts"; + +export const GetTrashList = async ( + req: AuthenticatedRequest, + res: Response +): Promise => { + try { + const { organization, role, userId } = req.user || {}; + if (!organization || !role || !userId) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await TrashDatas({ organization, role, userId }); + + switch (result.status) { + case "Trash is Empty": + res.status(200).json({ + message: "Trash is Empty", + TrashDatas: [], + }); + break; + + case "Success": + res.status(200).json({ + 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: AuthenticatedRequest, + res: Response +): Promise => { + try { + const { organization, role, userId } = req.user || {}; + const { projectId } = req.query as { + projectId: string; + }; + if (!organization || !projectId || !role || !userId) { + res.status(400).json({ + message: "All fields are required", + }); + return; + } + const result = await RestoreTrashData({ + organization, + projectId, + role, + userId, + }); + + 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", + }); + } +}; diff --git a/src/api-server/V1/v1Routes/authRoutes.ts b/src/api-server/V1/v1Routes/authRoutes.ts index 34e5528..b95d384 100644 --- a/src/api-server/V1/v1Routes/authRoutes.ts +++ b/src/api-server/V1/v1Routes/authRoutes.ts @@ -7,20 +7,6 @@ import { SignupController, } from "../v1Controllers/authController/authControllers.ts"; import { versioncontroller } from "../v1Controllers/versionController/versioncontroller.ts"; -import { - createProjectController, - GetProjects, - RemoveProject, - updateProjectController, - ViewData, -} from "../../controller/project/projectController.ts"; -import { tokenValidator } from "../../../shared/utils/token.ts"; -import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts"; -import { recentDataController } from "../../controller/home/homeControllers.ts"; -import { - GetTrashList, - RestoreTrash, -} from "../../controller/trash/trashcontrollers.ts"; const Authrouter = express.Router(); Authrouter.post("/Auth/signup", SignupController); @@ -30,54 +16,4 @@ Authrouter.post("/Auth/forgetPassword", ForgetPasswordController); Authrouter.post("/Auth/reset-password/:resetToken", ResetPasswordController); Authrouter.post("/Auth/versionData", versioncontroller); -// project -Authrouter.post("/Auth/upsertProject", tokenValidator, createProjectController); -Authrouter.get( - "/Auth/Projects", - tokenValidator, - authorizedRoles("Admin", "User"), - GetProjects -); -Authrouter.patch( - "/Auth/Project/archive/:projectId", - tokenValidator, - authorizedRoles("Admin", "User"), - RemoveProject -); - -Authrouter.patch( - "/Auth/Project/modify", - tokenValidator, - authorizedRoles("Admin", "User"), - updateProjectController -); -Authrouter.get( - "/Auth/Project/view", - tokenValidator, - authorizedRoles("Admin", "User"), - ViewData -); - -//home-Page -Authrouter.get( - "/Auth/RecentlyViewed", - tokenValidator, - authorizedRoles("Admin", "User"), - recentDataController -); - -//trash -Authrouter.get( - "/Auth/Trash/Lists", - tokenValidator, - authorizedRoles("Admin", "User"), - GetTrashList -); - -Authrouter.patch( - "/Auth/restore", - tokenValidator, - authorizedRoles("Admin", "User"), - RestoreTrash -); export default Authrouter; diff --git a/src/api-server/V1/v1Routes/v1-homeRoutes.ts b/src/api-server/V1/v1Routes/v1-homeRoutes.ts new file mode 100644 index 0000000..6f32f0f --- /dev/null +++ b/src/api-server/V1/v1Routes/v1-homeRoutes.ts @@ -0,0 +1,16 @@ +import express from "express"; +import { tokenValidator } from "../../../shared/utils/token.ts"; +import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts"; +import { recentDataController } from "../../V1/v1Controllers/homeController/v1homeController.ts"; + +const v1homeRoutes = express.Router(); + +//home-Page +v1homeRoutes.get( + "/RecentlyViewed", + tokenValidator, + authorizedRoles("Admin", "User"), + recentDataController +); + +export default v1homeRoutes; diff --git a/src/api-server/V1/v1Routes/v1-projectRoutes.ts b/src/api-server/V1/v1Routes/v1-projectRoutes.ts new file mode 100644 index 0000000..2a7cd50 --- /dev/null +++ b/src/api-server/V1/v1Routes/v1-projectRoutes.ts @@ -0,0 +1,42 @@ +import express from "express"; +import { + createProjectController, + GetProjects, + RemoveProject, + updateProjectController, + ViewData, +} from "../../V1/v1Controllers/projectController/v1projectController.ts"; +import { tokenValidator } from "../../../shared/utils/token.ts"; +import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts"; + +const v1projectRouter = express.Router(); + +// project +v1projectRouter.post("/upsertProject", tokenValidator, createProjectController); +v1projectRouter.get( + "/Projects", + tokenValidator, + authorizedRoles("Admin", "User"), + GetProjects +); +v1projectRouter.patch( + "/Project/archive/:projectId", + tokenValidator, + authorizedRoles("Admin", "User"), + RemoveProject +); + +v1projectRouter.patch( + "/Project/:projectId", + tokenValidator, + authorizedRoles("Admin", "User"), + updateProjectController +); +v1projectRouter.get( + "/Project/:projectId", + tokenValidator, + authorizedRoles("Admin", "User"), + ViewData +); + +export default v1projectRouter; diff --git a/src/api-server/V1/v1Routes/v1-trashRoutes.ts b/src/api-server/V1/v1Routes/v1-trashRoutes.ts new file mode 100644 index 0000000..d2603d1 --- /dev/null +++ b/src/api-server/V1/v1Routes/v1-trashRoutes.ts @@ -0,0 +1,25 @@ +import express from "express"; +import { tokenValidator } from "../../../shared/utils/token.ts"; +import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts"; +import { + GetTrashList, + RestoreTrash, +} from "../../V1/v1Controllers/trashController/v1trashController.ts"; + +const v1TrashRoutes = express.Router(); + +//trash +v1TrashRoutes.get( + "/TrashItems ", + tokenValidator, + authorizedRoles("Admin", "User"), + GetTrashList +); + +v1TrashRoutes.patch( + "/Trash/restore", + tokenValidator, + authorizedRoles("Admin", "User"), + RestoreTrash +); +export default v1TrashRoutes; diff --git a/src/api-server/app.ts b/src/api-server/app.ts index a3a8ae3..99ae949 100644 --- a/src/api-server/app.ts +++ b/src/api-server/app.ts @@ -22,6 +22,9 @@ import trashRouter from "./Routes/trashRoutes.ts"; import homePageRouter from "./Routes/homepageRoutes.ts"; import redis from "../shared/redis/redis.ts"; import Authrouter from "./V1/v1Routes/authRoutes.ts"; +import v1TrashRoutes from "./V1/v1Routes/v1-trashRoutes.ts"; +import v1homeRoutes from "./V1/v1Routes/v1-homeRoutes.ts"; +import v1projectRouter from "./V1/v1Routes/v1-projectRoutes.ts"; // import productFlowRoutes from "./Routes/productFlowRouts.ts"; redis; const app = express(); @@ -90,7 +93,10 @@ app.use("/api/v1", projectRouter); app.use("/api/v1", trashRouter); app.use("/api/v1", homePageRouter); -//New versions -app.use("/API/V1", Authrouter); +//New versions--based on the token and role based +app.use("/api", Authrouter); +app.use("/api/v2", v1projectRouter); +app.use("/api/v2", v1TrashRoutes); +app.use("/api/v2", v1homeRoutes); export default app; diff --git a/src/api-server/controller/home/homeControllers.ts b/src/api-server/controller/home/homeControllers.ts index 9907c9e..fd50cee 100644 --- a/src/api-server/controller/home/homeControllers.ts +++ b/src/api-server/controller/home/homeControllers.ts @@ -1,20 +1,23 @@ import { Request, Response } from "express"; -import { RecentlyAdded, searchProject, searchTrashProject } from "../../../shared/services/home/homeService.ts"; -import { AuthenticatedRequest } from "../../../shared/utils/token.ts"; +import { + RecentlyAdded, + searchProject, + searchTrashProject, +} from "../../../shared/services/home/homeService.ts"; export const recentDataController = async ( - req: AuthenticatedRequest, + req: Request, res: Response ): Promise => { try { - const { userId, organization,role } = req.user||{}; - if (!userId || !organization||!role) { + const { userId, organization } = req.params; + if (!userId || !organization) { res.status(400).json({ message: "All fields are required", }); return; } - const result = await RecentlyAdded({ userId, organization,role }); + const result = await RecentlyAdded({ userId, organization }); switch (result.status) { case "User not found": @@ -45,7 +48,10 @@ export const recentDataController = async ( return; } }; -export const searchProjectController = async (req: Request, res: Response): Promise => { +export const searchProjectController = async ( + req: Request, + res: Response +): Promise => { try { const { searchName, organization, userId } = req.query as { organization: string; @@ -92,7 +98,10 @@ export const searchProjectController = async (req: Request, res: Response): Prom return; } }; -export const searchTrashProjectController = async (req: Request, res: Response): Promise => { +export const searchTrashProjectController = async ( + req: Request, + res: Response +): Promise => { try { const { searchName, organization, userId } = req.query as { organization: string; @@ -138,4 +147,4 @@ export const searchTrashProjectController = async (req: Request, res: Response): }); return; } -}; \ No newline at end of file +}; diff --git a/src/api-server/controller/project/projectController.ts b/src/api-server/controller/project/projectController.ts index c86a4ee..a061d11 100644 --- a/src/api-server/controller/project/projectController.ts +++ b/src/api-server/controller/project/projectController.ts @@ -6,27 +6,20 @@ import { updateProject, viewProject, } from "../../../shared/services/project/project-Services.ts"; -import { AuthenticatedRequest } from "../../../shared/utils/token.ts"; export const createProjectController = async ( - req: AuthenticatedRequest, + req: Request, res: Response ): Promise => { try { - const { userId, organization } = req.user || {}; - console.log("req.user: ", req.user); - const { projectUuid, thumbnail } = req.body; - if (!req.user || !req.user.userId || !req.user.organization) { - res.status(401).json({ message: "Unauthorized" }); - return; - } - if (!projectUuid || !thumbnail) { + const { projectUuid, userId, thumbnail, organization } = req.body; + if (!projectUuid || !userId || !thumbnail || !organization) { res.status(400).json({ message: "All fields are required", }); return; } - const result = await createProject({ ...req.body, userId, organization }); + const result = await createProject(req.body); switch (result.status) { case "project_exists": @@ -61,19 +54,18 @@ export const createProjectController = async ( } }; export const GetProjects = async ( - req: AuthenticatedRequest, + req: Request, res: Response ): Promise => { try { - const { userId, organization, role } = req.user || {}; - // const { userId, organization } = req.params; - if (!userId || !organization || !role) { + const { userId, organization } = req.params; + if (!userId || !organization) { res.status(400).json({ message: "All fields are required", }); return; } - const result = await GetAllProjects({ userId, organization, role }); + const result = await GetAllProjects({ userId, organization }); switch (result?.status) { case "User not found": res.status(404).json({ @@ -100,34 +92,19 @@ export const GetProjects = async ( } }; export const RemoveProject = async ( - req: AuthenticatedRequest, + req: Request, res: Response ): Promise => { try { const { projectId } = req.params; - // const { organization, userId } = req.body; - const { organization, userId, role } = req.user || {}; - if ( - !req.user || - !req.user.userId || - !req.user.organization || - !req.user.role - ) { - res.status(401).json({ message: "Unauthorized" }); - return; - } - if (!projectId || !organization || !userId || !role) { + const { organization, userId } = req.body; + if (!projectId || !organization || !userId) { res.status(400).json({ message: "All fields are required", }); return; } - const result = await DeleteProject({ - projectId, - organization, - userId, - role, - }); + const result = await DeleteProject({ projectId, organization, userId }); switch (result?.status) { case "Project not found": res.status(404).json({ @@ -158,13 +135,13 @@ export const RemoveProject = async ( } }; export const updateProjectController = async ( - req: AuthenticatedRequest, + req: Request, res: Response ): Promise => { try { - const { userId, organization, role } = req.user || {}; - const { projectId, projectName, thumbnail } = req.body; - if (!userId || !organization || !projectId || !role) { + const { projectId, organization, projectName, thumbnail, userId } = + req.body; + if (!userId || !organization || !projectId) { res.status(400).json({ message: "All fields are required", }); @@ -176,7 +153,6 @@ export const updateProjectController = async ( userId, projectName, thumbnail, - role, }); switch (result?.status) { case "Project not found": @@ -208,25 +184,14 @@ export const updateProjectController = async ( return; } }; -export const ViewData = async ( - req: AuthenticatedRequest, - res: Response -): Promise => { +export const ViewData = async (req: Request, res: Response): Promise => { try { - const { organization, userId, role } = req.user || {}; - if ( - !req.user || - !req.user.userId || - !req.user.organization || - !req.user.role - ) { - res.status(401).json({ message: "Unauthorized" }); - return; - } - const { projectId } = req.query as { + const { projectId, organization, userId } = req.query as { + organization: string; projectId: string; + userId: string; }; - if (!userId || !organization || !projectId || !role) { + if (!userId || !organization || !projectId) { res.status(400).json({ message: "All fields are required", }); @@ -236,7 +201,6 @@ export const ViewData = async ( projectId, organization, userId, - role, }); switch (result?.status) { case "Project not found": diff --git a/src/api-server/controller/trash/trashcontrollers.ts b/src/api-server/controller/trash/trashcontrollers.ts index bfc54ee..7b02590 100644 --- a/src/api-server/controller/trash/trashcontrollers.ts +++ b/src/api-server/controller/trash/trashcontrollers.ts @@ -3,21 +3,20 @@ import { TrashDatas, RestoreTrashData, } from "../../../shared/services/trash/trashService.ts"; -import { AuthenticatedRequest } from "../../../shared/utils/token.ts"; export const GetTrashList = async ( - req: AuthenticatedRequest, + req: Request, res: Response ): Promise => { try { - const { organization, role, userId } = req.user || {}; - if (!organization || !role || !userId) { + const { organization } = req.query as { organization: string }; + if (!organization) { res.status(400).json({ message: "All fields are required", }); return; } - const result = await TrashDatas({ organization, role, userId }); + const result = await TrashDatas({ organization }); switch (result.status) { case "Trash is Empty": @@ -29,6 +28,7 @@ export const GetTrashList = async ( case "Success": res.status(200).json({ + // message: "Project created Successfully", TrashDatas: result.ListDatas, }); break; @@ -47,26 +47,22 @@ export const GetTrashList = async ( }; export const RestoreTrash = async ( - req: AuthenticatedRequest, + req: Request, res: Response ): Promise => { try { - const { organization, role, userId } = req.user || {}; - const { projectId } = req.query as { + const { organization, projectId } = req.query as { + organization: string; projectId: string; }; - if (!organization || !projectId || !role || !userId) { + console.log("organization: ", organization); + if (!organization || !projectId) { res.status(400).json({ message: "All fields are required", }); return; } - const result = await RestoreTrashData({ - organization, - projectId, - role, - userId, - }); + const result = await RestoreTrashData({ organization, projectId }); switch (result.status) { case "Project not found": diff --git a/src/shared/services/helpers/ProjecthelperFn.ts b/src/shared/services/helpers/ProjecthelperFn.ts index 3ce8cc3..62ff0d2 100644 --- a/src/shared/services/helpers/ProjecthelperFn.ts +++ b/src/shared/services/helpers/ProjecthelperFn.ts @@ -2,7 +2,6 @@ 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"; -import AuthModel from "../../V1Models/Auth/userAuthModel.ts"; export const existingProject = async ( projectUuid: string, organization: string, @@ -21,7 +20,7 @@ export const existingUser = async (userId: string, organization: string) => { console.log("Invalid ObjectId format"); return null; } - const userData = await AuthModel(organization).findOne({ + const userData = await userModel(organization).findOne({ _id: userId, }); return userData; diff --git a/src/shared/services/helpers/v1projecthelperFns.ts b/src/shared/services/helpers/v1projecthelperFns.ts new file mode 100644 index 0000000..0d4e0ac --- /dev/null +++ b/src/shared/services/helpers/v1projecthelperFns.ts @@ -0,0 +1,90 @@ +import projectModel from "../../V1Models/Project/project-model.ts"; +import { Types } from "mongoose"; +import versionModel from "../../V1Models/Version/versionModel.ts"; +import AuthModel from "../../V1Models/Auth/userAuthModel.ts"; +export const existingProject = async ( + projectUuid: string, + organization: string, + userId: string +) => { + const projectData = await projectModel(organization).findOne({ + projectUuid: projectUuid, + 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 AuthModel(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; +}; +export const generateUntitledProjectName = async ( + organization: string, + userId: string +): Promise => { + const projects = await projectModel(organization) + .find({ + createdBy: userId, + isArchive: false, + projectName: { $regex: /^Untitled(?: \s?\d+)?$/, $options: "i" }, + }) + .select("projectName"); + + const usedNumbers = new Set(); + + for (const proj of projects) { + const match = proj.projectName.match(/^Untitled(?:\s?(\d+))?$/); + if (match) { + const num = match[1] ? parseInt(match[1], 10) : 0; + usedNumbers.add(num); + } + } + + let newNumber = 0; + while (usedNumbers.has(newNumber)) { + newNumber++; + } + + return newNumber === 0 ? "Untitled" : `Untitled ${newNumber}`; +}; +export const existingProjectById = async ( + projectId: string, + organization: string, + userId: string +) => { + const projectData = await projectModel(organization).findOne({ + _id: projectId, + createdBy: userId, + isArchive: false, + }); + return projectData; +}; diff --git a/src/shared/services/home/homeService.ts b/src/shared/services/home/homeService.ts index 758d174..4559d1c 100644 --- a/src/shared/services/home/homeService.ts +++ b/src/shared/services/home/homeService.ts @@ -1,12 +1,10 @@ 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; @@ -21,31 +19,26 @@ interface searchProjectInterface { userId: string; organization: string; } -interface RoleFilter { - isArchive: boolean; - createdBy?: string; -} export const RecentlyAdded = async (data: IRecentData) => { try { - const { userId, organization, role } = data; + const { userId, organization } = data; const userExisting = await existingUser(userId, organization); if (!userExisting) return { status: "User not found" }; - const userRecentData = await UsersDataModel(organization) - .findOne({ userId: userId, isArchive: false }) + const userRecentData = await userModel(organization) + .findOne({ _id: userId }) .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(filter) + .findOne({ + _id: project._id, + isArchive: false, + }) .select("_id projectName createdBy thumbnail createdAt isViewed"); return projectExisting; }) diff --git a/src/shared/services/project/project-Services.ts b/src/shared/services/project/project-Services.ts index 17300cb..56c656d 100644 --- a/src/shared/services/project/project-Services.ts +++ b/src/shared/services/project/project-Services.ts @@ -1,8 +1,7 @@ -import { ObjectId } from "mongoose"; 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"; -import { AuthenticatedRequest } from "../../utils/token.ts"; import { existingProject, existingUser, @@ -10,7 +9,6 @@ import { previousVersion, generateUntitledProjectName, } from "../helpers/ProjecthelperFn.ts"; -import UsersDataModel from "../../V1Models/Auth/user.ts"; interface CreateProjectInput { projectName: string; projectUuid: string; @@ -26,26 +24,20 @@ interface updateProjectInput { thumbnail?: string; sharedUsers?: string[]; organization: string; - role: string; } interface GetProjectsInterface { userId: string; organization: string; - role: string; } interface ProjectInterface { projectId: string; userId: string; organization: string; - role: string; -} -interface RoleFilter { - isArchive: boolean; - createdBy?: string; } + export const createProject = async (data: CreateProjectInput) => { try { - const { thumbnail, sharedUsers, projectUuid, userId, organization } = data; + const { userId, thumbnail, sharedUsers, organization, projectUuid } = data; const userExisting = await existingUser(userId, organization); if (!userExisting) { return { @@ -102,16 +94,17 @@ export const createProject = async (data: CreateProjectInput) => { export const GetAllProjects = async (data: GetProjectsInterface) => { try { - const { userId, organization, role } = data; + const { userId, organization } = data; await existingUser(userId, organization); if (!existingUser) return { status: "User not found" }; - let filter = { isArchive: false } as RoleFilter; - if (role === "User") { - filter.createdBy = userId; - } const projectDatas = await projectModel(organization) - .find(filter) - .select("_id projectName createdBy thumbnail createdAt projectUuid"); + .find({ + createdBy: userId, + isArchive: false, + }) + .select( + "_id projectName createdBy thumbnail createdAt projectUuid createdAt" + ); if (projectDatas) return { status: "Success", Datas: projectDatas }; } catch (error: unknown) { return { status: error }; @@ -120,17 +113,17 @@ export const GetAllProjects = async (data: GetProjectsInterface) => { export const DeleteProject = async (data: ProjectInterface) => { try { - const { projectId, organization, userId, role } = data; + const { projectId, organization, userId } = data; const ExistingUser = await existingUser(userId, organization); if (!ExistingUser) return { status: "User not found" }; - let filter = { _id: projectId, isArchive: false } as RoleFilter; - if (role === "User") { - filter.createdBy = userId; - } - const existingProject = await projectModel(organization).findOne(filter); + const existingProject = await projectModel(organization).findOne({ + _id: projectId, + createdBy: userId, + isArchive: false, + }); if (!existingProject) return { status: "Project not found" }; const updateProject = await projectModel(organization).findOneAndUpdate( - filter, + { _id: projectId, isArchive: false }, { isArchive: true, DeletedAt: new Date() }, { new: true } ); @@ -141,25 +134,24 @@ export const DeleteProject = async (data: ProjectInterface) => { }; export const updateProject = async (data: updateProjectInput) => { try { - const { projectId, organization, userId, projectName, thumbnail, role } = - data; + const { projectId, organization, userId, projectName, thumbnail } = data; const ExistingUser = await existingUser(userId, organization); if (!ExistingUser) return { status: "User not found" }; - let filter = { _id: projectId, isArchive: false } as RoleFilter; - if (role === "User") { - filter.createdBy = userId; - } - const existingProject = await projectModel(organization).findOne(filter); + const existingProject = await projectModel(organization).findOne({ + _id: projectId, + createdBy: userId, + isArchive: false, + }); if (!existingProject) return { status: "Project not found" }; if (projectName !== undefined) projectName; if (thumbnail !== undefined) thumbnail; const updateProject = await projectModel(organization) .findOneAndUpdate( - filter, + { _id: projectId, isArchive: false }, { projectName: projectName, thumbnail: thumbnail }, { new: true } ) - .select("_id projectName createdBy thumbnail createdAt"); + .select("_id projectName createdBy thumbnail createdAt projectUuid"); if (updateProject) return { status: "Success", data: updateProject }; } catch (error: unknown) { return { status: error }; @@ -168,23 +160,18 @@ export const updateProject = async (data: updateProjectInput) => { const maxLength: number = 6; export const viewProject = async (data: ProjectInterface) => { try { - const { projectId, organization, userId, role } = data; + const { projectId, organization, userId } = data; const userExisting = await existingUser(userId, organization); if (!userExisting) return { status: "User not found" }; - const RecentUserDoc = await UsersDataModel(organization).findOne({ - userId: userId, + const existingProject = await projectModel(organization).findOne({ + _id: projectId, + createdBy: userId, isArchive: false, }); - let filter = { _id: projectId, isArchive: false } as RoleFilter; - if (role === "User") { - filter.createdBy = userId; - } - const existingProject = await projectModel(organization).findOne(filter); if (!existingProject) return { status: "Project not found" }; - const newArr = RecentUserDoc?.recentlyViewed || []; - if (RecentUserDoc?.recentlyViewed.length === 0) { + const newArr = userExisting?.recentlyViewed || []; + if (userExisting?.recentlyViewed.length === 0) { newArr.push(projectId); - await RecentUserDoc.save(); } else { const index = newArr.indexOf(projectId); if (index !== -1) { @@ -196,13 +183,21 @@ export const viewProject = async (data: ProjectInterface) => { newArr.pop(); } } - await UsersDataModel(organization).updateOne( + await userModel(organization).updateOne( { _id: userId }, { recentlyViewed: newArr }, { new: true } ); const projectData = await projectModel(organization) - .findOneAndUpdate(filter, { isViewed: Date.now() }, { new: true }) + .findOneAndUpdate( + { + _id: projectId, + createdBy: userId, + isArchive: false, + }, + { isViewed: Date.now() }, + { new: true } + ) .select("_id projectName createdBy thumbnail createdAt"); return { status: "Success", data: projectData }; } catch (error: unknown) { diff --git a/src/shared/services/trash/trashService.ts b/src/shared/services/trash/trashService.ts index ae833ff..2976f95 100644 --- a/src/shared/services/trash/trashService.ts +++ b/src/shared/services/trash/trashService.ts @@ -1,27 +1,19 @@ import projectModel from "../../model/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); + 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) { @@ -55,15 +47,14 @@ export const TrashDatas = async (data: IOrg) => { }; 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); + const { projectId, organization } = data; + const findProject = await projectModel(organization).findOne({ + _id: projectId, + isArchive: true, + }); if (!findProject) return { status: "Project not found" }; const restoreData = await projectModel(organization).findOneAndUpdate( - filter, + { _id: projectId, isArchive: true }, { isArchive: false, DeletedAt: null }, { new: true } ); diff --git a/src/shared/services/v1Project/v1projectservice.ts b/src/shared/services/v1Project/v1projectservice.ts new file mode 100644 index 0000000..c09a2b4 --- /dev/null +++ b/src/shared/services/v1Project/v1projectservice.ts @@ -0,0 +1,208 @@ +import projectModel from "../../V1Models/Project/project-model.ts"; +import versionModel from "../../V1Models/Version/versionModel.ts"; +import { + existingProject, + existingUser, + archiveProject, + previousVersion, + generateUntitledProjectName, +} from "../helpers/v1projecthelperFns.ts"; +import UsersDataModel from "../../V1Models/Auth/user.ts"; +interface CreateProjectInput { + projectName: string; + projectUuid: string; + userId: string; // user ID + thumbnail?: string; + sharedUsers?: string[]; + organization: string; +} +interface updateProjectInput { + projectName: string; + projectId: string; + userId: string; // user ID + thumbnail?: string; + sharedUsers?: string[]; + organization: string; + role: string; +} +interface GetProjectsInterface { + userId: string; + organization: string; + role: string; +} +interface ProjectInterface { + projectId: string; + userId: string; + organization: string; + role: string; +} +interface RoleFilter { + isArchive: boolean; + createdBy?: string; +} +export const createProject = async (data: CreateProjectInput) => { + try { + const { thumbnail, sharedUsers, projectUuid, userId, organization } = data; + const userExisting = await existingUser(userId, organization); + if (!userExisting) { + return { + status: "user_not_found", + }; + } + const projectExisting = await existingProject( + projectUuid, + organization, + userId + ); + + if (projectExisting) { + return { + status: "project_exists", + project: projectExisting, + }; + } + const newProjectName = await generateUntitledProjectName( + organization, + userId + ); + const project = await projectModel(organization).create({ + projectName: newProjectName, + projectUuid: projectUuid, + createdBy: userId, + thumbnail: thumbnail, + sharedUsers: sharedUsers || [], + isArchive: false, + }); + const versionData = await previousVersion(project._id, organization); + if (!versionData || versionData.length === 0) { + const newVersion = await versionModel(organization).create({ + projectId: project._id, + createdBy: userId, + version: 0.0, + }); + await projectModel(organization).findByIdAndUpdate( + { _id: project._id, isArchive: false }, + { total_versions: `v-${newVersion.version.toFixed(2)}` } + ); + } + return { + status: "Success", + project: project, + }; + } catch (error) { + console.log("error: ", error); + return { + status: error, + }; + } +}; + +export const GetAllProjects = async (data: GetProjectsInterface) => { + try { + const { userId, organization, role } = data; + await existingUser(userId, organization); + if (!existingUser) return { status: "User not found" }; + let filter = { isArchive: false } as RoleFilter; + if (role === "User") { + filter.createdBy = userId; + } + const projectDatas = await projectModel(organization) + .find(filter) + .select("_id projectName createdBy thumbnail createdAt projectUuid"); + if (projectDatas) return { status: "Success", Datas: projectDatas }; + } catch (error: unknown) { + return { status: error }; + } +}; + +export const DeleteProject = async (data: ProjectInterface) => { + try { + const { projectId, organization, userId, role } = data; + const ExistingUser = await existingUser(userId, organization); + if (!ExistingUser) return { status: "User not found" }; + let filter = { _id: projectId, isArchive: false } as RoleFilter; + if (role === "User") { + filter.createdBy = userId; + } + const existingProject = await projectModel(organization).findOne(filter); + if (!existingProject) return { status: "Project not found" }; + const updateProject = await projectModel(organization).findOneAndUpdate( + filter, + { isArchive: true, DeletedAt: new Date() }, + { new: true } + ); + if (updateProject) return { status: "Success", project: updateProject }; + } catch (error: unknown) { + return { status: error }; + } +}; +export const updateProject = async (data: updateProjectInput) => { + try { + const { projectId, organization, userId, projectName, thumbnail, role } = + data; + const ExistingUser = await existingUser(userId, organization); + if (!ExistingUser) return { status: "User not found" }; + let filter = { _id: projectId, isArchive: false } as RoleFilter; + if (role === "User") { + filter.createdBy = userId; + } + const existingProject = await projectModel(organization).findOne(filter); + if (!existingProject) return { status: "Project not found" }; + if (projectName !== undefined) projectName; + if (thumbnail !== undefined) thumbnail; + const updateProject = await projectModel(organization) + .findOneAndUpdate( + filter, + { projectName: projectName, thumbnail: thumbnail }, + { new: true } + ) + .select("_id projectName createdBy thumbnail createdAt"); + if (updateProject) return { status: "Success", data: updateProject }; + } catch (error: unknown) { + return { status: error }; + } +}; +const maxLength: number = 6; +export const viewProject = async (data: ProjectInterface) => { + try { + const { projectId, organization, userId, role } = data; + const userExisting = await existingUser(userId, organization); + if (!userExisting) return { status: "User not found" }; + const RecentUserDoc = await UsersDataModel(organization).findOne({ + userId: userId, + isArchive: false, + }); + let filter = { _id: projectId, isArchive: false } as RoleFilter; + if (role === "User") { + filter.createdBy = userId; + } + const existingProject = await projectModel(organization).findOne(filter); + if (!existingProject) return { status: "Project not found" }; + const newArr = RecentUserDoc?.recentlyViewed || []; + if (RecentUserDoc?.recentlyViewed.length === 0) { + newArr.push(projectId); + await RecentUserDoc.save(); + } else { + const index = newArr.indexOf(projectId); + if (index !== -1) { + newArr.splice(index, 1); + } + newArr.unshift(projectId); + + if (newArr.length > maxLength) { + newArr.pop(); + } + } + await UsersDataModel(organization).updateOne( + { _id: userId }, + { recentlyViewed: newArr }, + { new: true } + ); + const projectData = await projectModel(organization) + .findOneAndUpdate(filter, { isViewed: Date.now() }, { new: true }) + .select("_id projectName createdBy thumbnail createdAt"); + return { status: "Success", data: projectData }; + } catch (error: unknown) { + return { status: error }; + } +}; diff --git a/src/shared/services/v1home/v1homeservice.ts b/src/shared/services/v1home/v1homeservice.ts new file mode 100644 index 0000000..9ff155e --- /dev/null +++ b/src/shared/services/v1home/v1homeservice.ts @@ -0,0 +1,92 @@ +import projectModel from "../../V1Models/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; + projectName: string; + createdBy: string; + thumbnail?: string; + createdAt: Date; + isViewed?: number; +} +interface searchProjectInterface { + searchName: string; + userId: string; + organization: string; +} +interface RoleFilter { + isArchive: boolean; + createdBy?: string; +} +export const RecentlyAdded = async (data: IRecentData) => { + try { + const { userId, organization, role } = data; + const userExisting = await existingUser(userId, organization); + if (!userExisting) return { status: "User not found" }; + 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(filter) + .select("_id projectName createdBy thumbnail createdAt isViewed"); + return projectExisting; + }) + ); + + const filteredProjects = RecentDatas.filter(Boolean); + return { status: "Success", data: filteredProjects }; + } catch (error) { + return { status: error }; + } +}; +export const searchProject = 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" }, // 'i' makes it case-insensitive + 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" }; + return { status: "Success", data: findprojectName }; + } catch (error: unknown) { + return { status: error }; + } +}; diff --git a/src/shared/services/v1trash/v1trashservice.ts b/src/shared/services/v1trash/v1trashservice.ts new file mode 100644 index 0000000..4e68fe7 --- /dev/null +++ b/src/shared/services/v1trash/v1trashservice.ts @@ -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 }; + } +}; diff --git a/src/shared/services/version/versionService.ts b/src/shared/services/version/versionService.ts index fbd0bb2..c8bef9c 100644 --- a/src/shared/services/version/versionService.ts +++ b/src/shared/services/version/versionService.ts @@ -59,10 +59,10 @@ class VersionService { // Get all assets from previous version const previousVersion = parseFloat((newVersion.version - 0.1).toFixed(1)); const previousVersionDoc = await versionModel(db).findOne({ - projectId, - version: previousVersion, + projectId, + version: previousVersion, }); - console.log('previousVersionDoc: ', previousVersionDoc); + console.log("previousVersionDoc: ", previousVersionDoc); let previousAssets = []; if (previousVersionDoc) { @@ -75,8 +75,8 @@ class VersionService { // Copy assets to new version const newAssets = await Promise.all( - previousAssets.map(async (asset) => { - console.log('previousAssets: ', previousAssets); + previousAssets.map(async (asset) => { + console.log("previousAssets: ", previousAssets); const newAsset = { ...asset.toObject(), versionId: newVersion._id }; delete newAsset._id; return await assetModel(db).create(newAsset);