New version API collaboration and tested for Project

This commit is contained in:
2025-05-29 19:11:26 +05:30
parent 72faf6782e
commit 2bb3814d75
25 changed files with 526 additions and 88 deletions

View File

@@ -1,11 +1,17 @@
import * as express from "express";
import { recentDataController, searchProjectController, searchTrashProjectController } from "../controller/home/homeControllers.ts";
import { searchTrashProject } from "../../shared/services/home/homeService.ts";
import {
recentDataController,
searchProjectController,
searchTrashProjectController,
} from "../controller/home/homeControllers.ts";
import { tutorialsDataController } from "../controller/home/tutorialControllers.ts";
const homePageRouter = express.Router();
homePageRouter.get("/RecentlyViewed/:userId/:organization", recentDataController);
homePageRouter.get(
"/RecentlyViewed/:userId/:organization",
recentDataController
);
homePageRouter.get("/searchProjects", searchProjectController);
homePageRouter.get("/searchTrashProjects", searchTrashProjectController);
homePageRouter.get("/tutorials", tutorialsDataController);

View File

@@ -38,6 +38,11 @@ export const NewLineController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Success":
res.status(201).json(result.data);
break;
@@ -81,6 +86,11 @@ export const UpdateLineController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Success":
res.status(201).json(result.data);
break;
@@ -122,6 +132,11 @@ export const DeleteLineController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "line not found":
res.status(404).json({
message: "data not found",
@@ -168,6 +183,11 @@ export const DeleteLayerController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "layer not found":
res.status(404).json({
message: "data not found",
@@ -215,6 +235,11 @@ export const DeleteLinePointsController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Line not found":
res.status(404).json({
message: "data not found",
@@ -260,6 +285,11 @@ export const GetLinesController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Success":
res.status(200).json(result.data);
break;

View File

@@ -60,12 +60,12 @@ export const CreateAssetController = async (
switch (result.status) {
case "User not found":
res.status(200).json({
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(200).json({
res.status(404).json({
message: "Project not found",
});
break;

View File

@@ -40,22 +40,22 @@ export const SetNewCamera = async (
const result = await SetCamera(data);
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
TrashDatas: [],
});
break;
case "Update Success":
res.status(200).json({
TrashDatas: result.data,
});
res.status(200).json(result.data);
break;
case "Success":
res.status(200).json({
TrashDatas: result.data,
});
res.status(200).json(result.data);
break;
default:
res.status(500).json({
@@ -90,16 +90,18 @@ export const CameraList = async (
});
switch (result.status) {
case "User not found":
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
TrashDatas: [],
});
break;
case "Success":
res.status(200).json({
TrashDatas: result.data,
});
res.status(200).json(result.data);
break;
default:
res.status(500).json({
@@ -136,6 +138,11 @@ export const ActiveOnlineController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Success":
res.status(200).json(result.data);
break;

View File

@@ -56,7 +56,14 @@ export const WallSetup = async (
});
switch (result.status) {
case "User not found":
res.status(404).json({ message: "User not found" });
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Updated successfully":
res.status(200).json(result.data);
@@ -96,7 +103,14 @@ export const WallGet = async (
switch (result.status) {
case "User not found":
res.status(404).json({ message: "User not found" });
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "wallitems not found":
res.status(404).json({
@@ -141,7 +155,14 @@ export const WallDelete = async (
switch (result.status) {
case "User not found":
res.status(404).json({ message: "User not found" });
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "model not found":
res.status(404).json({

View File

@@ -32,10 +32,15 @@ export const CreateZoneController = async (
switch (result.status) {
case "User not found":
res.status(200).json({
res.status(404).json({
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "zone updated":
res.status(200).json({
message: "zone updated",
@@ -87,6 +92,11 @@ export const DeleteZoneController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Invalid zone ID":
res.status(404).json({
message: "Zone not found for the UUID",
@@ -134,6 +144,11 @@ export const GetZoneController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Invalid zone":
res.status(404).json({
message: "Zone not found for the UUID",
@@ -179,6 +194,11 @@ export const VizZoneController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the UUID":
res.status(404).json({
message: "Zone not found for the UUID",
@@ -226,6 +246,11 @@ export const ZoneDataController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found":
res.status(404).json({
message: "Zone not found",
@@ -272,6 +297,11 @@ export const SingleZonePanelController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the UUID":
res.status(404).json({
message: "Zone not found for the UUID",

View File

@@ -1,4 +1,4 @@
import { Request, Response } from "express";
import { Response } from "express";
import {
RecentlyAdded,
searchProject,

View File

@@ -1,7 +1,8 @@
import { Request, Response } from "express";
import { Response } from "express";
import {
createProject,
DeleteProject,
DuplicateProject,
GetAllProjects,
updateProject,
viewProject,
@@ -15,6 +16,7 @@ export const createProjectController = async (
try {
const { userId, organization } = req.user || {};
const { projectUuid, thumbnail } = req.body;
if (!req.user || !req.user.userId || !req.user.organization) {
res.status(401).json({ message: "Unauthorized" });
return;
@@ -105,17 +107,12 @@ export const RemoveProject = async (
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
) {
const { organization, userId } = req.user || {};
if (!req.user || !req.user.userId || !req.user.organization) {
res.status(401).json({ message: "Unauthorized" });
return;
}
if (!projectId || !organization || !userId || !role) {
if (!projectId || !organization || !userId) {
res.status(400).json({
message: "All fields are required",
});
@@ -125,7 +122,6 @@ export const RemoveProject = async (
projectId,
organization,
userId,
role,
});
switch (result?.status) {
case "Project not found":
@@ -267,3 +263,59 @@ export const ViewData = async (
return;
}
};
export const ProjectDuplicateController = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
try {
const { userId, organization } = req.user || {};
const { projectUuid, thumbnail, projectName } = req.body;
if (!req.user || !req.user.userId || !req.user.organization) {
res.status(401).json({ message: "Unauthorized" });
return;
}
if (!projectUuid || !thumbnail || !projectName) {
res.status(400).json({
message: "All fields are required",
});
return;
}
const result = await DuplicateProject({
...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 Duplicated 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;
}
};

View File

@@ -1,7 +1,8 @@
import { Request, Response } from "express";
import { Response } from "express";
import {
TrashDatas,
RestoreTrashData,
TrashDelete,
} from "../../../../shared/services/v1trash/v1trashservice.ts";
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
@@ -107,7 +108,7 @@ export const RestoreTrash = async (
});
}
};
export const DeleteTrash = async (
export const DeleteTrashData = async (
req: AuthenticatedRequest,
res: Response
): Promise<void> => {
@@ -122,7 +123,7 @@ export const DeleteTrash = async (
});
return;
}
const result = await RestoreTrashData({
const result = await TrashDelete({
organization,
projectId,
role,
@@ -140,14 +141,14 @@ export const DeleteTrash = async (
message: "Project not found",
});
break;
case "Project Trash Delete unsuccessfull":
case "Project Already Deleted":
res.status(200).json({
message: "Project Trash Delete unsuccessfull",
message: "Project Already Deleted",
});
break;
case "Trash Project Restored successfully":
case "Trash Project Delete successfully":
res.status(200).json({
message: "Trash Project Restored successfully",
message: "Trash Project Delete successfully",
});
break;
default:

View File

@@ -43,6 +43,11 @@ export const FloatAddController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the zoneId":
res.status(404).json({
message: "Zone not found for the zoneId",
@@ -102,6 +107,11 @@ export const DeleteFloatController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the zoneId":
res.status(404).json({
message: "Zone not found for the zoneId",
@@ -169,6 +179,11 @@ export const DuplicateFloatController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the zoneId":
res.status(404).json({
message: "Zone not found for the zoneId",
@@ -232,6 +247,11 @@ export const GetFloatController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found":
res.status(404).json({
message: "Zone not found",

View File

@@ -34,6 +34,11 @@ export const AddPanelController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found":
res.status(404).json({
message: "Zone not found",
@@ -89,6 +94,11 @@ export const DeletePanelController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found":
res.status(404).json({
message: "Zone not found",
@@ -143,6 +153,11 @@ export const ClearPanelController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found":
res.status(404).json({
message: "Zone not found",
@@ -202,6 +217,11 @@ export const LockedPanelController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found":
res.status(404).json({
message: "Zone not found",

View File

@@ -33,6 +33,11 @@ export const AddTemplateController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "TemplateID alreay exists":
res.status(200).json({
message: "TemplateID alreay exists",
@@ -87,6 +92,11 @@ export const AddTemToZoneController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found":
res.status(404).json({
message: "Zone not found",
@@ -141,6 +151,11 @@ export const TemplateDeleteController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Template not found":
res.status(404).json({
message: "Template not found",
@@ -193,6 +208,11 @@ export const GetTemplateController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "All Datas":
res.status(404).json([]);
break;

View File

@@ -34,6 +34,11 @@ export const AddWidgetController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the zoneId":
res.status(404).json({
message: "Zone not found",
@@ -102,6 +107,11 @@ export const WidgetDeleteController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the zoneId":
res.status(404).json({
message: "Zone not found for the zoneId",
@@ -169,6 +179,11 @@ export const WidgetUpdateController = async (
message: "Project not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the zoneId":
res.status(404).json({
message: "Zone not found for the zoneId",
@@ -232,6 +247,11 @@ export const GetWidgetController = async (
message: "Project not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the zoneId":
res.status(404).json({
message: "Zone not found for the zoneId",

View File

@@ -34,6 +34,11 @@ export const Add3dWidgetController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found for the zoneId":
res.status(200).json({
message: "Zone not found",
@@ -108,6 +113,11 @@ export const Update3DwidgetController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found":
res.status(404).json({
message: "Zone not found",
@@ -167,6 +177,11 @@ export const Delete3DwidgetController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found":
res.status(404).json({
message: "Zone not found",
@@ -225,6 +240,11 @@ export const Get3DWidgetController = async (
message: "User not found",
});
break;
case "Project not found":
res.status(404).json({
message: "Project not found",
});
break;
case "Zone not found":
res.status(404).json({
message: "Zone not found",

View File

@@ -2,6 +2,7 @@ import express from "express";
import {
createProjectController,
GetProjects,
ProjectDuplicateController,
RemoveProject,
updateProjectController,
ViewData,
@@ -12,7 +13,12 @@ import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
const v1projectRouter = express.Router();
// project
v1projectRouter.post("/upsertProject", tokenValidator, createProjectController);
v1projectRouter.post("/NewProject", tokenValidator, createProjectController);
v1projectRouter.post(
"/project/Duplicate",
tokenValidator,
ProjectDuplicateController
);
v1projectRouter.get(
"/Projects",
tokenValidator,
@@ -20,14 +26,14 @@ v1projectRouter.get(
GetProjects
);
v1projectRouter.patch(
"/Project/archive/:projectId",
"/Projects/Archive/:projectId",
tokenValidator,
// authorizedRoles("Admin", "User"),
RemoveProject
);
v1projectRouter.patch(
"/Project/:projectId",
"/Projects/:projectId",
tokenValidator,
// authorizedRoles("Admin", "User"),
updateProjectController

View File

@@ -2,7 +2,7 @@ import express from "express";
import { tokenValidator } from "../../../shared/utils/token.ts";
import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
import {
DeleteTrash,
DeleteTrashData,
GetTrashList,
RestoreTrash,
} from "../../V1/v1Controllers/trashController/v1trashController.ts";
@@ -22,11 +22,10 @@ v1TrashRoutes.patch(
// authorizedRoles("Admin", "User"),
RestoreTrash
);
v1TrashRoutes.patch(
"/Trash/Delete",
tokenValidator,
// authorizedRoles("Admin", "User"),
DeleteTrash
DeleteTrashData
);
export default v1TrashRoutes;

View File

@@ -22,6 +22,7 @@ export const existingUser = async (userId: string, organization: string) => {
}
const userData = await AuthModel(organization).findOne({
_id: userId,
isArchive: false,
});
return userData;
};
@@ -90,11 +91,11 @@ export const existingProjectById = async (
};
export const existingProjectByIdWithoutUser = async (
projectId: string,
organization: string,
organization: string
) => {
const projectData = await projectModel(organization).findOne({
_id: projectId,
isArchive: false,
});
return projectData;
};
};

View File

@@ -2,18 +2,14 @@ import projectModel from "../../model/project/project-model.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface IOrg {
organization: string;
userId: string;
}
interface IRestore {
projectId: string;
organization: string;
userId: string;
}
export const TrashDatas = async (data: IOrg) => {
try {
const { organization, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const { organization } = data;
const TrashLists = await projectModel(organization).find({
isArchive: true,
isDeleted: false,
@@ -51,9 +47,7 @@ export const TrashDatas = async (data: IOrg) => {
};
export const RestoreTrashData = async (data: IRestore) => {
try {
const { projectId, organization, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const { projectId, organization } = data;
const findProject = await projectModel(organization).findOne({
_id: projectId,
isArchive: true,
@@ -70,25 +64,4 @@ export const RestoreTrashData = async (data: IRestore) => {
return { status: error };
}
};
export const TrashDelete = async (data: IRestore) => {
try {
const { projectId, organization, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findProject = await projectModel(organization).findOne({
_id: projectId,
isArchive: true,
});
if (!findProject) return { status: "Project not found" };
const DeleteTrashData = await projectModel(organization).findOneAndUpdate(
{ _id: projectId, isArchive: true },
{ isDelete: true },
{ new: true }
);
if (!DeleteTrashData)
return { status: "Project Trash Delete unsuccessfull" };
return { status: "Trash Project Restored successfully" };
} catch (error) {
return { status: error };
}
};

View File

@@ -16,6 +16,14 @@ interface CreateProjectInput {
sharedUsers?: string[];
organization: string;
}
interface IProjectDuplicate {
projectName: string;
projectUuid: string;
userId: string; // user ID
thumbnail?: string;
sharedUsers?: string[];
organization: string;
}
interface updateProjectInput {
projectName: string;
projectId: string;
@@ -30,6 +38,11 @@ interface GetProjectsInterface {
organization: string;
role: string;
}
interface ProjectDelInterface {
projectId: string;
userId: string;
organization: string;
}
interface ProjectInterface {
projectId: string;
userId: string;
@@ -44,6 +57,7 @@ export const createProject = async (data: CreateProjectInput) => {
try {
const { thumbnail, sharedUsers, projectUuid, userId, organization } = data;
const userExisting = await existingUser(userId, organization);
console.log("userExisting: ", userExisting);
if (!userExisting) {
return {
status: "user_not_found",
@@ -115,16 +129,18 @@ export const GetAllProjects = async (data: GetProjectsInterface) => {
}
};
export const DeleteProject = async (data: ProjectInterface) => {
export const DeleteProject = async (data: ProjectDelInterface) => {
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);
console.log("existingProject: ", existingProject);
if (!existingProject) return { status: "Project not found" };
const updateProject = await projectModel(organization).findOneAndUpdate(
filter,
@@ -162,6 +178,63 @@ export const updateProject = async (data: updateProjectInput) => {
return { status: error };
}
};
export const DuplicateProject = async (data: IProjectDuplicate) => {
try {
const {
thumbnail,
sharedUsers,
projectUuid,
userId,
organization,
projectName,
} = 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 project = await projectModel(organization).create({
projectName: projectName,
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: unknown) {
return { status: error };
}
};
const maxLength: number = 6;
export const viewProject = async (data: ProjectInterface) => {
try {
@@ -193,8 +266,8 @@ export const viewProject = async (data: ProjectInterface) => {
newArr.pop();
}
}
await UsersDataModel(organization).updateOne(
{ _id: userId },
const datas = await UsersDataModel(organization).findOneAndUpdate(
{ userId: userId, isArchive: false },
{ recentlyViewed: newArr },
{ new: true }
);

View File

@@ -1,7 +1,6 @@
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";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface IRecentData {
organization: string;
@@ -29,7 +28,6 @@ export const RecentlyAdded = async (data: IRecentData) => {
try {
const { userId, organization, role } = data;
const userExisting = await existingUser(userId, organization);
console.log('userExisting: ', userExisting);
if (!userExisting) return { status: "User not found" };
const userRecentData = await UsersDataModel(organization)
.findOne({ userId: userId, isArchive: false })
@@ -43,16 +41,19 @@ export const RecentlyAdded = async (data: IRecentData) => {
// filter.createdBy = userId;
// }
const populatedProjects = userRecentData.recentlyViewed as IProject[];
console.log("populatedProjects: ", populatedProjects);
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;
})
);
console.log("RecentDatas: ", RecentDatas);
const filteredProjects = RecentDatas.filter(Boolean);
console.log("filteredProjects: ", filteredProjects);
return { status: "Success", data: filteredProjects };
} catch (error) {
return { status: error };

View File

@@ -1,4 +1,5 @@
import projectModel from "../../V1Models/Project/project-model.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
interface IOrg {
organization: string;
role: string;
@@ -21,6 +22,8 @@ export const TrashDatas = async (data: IOrg) => {
// if (role === "User") {
// filter.createdBy = userId;
// }
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const TrashLists = await projectModel(organization).find(filter);
if (!TrashLists) return { staus: "Trash is Empty" };
const TrashDocs: any[] = [];
@@ -56,6 +59,8 @@ export const TrashDatas = async (data: IOrg) => {
export const RestoreTrashData = async (data: IRestore) => {
try {
const { projectId, organization, role, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
let filter = { isArchive: true, _id: projectId } as RoleFilter;
// if (role === "User") {
// filter.createdBy = userId;
@@ -73,3 +78,24 @@ export const RestoreTrashData = async (data: IRestore) => {
return { status: error };
}
};
export const TrashDelete = async (data: IRestore) => {
try {
const { projectId, organization, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const findProject = await projectModel(organization).findOne({
_id: projectId,
isArchive: true,
});
if (!findProject) return { status: "Project not found" };
const DeleteTrashData = await projectModel(organization).findOneAndUpdate(
{ _id: projectId, isArchive: true, isDeleted: false },
{ isDeleted: true },
{ new: true }
);
if (!DeleteTrashData) return { status: "Project Already Deleted" };
return { status: "Trash Project Delete successfully" };
} catch (error) {
return { status: error };
}
};

View File

@@ -1,6 +1,9 @@
import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface IResult {
status: string;
@@ -75,6 +78,12 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
const { organization, widget, zoneId, index, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -163,6 +172,12 @@ export const DelFloat = async (data: IDelFloat): Promise<IResult> => {
const { organization, floatWidgetID, zoneId, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -210,6 +225,12 @@ export const DuplicateFloat = async (
const { organization, widget, zoneId, index, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -312,6 +333,12 @@ export const GetFloatWidget = async (data: IGetZoneFloat): Promise<IResult> => {
const { organization, zoneId, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -361,6 +388,7 @@ export const SingleFloatWidget = async (
const { organization, floatWidgetID, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const widgetData = await floatWidgetModel(organization)
.findOne({
floatWidgetID: floatWidgetID,

View File

@@ -1,7 +1,10 @@
import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface IResult {
status: string;
data?: object;
@@ -32,6 +35,12 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
const { organization, zoneId, panelOrder, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -97,6 +106,12 @@ export const DelPanel = async (data: IPanel): Promise<IResult> => {
const { organization, zoneId, panelName, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -156,6 +171,12 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
const { organization, zoneId, panelName, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -219,6 +240,12 @@ export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
const { organization, zoneId, lockedPanel, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -267,6 +294,8 @@ const getZoneAndPanelData = async (
projectId: string
) => {
try {
const existingZone = await zoneModel(organization)
.findOne({
zoneId: zoneId,

View File

@@ -3,7 +3,10 @@ import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface IResult {
status: string;
data?: object;
@@ -45,6 +48,12 @@ export const AddTemplate = async (data: IAddTemplate): Promise<IResult> => {
const { organization, template, projectId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingTemplate = await templateModel(organization).findOne({
templateID: template.id,
isArchive: false,
@@ -96,6 +105,12 @@ export const AddTemplateToZone = async (
const { organization, templateID, projectId, zoneId, userId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -238,6 +253,12 @@ export const TemplateDelete = async (data: ITemplate): Promise<IResult> => {
const { templateID, projectId, userId, organization } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingTemplate = await templateModel(organization).findOne({
templateID: templateID,
isArchive: false,
@@ -275,6 +296,12 @@ export const GetAllTemplates = async (data: IGetTemplate): Promise<IResult> => {
const { organization, userId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const templateDatas = await templateModel(organization)
.find({ projectId: projectId, isArchive: false })
.select("-_id -__v -isArchive -createdAt -updatedAt");

View File

@@ -1,6 +1,9 @@
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
import widget3dModel from "../../V1Models/Vizualization/3dwidget.ts";
import { existingUser } from "../helpers/v1projecthelperFns.ts";
import {
existingProjectById,
existingUser,
} from "../helpers/v1projecthelperFns.ts";
interface IResult {
status: string;
data?: object;
@@ -47,6 +50,12 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
const { organization, widget, userId, zoneId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -120,6 +129,13 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -183,6 +199,12 @@ export const Delete3Dwidget = async (
const { organization, id, userId, zoneId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,
@@ -238,6 +260,12 @@ export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
const { organization, userId, zoneId, projectId } = data;
const UserExists = await existingUser(userId, organization);
if (!UserExists) return { status: "User not found" };
const LivingProject = await existingProjectById(
projectId,
organization,
userId
);
if (!LivingProject) return { status: "Project not found" };
const existingZone = await zoneModel(organization).findOne({
zoneId: zoneId,
isArchive: false,