Version based API - Pushed here before the 5000 and 8000
This commit is contained in:
48
package-lock.json
generated
48
package-lock.json
generated
@@ -23,7 +23,8 @@
|
|||||||
"nodemailer": "^7.0.3",
|
"nodemailer": "^7.0.3",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"swagger-autogen": "^2.23.7",
|
"swagger-autogen": "^2.23.7",
|
||||||
"swagger-ui-express": "^5.0.1"
|
"swagger-ui-express": "^5.0.1",
|
||||||
|
"yjs": "^13.6.27"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcryptjs": "^3.0.0",
|
"@types/bcryptjs": "^3.0.0",
|
||||||
@@ -1446,6 +1447,15 @@
|
|||||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||||
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
|
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/isomorphic.js": {
|
||||||
|
"version": "0.2.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/isomorphic.js/-/isomorphic.js-0.2.5.tgz",
|
||||||
|
"integrity": "sha512-PIeMbHqMt4DnUP3MA/Flc0HElYjMXArsw1qwJZcm9sqR8mq3l8NYizFMty0pWwE/tzIGH3EKK5+jes5mAr85yw==",
|
||||||
|
"funding": {
|
||||||
|
"type": "GitHub Sponsors ❤",
|
||||||
|
"url": "https://github.com/sponsors/dmonad"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/json5": {
|
"node_modules/json5": {
|
||||||
"version": "2.2.3",
|
"version": "2.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
|
||||||
@@ -1510,6 +1520,26 @@
|
|||||||
"node": ">=12.0.0"
|
"node": ">=12.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/lib0": {
|
||||||
|
"version": "0.2.108",
|
||||||
|
"resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.108.tgz",
|
||||||
|
"integrity": "sha512-+3eK/B0SqYoZiQu9fNk4VEc6EX8cb0Li96tPGKgugzoGj/OdRdREtuTLvUW+mtinoB2mFiJjSqOJBIaMkAGhxQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"isomorphic.js": "^0.2.4"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"0ecdsa-generate-keypair": "bin/0ecdsa-generate-keypair.js",
|
||||||
|
"0gentesthtml": "bin/gentesthtml.js",
|
||||||
|
"0serve": "bin/0serve.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "GitHub Sponsors ❤",
|
||||||
|
"url": "https://github.com/sponsors/dmonad"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/lodash": {
|
"node_modules/lodash": {
|
||||||
"version": "4.17.21",
|
"version": "4.17.21",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
@@ -2849,6 +2879,22 @@
|
|||||||
"node": ">=0.4"
|
"node": ">=0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/yjs": {
|
||||||
|
"version": "13.6.27",
|
||||||
|
"resolved": "https://registry.npmjs.org/yjs/-/yjs-13.6.27.tgz",
|
||||||
|
"integrity": "sha512-OIDwaflOaq4wC6YlPBy2L6ceKeKuF7DeTxx+jPzv1FHn9tCZ0ZwSRnUBxD05E3yed46fv/FWJbvR+Ud7x0L7zw==",
|
||||||
|
"dependencies": {
|
||||||
|
"lib0": "^0.2.99"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16.0.0",
|
||||||
|
"npm": ">=8.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "GitHub Sponsors ❤",
|
||||||
|
"url": "https://github.com/sponsors/dmonad"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/yn": {
|
"node_modules/yn": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
|
||||||
|
|||||||
@@ -27,7 +27,8 @@
|
|||||||
"nodemailer": "^7.0.3",
|
"nodemailer": "^7.0.3",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"swagger-autogen": "^2.23.7",
|
"swagger-autogen": "^2.23.7",
|
||||||
"swagger-ui-express": "^5.0.1"
|
"swagger-ui-express": "^5.0.1",
|
||||||
|
"yjs": "^13.6.27"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bcryptjs": "^3.0.0",
|
"@types/bcryptjs": "^3.0.0",
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ USER appuser
|
|||||||
COPY . .
|
COPY . .
|
||||||
# Expose the port that the application listens on.
|
# Expose the port that the application listens on.
|
||||||
|
|
||||||
EXPOSE 4999
|
EXPOSE 3503
|
||||||
|
|
||||||
|
|
||||||
# Run the application.
|
# Run the application.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import {
|
import {
|
||||||
AuthLogin,
|
AuthLogin,
|
||||||
|
AuthLogins,
|
||||||
AuthLogout,
|
AuthLogout,
|
||||||
AuthSignup,
|
AuthSignup,
|
||||||
forgetPassword,
|
forgetPassword,
|
||||||
@@ -12,7 +13,6 @@ export const SignupController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userName, Email, Password } = req.body;
|
const { userName, Email, Password } = req.body;
|
||||||
console.log('req.body: ', req.body);
|
|
||||||
if (!userName || !Email || !Password) {
|
if (!userName || !Email || !Password) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -20,7 +20,6 @@ export const SignupController = async (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result = await AuthSignup(req.body);
|
const result = await AuthSignup(req.body);
|
||||||
console.log('result: ', result);
|
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User already exists":
|
case "User already exists":
|
||||||
@@ -78,7 +77,6 @@ export const SignInController = async (
|
|||||||
ForceLogoutData: result.data,
|
ForceLogoutData: result.data,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "User_Datas not found":
|
case "User_Datas not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "User_Datas not found",
|
message: "User_Datas not found",
|
||||||
@@ -245,3 +243,69 @@ export const ResetPasswordController = async (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// export const SignInController = async (
|
||||||
|
// req: Request,
|
||||||
|
// res: Response
|
||||||
|
// ): Promise<void> => {
|
||||||
|
// try {
|
||||||
|
// const { Email, Password, fingerprint } = req.body;
|
||||||
|
// if (!fingerprint || !Email || !Password) {
|
||||||
|
// res.status(400).json({
|
||||||
|
// message: "All fields are required",
|
||||||
|
// });
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// const result = await AuthLogins(req.body);
|
||||||
|
|
||||||
|
// switch (result.status) {
|
||||||
|
// case "User Not Found!!! Kindly signup...":
|
||||||
|
// res.status(404).json({
|
||||||
|
// message: "User Not Found!!! Kindly signup...",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Email & Password is invalid...Check the credentials":
|
||||||
|
// res.status(400).json({
|
||||||
|
// message: "Email & Password is invalid...Check the credentials",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// // case "Already LoggedIn on another browser....Please logout!!!":
|
||||||
|
// // res.status(403).json({
|
||||||
|
// // message: "Already LoggedIn on another browser....Please logout!!!",
|
||||||
|
// // ForceLogoutData: result.data,
|
||||||
|
// // });
|
||||||
|
// // break;
|
||||||
|
// case "Already LoggedIn on another browser....ForceLogout Implemented!!!":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: result.data
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "User_Datas not found":
|
||||||
|
// res.status(404).json({
|
||||||
|
// message: "User_Datas not found",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "User update failed.":
|
||||||
|
// res.status(400).json({
|
||||||
|
// message: "User update failed.",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// case "Success":
|
||||||
|
// res.status(200).json({
|
||||||
|
// message: result.data,
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "Internal server error",
|
||||||
|
// });
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// res.status(500).json({
|
||||||
|
// message: "An unexpected error occurred",
|
||||||
|
// });
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// };
|
||||||
@@ -12,8 +12,8 @@ export const UpsertAisleController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { aisleUuid, points, type, projectId } = req.body;
|
const { aisleUuid, points, type, projectId, versionId } = req.body;
|
||||||
if (!organization || !userId || !aisleUuid || !projectId) {
|
if (!organization || !userId || !aisleUuid || !projectId || !versionId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -24,6 +24,7 @@ export const UpsertAisleController = async (
|
|||||||
type,
|
type,
|
||||||
aisleUuid,
|
aisleUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
organization,
|
organization,
|
||||||
userId,
|
userId,
|
||||||
};
|
};
|
||||||
@@ -39,6 +40,11 @@ export const UpsertAisleController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Aisle Not Updated":
|
case "Aisle Not Updated":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "Aisle Not Updated",
|
message: "Aisle Not Updated",
|
||||||
@@ -83,8 +89,8 @@ export const DeleteAisleController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { aisleUuid, projectId } = req.body;
|
const { aisleUuid, projectId, versionId } = req.body;
|
||||||
if (!organization || !userId || !aisleUuid || !projectId) {
|
if (!organization || !userId || !aisleUuid || !projectId || !versionId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -95,6 +101,7 @@ export const DeleteAisleController = async (
|
|||||||
projectId,
|
projectId,
|
||||||
organization,
|
organization,
|
||||||
userId,
|
userId,
|
||||||
|
versionId,
|
||||||
};
|
};
|
||||||
const result = await DeleteAisle(data);
|
const result = await DeleteAisle(data);
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -108,6 +115,11 @@ export const DeleteAisleController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Aisle not found":
|
case "Aisle not found":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "Aisle not found",
|
message: "Aisle not found",
|
||||||
@@ -136,7 +148,7 @@ export const AllAisleController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId } = req.params;
|
const { projectId, versionId } = req.params;
|
||||||
if (!organization || !userId || !projectId) {
|
if (!organization || !userId || !projectId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -145,6 +157,7 @@ export const AllAisleController = async (
|
|||||||
}
|
}
|
||||||
const data = {
|
const data = {
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
organization,
|
organization,
|
||||||
userId,
|
userId,
|
||||||
};
|
};
|
||||||
@@ -160,6 +173,11 @@ export const AllAisleController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Aisle not found":
|
case "Aisle not found":
|
||||||
res.status(200).json(result.data);
|
res.status(200).json(result.data);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -15,8 +15,16 @@ export const NewLineController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { line, type, layer, projectId } = req.body;
|
const { line, type, layer, projectId, versionId } = req.body;
|
||||||
if (!organization || !userId || !line || !type || !layer || !projectId) {
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!line ||
|
||||||
|
!type ||
|
||||||
|
!layer ||
|
||||||
|
!projectId ||
|
||||||
|
!versionId
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -28,6 +36,7 @@ export const NewLineController = async (
|
|||||||
layer,
|
layer,
|
||||||
projectId,
|
projectId,
|
||||||
organization,
|
organization,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
};
|
};
|
||||||
const result = await CreateLineItems(data);
|
const result = await CreateLineItems(data);
|
||||||
@@ -43,6 +52,11 @@ export const NewLineController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(201).json(result.data);
|
res.status(201).json(result.data);
|
||||||
break;
|
break;
|
||||||
@@ -64,8 +78,15 @@ export const UpdateLineController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { uuid, position, projectId } = req.body;
|
const { uuid, position, projectId, versionId } = req.body;
|
||||||
if (!organization || !userId || !uuid || !position || projectId) {
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!uuid ||
|
||||||
|
!position ||
|
||||||
|
projectId ||
|
||||||
|
!versionId
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -74,6 +95,7 @@ export const UpdateLineController = async (
|
|||||||
const result = await UpdateLineItems({
|
const result = await UpdateLineItems({
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
uuid,
|
uuid,
|
||||||
position,
|
position,
|
||||||
userId,
|
userId,
|
||||||
@@ -90,8 +112,13 @@ export const UpdateLineController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Success":
|
case "Success":
|
||||||
res.status(201).json(result.data);
|
res.status(200).json(result.data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
@@ -111,8 +138,8 @@ export const DeleteLineController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId, line } = req.body;
|
const { projectId, line, versionId } = req.body;
|
||||||
if (!organization || !userId || !projectId || !line) {
|
if (!organization || !userId || !projectId || !line || !versionId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -121,6 +148,7 @@ export const DeleteLineController = async (
|
|||||||
const result = await DeleteLineItems({
|
const result = await DeleteLineItems({
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
line,
|
line,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
@@ -136,6 +164,11 @@ export const DeleteLineController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "line not found":
|
case "line not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "data not found",
|
message: "data not found",
|
||||||
@@ -162,8 +195,8 @@ export const DeleteLayerController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId, layer } = req.body;
|
const { projectId, layer, versionId } = req.body;
|
||||||
if (!organization || !userId || !projectId || !layer) {
|
if (!organization || !userId || !projectId || !layer || !versionId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -172,6 +205,7 @@ export const DeleteLayerController = async (
|
|||||||
const result = await DeleteLayer({
|
const result = await DeleteLayer({
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
layer,
|
layer,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
@@ -187,6 +221,11 @@ export const DeleteLayerController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "layer not found":
|
case "layer not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "data not found",
|
message: "data not found",
|
||||||
@@ -214,8 +253,8 @@ export const DeleteLinePointsController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId, uuid } = req.body;
|
const { projectId, uuid, versionId } = req.body;
|
||||||
if (!organization || !userId || !projectId || !uuid) {
|
if (!organization || !userId || !projectId || !uuid || !versionId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -223,6 +262,7 @@ export const DeleteLinePointsController = async (
|
|||||||
}
|
}
|
||||||
const result = await DeleteLinePoints({
|
const result = await DeleteLinePoints({
|
||||||
organization,
|
organization,
|
||||||
|
versionId,
|
||||||
projectId,
|
projectId,
|
||||||
uuid,
|
uuid,
|
||||||
userId,
|
userId,
|
||||||
@@ -239,6 +279,11 @@ export const DeleteLinePointsController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Line not found":
|
case "Line not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "data not found",
|
message: "data not found",
|
||||||
@@ -265,7 +310,7 @@ export const GetLinesController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId } = req.params;
|
const {versionId, projectId } = req.params;
|
||||||
if (!organization || !userId || !projectId) {
|
if (!organization || !userId || !projectId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -274,7 +319,7 @@ export const GetLinesController = async (
|
|||||||
}
|
}
|
||||||
const result = await GetLinesService({
|
const result = await GetLinesService({
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,versionId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -289,6 +334,11 @@ export const GetLinesController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Line not found":
|
case "Line not found":
|
||||||
res.status(200).json(result.data);
|
res.status(200).json(result.data);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -25,13 +25,9 @@ export const CreateAssetController = async (
|
|||||||
isLocked,
|
isLocked,
|
||||||
isVisible,
|
isVisible,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
if (
|
if (!organization || !userId || !projectId || !modelUuid || !versionId) {
|
||||||
!organization ||
|
|
||||||
!userId ||
|
|
||||||
!projectId ||
|
|
||||||
!modelUuid
|
|
||||||
) {
|
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -49,6 +45,7 @@ export const CreateAssetController = async (
|
|||||||
isLocked,
|
isLocked,
|
||||||
isVisible,
|
isVisible,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
};
|
};
|
||||||
const result = await setAssetModel(data);
|
const result = await setAssetModel(data);
|
||||||
|
|
||||||
@@ -63,6 +60,11 @@ export const CreateAssetController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Updated successfully":
|
case "Updated successfully":
|
||||||
res.status(200).json(result.data);
|
res.status(200).json(result.data);
|
||||||
break;
|
break;
|
||||||
@@ -89,8 +91,15 @@ export const DeleteAssetController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { modelUuid, modelName, projectId } = req.body;
|
const { modelUuid, modelName, projectId, versionId } = req.body;
|
||||||
if (!organization || !userId || !modelUuid || !projectId || !modelName) {
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!modelUuid ||
|
||||||
|
!projectId ||
|
||||||
|
!modelName ||
|
||||||
|
!versionId
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -101,6 +110,7 @@ export const DeleteAssetController = async (
|
|||||||
modelName,
|
modelName,
|
||||||
modelUuid,
|
modelUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -115,6 +125,11 @@ export const DeleteAssetController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "model not found":
|
case "model not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Model not found",
|
message: "Model not found",
|
||||||
@@ -148,7 +163,7 @@ export const GetAssetController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId } = req.params;
|
const { projectId,versionId } = req.params;
|
||||||
if (!organization || !userId || !projectId) {
|
if (!organization || !userId || !projectId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -158,7 +173,7 @@ export const GetAssetController = async (
|
|||||||
const result = await getFloorItems({
|
const result = await getFloorItems({
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,versionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -172,6 +187,11 @@ export const GetAssetController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "floorItems not found":
|
case "floorItems not found":
|
||||||
res.status(200).json([]);
|
res.status(200).json([]);
|
||||||
break;
|
break;
|
||||||
@@ -196,8 +216,15 @@ export const ReplaceEventDataController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { modelUuid, eventData, projectId } = req.body;
|
const { modelUuid, eventData, projectId, versionId } = req.body;
|
||||||
if (!organization || !userId || !projectId || !modelUuid || !eventData) {
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!projectId ||
|
||||||
|
!modelUuid ||
|
||||||
|
!versionId ||
|
||||||
|
!eventData
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -207,6 +234,7 @@ export const ReplaceEventDataController = async (
|
|||||||
modelUuid,
|
modelUuid,
|
||||||
organization,
|
organization,
|
||||||
eventData,
|
eventData,
|
||||||
|
versionId,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
@@ -222,6 +250,11 @@ export const ReplaceEventDataController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Model not for this UUID":
|
case "Model not for this UUID":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Model not for this UUID",
|
message: "Model not for this UUID",
|
||||||
@@ -256,6 +289,7 @@ export const AssetUpdatePosRotController = async (
|
|||||||
isLocked,
|
isLocked,
|
||||||
isVisible,
|
isVisible,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
if (
|
if (
|
||||||
!organization ||
|
!organization ||
|
||||||
@@ -266,6 +300,7 @@ export const AssetUpdatePosRotController = async (
|
|||||||
!rotation ||
|
!rotation ||
|
||||||
!modelName ||
|
!modelName ||
|
||||||
!projectId ||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
!modelUuid
|
!modelUuid
|
||||||
) {
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
@@ -283,6 +318,7 @@ export const AssetUpdatePosRotController = async (
|
|||||||
isLocked,
|
isLocked,
|
||||||
isVisible,
|
isVisible,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -296,6 +332,11 @@ export const AssetUpdatePosRotController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Asset not found":
|
case "Asset not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Asset not found",
|
message: "Asset not found",
|
||||||
|
|||||||
@@ -13,13 +13,14 @@ export const SetNewCamera = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { position, target, rotation, projectId } = req.body;
|
const { position, target, rotation, projectId,versionId } = req.body;
|
||||||
if (
|
if (
|
||||||
!organization ||
|
!organization ||
|
||||||
!userId ||
|
!userId ||
|
||||||
!position ||
|
!position ||
|
||||||
!target ||
|
!target ||
|
||||||
!rotation ||
|
!rotation ||
|
||||||
|
!versionId ||
|
||||||
!projectId
|
!projectId
|
||||||
) {
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
@@ -32,7 +33,7 @@ export const SetNewCamera = async (
|
|||||||
target,
|
target,
|
||||||
rotation,
|
rotation,
|
||||||
projectId,
|
projectId,
|
||||||
organization,
|
organization,versionId,
|
||||||
userId,
|
userId,
|
||||||
};
|
};
|
||||||
const result = await SetCamera(data);
|
const result = await SetCamera(data);
|
||||||
@@ -48,7 +49,11 @@ export const SetNewCamera = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Update Success":
|
case "Update Success":
|
||||||
res.status(200).json(result.data);
|
res.status(200).json(result.data);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -16,27 +16,16 @@ export const WallSetup = async (
|
|||||||
modelUuid,
|
modelUuid,
|
||||||
modelName,
|
modelName,
|
||||||
position,
|
position,
|
||||||
type,
|
|
||||||
assetId,
|
assetId,
|
||||||
|
type,
|
||||||
csgposition,
|
csgposition,
|
||||||
csgscale,
|
csgscale,
|
||||||
quaternion,
|
quaternion,
|
||||||
scale,
|
scale,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
if (
|
if (!modelUuid || !organization || !userId || !projectId || !versionId) {
|
||||||
!modelUuid ||
|
|
||||||
!modelName ||
|
|
||||||
!position ||
|
|
||||||
!type ||
|
|
||||||
!projectId ||
|
|
||||||
!csgscale ||
|
|
||||||
!csgposition ||
|
|
||||||
!quaternion ||
|
|
||||||
!scale ||
|
|
||||||
!organization ||
|
|
||||||
!userId
|
|
||||||
) {
|
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required!",
|
message: "All fields are required!",
|
||||||
});
|
});
|
||||||
@@ -44,17 +33,18 @@ export const WallSetup = async (
|
|||||||
}
|
}
|
||||||
const result = await setWallItems({
|
const result = await setWallItems({
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
modelUuid,
|
modelUuid,
|
||||||
modelName,
|
modelName,
|
||||||
position,
|
position,
|
||||||
type,
|
type,
|
||||||
assetId,
|
|
||||||
csgposition,
|
csgposition,
|
||||||
csgscale,
|
csgscale,
|
||||||
quaternion,
|
quaternion,
|
||||||
scale,
|
scale,
|
||||||
organization,
|
organization,
|
||||||
userId,
|
userId,
|
||||||
|
assetId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
@@ -67,10 +57,15 @@ export const WallSetup = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Updated successfully":
|
case "Updated successfully":
|
||||||
res.status(200).json(result.data);
|
res.status(200).json(result.data);
|
||||||
break;
|
break;
|
||||||
case "wall Item created successfully":
|
case "Success":
|
||||||
res.status(201).json(result.data);
|
res.status(201).json(result.data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -90,7 +85,7 @@ export const WallGet = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId } = req.params;
|
const { versionId, projectId } = req.params;
|
||||||
if (!organization || !userId || !projectId) {
|
if (!organization || !userId || !projectId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -101,6 +96,7 @@ export const WallGet = async (
|
|||||||
organization,
|
organization,
|
||||||
userId,
|
userId,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -114,6 +110,11 @@ export const WallGet = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "wallitems not found":
|
case "wallitems not found":
|
||||||
res.status(200).json(result.data);
|
res.status(200).json(result.data);
|
||||||
break;
|
break;
|
||||||
@@ -138,8 +139,15 @@ export const WallDelete = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId, modelName, modelUuid } = req.body;
|
const { projectId, versionId, modelName, modelUuid } = req.body;
|
||||||
if (!organization || !userId || !projectId || !modelName || !modelUuid) {
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!projectId ||
|
||||||
|
!modelName ||
|
||||||
|
!versionId ||
|
||||||
|
!modelUuid
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -149,6 +157,7 @@ export const WallDelete = async (
|
|||||||
organization,
|
organization,
|
||||||
userId,
|
userId,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
modelName,
|
modelName,
|
||||||
modelUuid,
|
modelUuid,
|
||||||
});
|
});
|
||||||
@@ -164,6 +173,11 @@ export const WallDelete = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "model not found":
|
case "model not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "model not found",
|
message: "model not found",
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ export const CreateZoneController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { zoneData, projectId } = req.body;
|
const { zoneData, projectId, versionId } = req.body;
|
||||||
if (!organization || !userId || !zoneData || !projectId) {
|
if (!organization || !userId || !zoneData || !projectId || !versionId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -25,6 +25,7 @@ export const CreateZoneController = async (
|
|||||||
const data = {
|
const data = {
|
||||||
zoneData,
|
zoneData,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
organization,
|
organization,
|
||||||
userId,
|
userId,
|
||||||
};
|
};
|
||||||
@@ -41,6 +42,11 @@ export const CreateZoneController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "zone updated":
|
case "zone updated":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "zone updated",
|
message: "zone updated",
|
||||||
@@ -71,8 +77,8 @@ export const DeleteZoneController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { zoneUuid, projectId } = req.body;
|
const { zoneUuid, projectId, versionId } = req.body;
|
||||||
if (!organization || !userId || !zoneUuid || !projectId) {
|
if (!organization || !userId || !zoneUuid || !projectId || !versionId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -82,6 +88,7 @@ export const DeleteZoneController = async (
|
|||||||
organization,
|
organization,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -96,6 +103,11 @@ export const DeleteZoneController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Invalid zone ID":
|
case "Invalid zone ID":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found for the UUID",
|
message: "Zone not found for the UUID",
|
||||||
@@ -124,7 +136,7 @@ export const GetZoneController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId } = req.params;
|
const { projectId, versionId } = req.params;
|
||||||
if (!organization || !userId || !projectId) {
|
if (!organization || !userId || !projectId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -135,6 +147,7 @@ export const GetZoneController = async (
|
|||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -148,6 +161,11 @@ export const GetZoneController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Invalid zone":
|
case "Invalid zone":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found for the UUID",
|
message: "Zone not found for the UUID",
|
||||||
@@ -174,7 +192,7 @@ export const VizZoneController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId } = req.params;
|
const { projectId, versionId } = req.params;
|
||||||
if (!organization || !userId || !projectId) {
|
if (!organization || !userId || !projectId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -184,6 +202,7 @@ export const VizZoneController = async (
|
|||||||
const result = await VizZoneDatas({
|
const result = await VizZoneDatas({
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -198,6 +217,11 @@ export const VizZoneController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found for the UUID":
|
case "Zone not found for the UUID":
|
||||||
res.status(200).json(result.data);
|
res.status(200).json(result.data);
|
||||||
break;
|
break;
|
||||||
@@ -223,7 +247,7 @@ export const ZoneDataController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId, zoneUuid } = req.params;
|
const { projectId, zoneUuid, versionId } = req.params;
|
||||||
if (!organization || !userId || !projectId || !zoneUuid) {
|
if (!organization || !userId || !projectId || !zoneUuid) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -234,6 +258,7 @@ export const ZoneDataController = async (
|
|||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
|
versionId,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -248,6 +273,11 @@ export const ZoneDataController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found":
|
case "Zone not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
@@ -274,7 +304,7 @@ export const SingleZonePanelController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId } = req.user || {};
|
const { organization, userId } = req.user || {};
|
||||||
const { projectId, zoneUuid } = req.params;
|
const { versionId, projectId, zoneUuid } = req.params;
|
||||||
if (!organization || !userId || !projectId || !zoneUuid) {
|
if (!organization || !userId || !projectId || !zoneUuid) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -285,6 +315,7 @@ export const SingleZonePanelController = async (
|
|||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
|
versionId,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -299,6 +330,11 @@ export const SingleZonePanelController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found for the UUID":
|
case "Zone not found for the UUID":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found for the UUID",
|
message: "Zone not found for the UUID",
|
||||||
|
|||||||
@@ -0,0 +1,396 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AllProductDatas,
|
||||||
|
EventDataDelete,
|
||||||
|
getProductDatas,
|
||||||
|
productAdd,
|
||||||
|
productDataDelete,
|
||||||
|
productRename,
|
||||||
|
} from "../../../../shared/services/simulation/productService.ts";
|
||||||
|
import { productAdddummy } from "../../../../shared/services/dummyservice.ts";
|
||||||
|
|
||||||
|
export const AddProductControllerdumy = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { productUuid, eventDatas, projectId, productName } = req.body;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!productUuid ||
|
||||||
|
!productName ||
|
||||||
|
!projectId ||
|
||||||
|
!userId ||
|
||||||
|
!organization
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await productAdddummy({
|
||||||
|
productName,
|
||||||
|
productUuid,
|
||||||
|
eventDatas,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "EventData updated successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "EventData updated successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "EventData add successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "EventData add successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Product created Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetProductEventDatas = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { productUuid, projectId } = req.query as {
|
||||||
|
productUuid: string;
|
||||||
|
projectId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!productUuid || !projectId || !userId || !organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await getProductDatas({
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Product not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Product not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Events not found":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(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 DeleteProductController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { productUuid, projectId } = req.body;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!productUuid || !projectId || !userId || !organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await productDataDelete({
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Product not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Product not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Product 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 DeleteEventsController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { productUuid, projectId, modelUuid } = req.body;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!productUuid || !projectId || !userId || !organization || !modelUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await EventDataDelete({
|
||||||
|
productUuid,
|
||||||
|
modelUuid,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Product not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Product not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Event Delete Unsuccessful":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Event Delete Unsuccessful",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Events 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 ProjectBasedProductsController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!projectId || !userId || !organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AllProductDatas({
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "No products found":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(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 RenameProductController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { productName, productUuid, projectId } = req.body;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!projectId ||
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!productName ||
|
||||||
|
!productUuid
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await productRename({
|
||||||
|
projectId,
|
||||||
|
productName,
|
||||||
|
productUuid,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Product not found":
|
||||||
|
res.status(404).json({ message: "Product not found" });
|
||||||
|
break;
|
||||||
|
case "Rename Unsuccessful":
|
||||||
|
res.status(200).json({ message: "Product Rename Not Updated" });
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({ message: "Product Rename Successfull" });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -15,7 +15,8 @@ export const AddProductController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { productUuid, eventDatas, projectId, productName } = req.body;
|
const { productUuid, eventDatas, projectId, versionId, productName } =
|
||||||
|
req.body;
|
||||||
|
|
||||||
if (!req.user?.userId || !req.user?.organization) {
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
res.status(401).json({ message: "Unauthorized" });
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
@@ -25,6 +26,7 @@ export const AddProductController = async (
|
|||||||
!productUuid ||
|
!productUuid ||
|
||||||
!productName ||
|
!productName ||
|
||||||
!projectId ||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
!userId ||
|
!userId ||
|
||||||
!organization
|
!organization
|
||||||
) {
|
) {
|
||||||
@@ -38,6 +40,7 @@ export const AddProductController = async (
|
|||||||
productUuid,
|
productUuid,
|
||||||
eventDatas,
|
eventDatas,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
organization,
|
organization,
|
||||||
});
|
});
|
||||||
@@ -88,9 +91,10 @@ export const GetProductEventDatas = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { productUuid, projectId } = req.query as {
|
const { productUuid, projectId, versionId } = req.query as {
|
||||||
productUuid: string;
|
productUuid: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!req.user?.userId || !req.user?.organization) {
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
@@ -105,6 +109,7 @@ export const GetProductEventDatas = async (
|
|||||||
}
|
}
|
||||||
const result = await getProductDatas({
|
const result = await getProductDatas({
|
||||||
productUuid,
|
productUuid,
|
||||||
|
versionId,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
organization,
|
organization,
|
||||||
@@ -116,6 +121,11 @@ export const GetProductEventDatas = async (
|
|||||||
message: "User not found",
|
message: "User not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
case "Project not found":
|
case "Project not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
@@ -152,13 +162,13 @@ export const DeleteProductController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { productUuid, projectId } = req.body;
|
const { productUuid, projectId, versionId } = req.body;
|
||||||
|
|
||||||
if (!req.user?.userId || !req.user?.organization) {
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
res.status(401).json({ message: "Unauthorized" });
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!productUuid || !projectId || !userId || !organization) {
|
if (!productUuid || !projectId || !versionId || !userId || !organization) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -167,6 +177,7 @@ export const DeleteProductController = async (
|
|||||||
const result = await productDataDelete({
|
const result = await productDataDelete({
|
||||||
productUuid,
|
productUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
organization,
|
organization,
|
||||||
});
|
});
|
||||||
@@ -212,13 +223,20 @@ export const DeleteEventsController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { productUuid, projectId, modelUuid } = req.body;
|
const { productUuid, projectId, modelUuid, versionId } = req.body;
|
||||||
|
|
||||||
if (!req.user?.userId || !req.user?.organization) {
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
res.status(401).json({ message: "Unauthorized" });
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!productUuid || !projectId || !userId || !organization || !modelUuid) {
|
if (
|
||||||
|
!productUuid ||
|
||||||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!modelUuid
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -228,6 +246,7 @@ export const DeleteEventsController = async (
|
|||||||
productUuid,
|
productUuid,
|
||||||
modelUuid,
|
modelUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
organization,
|
organization,
|
||||||
});
|
});
|
||||||
@@ -278,7 +297,7 @@ export const ProjectBasedProductsController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { projectId } = req.params;
|
const { projectId, versionId } = req.params;
|
||||||
|
|
||||||
if (!req.user?.userId || !req.user?.organization) {
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
res.status(401).json({ message: "Unauthorized" });
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
@@ -293,6 +312,7 @@ export const ProjectBasedProductsController = async (
|
|||||||
const result = await AllProductDatas({
|
const result = await AllProductDatas({
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
|
versionId,
|
||||||
organization,
|
organization,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -308,6 +328,11 @@ export const ProjectBasedProductsController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "No products found":
|
case "No products found":
|
||||||
res.status(200).json(result.data);
|
res.status(200).json(result.data);
|
||||||
break;
|
break;
|
||||||
@@ -333,7 +358,7 @@ export const RenameProductController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { productName, productUuid, projectId } = req.body;
|
const { productName, productUuid, projectId, versionId } = req.body;
|
||||||
|
|
||||||
if (!req.user?.userId || !req.user?.organization) {
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
res.status(401).json({ message: "Unauthorized" });
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
@@ -341,6 +366,7 @@ export const RenameProductController = async (
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!projectId ||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
!userId ||
|
!userId ||
|
||||||
!organization ||
|
!organization ||
|
||||||
!productName ||
|
!productName ||
|
||||||
@@ -353,6 +379,7 @@ export const RenameProductController = async (
|
|||||||
}
|
}
|
||||||
const result = await productRename({
|
const result = await productRename({
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
productName,
|
productName,
|
||||||
productUuid,
|
productUuid,
|
||||||
userId,
|
userId,
|
||||||
|
|||||||
@@ -0,0 +1,346 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
addComments,
|
||||||
|
createThread,
|
||||||
|
deleteComments,
|
||||||
|
deleteThread,
|
||||||
|
findThreads,
|
||||||
|
updateThreadTitle,
|
||||||
|
} from "../../../../shared/services/Thread/ThreadService.ts";
|
||||||
|
export const threadCreate = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId } = req.body;
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!projectId || !organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await createThread({ ...req.body, userId, organization });
|
||||||
|
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "CurrentVersion Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Thread created Successfully",
|
||||||
|
threadData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const threaddelete = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId } = req.body;
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!projectId || !organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await deleteThread({ ...req.body, userId, organization });
|
||||||
|
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "CurrentVersion Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Thread deleted Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const threadUpdateTitle = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId, threadId } = req.body;
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!projectId || !threadId || !organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await updateThreadTitle({
|
||||||
|
...req.body,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "CurrentVersion Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "ThreadTitle updated Successfully",
|
||||||
|
data: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const threadComment = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId, threadId } = req.body;
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!projectId || !threadId || !organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await addComments({ ...req.body, userId, organization });
|
||||||
|
console.log("result: ", result);
|
||||||
|
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "CurrentVersion Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "updated":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Comment updated successfully",
|
||||||
|
data: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Thread comments add Successfully",
|
||||||
|
data: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const threadCommentDelete = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId, threadId, commentId } = req.body;
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!projectId || !commentId || !threadId || !organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await deleteComments({ ...req.body, userId, organization });
|
||||||
|
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "CurrentVersion Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "thread not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "thread not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "unauthorized":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "You can only delete your own comment.",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Thread comment deleted Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const getALLthreads = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!projectId || !organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await findThreads({ projectId, userId, organization });
|
||||||
|
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "CurrentVersion Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
data: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,24 +1,224 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import versionService from "../../../../shared/services/version/versionService.ts";
|
import {
|
||||||
|
CreateVersion,
|
||||||
|
GetVersionById,
|
||||||
|
RollBackversion,
|
||||||
|
VersionHistory,
|
||||||
|
} from "../../../../shared/services/version/versionService.ts";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
|
||||||
export const versioncontroller = async (
|
export const versionAddcontroller = async (
|
||||||
req: Request,
|
req: AuthenticatedRequest,
|
||||||
res: Response
|
res: Response
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { projectId, userId, description, db } = req.body;
|
const { organization, role, userId } = req.user || {};
|
||||||
|
if (!organization || !role || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { projectId, versionName, hierarchyVersion, description, createdBy } =
|
||||||
|
req.body;
|
||||||
|
|
||||||
const result = await versionService.saveCurrentStateAsVersion(
|
const result = await CreateVersion({
|
||||||
db,
|
organization,
|
||||||
|
hierarchyVersion,
|
||||||
|
createdBy,
|
||||||
|
versionName,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
description
|
description,
|
||||||
);
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Parent Version not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Parent Version not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
message: "An unexpected error occurred",
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GetversionList = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, role, userId } = req.user || {};
|
||||||
|
if (!organization || !role || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { projectId, versionId } = req.params;
|
||||||
|
const result = await GetVersionById({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Version not found for the project":
|
||||||
|
res.status(200).json([]);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
versionDatas: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const rollbackcontroller = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, role, userId } = req.user || {};
|
||||||
|
if (!organization || !role || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { versionId, projectId } = req.body;
|
||||||
|
|
||||||
|
const result = await RollBackversion({
|
||||||
|
organization,
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Mentioned Version not found for the Rollback":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Mentioned Version not found for the Rollback",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Rollback successfull",
|
||||||
|
versionId: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GetversionHistory = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, role, userId } = req.user || {};
|
||||||
|
if (!organization || !role || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { projectId } = req.params;
|
||||||
|
const page = parseInt(req.query.page as string) || 1;
|
||||||
|
const limit = parseInt(req.query.limit as string) || 10;
|
||||||
|
const result = await VersionHistory({
|
||||||
|
organization,
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Versions not found":
|
||||||
|
res.status(200).json([]);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ export const FloatAddController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { widget, zoneUuid, index, projectId } = req.body;
|
const { widget, zoneUuid, index, projectId, versionId } = req.body;
|
||||||
if (
|
if (
|
||||||
!userId ||
|
!userId ||
|
||||||
!organization ||
|
!organization ||
|
||||||
!widget ||
|
!widget ||
|
||||||
!zoneUuid ||
|
!zoneUuid ||
|
||||||
!index ||
|
!versionId ||
|
||||||
!projectId
|
!projectId
|
||||||
) {
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
@@ -30,6 +30,7 @@ export const FloatAddController = async (
|
|||||||
}
|
}
|
||||||
const result = await AddFloat({
|
const result = await AddFloat({
|
||||||
organization,
|
organization,
|
||||||
|
versionId,
|
||||||
widget,
|
widget,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
index,
|
index,
|
||||||
@@ -48,6 +49,11 @@ export const FloatAddController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found for the zoneUuid":
|
case "Zone not found for the zoneUuid":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found for the zoneUuid",
|
message: "Zone not found for the zoneUuid",
|
||||||
@@ -87,8 +93,15 @@ export const DeleteFloatController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { floatWidgetID, projectId, zoneUuid } = req.body;
|
const { floatWidgetID, projectId, zoneUuid, versionId } = req.body;
|
||||||
if (!userId || !organization || !floatWidgetID || !projectId || !zoneUuid) {
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!floatWidgetID ||
|
||||||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
|
!zoneUuid
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -98,6 +111,7 @@ export const DeleteFloatController = async (
|
|||||||
organization,
|
organization,
|
||||||
floatWidgetID,
|
floatWidgetID,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
versionId,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
@@ -112,6 +126,11 @@ export const DeleteFloatController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found for the zoneUuid":
|
case "Zone not found for the zoneUuid":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found for the zoneUuid",
|
message: "Zone not found for the zoneUuid",
|
||||||
@@ -151,13 +170,14 @@ export const DuplicateFloatController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { widget, projectId, zoneUuid, index } = req.body;
|
const { widget, projectId, zoneUuid, index, versionId } = req.body;
|
||||||
if (
|
if (
|
||||||
!userId ||
|
!userId ||
|
||||||
!organization ||
|
!organization ||
|
||||||
!widget ||
|
!widget ||
|
||||||
!projectId ||
|
!projectId ||
|
||||||
!zoneUuid ||
|
!zoneUuid ||
|
||||||
|
!versionId ||
|
||||||
!index
|
!index
|
||||||
) {
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
@@ -169,6 +189,7 @@ export const DuplicateFloatController = async (
|
|||||||
organization,
|
organization,
|
||||||
widget,
|
widget,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
versionId,
|
||||||
index,
|
index,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
@@ -184,6 +205,11 @@ export const DuplicateFloatController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found for the zoneUuid":
|
case "Zone not found for the zoneUuid":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found for the zoneUuid",
|
message: "Zone not found for the zoneUuid",
|
||||||
@@ -228,7 +254,7 @@ export const GetFloatController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { projectId, zoneUuid } = req.params;
|
const { projectId, zoneUuid,versionId } = req.params;
|
||||||
if (!userId || !organization || !projectId || !zoneUuid) {
|
if (!userId || !organization || !projectId || !zoneUuid) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -236,7 +262,7 @@ export const GetFloatController = async (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const result = await GetFloatWidget({
|
const result = await GetFloatWidget({
|
||||||
organization,
|
organization,versionId,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
@@ -252,6 +278,11 @@ export const GetFloatController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found":
|
case "Zone not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
|
|||||||
@@ -13,8 +13,15 @@ export const AddPanelController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { panelOrder, zoneUuid, projectId } = req.body;
|
const { panelOrder, zoneUuid, projectId, versionId } = req.body;
|
||||||
if (!userId || !organization || !panelOrder || !zoneUuid || !projectId) {
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!panelOrder ||
|
||||||
|
!versionId ||
|
||||||
|
!zoneUuid ||
|
||||||
|
!projectId
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -24,6 +31,7 @@ export const AddPanelController = async (
|
|||||||
organization,
|
organization,
|
||||||
panelOrder,
|
panelOrder,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
versionId,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
@@ -39,6 +47,11 @@ export const AddPanelController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found":
|
case "Zone not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
@@ -74,8 +87,15 @@ export const DeletePanelController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { panelName, projectId, zoneUuid } = req.body;
|
const { panelName, projectId, zoneUuid, versionId } = req.body;
|
||||||
if (!userId || !organization || !panelName || !projectId || !zoneUuid) {
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!panelName ||
|
||||||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
|
!zoneUuid
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -86,6 +106,7 @@ export const DeletePanelController = async (
|
|||||||
panelName,
|
panelName,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -99,6 +120,11 @@ export const DeletePanelController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found":
|
case "Zone not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
@@ -133,8 +159,15 @@ export const ClearPanelController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { panelName, projectId, zoneUuid } = req.body;
|
const { panelName, projectId, zoneUuid, versionId } = req.body;
|
||||||
if (!userId || !organization || !panelName || !projectId || !zoneUuid) {
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!panelName ||
|
||||||
|
!versionId ||
|
||||||
|
!projectId ||
|
||||||
|
!zoneUuid
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -145,6 +178,7 @@ export const ClearPanelController = async (
|
|||||||
panelName,
|
panelName,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -158,6 +192,11 @@ export const ClearPanelController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found":
|
case "Zone not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
@@ -197,8 +236,15 @@ export const LockedPanelController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { projectId, zoneUuid, lockedPanel } = req.body;
|
const { projectId, zoneUuid, lockedPanel, versionId } = req.body;
|
||||||
if (!userId || !organization || !projectId || !zoneUuid || !lockedPanel) {
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
|
!zoneUuid ||
|
||||||
|
!lockedPanel
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -210,6 +256,7 @@ export const LockedPanelController = async (
|
|||||||
lockedPanel,
|
lockedPanel,
|
||||||
userId,
|
userId,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
@@ -222,6 +269,11 @@ export const LockedPanelController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found":
|
case "Zone not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ export const AddTemplateController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { template, projectId } = req.body;
|
const { template, projectId, versionId } = req.body;
|
||||||
if (!userId || !organization || !template || !projectId) {
|
if (!userId || !organization || !template || !projectId || !versionId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -25,6 +25,7 @@ export const AddTemplateController = async (
|
|||||||
template,
|
template,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -38,6 +39,11 @@ export const AddTemplateController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "TemplateID alreay exists":
|
case "TemplateID alreay exists":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "TemplateID alreay exists",
|
message: "TemplateID alreay exists",
|
||||||
@@ -72,8 +78,15 @@ export const AddTemToZoneController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { templateID, projectId, zoneUuid } = req.body;
|
const { templateID, projectId, zoneUuid, versionId } = req.body;
|
||||||
if (!userId || !organization || !templateID || !projectId || !zoneUuid) {
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!templateID ||
|
||||||
|
!versionId ||
|
||||||
|
!projectId ||
|
||||||
|
!zoneUuid
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -85,6 +98,7 @@ export const AddTemToZoneController = async (
|
|||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
@@ -97,6 +111,11 @@ export const AddTemToZoneController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found":
|
case "Zone not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
@@ -132,8 +151,8 @@ export const TemplateDeleteController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { templateID, projectId } = req.body;
|
const { templateID, projectId, versionId } = req.body;
|
||||||
if (!userId || !organization || !templateID || !projectId) {
|
if (!userId || !organization || !templateID || !projectId || !versionId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -144,6 +163,7 @@ export const TemplateDeleteController = async (
|
|||||||
organization,
|
organization,
|
||||||
templateID,
|
templateID,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
@@ -156,6 +176,11 @@ export const TemplateDeleteController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Template not found":
|
case "Template not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Template not found",
|
message: "Template not found",
|
||||||
@@ -190,7 +215,7 @@ export const GetTemplateController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { projectId } = req.params;
|
const { projectId,versionId } = req.params;
|
||||||
if (!userId || !organization || !projectId) {
|
if (!userId || !organization || !projectId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -199,7 +224,7 @@ export const GetTemplateController = async (
|
|||||||
}
|
}
|
||||||
const result = await GetAllTemplates({
|
const result = await GetAllTemplates({
|
||||||
organization,
|
organization,
|
||||||
userId,
|
userId,versionId,
|
||||||
projectId,
|
projectId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -213,6 +238,11 @@ export const GetTemplateController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "All Datas":
|
case "All Datas":
|
||||||
res.status(404).json([]);
|
res.status(404).json([]);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -13,8 +13,15 @@ export const AddWidgetController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { widget, projectId, zoneUuid } = req.body;
|
const { widget, projectId, zoneUuid, versionId } = req.body;
|
||||||
if (!userId || !organization || !widget || !projectId || !zoneUuid) {
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!widget ||
|
||||||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
|
!zoneUuid
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -26,6 +33,7 @@ export const AddWidgetController = async (
|
|||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -39,6 +47,11 @@ export const AddWidgetController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found for the zoneUuid":
|
case "Zone not found for the zoneUuid":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
@@ -88,8 +101,15 @@ export const WidgetDeleteController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { widgetID, projectId, zoneUuid } = req.body;
|
const { widgetID, projectId, zoneUuid, versionId } = req.body;
|
||||||
if (!userId || !organization || !widgetID || !projectId || !zoneUuid) {
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!widgetID ||
|
||||||
|
!versionId ||
|
||||||
|
!projectId ||
|
||||||
|
!zoneUuid
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -101,6 +121,7 @@ export const WidgetDeleteController = async (
|
|||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
@@ -113,6 +134,11 @@ export const WidgetDeleteController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found for the zoneUuid":
|
case "Zone not found for the zoneUuid":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found for the zoneUuid",
|
message: "Zone not found for the zoneUuid",
|
||||||
@@ -147,13 +173,14 @@ export const WidgetUpdateController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { values, projectId, zoneUuid, widgetID } = req.body;
|
const { values, projectId, zoneUuid, widgetID, versionId } = req.body;
|
||||||
if (
|
if (
|
||||||
!userId ||
|
!userId ||
|
||||||
!organization ||
|
!organization ||
|
||||||
!widgetID ||
|
!widgetID ||
|
||||||
!values ||
|
!values ||
|
||||||
!projectId ||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
!zoneUuid
|
!zoneUuid
|
||||||
) {
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
@@ -168,6 +195,7 @@ export const WidgetUpdateController = async (
|
|||||||
widgetID,
|
widgetID,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
@@ -180,6 +208,12 @@ export const WidgetUpdateController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found for the zoneUuid":
|
case "Zone not found for the zoneUuid":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found for the zoneUuid",
|
message: "Zone not found for the zoneUuid",
|
||||||
@@ -214,8 +248,9 @@ export const GetWidgetController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { projectId, zoneUuid, widgetID } = req.query as {
|
const { projectId, zoneUuid, widgetID, versionId } = req.query as {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
widgetID: string;
|
widgetID: string;
|
||||||
};
|
};
|
||||||
@@ -230,6 +265,7 @@ export const GetWidgetController = async (
|
|||||||
zoneUuid,
|
zoneUuid,
|
||||||
widgetID,
|
widgetID,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -243,6 +279,12 @@ export const GetWidgetController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found for the zoneUuid":
|
case "Zone not found for the zoneUuid":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found for the zoneUuid",
|
message: "Zone not found for the zoneUuid",
|
||||||
|
|||||||
@@ -13,8 +13,15 @@ export const Add3dWidgetController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { widget, projectId, zoneUuid } = req.body;
|
const { widget, projectId, zoneUuid, versionId } = req.body;
|
||||||
if (!userId || !organization || !widget || !projectId || !zoneUuid) {
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!widget ||
|
||||||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
|
!zoneUuid
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -26,6 +33,7 @@ export const Add3dWidgetController = async (
|
|||||||
userId,
|
userId,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -39,6 +47,11 @@ export const Add3dWidgetController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found for the zoneUuid":
|
case "Zone not found for the zoneUuid":
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
@@ -83,7 +96,7 @@ export const Update3DwidgetController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { id, position, rotation, projectId, zoneUuid } = req.body;
|
const { id, position, rotation, projectId, zoneUuid, versionId } = req.body;
|
||||||
if (
|
if (
|
||||||
!userId ||
|
!userId ||
|
||||||
!organization ||
|
!organization ||
|
||||||
@@ -91,6 +104,7 @@ export const Update3DwidgetController = async (
|
|||||||
!position ||
|
!position ||
|
||||||
!rotation ||
|
!rotation ||
|
||||||
!projectId ||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
!zoneUuid
|
!zoneUuid
|
||||||
) {
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
@@ -106,6 +120,7 @@ export const Update3DwidgetController = async (
|
|||||||
userId,
|
userId,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
@@ -118,6 +133,11 @@ export const Update3DwidgetController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found":
|
case "Zone not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
@@ -157,8 +177,15 @@ export const Delete3DwidgetController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { id, projectId, zoneUuid } = req.body;
|
const { id, projectId, zoneUuid, versionId } = req.body;
|
||||||
if (!userId || !organization || !id || !projectId || !zoneUuid) {
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!id ||
|
||||||
|
!projectId ||
|
||||||
|
!versionId ||
|
||||||
|
!zoneUuid
|
||||||
|
) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
});
|
});
|
||||||
@@ -170,6 +197,7 @@ export const Delete3DwidgetController = async (
|
|||||||
userId,
|
userId,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "User not found":
|
case "User not found":
|
||||||
@@ -182,6 +210,11 @@ export const Delete3DwidgetController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found":
|
case "Zone not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
@@ -221,7 +254,7 @@ export const Get3DWidgetController = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { userId, organization } = req.user || {};
|
const { userId, organization } = req.user || {};
|
||||||
const { projectId, zoneUuid } = req.params;
|
const { projectId, zoneUuid, versionId } = req.params;
|
||||||
if (!userId || !organization || !projectId) {
|
if (!userId || !organization || !projectId) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
message: "All fields are required",
|
message: "All fields are required",
|
||||||
@@ -232,6 +265,7 @@ export const Get3DWidgetController = async (
|
|||||||
organization,
|
organization,
|
||||||
userId,
|
userId,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
versionId,
|
||||||
projectId,
|
projectId,
|
||||||
});
|
});
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
@@ -245,6 +279,11 @@ export const Get3DWidgetController = async (
|
|||||||
message: "Project not found",
|
message: "Project not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "Version Data not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Version Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "Zone not found":
|
case "Zone not found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
message: "Zone not found",
|
message: "Zone not found",
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import { restoreSnapshotService } from "../../../../shared/services/yjs/snapshot.ts";
|
||||||
|
import { clearSnapshotController, restoreYDocFromAutoSave } from "../../../../shared/services/yjs/auto-save.ts";
|
||||||
|
|
||||||
|
export const autoSaveRestore = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, versionId, projectId, } = req.body;
|
||||||
|
if (!organization || !versionId ) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await restoreYDocFromAutoSave({ organization, versionId,projectId });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Snapshot not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Snapshot not found",
|
||||||
|
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
AutoSave: result,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const clearAutoSaveRestore = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, versionId, projectId, } = req.body;
|
||||||
|
if (!organization || !versionId ) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await clearSnapshotController({ organization, versionId,projectId });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Snapshot not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Snapshot not found",
|
||||||
|
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Snapshot autosave deleted",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import { listSnapshotService, restoreSnapshotService } from "../../../../shared/services/yjs/snapshot.ts";
|
||||||
|
|
||||||
|
export const SnapshotRestore = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, snapshotId, userId,ydoc } = req.body;
|
||||||
|
if (!organization || !snapshotId ) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await restoreSnapshotService({ organization, snapshotId,ydoc });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Snapshot not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Snapshot not found",
|
||||||
|
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
Snapshot: result,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const SnapshotList = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { projectId, versionId, organization } = req.body;
|
||||||
|
if (!organization || !versionId ) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await listSnapshotService({ projectId, versionId, organization});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Snapshot not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Snapshot not found",
|
||||||
|
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
Snapshot: result,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -10,6 +10,6 @@ const V1Aisle = express.Router();
|
|||||||
|
|
||||||
V1Aisle.post("/UpsertAisle", tokenValidator, UpsertAisleController);
|
V1Aisle.post("/UpsertAisle", tokenValidator, UpsertAisleController);
|
||||||
V1Aisle.patch("/DeleteAisle", tokenValidator, DeleteAisleController);
|
V1Aisle.patch("/DeleteAisle", tokenValidator, DeleteAisleController);
|
||||||
V1Aisle.get("/Aisles/:projectId", tokenValidator, AllAisleController);
|
V1Aisle.get("/Aisles/:projectId/:versionId", tokenValidator, AllAisleController);
|
||||||
|
|
||||||
export default V1Aisle;
|
export default V1Aisle;
|
||||||
|
|||||||
@@ -15,20 +15,20 @@ V1Zone.post("/zones", tokenValidator, CreateZoneController);
|
|||||||
V1Zone.patch("/zones/delete", tokenValidator, DeleteZoneController);
|
V1Zone.patch("/zones/delete", tokenValidator, DeleteZoneController);
|
||||||
|
|
||||||
V1Zone.get(
|
V1Zone.get(
|
||||||
"/zones/visualization/:projectId",
|
"/zones/visualization/:projectId/:versionId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
VizZoneController
|
VizZoneController
|
||||||
);
|
);
|
||||||
|
|
||||||
V1Zone.get(
|
V1Zone.get(
|
||||||
"/zones/:projectId/:zoneUuid",
|
"/zones/:projectId/:zoneUuid/:versionId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
ZoneDataController
|
ZoneDataController
|
||||||
);
|
);
|
||||||
V1Zone.get(
|
V1Zone.get(
|
||||||
"/zones/panel/:projectId/:zoneUuid",
|
"/zones/panel/:projectId/:zoneUuid/:versionId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
SingleZonePanelController
|
SingleZonePanelController
|
||||||
);
|
);
|
||||||
V1Zone.get("/zones/:projectId", tokenValidator, GetZoneController);
|
V1Zone.get("/zones/:projectId/:versionId", tokenValidator, GetZoneController);
|
||||||
export default V1Zone;
|
export default V1Zone;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ V1Asset.patch(
|
|||||||
AssetUpdatePosRotController
|
AssetUpdatePosRotController
|
||||||
);
|
);
|
||||||
V1Asset.get(
|
V1Asset.get(
|
||||||
"/floorAssets/:projectId",
|
"/floorAssets/:projectId/:versionId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetAssetController
|
GetAssetController
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -16,5 +16,5 @@ V1Line.post("/points", tokenValidator, UpdateLineController);
|
|||||||
V1Line.patch("/layers/delete", tokenValidator, DeleteLayerController);
|
V1Line.patch("/layers/delete", tokenValidator, DeleteLayerController);
|
||||||
V1Line.patch("/lines/delete", tokenValidator, DeleteLineController);
|
V1Line.patch("/lines/delete", tokenValidator, DeleteLineController);
|
||||||
V1Line.patch("/points/delete", tokenValidator, DeleteLinePointsController);
|
V1Line.patch("/points/delete", tokenValidator, DeleteLinePointsController);
|
||||||
V1Line.get("/lines/:projectId", tokenValidator, GetLinesController);
|
V1Line.get("/lines/:projectId/:versionId", tokenValidator, GetLinesController);
|
||||||
export default V1Line;
|
export default V1Line;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ V1Wall.patch(
|
|||||||
WallDelete
|
WallDelete
|
||||||
);
|
);
|
||||||
V1Wall.get(
|
V1Wall.get(
|
||||||
"/walls/:projectId",
|
"/walls/:projectId/:versionId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
WallGet
|
WallGet
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ V1Product.get("/EventsByProduct", tokenValidator, GetProductEventDatas);
|
|||||||
V1Product.patch("/DeleteEvent", tokenValidator, DeleteEventsController);
|
V1Product.patch("/DeleteEvent", tokenValidator, DeleteEventsController);
|
||||||
V1Product.patch("/DeleteProduct", tokenValidator, DeleteProductController);
|
V1Product.patch("/DeleteProduct", tokenValidator, DeleteProductController);
|
||||||
V1Product.get(
|
V1Product.get(
|
||||||
"/ProjectProducts/:projectId",
|
"/ProjectProducts/:projectId/:versionId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
ProjectBasedProductsController
|
ProjectBasedProductsController
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
SignOutController,
|
SignOutController,
|
||||||
SignupController,
|
SignupController,
|
||||||
} from "../v1Controllers/authController/authControllers.ts";
|
} from "../v1Controllers/authController/authControllers.ts";
|
||||||
import { versioncontroller } from "../v1Controllers/versionController/versioncontroller.ts";
|
|
||||||
|
|
||||||
const Authrouter = express.Router();
|
const Authrouter = express.Router();
|
||||||
Authrouter.post("/Auth/signup", SignupController);
|
Authrouter.post("/Auth/signup", SignupController);
|
||||||
@@ -14,6 +13,5 @@ Authrouter.post("/Auth/login", SignInController);
|
|||||||
Authrouter.post("/Auth/logout", SignOutController);
|
Authrouter.post("/Auth/logout", SignOutController);
|
||||||
Authrouter.post("/Auth/forgetPassword", ForgetPasswordController);
|
Authrouter.post("/Auth/forgetPassword", ForgetPasswordController);
|
||||||
Authrouter.post("/Auth/reset-password/:resetToken", ResetPasswordController);
|
Authrouter.post("/Auth/reset-password/:resetToken", ResetPasswordController);
|
||||||
Authrouter.post("/Auth/versionData", versioncontroller);
|
|
||||||
|
|
||||||
export default Authrouter;
|
export default Authrouter;
|
||||||
|
|||||||
12
src/api-server/V1/v1Routes/dummyroutes.ts
Normal file
12
src/api-server/V1/v1Routes/dummyroutes.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||||
|
import { AddProductControllerdumy } from "../v1Controllers/dummycontroller.ts/productdummycontroller.ts";
|
||||||
|
|
||||||
|
const Dummyrouter = express.Router();
|
||||||
|
Dummyrouter.post(
|
||||||
|
"/ProductUpsertdummy",
|
||||||
|
tokenValidator,
|
||||||
|
AddProductControllerdumy
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Dummyrouter;
|
||||||
@@ -4,15 +4,11 @@ import {
|
|||||||
recentDataController,
|
recentDataController,
|
||||||
searchProjectController,
|
searchProjectController,
|
||||||
searchTrashProjectController,
|
searchTrashProjectController,
|
||||||
} from "../../V1/v1Controllers/homeController/v1homeController.ts";
|
} from "../v1Controllers/homeController/v1homeController.ts";
|
||||||
|
|
||||||
const V1homeRoutes = express.Router();
|
const V1homeRoutes = express.Router();
|
||||||
|
|
||||||
V1homeRoutes.get(
|
V1homeRoutes.get("/RecentlyViewed", tokenValidator, recentDataController);
|
||||||
"/RecentlyViewed",
|
|
||||||
tokenValidator,
|
|
||||||
recentDataController
|
|
||||||
);
|
|
||||||
V1homeRoutes.get(
|
V1homeRoutes.get(
|
||||||
"/search/searchProjects",
|
"/search/searchProjects",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
RemoveProject,
|
RemoveProject,
|
||||||
updateProjectController,
|
updateProjectController,
|
||||||
ViewData,
|
ViewData,
|
||||||
} from "../../V1/v1Controllers/projectController/v1projectController.ts";
|
} from "../v1Controllers/projectController/v1projectController.ts";
|
||||||
import { tokenValidator } from "../../../shared/utils/token.ts";
|
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||||
|
|
||||||
const V1projectRouter = express.Router();
|
const V1projectRouter = express.Router();
|
||||||
@@ -17,11 +17,7 @@ V1projectRouter.post(
|
|||||||
tokenValidator,
|
tokenValidator,
|
||||||
ProjectDuplicateController
|
ProjectDuplicateController
|
||||||
);
|
);
|
||||||
V1projectRouter.get(
|
V1projectRouter.get("/Projects", tokenValidator, GetProjects);
|
||||||
"/Projects",
|
|
||||||
tokenValidator,
|
|
||||||
GetProjects
|
|
||||||
);
|
|
||||||
V1projectRouter.patch(
|
V1projectRouter.patch(
|
||||||
"/Projects/Archive/:projectId",
|
"/Projects/Archive/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
@@ -33,10 +29,6 @@ V1projectRouter.patch(
|
|||||||
tokenValidator,
|
tokenValidator,
|
||||||
updateProjectController
|
updateProjectController
|
||||||
);
|
);
|
||||||
V1projectRouter.get(
|
V1projectRouter.get("/Project/:projectId", tokenValidator, ViewData);
|
||||||
"/Project/:projectId",
|
|
||||||
tokenValidator,
|
|
||||||
ViewData
|
|
||||||
);
|
|
||||||
|
|
||||||
export default V1projectRouter;
|
export default V1projectRouter;
|
||||||
|
|||||||
35
src/api-server/V1/v1Routes/v1-threadRoutes.ts
Normal file
35
src/api-server/V1/v1Routes/v1-threadRoutes.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||||
|
import { getALLthreads, threadComment, threadCommentDelete, threadCreate, threaddelete, threadUpdateTitle } from "../v1Controllers/threadController/threadController.ts";
|
||||||
|
const V1ThreadRoutes = express.Router();
|
||||||
|
V1ThreadRoutes.post(
|
||||||
|
"/upsetThread/",
|
||||||
|
tokenValidator,
|
||||||
|
threadCreate
|
||||||
|
);
|
||||||
|
V1ThreadRoutes.patch(
|
||||||
|
"/Thread/delete",
|
||||||
|
tokenValidator,
|
||||||
|
threaddelete
|
||||||
|
);
|
||||||
|
V1ThreadRoutes.patch(
|
||||||
|
"/Thread/updateTitle",
|
||||||
|
tokenValidator,
|
||||||
|
threadUpdateTitle
|
||||||
|
);
|
||||||
|
V1ThreadRoutes.post(
|
||||||
|
"/Thread/addComment",
|
||||||
|
tokenValidator,
|
||||||
|
threadComment
|
||||||
|
);
|
||||||
|
V1ThreadRoutes.patch(
|
||||||
|
"/Thread/deleteComment",
|
||||||
|
tokenValidator,
|
||||||
|
threadCommentDelete
|
||||||
|
);
|
||||||
|
V1ThreadRoutes.get(
|
||||||
|
"/Threads/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
getALLthreads
|
||||||
|
);
|
||||||
|
export default V1ThreadRoutes
|
||||||
@@ -4,23 +4,11 @@ import {
|
|||||||
DeleteTrashData,
|
DeleteTrashData,
|
||||||
GetTrashList,
|
GetTrashList,
|
||||||
RestoreTrash,
|
RestoreTrash,
|
||||||
} from "../../V1/v1Controllers/trashController/v1trashController.ts";
|
} from "../v1Controllers/trashController/v1trashController.ts";
|
||||||
|
|
||||||
const V1TrashRoutes = express.Router();
|
const V1TrashRoutes = express.Router();
|
||||||
V1TrashRoutes.get(
|
V1TrashRoutes.get("/TrashItems", tokenValidator, GetTrashList);
|
||||||
"/TrashItems",
|
|
||||||
tokenValidator,
|
|
||||||
GetTrashList
|
|
||||||
);
|
|
||||||
|
|
||||||
V1TrashRoutes.patch(
|
V1TrashRoutes.patch("/Trash/restore", tokenValidator, RestoreTrash);
|
||||||
"/Trash/restore",
|
V1TrashRoutes.patch("/Trash/Delete", tokenValidator, DeleteTrashData);
|
||||||
tokenValidator,
|
|
||||||
RestoreTrash
|
|
||||||
);
|
|
||||||
V1TrashRoutes.patch(
|
|
||||||
"/Trash/Delete",
|
|
||||||
tokenValidator,
|
|
||||||
DeleteTrashData
|
|
||||||
);
|
|
||||||
export default V1TrashRoutes;
|
export default V1TrashRoutes;
|
||||||
|
|||||||
21
src/api-server/V1/v1Routes/v1-versionRoutes.ts
Normal file
21
src/api-server/V1/v1Routes/v1-versionRoutes.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
GetversionHistory,
|
||||||
|
GetversionList,
|
||||||
|
rollbackcontroller,
|
||||||
|
versionAddcontroller,
|
||||||
|
} from "../v1Controllers/versionController/versioncontroller.ts";
|
||||||
|
|
||||||
|
const V1versionRoutes = express.Router();
|
||||||
|
|
||||||
|
V1versionRoutes.post("/generateVersion", tokenValidator, versionAddcontroller);
|
||||||
|
V1versionRoutes.get(
|
||||||
|
"/version/:versionId/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
GetversionList
|
||||||
|
);
|
||||||
|
V1versionRoutes.get("/:projectId/versions", tokenValidator, GetversionHistory);
|
||||||
|
V1versionRoutes.post("/version/rollback", tokenValidator, rollbackcontroller);
|
||||||
|
|
||||||
|
export default V1versionRoutes;
|
||||||
@@ -21,7 +21,7 @@ V1FloatWidget.patch(
|
|||||||
DeleteFloatController
|
DeleteFloatController
|
||||||
);
|
);
|
||||||
V1FloatWidget.get(
|
V1FloatWidget.get(
|
||||||
"/floatWidgets/:zoneUuid/:projectId",
|
"/floatWidgets/:zoneUuid/:projectId/:versionId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetFloatController
|
GetFloatController
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ V1Template.post(
|
|||||||
AddTemToZoneController
|
AddTemToZoneController
|
||||||
);
|
);
|
||||||
V1Template.get(
|
V1Template.get(
|
||||||
"/template/data/:projectId",
|
"/template/data/:projectId/:versionId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetTemplateController
|
GetTemplateController
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ V1Widget3d.patch(
|
|||||||
Update3DwidgetController
|
Update3DwidgetController
|
||||||
);
|
);
|
||||||
V1Widget3d.get(
|
V1Widget3d.get(
|
||||||
"/widget3d/data/:zoneUuid/:projectId",
|
"/widget3d/data/:zoneUuid/:projectId/:versionId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
Get3DWidgetController
|
Get3DWidgetController
|
||||||
);
|
);
|
||||||
|
|||||||
17
src/api-server/V1/v1Routes/yjsRoutes.ts/autosaveRoutes.ts
Normal file
17
src/api-server/V1/v1Routes/yjsRoutes.ts/autosaveRoutes.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import express from "express";
|
||||||
|
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import { autoSaveRestore, clearAutoSaveRestore } from "../../v1Controllers/yjsController/auto-saveControlle.ts";
|
||||||
|
const V1AutoSaveRoutes = express.Router();
|
||||||
|
V1AutoSaveRoutes.get(
|
||||||
|
"/restoreAutoSave/",
|
||||||
|
// tokenValidator,
|
||||||
|
autoSaveRestore
|
||||||
|
);
|
||||||
|
V1AutoSaveRoutes.post(
|
||||||
|
"/clearSnapAutoSave/",
|
||||||
|
// tokenValidator,
|
||||||
|
clearAutoSaveRestore
|
||||||
|
);
|
||||||
|
|
||||||
|
export default V1AutoSaveRoutes
|
||||||
16
src/api-server/V1/v1Routes/yjsRoutes.ts/snapshotRoutes.ts
Normal file
16
src/api-server/V1/v1Routes/yjsRoutes.ts/snapshotRoutes.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import express from "express";
|
||||||
|
|
||||||
|
import { SnapshotList, SnapshotRestore } from "../../v1Controllers/yjsController/yjsSnapController.ts";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
const V1SnapshotRoutes = express.Router();
|
||||||
|
V1SnapshotRoutes.get(
|
||||||
|
"/restoreSnap/",
|
||||||
|
// tokenValidator,
|
||||||
|
SnapshotRestore
|
||||||
|
);
|
||||||
|
V1SnapshotRoutes.get(
|
||||||
|
"/listSnap/",
|
||||||
|
// tokenValidator,
|
||||||
|
SnapshotList
|
||||||
|
);
|
||||||
|
export default V1SnapshotRoutes
|
||||||
@@ -38,6 +38,11 @@ import V1Widget from "./V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts";
|
|||||||
import V1Widget3d from "./V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts";
|
import V1Widget3d from "./V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts";
|
||||||
import V1Product from "./V1/v1Routes/SimulationRoutes/v1-ProductRoutes.ts";
|
import V1Product from "./V1/v1Routes/SimulationRoutes/v1-ProductRoutes.ts";
|
||||||
import V1Aisle from "./V1/v1Routes/BuilderRoutes/V1-AisleRoutes.ts";
|
import V1Aisle from "./V1/v1Routes/BuilderRoutes/V1-AisleRoutes.ts";
|
||||||
|
import V1ThreadRoutes from "./V1/v1Routes/v1-threadRoutes.ts";
|
||||||
|
import V1versionRoutes from "./V1/v1Routes/v1-versionRoutes.ts";
|
||||||
|
import Dummyrouter from "./V1/v1Routes/dummyroutes.ts";
|
||||||
|
import V1SnapshotRoutes from "./V1/v1Routes/yjsRoutes.ts/snapshotRoutes.ts";
|
||||||
|
import V1AutoSaveRoutes from "./V1/v1Routes/yjsRoutes.ts/autosaveRoutes.ts";
|
||||||
redis;
|
redis;
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
@@ -90,5 +95,10 @@ app.use("/api/V1", V1Widget);
|
|||||||
app.use("/api/V1", V1Widget3d);
|
app.use("/api/V1", V1Widget3d);
|
||||||
app.use("/api/V1", V1Product);
|
app.use("/api/V1", V1Product);
|
||||||
app.use("/api/V1", V1Aisle);
|
app.use("/api/V1", V1Aisle);
|
||||||
|
app.use("/api/V1", V1ThreadRoutes);
|
||||||
|
app.use("/api/V1", V1versionRoutes);
|
||||||
|
app.use("/api/V1", Dummyrouter);
|
||||||
|
app.use("/api/V1", V1SnapshotRoutes);
|
||||||
|
app.use("/api/V1", V1AutoSaveRoutes);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
@@ -5,13 +5,29 @@ import fs from "fs";
|
|||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
|
||||||
let swaggerDocument = {};
|
let swaggerDocument = {};
|
||||||
|
let swaggerNewVersionDocument = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
swaggerDocument = JSON.parse(fs.readFileSync("swagger-output.json", "utf-8"));
|
swaggerDocument = JSON.parse(fs.readFileSync("swagger-output.json", "utf-8"));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error loading Swagger JSON:", error);
|
console.error("Error loading Swagger JSON:", error);
|
||||||
}
|
}
|
||||||
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
// app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||||
|
app.use(
|
||||||
|
"/api-docs",
|
||||||
|
swaggerUi.serveFiles(swaggerDocument),
|
||||||
|
swaggerUi.setup(swaggerDocument)
|
||||||
|
);
|
||||||
|
// app.use(
|
||||||
|
// "/NewVersion/api-docs",
|
||||||
|
// swaggerUi.serve,
|
||||||
|
// swaggerUi.setup(swaggerNewVersionDocument)
|
||||||
|
// );
|
||||||
|
app.use(
|
||||||
|
"/NewVersion/api-docs",
|
||||||
|
swaggerUi.serveFiles(swaggerNewVersionDocument),
|
||||||
|
swaggerUi.setup(swaggerNewVersionDocument)
|
||||||
|
);
|
||||||
const organization = process.env.ORGANIZATION_NAME || "defaultOrganization";
|
const organization = process.env.ORGANIZATION_NAME || "defaultOrganization";
|
||||||
|
|
||||||
if (!organization) {
|
if (!organization) {
|
||||||
@@ -22,4 +38,7 @@ const PORT = process.env.API_PORT;
|
|||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
console.log(`API-Server running on http://localhost:${PORT}`);
|
console.log(`API-Server running on http://localhost:${PORT}`);
|
||||||
console.log(`Swagger UI available at http://localhost:${PORT}/api-docs`);
|
console.log(`Swagger UI available at http://localhost:${PORT}/api-docs`);
|
||||||
|
console.log(
|
||||||
|
`Swagger UI available at http://localhost:${PORT}/NewVersion/api-docs`
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Schema, Document } from "mongoose";
|
|||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
import { User } from "../Auth/userAuthModel.ts";
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
import { Project } from "../Project/project-model.ts";
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
type PointTypes = "Aisle";
|
type PointTypes = "Aisle";
|
||||||
|
|
||||||
export interface Point {
|
export interface Point {
|
||||||
@@ -116,6 +116,7 @@ export interface Aisle extends Document {
|
|||||||
aisleUuid: string;
|
aisleUuid: string;
|
||||||
points: [Point, Point];
|
points: [Point, Point];
|
||||||
projectId: Project["_id"];
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
createdBy: User["_id"];
|
createdBy: User["_id"];
|
||||||
type: AisleType;
|
type: AisleType;
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
@@ -126,6 +127,7 @@ const AisleSchema: Schema = new Schema(
|
|||||||
aisleUuid: { type: String, required: true },
|
aisleUuid: { type: String, required: true },
|
||||||
createdBy: { type: Schema.Types.ObjectId, ref: "User" },
|
createdBy: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
points: {
|
points: {
|
||||||
type: [
|
type: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,22 +1,41 @@
|
|||||||
import mongoose, { Schema } from "mongoose";
|
import mongoose, { Schema } from "mongoose";
|
||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
const positionSchema = new mongoose.Schema({
|
const positionSchema = new mongoose.Schema({
|
||||||
x: { type: Number },
|
x: { type: Number },
|
||||||
y: { type: Number },
|
y: { type: Number },
|
||||||
z: { type: Number },
|
z: { type: Number },
|
||||||
});
|
});
|
||||||
|
|
||||||
const Vector3 = new mongoose.Schema({
|
const vector3Schema = new mongoose.Schema({
|
||||||
position: { type: positionSchema, required: false },
|
position: { type: positionSchema, required: false },
|
||||||
uuid: { type: String, required: false },
|
uuid: { type: String, required: false },
|
||||||
});
|
});
|
||||||
|
export interface Vector3 {
|
||||||
|
uuid: string;
|
||||||
|
position: {
|
||||||
|
x: { type: Number };
|
||||||
|
y: { type: Number };
|
||||||
|
z: { type: Number };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ILines extends Document {
|
||||||
|
userId: User["_id"];
|
||||||
|
projectId: User["_id"];
|
||||||
|
versionId: User["_id"];
|
||||||
|
layer: number;
|
||||||
|
line: Vector3[];
|
||||||
|
type: string;
|
||||||
|
isArchive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
const LineSchema = new mongoose.Schema({
|
const LineSchema = new mongoose.Schema({
|
||||||
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
layer: { type: Number, required: true },
|
layer: { type: Number, required: true },
|
||||||
line: { type: [Vector3], required: true },
|
line: { type: [vector3Schema], required: true },
|
||||||
type: { type: String, required: false },
|
type: { type: String, required: false },
|
||||||
isArchive: { type: Boolean, default: false },
|
isArchive: { type: Boolean, default: false },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export interface WallItems extends Document {
|
|||||||
position: [];
|
position: [];
|
||||||
quaternion: [];
|
quaternion: [];
|
||||||
scale: [];
|
scale: [];
|
||||||
|
isArchive: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wallItemsSchema: Schema = new Schema({
|
const wallItemsSchema: Schema = new Schema({
|
||||||
@@ -27,6 +28,7 @@ const wallItemsSchema: Schema = new Schema({
|
|||||||
modelName: { type: String },
|
modelName: { type: String },
|
||||||
type: { type: String },
|
type: { type: String },
|
||||||
csgposition: { type: Array },
|
csgposition: { type: Array },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
csgscale: { type: Array },
|
csgscale: { type: Array },
|
||||||
position: { type: Array },
|
position: { type: Array },
|
||||||
quaternion: { type: Array },
|
quaternion: { type: Array },
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ import { Document, Schema } from "mongoose";
|
|||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
import { User } from "../Auth/userAuthModel.ts";
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
import { Project } from "../Project/project-model.ts";
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
export interface Environment extends Document {
|
export interface Environment extends Document {
|
||||||
userId: User["_id"];
|
userId: User["_id"];
|
||||||
projectId: Project["_id"];
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
roofVisibility: boolean;
|
roofVisibility: boolean;
|
||||||
wallVisibility: boolean;
|
wallVisibility: boolean;
|
||||||
renderDistance: number;
|
renderDistance: number;
|
||||||
@@ -16,6 +18,7 @@ export interface Environment extends Document {
|
|||||||
const environmentSchema: Schema = new Schema({
|
const environmentSchema: Schema = new Schema({
|
||||||
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
roofVisibility: { type: Boolean, default: false },
|
roofVisibility: { type: Boolean, default: false },
|
||||||
wallVisibility: { type: Boolean, default: false },
|
wallVisibility: { type: Boolean, default: false },
|
||||||
shadowVisibility: { type: Boolean, default: false },
|
shadowVisibility: { type: Boolean, default: false },
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
import { User } from "../Auth/userAuthModel.ts";
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
|
||||||
export interface Project extends Document {
|
export interface Project extends Document {
|
||||||
projectUuid: string;
|
projectUuid: string;
|
||||||
@@ -13,7 +14,7 @@ export interface Project extends Document {
|
|||||||
DeletedAt: Date;
|
DeletedAt: Date;
|
||||||
isViewed: number;
|
isViewed: number;
|
||||||
total_versions: string;
|
total_versions: string;
|
||||||
Present_version: string;
|
Present_version: Version["_id"];
|
||||||
}
|
}
|
||||||
const projectSchema: Schema = new Schema(
|
const projectSchema: Schema = new Schema(
|
||||||
{
|
{
|
||||||
@@ -27,7 +28,7 @@ const projectSchema: Schema = new Schema(
|
|||||||
isDeleted: { type: Boolean, default: false },
|
isDeleted: { type: Boolean, default: false },
|
||||||
isViewed: { type: Number },
|
isViewed: { type: Number },
|
||||||
total_versions: { type: String },
|
total_versions: { type: String },
|
||||||
Present_version: { type: String },
|
Present_version: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
import { Project } from "../Project/project-model.ts";
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
interface AssetEventSchema {
|
interface AssetEventSchema {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
modelName: string;
|
modelName: string;
|
||||||
@@ -124,7 +125,7 @@ interface StorageEventSchema extends AssetEventSchema {
|
|||||||
type: "storageUnit";
|
type: "storageUnit";
|
||||||
point: StoragePointSchema;
|
point: StoragePointSchema;
|
||||||
}
|
}
|
||||||
interface IPointModel extends Document {
|
export interface IPointModel extends Document {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
modelName: string;
|
modelName: string;
|
||||||
position: [number];
|
position: [number];
|
||||||
@@ -132,6 +133,7 @@ interface IPointModel extends Document {
|
|||||||
state: string;
|
state: string;
|
||||||
productUuid: string;
|
productUuid: string;
|
||||||
projectId: Project["_id"];
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
type: "transfer" | "vehicle" | "roboticArm" | "machine" | "storageUnit";
|
type: "transfer" | "vehicle" | "roboticArm" | "machine" | "storageUnit";
|
||||||
speed: number;
|
speed: number;
|
||||||
@@ -167,6 +169,7 @@ const BaseEventSchema = new Schema<IPointModel>(
|
|||||||
type: Schema.Types.Mixed,
|
type: Schema.Types.Mixed,
|
||||||
},
|
},
|
||||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
productUuid: { type: String, required: true },
|
productUuid: { type: String, required: true },
|
||||||
isArchive: { type: Boolean, default: false },
|
isArchive: { type: Boolean, default: false },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,38 +4,45 @@ import { Project } from "../Project/project-model.ts";
|
|||||||
import { Version } from "../Version/versionModel.ts";
|
import { Version } from "../Version/versionModel.ts";
|
||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
interface IComment {
|
interface IComment {
|
||||||
userId: User["_id"];
|
userId: User["_id"];
|
||||||
comment: string;
|
comment: string;
|
||||||
timestamp:number
|
isArchive: boolean;
|
||||||
|
createdAt: number
|
||||||
}
|
}
|
||||||
export interface IThread extends Document {
|
export interface IThread extends Document {
|
||||||
projectId: Project["_id"];
|
projectId: Project["_id"];
|
||||||
versionId: Version["_id"];
|
versionId: Version["_id"];
|
||||||
state: string;
|
state: string;
|
||||||
commentId: string;
|
threadTitle: string;
|
||||||
createdBy: User["_id"];
|
createdBy: User["_id"];
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
lastUpdatedAt: string;
|
lastUpdatedAt: string;
|
||||||
position: [number, number, number];
|
position: [number, number, number];
|
||||||
rotation: [number, number, number];
|
rotation: [number, number, number];
|
||||||
replies: IComment[];
|
comments: IComment[];
|
||||||
|
isArchive: boolean;
|
||||||
|
isResolved: boolean;
|
||||||
|
|
||||||
}
|
}
|
||||||
const CommentSchema = new Schema<IComment>(
|
const CommentSchema = new Schema<IComment>(
|
||||||
{
|
{
|
||||||
userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },
|
userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },
|
||||||
comment: { type: String,},
|
comment: { type: String, },
|
||||||
timestamp:{
|
isArchive: { type: Boolean, default: false },
|
||||||
type: Number,
|
createdAt: {
|
||||||
default:Date.now()}
|
type: Number,
|
||||||
|
default: Date.now()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const threadSchema = new Schema<IThread>({
|
const threadSchema = new Schema<IThread>({
|
||||||
projectId: { type: Schema.Types.ObjectId, ref: 'Project', required: true },
|
projectId: { type: Schema.Types.ObjectId, ref: 'Project', required: true },
|
||||||
state: { type: String, enum: ['active', 'inactive'], required: true },
|
state: { type: String, enum: ['active', 'inactive'], required: true },
|
||||||
commentId: { type: String, },
|
threadTitle: { type: String, },
|
||||||
createdBy: { type: Schema.Types.ObjectId, ref: 'User', required: true },
|
createdBy: { type: Schema.Types.ObjectId, ref: 'User', required: true },
|
||||||
createdAt: { type: Number,},
|
createdAt: { type: Number, },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
isResolved: { type: Boolean, default: false },
|
||||||
lastUpdatedAt: { type: String, },
|
lastUpdatedAt: { type: String, },
|
||||||
position: {
|
position: {
|
||||||
type: [Number],
|
type: [Number],
|
||||||
@@ -45,7 +52,7 @@ const threadSchema = new Schema<IThread>({
|
|||||||
type: [Number],
|
type: [Number],
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
replies: { type: [CommentSchema ], default: [] },
|
comments: { type: [CommentSchema], default: [] },
|
||||||
});
|
});
|
||||||
|
|
||||||
const ThreadModel = (db: string) => {
|
const ThreadModel = (db: string) => {
|
||||||
|
|||||||
@@ -4,15 +4,23 @@ import { Project } from "../Project/project-model.ts";
|
|||||||
import { User } from "../Auth/userAuthModel.ts";
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
export interface Version extends Document {
|
export interface Version extends Document {
|
||||||
versionName: string;
|
versionName: string;
|
||||||
|
previous_Version: string;
|
||||||
projectId: Project["_id"];
|
projectId: Project["_id"];
|
||||||
createdBy: User["_id"];
|
createdBy: User["_id"];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
version: number;
|
version: number;
|
||||||
|
rollBackComment: string;
|
||||||
|
description: string;
|
||||||
|
parentVersionID: Version["_id"];
|
||||||
}
|
}
|
||||||
const versionSchema: Schema = new Schema(
|
const versionSchema: Schema = new Schema(
|
||||||
{
|
{
|
||||||
versionName: { type: String },
|
versionName: { type: String, default: "" },
|
||||||
|
rollBackComment: { type: String },
|
||||||
|
description: { type: String, default: "" },
|
||||||
version: { type: Number },
|
version: { type: Number },
|
||||||
|
parentVersionID: { type: Schema.Types.ObjectId, ref: "version" },
|
||||||
|
previous_Version: { type: String },
|
||||||
isArchive: { type: Boolean, default: false },
|
isArchive: { type: Boolean, default: false },
|
||||||
projectId: { type: Schema.Types.ObjectId, ref: "project" },
|
projectId: { type: Schema.Types.ObjectId, ref: "project" },
|
||||||
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
|
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
export interface Widget3d extends Document {
|
export interface Widget3d extends Document {
|
||||||
type: string;
|
type: string;
|
||||||
widgetID: string;
|
widgetID: string;
|
||||||
@@ -7,20 +9,24 @@ export interface Widget3d extends Document {
|
|||||||
position: [];
|
position: [];
|
||||||
rotation: [];
|
rotation: [];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
zoneUuid:string
|
zoneUuid: string;
|
||||||
Data: {
|
Data: {
|
||||||
measurements: {};
|
measurements: {};
|
||||||
duration: string;
|
duration: string;
|
||||||
};
|
};
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
}
|
}
|
||||||
const Widget3dSchema: Schema = new Schema(
|
const Widget3dSchema: Schema = new Schema(
|
||||||
{
|
{
|
||||||
type: { type: String },
|
type: { type: String },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
widgetID: { type: String },
|
widgetID: { type: String },
|
||||||
widgetName: { type: String, default: "Widget3D" },
|
widgetName: { type: String, default: "Widget3D" },
|
||||||
position: { type: Array },
|
position: { type: Array },
|
||||||
rotation: { type: Array },
|
rotation: { type: Array },
|
||||||
zoneUuid:{ type: String },
|
zoneUuid: { type: String },
|
||||||
Data: {
|
Data: {
|
||||||
measurements: { type: Object, default: {} },
|
measurements: { type: Object, default: {} },
|
||||||
duration: { type: String, default: "1h" },
|
duration: { type: String, default: "1h" },
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
export interface FloatingWidget extends Document {
|
export interface FloatingWidget extends Document {
|
||||||
className: string;
|
className: string;
|
||||||
iconName: string;
|
iconName: string;
|
||||||
@@ -9,11 +11,13 @@ export interface FloatingWidget extends Document {
|
|||||||
per: string;
|
per: string;
|
||||||
value: string;
|
value: string;
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
zoneUuid: string
|
zoneUuid: string;
|
||||||
Data: {
|
Data: {
|
||||||
measurements: {};
|
measurements: {};
|
||||||
duration: string;
|
duration: string;
|
||||||
};
|
};
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
}
|
}
|
||||||
const floatingWidgetSchema: Schema = new Schema(
|
const floatingWidgetSchema: Schema = new Schema(
|
||||||
{
|
{
|
||||||
@@ -25,6 +29,8 @@ const floatingWidgetSchema: Schema = new Schema(
|
|||||||
per: { type: String },
|
per: { type: String },
|
||||||
value: { type: String },
|
value: { type: String },
|
||||||
zoneUuid: { type: String },
|
zoneUuid: { type: String },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
Data: {
|
Data: {
|
||||||
measurements: { type: Object, default: {} },
|
measurements: { type: Object, default: {} },
|
||||||
duration: { type: String, default: "1h" },
|
duration: { type: String, default: "1h" },
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
import mongoose, { Schema, Document } from "mongoose";
|
import mongoose, { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
export interface Panel extends Document {
|
export interface Panel extends Document {
|
||||||
zoneUuid: string
|
zoneUuid: string;
|
||||||
panelName: string;
|
panelName: string;
|
||||||
widgets: [mongoose.Types.ObjectId];
|
widgets: [mongoose.Types.ObjectId];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
}
|
}
|
||||||
const panelSchema: Schema = new Schema(
|
const panelSchema: Schema = new Schema(
|
||||||
{
|
{
|
||||||
zoneUuid: { type: String },
|
zoneUuid: { type: String },
|
||||||
panelName: { type: String },
|
panelName: { type: String },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
widgets: [{ type: mongoose.Schema.Types.ObjectId, ref: "Widget" }],
|
widgets: [{ type: mongoose.Schema.Types.ObjectId, ref: "Widget" }],
|
||||||
isArchive: { type: Boolean, default: false },
|
isArchive: { type: Boolean, default: false },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import mongoose, { Schema, Document } from "mongoose";
|
import mongoose, { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
export interface Widget extends Document {
|
export interface Widget extends Document {
|
||||||
widgetName: string;
|
widgetName: string;
|
||||||
widgetside: string;
|
widgetside: string;
|
||||||
widgetID: string;
|
widgetID: string;
|
||||||
widgetOrder: string;
|
widgetOrder: string;
|
||||||
elementType: string;
|
elementType: string;
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
elementColor: string;
|
elementColor: string;
|
||||||
fontFamily: string;
|
fontFamily: string;
|
||||||
fontStyle: string;
|
fontStyle: string;
|
||||||
@@ -16,13 +20,15 @@ export interface Widget extends Document {
|
|||||||
measurements: {};
|
measurements: {};
|
||||||
duration: string;
|
duration: string;
|
||||||
};
|
};
|
||||||
zoneUuid: string
|
zoneUuid: string;
|
||||||
}
|
}
|
||||||
const widgetSchema: Schema = new Schema(
|
const widgetSchema: Schema = new Schema(
|
||||||
{
|
{
|
||||||
widgetName: { type: String, default: "Widget" },
|
widgetName: { type: String, default: "Widget" },
|
||||||
widgetside: { type: String },
|
widgetside: { type: String },
|
||||||
widgetID: { type: String },
|
widgetID: { type: String },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
widgetOrder: { type: String },
|
widgetOrder: { type: String },
|
||||||
elementType: { type: String },
|
elementType: { type: String },
|
||||||
elementColor: { type: String },
|
elementColor: { type: String },
|
||||||
@@ -35,7 +41,7 @@ const widgetSchema: Schema = new Schema(
|
|||||||
fontWeight: { type: String },
|
fontWeight: { type: String },
|
||||||
isArchive: { type: Boolean, default: false },
|
isArchive: { type: Boolean, default: false },
|
||||||
panelID: { type: mongoose.Schema.Types.ObjectId, ref: "Panel" },
|
panelID: { type: mongoose.Schema.Types.ObjectId, ref: "Panel" },
|
||||||
zoneUuid: { type: String }
|
zoneUuid: { type: String },
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|||||||
155
src/shared/V1Models/dummy/actionDummy.ts
Normal file
155
src/shared/V1Models/dummy/actionDummy.ts
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
interface AssetEventSchema {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
state: "idle" | "running" | "stopped" | "disabled" | "error";
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TriggerSchema {
|
||||||
|
triggerUuid: string;
|
||||||
|
triggerName: string;
|
||||||
|
triggerType: "onComplete" | "onStart" | "onStop" | "delay" | "onError";
|
||||||
|
delay: number;
|
||||||
|
triggeredAsset: {
|
||||||
|
triggeredModel: { modelName: string; modelUuid: string };
|
||||||
|
triggeredPoint: { pointName: string; pointUuid: string };
|
||||||
|
triggeredAction: { actionName: string; actionUuid: string };
|
||||||
|
} | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConveyorPointActionSchema {
|
||||||
|
uuid: string;
|
||||||
|
action: {
|
||||||
|
actionUuid: string;
|
||||||
|
actionName: string;
|
||||||
|
actionType: "default" | "spawn" | "swap" | "despawn";
|
||||||
|
material: string;
|
||||||
|
delay: number | "inherit";
|
||||||
|
spawnInterval: number | "inherit";
|
||||||
|
spawnCount: number | "inherit";
|
||||||
|
triggers: TriggerSchema[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface VehiclePointActionSchema {
|
||||||
|
uuid: string;
|
||||||
|
action: {
|
||||||
|
actionUuid: string;
|
||||||
|
actionName: string;
|
||||||
|
actionType: "travel";
|
||||||
|
material: string | null;
|
||||||
|
unLoadDuration: number;
|
||||||
|
loadCapacity: number;
|
||||||
|
pickUpPoint: { x: number; y: number; z: number } | null;
|
||||||
|
unLoadPoint: { x: number; y: number; z: number } | null;
|
||||||
|
triggers: TriggerSchema[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RoboticArmPointActionSchema {
|
||||||
|
uuid: string;
|
||||||
|
actions: {
|
||||||
|
actionUuid: string;
|
||||||
|
actionName: string;
|
||||||
|
actionType: "pickAndPlace";
|
||||||
|
process: {
|
||||||
|
startPoint: [number, number, number];
|
||||||
|
endPoint: [number, number, number];
|
||||||
|
};
|
||||||
|
triggers: TriggerSchema[];
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MachinePointActionSchema {
|
||||||
|
uuid: string;
|
||||||
|
action: {
|
||||||
|
actionUuid: string;
|
||||||
|
actionName: string;
|
||||||
|
actionType: "process";
|
||||||
|
processTime: number;
|
||||||
|
swapMaterial: string;
|
||||||
|
triggers: TriggerSchema[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StoragePointActionSchema {
|
||||||
|
uuid: string;
|
||||||
|
action: {
|
||||||
|
actionUuid: string;
|
||||||
|
actionName: string;
|
||||||
|
actionType: "storage";
|
||||||
|
materials: { materialName: string; materialId: string }[];
|
||||||
|
storageCapacity: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConveyorActionSchema extends AssetEventSchema {
|
||||||
|
type: "transfer";
|
||||||
|
Action: ConveyorPointActionSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VehicleActionSchema extends AssetEventSchema {
|
||||||
|
type: "vehicle";
|
||||||
|
Action: VehiclePointActionSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RoboticArmActionSchema extends AssetEventSchema {
|
||||||
|
type: "roboticArm";
|
||||||
|
Actions: RoboticArmPointActionSchema[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MachineActionSchema extends AssetEventSchema {
|
||||||
|
type: "machine";
|
||||||
|
Action: MachinePointActionSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StorageActionSchema extends AssetEventSchema {
|
||||||
|
type: "storageUnit";
|
||||||
|
Action: StoragePointActionSchema;
|
||||||
|
}
|
||||||
|
interface IActionModel extends Document {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
productUuid: string;
|
||||||
|
projectId: Project["_id"];
|
||||||
|
isArchive: boolean;
|
||||||
|
type: "transfer" | "vehicle" | "roboticArm" | "machine" | "storageUnit";
|
||||||
|
Action:
|
||||||
|
| VehicleActionSchema
|
||||||
|
| ConveyorActionSchema
|
||||||
|
| MachineActionSchema
|
||||||
|
| StorageActionSchema;
|
||||||
|
Actions: RoboticArmActionSchema[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const BaseEventSchema = new Schema<IActionModel>(
|
||||||
|
{
|
||||||
|
modelUuid: { type: String, required: true },
|
||||||
|
modelName: { type: String, required: true },
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
enum: ["transfer", "vehicle", "roboticArm", "machine", "storageUnit"],
|
||||||
|
},
|
||||||
|
Action: {
|
||||||
|
type: Schema.Types.Mixed,
|
||||||
|
},
|
||||||
|
Actions: {
|
||||||
|
type: Schema.Types.Mixed,
|
||||||
|
},
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
productUuid: { type: String, required: true },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
{ discriminatorKey: "type", timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const actionDummyModel = (db: string) => {
|
||||||
|
return MainModel(db, "Actions", BaseEventSchema, "Actions");
|
||||||
|
};
|
||||||
|
|
||||||
|
export default actionDummyModel;
|
||||||
149
src/shared/V1Models/dummy/eventDummy.ts
Normal file
149
src/shared/V1Models/dummy/eventDummy.ts
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
interface AssetEventSchema {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
state: "idle" | "running" | "stopped" | "disabled" | "error";
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TriggerSchema {
|
||||||
|
triggerUuid: string;
|
||||||
|
triggerName: string;
|
||||||
|
triggerType: "onComplete" | "onStart" | "onStop" | "delay" | "onError";
|
||||||
|
delay: number;
|
||||||
|
triggeredAsset: {
|
||||||
|
triggeredModel: { modelName: string; modelUuid: string };
|
||||||
|
triggeredPoint: { pointName: string; pointUuid: string };
|
||||||
|
triggeredAction: { actionName: string; actionUuid: string };
|
||||||
|
} | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConveyorPointSchema {
|
||||||
|
uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
action: {
|
||||||
|
actionUuid: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface VehiclePointSchema {
|
||||||
|
uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
action: {
|
||||||
|
actionUuid: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RoboticArmPointSchema {
|
||||||
|
uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
actions: {
|
||||||
|
actionUuid: string;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MachinePointSchema {
|
||||||
|
uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
action: {
|
||||||
|
actionUuid: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StoragePointSchema {
|
||||||
|
uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
action: {
|
||||||
|
actionUuid: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConveyorEventSchema extends AssetEventSchema {
|
||||||
|
type: "transfer";
|
||||||
|
speed: number;
|
||||||
|
points: ConveyorPointSchema[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface VehicleEventSchema extends AssetEventSchema {
|
||||||
|
type: "vehicle";
|
||||||
|
speed: number;
|
||||||
|
point: VehiclePointSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RoboticArmEventSchema extends AssetEventSchema {
|
||||||
|
type: "roboticArm";
|
||||||
|
speed: number;
|
||||||
|
point: RoboticArmPointSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MachineEventSchema extends AssetEventSchema {
|
||||||
|
type: "machine";
|
||||||
|
point: MachinePointSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StorageEventSchema extends AssetEventSchema {
|
||||||
|
type: "storageUnit";
|
||||||
|
point: StoragePointSchema;
|
||||||
|
}
|
||||||
|
interface IPointModel extends Document {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
position: [number];
|
||||||
|
rotation: [number];
|
||||||
|
state: string;
|
||||||
|
productUuid: string;
|
||||||
|
projectId: Project["_id"];
|
||||||
|
isArchive: boolean;
|
||||||
|
type: "transfer" | "vehicle" | "roboticArm" | "machine" | "storageUnit";
|
||||||
|
speed: number;
|
||||||
|
point:
|
||||||
|
| VehicleEventSchema
|
||||||
|
| RoboticArmEventSchema
|
||||||
|
| MachineEventSchema
|
||||||
|
| StorageEventSchema;
|
||||||
|
points: ConveyorEventSchema[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const BaseEventSchema = new Schema<IPointModel>(
|
||||||
|
{
|
||||||
|
modelUuid: { type: String, required: true },
|
||||||
|
modelName: { type: String, required: true },
|
||||||
|
position: { type: [Number], required: true },
|
||||||
|
rotation: { type: [Number], required: true },
|
||||||
|
speed: { type: Number },
|
||||||
|
state: {
|
||||||
|
type: String,
|
||||||
|
enum: ["idle", "running", "stopped", "disabled", "error"],
|
||||||
|
default: "idle",
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
enum: ["transfer", "vehicle", "roboticArm", "machine", "storageUnit"],
|
||||||
|
},
|
||||||
|
point: {
|
||||||
|
type: Schema.Types.Mixed,
|
||||||
|
},
|
||||||
|
points: {
|
||||||
|
type: Schema.Types.Mixed,
|
||||||
|
},
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
productUuid: { type: String, required: true },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
{ discriminatorKey: "type", timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const EventsDataModel = (db: string) => {
|
||||||
|
return MainModel(db, "EventDatas", BaseEventSchema, "EventDatas");
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EventsDataModel;
|
||||||
28
src/shared/V1Models/dummy/productDumy.ts
Normal file
28
src/shared/V1Models/dummy/productDumy.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
export interface Product extends Document {
|
||||||
|
productName: string;
|
||||||
|
userId: User["_id"];
|
||||||
|
productUuid: string;
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
|
isArchive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProductSchema = new Schema({
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
|
productName: { type: String, required: true },
|
||||||
|
productUuid: { type: String, required: true },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
const ProductModel = (db: string) => {
|
||||||
|
return MainModel(db, "Products", ProductSchema, "Products");
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProductModel;
|
||||||
26
src/shared/V1Models/yjs/auto-saveModel.ts
Normal file
26
src/shared/V1Models/yjs/auto-saveModel.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
|
||||||
|
export interface autoSave extends Document {
|
||||||
|
|
||||||
|
yjsData: Buffer;
|
||||||
|
isArchive: boolean;
|
||||||
|
createdBy: User["_id"];
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: string;
|
||||||
|
}
|
||||||
|
const YjsSchema: Schema = new Schema({
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: String, },
|
||||||
|
// versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
|
yjsData: Buffer,
|
||||||
|
updatedAt: { type: Date, default: Date.now },
|
||||||
|
});
|
||||||
|
|
||||||
|
const autosaveModel = (db: any) => {
|
||||||
|
return MainModel(db, "autosave", YjsSchema, "autosave");
|
||||||
|
};
|
||||||
|
export default autosaveModel;
|
||||||
30
src/shared/V1Models/yjs/snapshotModel.ts
Normal file
30
src/shared/V1Models/yjs/snapshotModel.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
|
||||||
|
export interface snapshot extends Document {
|
||||||
|
snapshotData: Buffer;
|
||||||
|
isArchive: boolean;
|
||||||
|
label: string;
|
||||||
|
createdBy: User["_id"];
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: string;
|
||||||
|
// versionId: Version["_id"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const SnapshotSchema: Schema = new Schema({
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: String, },
|
||||||
|
// versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
|
label: String, // e.g., "v1.2 layout change"
|
||||||
|
snapshotData: Buffer,
|
||||||
|
createdBy: String,
|
||||||
|
createdAt: { type: Date, default: Date.now },
|
||||||
|
});
|
||||||
|
const snapshotModel = (db: any) => {
|
||||||
|
return MainModel(db, "snapshot", SnapshotSchema, "snapshot");
|
||||||
|
};
|
||||||
|
export default snapshotModel;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Response, NextFunction } from "express";
|
import { Response, NextFunction } from "express";
|
||||||
import { AuthenticatedRequest } from "../../shared/utils/token.ts";
|
import { AuthenticatedRequest } from "../utils/token.ts";
|
||||||
type Role = "Admin" | "User";
|
type Role = "Admin" | "User";
|
||||||
const authorizedRoles = (...allowedRoles: Role[]) => {
|
const authorizedRoles = (...allowedRoles: Role[]) => {
|
||||||
return (req: AuthenticatedRequest, res: Response, next: NextFunction) => {
|
return (req: AuthenticatedRequest, res: Response, next: NextFunction) => {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { User } from "../user-Model.ts";
|
|||||||
export interface Version extends Document {
|
export interface Version extends Document {
|
||||||
versionName: string;
|
versionName: string;
|
||||||
projectId: Project["_id"];
|
projectId: Project["_id"];
|
||||||
|
|
||||||
createdBy: User["_id"];
|
createdBy: User["_id"];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
version: number;
|
version: number;
|
||||||
|
|||||||
@@ -1,26 +1,51 @@
|
|||||||
import ThreadModel from "../../V1Models/Thread/thread-Model.ts";
|
import ThreadModel from "../../V1Models/Thread/thread-Model.ts";
|
||||||
import { existingProjectByIdWithoutUser, existingUser } from "../helpers/v1projecthelperFns.ts";
|
import { Types } from "mongoose";
|
||||||
|
import {
|
||||||
|
existingProjectByIdWithoutUser,
|
||||||
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
|
||||||
interface IThread {
|
interface IThread {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
versionId: string;
|
versionId: string;
|
||||||
state: string
|
state: string;
|
||||||
commentId: string;
|
commentId: string;
|
||||||
|
threadTitle: string;
|
||||||
threadId: string;
|
threadId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
lastUpdatedAt: string;
|
lastUpdatedAt: string;
|
||||||
position: [number, number, number];
|
position: [number, number, number];
|
||||||
rotation: [number, number, number];
|
rotation: [number, number, number];
|
||||||
comments: string
|
comment: string;
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
|
organization: string;
|
||||||
|
}
|
||||||
|
interface IComment {
|
||||||
|
_id?: Types.ObjectId;
|
||||||
|
userId: string;
|
||||||
|
comment: string;
|
||||||
|
isArchive: boolean;
|
||||||
|
createdAt: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IgetThread {
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
}
|
}
|
||||||
export const createThread = async (data: IThread) => {
|
export const createThread = async (data: IThread) => {
|
||||||
try {
|
try {
|
||||||
const { projectId, state, userId, position, rotation, comments, organization } = data
|
const {
|
||||||
|
projectId,
|
||||||
|
state,
|
||||||
|
userId,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
threadTitle,
|
||||||
|
organization,
|
||||||
|
} = data;
|
||||||
const userExisting = await existingUser(userId, organization);
|
const userExisting = await existingUser(userId, organization);
|
||||||
if (!userExisting) {
|
if (!userExisting) {
|
||||||
return {
|
return {
|
||||||
@@ -29,35 +54,54 @@ export const createThread = async (data: IThread) => {
|
|||||||
}
|
}
|
||||||
const projectExisting = await existingProjectByIdWithoutUser(
|
const projectExisting = await existingProjectByIdWithoutUser(
|
||||||
projectId,
|
projectId,
|
||||||
organization,
|
organization
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!projectExisting) {
|
if (!projectExisting) {
|
||||||
return { status: "Project not found" };
|
return { status: "Project not found" };
|
||||||
}
|
}
|
||||||
|
const currentVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
projectExisting._id,
|
||||||
|
projectExisting.Present_version
|
||||||
|
);
|
||||||
|
if (!currentVersion) return { status: "CurrentVersion Data not found" };
|
||||||
const newThread = await ThreadModel(organization).create({
|
const newThread = await ThreadModel(organization).create({
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId: currentVersion._id,
|
||||||
state,
|
state,
|
||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
position,
|
position,
|
||||||
|
threadTitle,
|
||||||
rotation,
|
rotation,
|
||||||
comments,
|
isArchive: false,
|
||||||
createdAt: Date.now()
|
createdAt: Date.now(),
|
||||||
});
|
});
|
||||||
|
const responseData = {
|
||||||
|
_id: newThread._id,
|
||||||
|
projectId: newThread.projectId,
|
||||||
|
versionId: newThread.versionId,
|
||||||
|
state: newThread.state,
|
||||||
|
createdBy: newThread.createdBy,
|
||||||
|
createdAt: newThread.createdAt,
|
||||||
|
isArchive: newThread.isArchive,
|
||||||
|
position: newThread.position,
|
||||||
|
rotation: newThread.rotation,
|
||||||
|
threadTitle: newThread.threadTitle,
|
||||||
|
};
|
||||||
return {
|
return {
|
||||||
status: "Success",
|
status: "Success",
|
||||||
data: newThread,
|
data: responseData,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
status: error,
|
status: error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
export const deleteThread = async (data: IThread) => {
|
export const deleteThread = async (data: IThread) => {
|
||||||
try {
|
try {
|
||||||
const { projectId, userId, organization, threadId } = data
|
const { projectId, userId, organization, threadId } = data;
|
||||||
const userExisting = await existingUser(userId, organization);
|
const userExisting = await existingUser(userId, organization);
|
||||||
if (!userExisting) {
|
if (!userExisting) {
|
||||||
return {
|
return {
|
||||||
@@ -66,32 +110,98 @@ export const deleteThread = async (data: IThread) => {
|
|||||||
}
|
}
|
||||||
const projectExisting = await existingProjectByIdWithoutUser(
|
const projectExisting = await existingProjectByIdWithoutUser(
|
||||||
projectId,
|
projectId,
|
||||||
organization,
|
organization
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!projectExisting) {
|
if (!projectExisting) {
|
||||||
return { status: "Project not found" };
|
return { status: "Project not found" };
|
||||||
}
|
}
|
||||||
const findThreadId = await ThreadModel(organization).findOne({ _id: threadId, createdBy: userId })
|
const currentVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
projectExisting._id,
|
||||||
|
projectExisting.Present_version
|
||||||
|
);
|
||||||
|
if (!currentVersion) return { status: "CurrentVersion Data not found" };
|
||||||
|
const findThreadId = await ThreadModel(organization).findOne({
|
||||||
|
_id: threadId,
|
||||||
|
createdBy: userId,
|
||||||
|
});
|
||||||
if (!findThreadId) {
|
if (!findThreadId) {
|
||||||
return { status: "can't deleted" };
|
return { status: "can't deleted" };
|
||||||
}
|
}
|
||||||
const deleteThread = await ThreadModel(organization).findOneAndDelete({ _id: threadId, createdBy: userId })
|
const deleteThread = await ThreadModel(organization).findOneAndUpdate(
|
||||||
|
{ _id: threadId, createdBy: userId },
|
||||||
|
{ isArchive: true }
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
status: "Success",
|
status: "Success",
|
||||||
data: deleteThread,
|
data: deleteThread,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("error: ", error);
|
|
||||||
return {
|
return {
|
||||||
status: error,
|
status: error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
export const updateThreadTitle = async (data: IThread) => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
threadTitle,
|
||||||
|
organization,
|
||||||
|
threadId,
|
||||||
|
commentId,
|
||||||
|
} = data;
|
||||||
|
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) {
|
||||||
|
return {
|
||||||
|
status: "user_not_found",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const projectExisting = await existingProjectByIdWithoutUser(
|
||||||
|
projectId,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!projectExisting) {
|
||||||
|
return { status: "Project not found" };
|
||||||
|
}
|
||||||
|
const currentVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
projectExisting._id,
|
||||||
|
projectExisting.Present_version
|
||||||
|
);
|
||||||
|
if (!currentVersion) return { status: "CurrentVersion Data not found" };
|
||||||
|
const findThreadId = await ThreadModel(organization).findById(threadId);
|
||||||
|
if (findThreadId) {
|
||||||
|
const updateThread = await ThreadModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
_id: threadId,
|
||||||
|
createdBy: userId,
|
||||||
|
},
|
||||||
|
{ threadTitle: threadTitle },
|
||||||
|
{
|
||||||
|
new: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: updateThread,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
status: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
export const addComments = async (data: IThread) => {
|
export const addComments = async (data: IThread) => {
|
||||||
try {
|
try {
|
||||||
const { projectId, userId, comments, organization, threadId } = data
|
const { projectId, userId, comment, organization, threadId, commentId } =
|
||||||
|
data;
|
||||||
const userExisting = await existingUser(userId, organization);
|
const userExisting = await existingUser(userId, organization);
|
||||||
if (!userExisting) {
|
if (!userExisting) {
|
||||||
return {
|
return {
|
||||||
@@ -100,31 +210,73 @@ export const addComments = async (data: IThread) => {
|
|||||||
}
|
}
|
||||||
const projectExisting = await existingProjectByIdWithoutUser(
|
const projectExisting = await existingProjectByIdWithoutUser(
|
||||||
projectId,
|
projectId,
|
||||||
organization,
|
organization
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!projectExisting) {
|
if (!projectExisting) {
|
||||||
return { status: "Project not found" };
|
return { status: "Project not found" };
|
||||||
}
|
}
|
||||||
const findThreadId = await ThreadModel(organization).findById(threadId)
|
const currentVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
projectExisting._id,
|
||||||
|
projectExisting.Present_version
|
||||||
|
);
|
||||||
|
if (!currentVersion) return { status: "CurrentVersion Data not found" };
|
||||||
|
const findThreadId = await ThreadModel(organization).findById(threadId);
|
||||||
|
if (commentId) {
|
||||||
|
const updated = await ThreadModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
_id: threadId,
|
||||||
|
"comments._id": commentId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
"comments.$.comment": comment,
|
||||||
|
"comments.$.createdAt": Date.now(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
new: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const newComment = { userId, comment: comments, timestamp: Date.now() };
|
if (updated) {
|
||||||
findThreadId?.replies.push(newComment)
|
const updatedComment = updated?.comments?.find(
|
||||||
await findThreadId?.save()
|
(c: any) => c._id.toString() === commentId
|
||||||
return {
|
);
|
||||||
status: "Success",
|
|
||||||
data: newComment.comment,
|
return {
|
||||||
};
|
status: "updated",
|
||||||
|
data: updatedComment,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const newComment = {
|
||||||
|
userId,
|
||||||
|
comment: comment,
|
||||||
|
isArchive: false,
|
||||||
|
createdAt: Date.now(),
|
||||||
|
};
|
||||||
|
findThreadId?.comments.push(newComment);
|
||||||
|
await findThreadId?.save();
|
||||||
|
const savedComment = findThreadId?.comments[
|
||||||
|
findThreadId.comments.length - 1
|
||||||
|
] as IComment;
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: savedComment,
|
||||||
|
};
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("error: ", error);
|
|
||||||
return {
|
return {
|
||||||
status: error,
|
status: error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
export const deleteComments = async (data: IThread) => {
|
export const deleteComments = async (data: IThread) => {
|
||||||
try {
|
try {
|
||||||
const { projectId, userId, commentId, organization, threadId } = data
|
const { projectId, userId, commentId, organization, threadId } = data;
|
||||||
const userExisting = await existingUser(userId, organization);
|
const userExisting = await existingUser(userId, organization);
|
||||||
if (!userExisting) {
|
if (!userExisting) {
|
||||||
return {
|
return {
|
||||||
@@ -133,40 +285,100 @@ export const deleteComments = async (data: IThread) => {
|
|||||||
}
|
}
|
||||||
const projectExisting = await existingProjectByIdWithoutUser(
|
const projectExisting = await existingProjectByIdWithoutUser(
|
||||||
projectId,
|
projectId,
|
||||||
organization,
|
organization
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!projectExisting) {
|
if (!projectExisting) {
|
||||||
return { status: "Project not found" };
|
return { status: "Project not found" };
|
||||||
}
|
}
|
||||||
const findThreadId = await ThreadModel(organization).findOne({ _id: threadId })
|
const currentVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
projectExisting._id,
|
||||||
|
projectExisting.Present_version
|
||||||
|
);
|
||||||
|
if (!currentVersion) return { status: "CurrentVersion Data not found" };
|
||||||
|
const findThreadId = await ThreadModel(organization).findOne({
|
||||||
|
_id: threadId,
|
||||||
|
});
|
||||||
if (!findThreadId) {
|
if (!findThreadId) {
|
||||||
return { status: "thread not found" };
|
return { status: "thread not found" };
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleted = await ThreadModel(organization).updateOne(
|
const deleted = await ThreadModel(organization).findOneAndUpdate(
|
||||||
{ _id: threadId },
|
|
||||||
{
|
{
|
||||||
$pull: {
|
_id: threadId,
|
||||||
replies: {
|
"comments._id": commentId,
|
||||||
_id: commentId,
|
},
|
||||||
userId: userId,
|
{
|
||||||
},
|
$set: {
|
||||||
|
"comments.$.isArchive": true,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
new: true, // returns the updated document
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (deleted.modifiedCount === 0) {
|
|
||||||
return { status: "unauthorized" };
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
status: "Success",
|
status: "Success",
|
||||||
data: deleted
|
data: deleted,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("error: ", error);
|
|
||||||
return {
|
return {
|
||||||
status: error,
|
status: error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
export const findThreads = async (data: IgetThread) => {
|
||||||
|
try {
|
||||||
|
const { projectId, userId, organization } = data;
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) {
|
||||||
|
return {
|
||||||
|
status: "user_not_found",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const projectExisting = await existingProjectByIdWithoutUser(
|
||||||
|
projectId,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!projectExisting) {
|
||||||
|
return { status: "Project not found" };
|
||||||
|
}
|
||||||
|
const currentVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
projectExisting._id,
|
||||||
|
projectExisting.Present_version
|
||||||
|
);
|
||||||
|
if (!currentVersion) return { status: "CurrentVersion Data not found" };
|
||||||
|
const findThreads = await ThreadModel(organization)
|
||||||
|
.find({ isArchive: false, projectId, versionId: currentVersion._id })
|
||||||
|
.lean();
|
||||||
|
|
||||||
|
const formattedThreads = findThreads.map((thread) => {
|
||||||
|
const filteredComments = (thread.comments || []).filter(
|
||||||
|
(comment) => comment.isArchive === false
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
state: thread.state,
|
||||||
|
threadId: thread._id.toString(),
|
||||||
|
creatorId: thread.createdBy.toString(),
|
||||||
|
createdAt: thread.createdAt,
|
||||||
|
threadTitle: thread.threadTitle,
|
||||||
|
// lastUpdatedAt: lastUpdatedAt,
|
||||||
|
position: thread.position,
|
||||||
|
rotation: thread.rotation,
|
||||||
|
comments: filteredComments,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: formattedThreads,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
status: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -119,9 +119,62 @@ export const AuthLogin = async (
|
|||||||
{ userId: Existing_User._id },
|
{ userId: Existing_User._id },
|
||||||
{ refreshToken: "" }
|
{ refreshToken: "" }
|
||||||
);
|
);
|
||||||
return {
|
const UserData = await UsersDataModel(organization).findOne({
|
||||||
status: "Already LoggedIn on another browser....Please logout!!!",
|
userId: existingMail._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!UserData)
|
||||||
|
return {
|
||||||
|
status: "User_Datas not found",
|
||||||
|
};
|
||||||
|
const tokenValidation = tokenGenerator(
|
||||||
|
existingMail.Email,
|
||||||
|
UserData.role,
|
||||||
|
existingMail._id,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
const refreshTokenvalidation = tokenRefreshGenerator(
|
||||||
|
existingMail.Email,
|
||||||
|
UserData.role,
|
||||||
|
existingMail._id,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
|
||||||
|
await handleTokenCache(
|
||||||
|
existingMail._id.toString(),
|
||||||
|
existingMail.Email,
|
||||||
|
tokenValidation,
|
||||||
|
refreshTokenvalidation
|
||||||
|
);
|
||||||
|
|
||||||
|
const updatedUser = await AuthModel(organization)
|
||||||
|
.findByIdAndUpdate(
|
||||||
|
existingMail._id,
|
||||||
|
{ visitorBrowserID: fingerprint },
|
||||||
|
{ new: true }
|
||||||
|
)
|
||||||
|
.select("-__v -Profilepicture");
|
||||||
|
if (!updatedUser)
|
||||||
|
return {
|
||||||
|
status: "User update failed.",
|
||||||
|
};
|
||||||
|
await redis.setex(
|
||||||
|
`user:${existingMail.Email}`,
|
||||||
|
3600,
|
||||||
|
JSON.stringify(updatedUser)
|
||||||
|
);
|
||||||
|
const finalResult = {
|
||||||
|
message: "login successfull",
|
||||||
|
email: existingMail.Email,
|
||||||
|
name: existingMail.userName,
|
||||||
|
userId: existingMail._id,
|
||||||
|
isShare: UserData.isShare,
|
||||||
|
token: tokenValidation,
|
||||||
|
refreshToken: refreshTokenvalidation,
|
||||||
};
|
};
|
||||||
|
// return {
|
||||||
|
// status: "Already LoggedIn on another browser....Please logout!!!",
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
const UserData = await UsersDataModel(organization).findOne({
|
const UserData = await UsersDataModel(organization).findOne({
|
||||||
userId: existingMail._id,
|
userId: existingMail._id,
|
||||||
@@ -463,3 +516,136 @@ async function handleTokenCache(
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const AuthLogins = async (
|
||||||
|
data: IloginUser
|
||||||
|
): Promise<{ status: string; data?: object }> => {
|
||||||
|
try {
|
||||||
|
const { Email, Password, fingerprint } = data;
|
||||||
|
const email = Email.toLowerCase();
|
||||||
|
const organization = extractOrg(email);
|
||||||
|
|
||||||
|
const existingUser = await findExistingUserEmail(email);
|
||||||
|
if (!existingUser) return { status: "User Not Found!!! Kindly signup..." };
|
||||||
|
|
||||||
|
const userFromCacheOrDb = await getUserFromCacheOrDB(email);
|
||||||
|
const passwordValid = await hashValidator(
|
||||||
|
Password,
|
||||||
|
userFromCacheOrDb.Password
|
||||||
|
);
|
||||||
|
if (!passwordValid)
|
||||||
|
return { status: "Email & Password is invalid...Check the credentials" };
|
||||||
|
|
||||||
|
const userData = await UsersDataModel(organization).findOne({
|
||||||
|
userId: userFromCacheOrDb._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!userData) return { status: "User_Datas not found" };
|
||||||
|
|
||||||
|
const alreadyLoggedInElsewhere =
|
||||||
|
userFromCacheOrDb.visitorBrowserID &&
|
||||||
|
userFromCacheOrDb.visitorBrowserID !== fingerprint;
|
||||||
|
|
||||||
|
const generateTokensAndUpdateUser = async () => {
|
||||||
|
const token = tokenGenerator(
|
||||||
|
email,
|
||||||
|
userData.role,
|
||||||
|
userFromCacheOrDb._id,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
const refreshToken = tokenRefreshGenerator(
|
||||||
|
email,
|
||||||
|
userData.role,
|
||||||
|
userFromCacheOrDb._id,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
|
||||||
|
await handleTokenCache(
|
||||||
|
userFromCacheOrDb._id.toString(),
|
||||||
|
email,
|
||||||
|
token,
|
||||||
|
refreshToken
|
||||||
|
);
|
||||||
|
|
||||||
|
const updatedUser = await AuthModel(organization)
|
||||||
|
.findByIdAndUpdate(
|
||||||
|
userFromCacheOrDb._id,
|
||||||
|
{ visitorBrowserID: fingerprint },
|
||||||
|
{ new: true }
|
||||||
|
)
|
||||||
|
.select("-__v -Profilepicture");
|
||||||
|
|
||||||
|
if (!updatedUser) return null;
|
||||||
|
|
||||||
|
await redis.setex(`user:${email}`, 3600, JSON.stringify(updatedUser));
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: "login successfull",
|
||||||
|
email,
|
||||||
|
name: userFromCacheOrDb.userName,
|
||||||
|
userId: userFromCacheOrDb._id,
|
||||||
|
isShare: userData.isShare,
|
||||||
|
token,
|
||||||
|
refreshToken,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
if (alreadyLoggedInElsewhere) {
|
||||||
|
await Promise.all([
|
||||||
|
redis.del(`token:${email}`),
|
||||||
|
redis.del(`user:${email}`),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await AuthModel(organization).updateOne(
|
||||||
|
{ Email: email },
|
||||||
|
{ visitorBrowserID: "" }
|
||||||
|
);
|
||||||
|
await tokenType(organization).updateOne(
|
||||||
|
{ userId: existingUser._id },
|
||||||
|
{ refreshToken: "" }
|
||||||
|
);
|
||||||
|
|
||||||
|
const newLogin = await generateTokensAndUpdateUser();
|
||||||
|
if (!newLogin) return { status: "User update failed." };
|
||||||
|
|
||||||
|
return {
|
||||||
|
status:
|
||||||
|
"Already LoggedIn on another browser....ForceLogout Implemented!!!",
|
||||||
|
data: newLogin,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check redis token
|
||||||
|
const cachedTokensRaw = await redis.get(`token:${email}`);
|
||||||
|
if (cachedTokensRaw) {
|
||||||
|
try {
|
||||||
|
const cachedTokens = JSON.parse(cachedTokensRaw);
|
||||||
|
Jwt.verify(cachedTokens.token, jwt_secret);
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: {
|
||||||
|
message: "login successfull",
|
||||||
|
email,
|
||||||
|
name: userFromCacheOrDb.userName,
|
||||||
|
userId: userFromCacheOrDb._id,
|
||||||
|
isShare: userData.isShare,
|
||||||
|
token: cachedTokens.token,
|
||||||
|
refreshToken: cachedTokens.refreshToken,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
console.log("Access token expired. Generating new...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const freshLogin = await generateTokensAndUpdateUser();
|
||||||
|
if (!freshLogin) return { status: "User update failed." };
|
||||||
|
|
||||||
|
return { status: "Success", data: freshLogin };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
return {
|
||||||
|
status:
|
||||||
|
error instanceof Error ? error.message : "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import AisleModel, {
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
interface IAisleDatas {
|
interface IAisleDatas {
|
||||||
userId: string;
|
userId: string;
|
||||||
@@ -13,23 +14,34 @@ interface IAisleDatas {
|
|||||||
type?: AisleType;
|
type?: AisleType;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface IAisleDelete {
|
interface IAisleDelete {
|
||||||
userId: string;
|
userId: string;
|
||||||
aisleUuid: string;
|
aisleUuid: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface IProjectAisles {
|
interface IProjectAisles {
|
||||||
userId: string;
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
export const SetAisle = async (
|
export const SetAisle = async (
|
||||||
data: IAisleDatas
|
data: IAisleDatas
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { aisleUuid, points, type, organization, projectId, userId } = data;
|
const {
|
||||||
|
aisleUuid,
|
||||||
|
points,
|
||||||
|
type,
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
versionId,
|
||||||
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -38,14 +50,26 @@ export const SetAisle = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const ExistingAisle = await AisleModel(organization).findOne({
|
const ExistingAisle = await AisleModel(organization).findOne({
|
||||||
aisleUuid: aisleUuid,
|
aisleUuid: aisleUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (ExistingAisle) {
|
if (ExistingAisle) {
|
||||||
const UpdateAisle = await AisleModel(organization).findOneAndUpdate(
|
const UpdateAisle = await AisleModel(organization).findOneAndUpdate(
|
||||||
{ aisleUuid: aisleUuid, projectId: projectId, isArchive: false },
|
{
|
||||||
|
aisleUuid: aisleUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{ type: type, points: points },
|
{ type: type, points: points },
|
||||||
{ new: true, runValidators: true }
|
{ new: true, runValidators: true }
|
||||||
);
|
);
|
||||||
@@ -55,6 +79,7 @@ export const SetAisle = async (
|
|||||||
const NewAisle = await AisleModel(organization).create({
|
const NewAisle = await AisleModel(organization).create({
|
||||||
aisleUuid,
|
aisleUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId: versionId,
|
||||||
type: type,
|
type: type,
|
||||||
points: points,
|
points: points,
|
||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
@@ -83,7 +108,7 @@ export const DeleteAisle = async (
|
|||||||
data: IAisleDelete
|
data: IAisleDelete
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { aisleUuid, organization, projectId, userId } = data;
|
const { aisleUuid, organization, projectId, userId, versionId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -92,14 +117,26 @@ export const DeleteAisle = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const ExistingAisle = await AisleModel(organization).findOne({
|
const ExistingAisle = await AisleModel(organization).findOne({
|
||||||
aisleUuid: aisleUuid,
|
aisleUuid: aisleUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (ExistingAisle) {
|
if (ExistingAisle) {
|
||||||
await AisleModel(organization).updateOne(
|
await AisleModel(organization).updateOne(
|
||||||
{ aisleUuid: aisleUuid, projectId: projectId, isArchive: false },
|
{
|
||||||
|
aisleUuid: aisleUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{ isArchive: true }
|
{ isArchive: true }
|
||||||
);
|
);
|
||||||
return { status: "Success" };
|
return { status: "Success" };
|
||||||
@@ -121,7 +158,7 @@ export const GetProjectAisles = async (
|
|||||||
data: IProjectAisles
|
data: IProjectAisles
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, userId } = data;
|
const { organization, projectId, versionId, userId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -130,9 +167,17 @@ export const GetProjectAisles = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const ExistingAisle = await AisleModel(organization)
|
const ExistingAisle = await AisleModel(organization)
|
||||||
.find({
|
.find({
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
})
|
})
|
||||||
.select("aisleUuid points type");
|
.select("aisleUuid points type");
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ export const setEnvironment = async (
|
|||||||
userId,
|
userId,
|
||||||
projectId,
|
projectId,
|
||||||
roofVisibility,
|
roofVisibility,
|
||||||
|
versionId: LivingProject.Present_version,
|
||||||
wallVisibility,
|
wallVisibility,
|
||||||
shadowVisibility,
|
shadowVisibility,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import EventsDataModel from "../../V1Models/Simulation/eventsDataModel.ts";
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
import versionModel from "../../V1Models/Version/versionModel.ts";
|
||||||
|
|
||||||
interface SetAssetInput {
|
interface SetAssetInput {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
@@ -17,6 +19,7 @@ interface SetAssetInput {
|
|||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface AssetUpdate {
|
interface AssetUpdate {
|
||||||
@@ -28,6 +31,7 @@ interface AssetUpdate {
|
|||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface DelAssetInput {
|
interface DelAssetInput {
|
||||||
@@ -35,16 +39,19 @@ interface DelAssetInput {
|
|||||||
modelName: string;
|
modelName: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface GetAssetInput {
|
interface GetAssetInput {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface ReplaceEventInput {
|
interface ReplaceEventInput {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
eventData: Mixed;
|
eventData: Mixed;
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
@@ -64,6 +71,7 @@ export const setAssetModel = async (
|
|||||||
isVisible,
|
isVisible,
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
} = data;
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
@@ -74,9 +82,16 @@ export const setAssetModel = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findvalue = await assetModel(organization).findOne({
|
const findvalue = await assetModel(organization).findOne({
|
||||||
modelUuid: modelUuid,
|
modelUuid: modelUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
@@ -85,6 +100,7 @@ export const setAssetModel = async (
|
|||||||
{
|
{
|
||||||
modelUuid: modelUuid,
|
modelUuid: modelUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
@@ -114,6 +130,7 @@ export const setAssetModel = async (
|
|||||||
rotation,
|
rotation,
|
||||||
isLocked,
|
isLocked,
|
||||||
isVisible,
|
isVisible,
|
||||||
|
versionId,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (eventData) {
|
if (eventData) {
|
||||||
@@ -163,6 +180,7 @@ export const setAssetModel = async (
|
|||||||
if (typedEventData && typedEventData.type === "Conveyor") {
|
if (typedEventData && typedEventData.type === "Conveyor") {
|
||||||
assetDatas = {
|
assetDatas = {
|
||||||
projectId: assetDoc.projectId,
|
projectId: assetDoc.projectId,
|
||||||
|
versionId: assetDoc.versionId,
|
||||||
userId: assetDoc.userId,
|
userId: assetDoc.userId,
|
||||||
modelUuid: assetDoc.modelUuid,
|
modelUuid: assetDoc.modelUuid,
|
||||||
modelName: assetDoc.modelName,
|
modelName: assetDoc.modelName,
|
||||||
@@ -176,6 +194,7 @@ export const setAssetModel = async (
|
|||||||
} else if (eventData && assetDoc.type === "Vehicle") {
|
} else if (eventData && assetDoc.type === "Vehicle") {
|
||||||
assetDatas = {
|
assetDatas = {
|
||||||
projectId: assetDoc.projectId,
|
projectId: assetDoc.projectId,
|
||||||
|
versionId: assetDoc.versionId,
|
||||||
userId: assetDoc.userId,
|
userId: assetDoc.userId,
|
||||||
modelUuid: assetDoc.modelUuid,
|
modelUuid: assetDoc.modelUuid,
|
||||||
modelName: assetDoc.modelName,
|
modelName: assetDoc.modelName,
|
||||||
@@ -192,6 +211,7 @@ export const setAssetModel = async (
|
|||||||
} else if (eventData && assetDoc.type === "ArmBot") {
|
} else if (eventData && assetDoc.type === "ArmBot") {
|
||||||
assetDatas = {
|
assetDatas = {
|
||||||
projectId: assetDoc.projectId,
|
projectId: assetDoc.projectId,
|
||||||
|
versionId: assetDoc.versionId,
|
||||||
userId: assetDoc.userId,
|
userId: assetDoc.userId,
|
||||||
modelUuid: assetDoc.modelUuid,
|
modelUuid: assetDoc.modelUuid,
|
||||||
modelName: assetDoc.modelName,
|
modelName: assetDoc.modelName,
|
||||||
@@ -208,6 +228,7 @@ export const setAssetModel = async (
|
|||||||
} else if (eventData && assetDoc.type === "StaticMachine") {
|
} else if (eventData && assetDoc.type === "StaticMachine") {
|
||||||
assetDatas = {
|
assetDatas = {
|
||||||
projectId: assetDoc.projectId,
|
projectId: assetDoc.projectId,
|
||||||
|
versionId: assetDoc.versionId,
|
||||||
userId: assetDoc.userId,
|
userId: assetDoc.userId,
|
||||||
modelUuid: assetDoc.modelUuid,
|
modelUuid: assetDoc.modelUuid,
|
||||||
modelName: assetDoc.modelName,
|
modelName: assetDoc.modelName,
|
||||||
@@ -224,6 +245,7 @@ export const setAssetModel = async (
|
|||||||
} else {
|
} else {
|
||||||
assetDatas = {
|
assetDatas = {
|
||||||
projectId: assetDoc.projectId,
|
projectId: assetDoc.projectId,
|
||||||
|
versionId: assetDoc.versionId,
|
||||||
userId: assetDoc.userId,
|
userId: assetDoc.userId,
|
||||||
modelUuid: assetDoc.modelUuid,
|
modelUuid: assetDoc.modelUuid,
|
||||||
modelName: assetDoc.modelName,
|
modelName: assetDoc.modelName,
|
||||||
@@ -256,7 +278,8 @@ export const deleteAssetModel = async (
|
|||||||
data: DelAssetInput
|
data: DelAssetInput
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { modelUuid, modelName, organization, projectId, userId } = data;
|
const { modelUuid, modelName, organization, versionId, projectId, userId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -265,10 +288,17 @@ export const deleteAssetModel = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const asset = await assetModel(organization).findOne({
|
const asset = await assetModel(organization).findOne({
|
||||||
modelUuid,
|
modelUuid,
|
||||||
modelName,
|
modelName,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!asset) {
|
if (!asset) {
|
||||||
@@ -277,7 +307,7 @@ export const deleteAssetModel = async (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const archivedAsset = await assetModel(organization).findOneAndUpdate(
|
const archivedAsset = await assetModel(organization).findOneAndUpdate(
|
||||||
{ modelUuid, modelName, projectId },
|
{ modelUuid, modelName, projectId, versionId },
|
||||||
{ $set: { isArchive: true } },
|
{ $set: { isArchive: true } },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
@@ -287,7 +317,7 @@ export const deleteAssetModel = async (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
await EventsDataModel(organization).updateMany(
|
await EventsDataModel(organization).updateMany(
|
||||||
{ modelUuid, projectId: projectId },
|
{ modelUuid, projectId: projectId, versionId: versionId },
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -311,7 +341,8 @@ export const replaceEventDatas = async (
|
|||||||
data: ReplaceEventInput
|
data: ReplaceEventInput
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { modelUuid, organization, eventData, projectId, userId } = data;
|
const { modelUuid, organization, eventData, versionId, projectId, userId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -320,9 +351,16 @@ export const replaceEventDatas = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingModel = await assetModel(organization).findOne({
|
const existingModel = await assetModel(organization).findOne({
|
||||||
modelUuid: modelUuid,
|
modelUuid: modelUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!existingModel) {
|
if (!existingModel) {
|
||||||
@@ -339,7 +377,12 @@ export const replaceEventDatas = async (
|
|||||||
speed = typedEventData?.speed;
|
speed = typedEventData?.speed;
|
||||||
}
|
}
|
||||||
const updatedModel = await assetModel(organization).findOneAndUpdate(
|
const updatedModel = await assetModel(organization).findOneAndUpdate(
|
||||||
{ modelUuid, projectId, isArchive: false },
|
{
|
||||||
|
modelUuid,
|
||||||
|
projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
points: typedEventData?.points,
|
points: typedEventData?.points,
|
||||||
type: typedEventData?.type ?? existingModel?.type,
|
type: typedEventData?.type ?? existingModel?.type,
|
||||||
@@ -377,6 +420,7 @@ export const updateAssetPositionRotation = async (
|
|||||||
isVisible,
|
isVisible,
|
||||||
organization,
|
organization,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
} = data;
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
@@ -387,9 +431,16 @@ export const updateAssetPositionRotation = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const currentVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!currentVersion) return { status: "Version Data not found" };
|
||||||
const existingAsset = await assetModel(organization).findOne({
|
const existingAsset = await assetModel(organization).findOne({
|
||||||
modelUuid: modelUuid,
|
modelUuid: modelUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!existingAsset) {
|
if (!existingAsset) {
|
||||||
@@ -399,6 +450,7 @@ export const updateAssetPositionRotation = async (
|
|||||||
{
|
{
|
||||||
modelUuid: modelUuid,
|
modelUuid: modelUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
modelName: modelName,
|
modelName: modelName,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
@@ -429,7 +481,7 @@ export const getFloorItems = async (
|
|||||||
data: GetAssetInput
|
data: GetAssetInput
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, userId } = data;
|
const { organization, projectId, versionId, userId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -438,8 +490,20 @@ export const getFloorItems = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findValues = await assetModel(organization)
|
const findValues = await assetModel(organization)
|
||||||
.find({ isArchive: false, projectId: projectId })
|
.find({
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
|
})
|
||||||
.select("-_id -isArchive");
|
.select("-_id -isArchive");
|
||||||
|
|
||||||
if (!findValues || findValues.length === 0) {
|
if (!findValues || findValues.length === 0) {
|
||||||
@@ -449,6 +513,7 @@ export const getFloorItems = async (
|
|||||||
const response = findValues.map((item) => {
|
const response = findValues.map((item) => {
|
||||||
const responseItem: any = {
|
const responseItem: any = {
|
||||||
projectId: item.productId,
|
projectId: item.productId,
|
||||||
|
versionId: item.versionId,
|
||||||
modelUuid: item.modelUuid,
|
modelUuid: item.modelUuid,
|
||||||
modelName: item.modelName,
|
modelName: item.modelName,
|
||||||
position: item.position,
|
position: item.position,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import cameraModel from "../../V1Models/Builder/cameraModel.ts";
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
interface IcameraData {
|
interface IcameraData {
|
||||||
userId: string;
|
userId: string;
|
||||||
@@ -25,8 +26,14 @@ export const SetCamera = async (
|
|||||||
data: IcameraData
|
data: IcameraData
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { userId, position, target, rotation, organization, projectId } =
|
const {
|
||||||
data;
|
userId,
|
||||||
|
position,
|
||||||
|
target,
|
||||||
|
rotation,
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -38,6 +45,7 @@ export const SetCamera = async (
|
|||||||
const existingCamera = await cameraModel(organization).findOne({
|
const existingCamera = await cameraModel(organization).findOne({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (existingCamera) {
|
if (existingCamera) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import lineModel from "../../V1Models/Builder/linesModel.ts";
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
interface ILineItems {
|
interface ILineItems {
|
||||||
organization: string;
|
organization: string;
|
||||||
@@ -9,11 +10,13 @@ interface ILineItems {
|
|||||||
line: [];
|
line: [];
|
||||||
type: string;
|
type: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface ILineGet {
|
interface ILineGet {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface ILineUpdate {
|
interface ILineUpdate {
|
||||||
@@ -21,31 +24,36 @@ interface ILineUpdate {
|
|||||||
uuid: number;
|
uuid: number;
|
||||||
position: {};
|
position: {};
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface ILineDelete {
|
interface ILineDelete {
|
||||||
organization: string;
|
organization: string;
|
||||||
line: [];
|
line: [];
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface ILinePointsDelete {
|
interface ILinePointsDelete {
|
||||||
organization: string;
|
organization: string;
|
||||||
uuid: string;
|
uuid: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface ILayerDelete {
|
interface ILayerDelete {
|
||||||
organization: string;
|
organization: string;
|
||||||
layer: number;
|
layer: number;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
export const CreateLineItems = async (
|
export const CreateLineItems = async (
|
||||||
data: ILineItems
|
data: ILineItems
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, line, type, layer, projectId, userId } = data;
|
const { organization, line, type, layer, projectId, versionId, userId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -54,11 +62,18 @@ export const CreateLineItems = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const newLine = await lineModel(organization).create({
|
const newLine = await lineModel(organization).create({
|
||||||
layer,
|
layer,
|
||||||
line,
|
line,
|
||||||
type,
|
type,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId: versionId,
|
||||||
});
|
});
|
||||||
return { status: "Success", data: newLine };
|
return { status: "Success", data: newLine };
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
@@ -77,7 +92,7 @@ export const UpdateLineItems = async (
|
|||||||
data: ILineUpdate
|
data: ILineUpdate
|
||||||
): Promise<{ status: string; data?: Object }> => {
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, uuid, position, userId } = data;
|
const { organization, projectId, versionId, uuid, position, userId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -86,8 +101,18 @@ export const UpdateLineItems = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const updateResult = await lineModel(organization).updateMany(
|
const updateResult = await lineModel(organization).updateMany(
|
||||||
{ "line.uuid": uuid, projectId: projectId },
|
{
|
||||||
|
"line.uuid": uuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
},
|
||||||
{ $set: { "line.$.position": position } }
|
{ $set: { "line.$.position": position } }
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -111,7 +136,7 @@ export const DeleteLineItems = async (
|
|||||||
data: ILineDelete
|
data: ILineDelete
|
||||||
): Promise<{ status: string; data?: object }> => {
|
): Promise<{ status: string; data?: object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, line, userId } = data;
|
const { organization, projectId, versionId, line, userId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -120,12 +145,19 @@ export const DeleteLineItems = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const inputUuids = line.map((item: any) => {
|
const inputUuids = line.map((item: any) => {
|
||||||
return item.uuid;
|
return item.uuid;
|
||||||
});
|
});
|
||||||
|
|
||||||
const findValue = await lineModel(organization).findOneAndDelete({
|
const findValue = await lineModel(organization).findOneAndDelete({
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
"line.uuid": { $all: inputUuids },
|
"line.uuid": { $all: inputUuids },
|
||||||
});
|
});
|
||||||
@@ -156,7 +188,7 @@ export const DeleteLayer = async (
|
|||||||
data: ILayerDelete
|
data: ILayerDelete
|
||||||
): Promise<{ status: string; data?: object }> => {
|
): Promise<{ status: string; data?: object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, layer, userId } = data;
|
const { organization, projectId, versionId, layer, userId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -165,9 +197,16 @@ export const DeleteLayer = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findValue = await lineModel(organization).find({
|
const findValue = await lineModel(organization).find({
|
||||||
layer: layer,
|
layer: layer,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -175,7 +214,12 @@ export const DeleteLayer = async (
|
|||||||
return { status: "layer not found" };
|
return { status: "layer not found" };
|
||||||
} else {
|
} else {
|
||||||
await lineModel(organization).deleteMany(
|
await lineModel(organization).deleteMany(
|
||||||
{ projectId: projectId, layer: layer, isArchive: false },
|
{
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
layer: layer,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{ layer: layer }
|
{ layer: layer }
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -205,11 +249,25 @@ export const GetLinesService = async (
|
|||||||
data: ILineGet
|
data: ILineGet
|
||||||
): Promise<{ status: string; data?: object }> => {
|
): Promise<{ status: string; data?: object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, userId } = data;
|
const { organization, projectId, versionId,userId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findValue = await lineModel(organization).find({
|
const findValue = await lineModel(organization).find({
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!findValue) {
|
if (!findValue) {
|
||||||
@@ -233,7 +291,7 @@ export const DeleteLinePoints = async (
|
|||||||
data: ILinePointsDelete
|
data: ILinePointsDelete
|
||||||
): Promise<{ status: string; data?: object | string }> => {
|
): Promise<{ status: string; data?: object | string }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, uuid, userId } = data;
|
const { organization, projectId, uuid, userId, versionId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -242,8 +300,19 @@ export const DeleteLinePoints = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findValue = await lineModel(organization).deleteMany(
|
const findValue = await lineModel(organization).deleteMany(
|
||||||
{ projectId: projectId, isArchive: false, "line.uuid": uuid },
|
{
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
"line.uuid": uuid,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"line.uuid": uuid,
|
"line.uuid": uuid,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
|
import wallItemModel from "../../V1Models/Builder/wallItemsModel.ts";
|
||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
interface IWallSetupData {
|
interface IWallSetupData {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
assetId: string;
|
|
||||||
modelName: string;
|
modelName: string;
|
||||||
type: string;
|
type: string;
|
||||||
csgposition: [];
|
csgposition: [];
|
||||||
@@ -15,12 +15,15 @@ interface IWallSetupData {
|
|||||||
scale: [];
|
scale: [];
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
|
assetId: string;
|
||||||
}
|
}
|
||||||
interface IWallGet {
|
interface IWallGet {
|
||||||
userId: string;
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface IWallDelete {
|
interface IWallDelete {
|
||||||
userId: string;
|
userId: string;
|
||||||
@@ -28,6 +31,7 @@ interface IWallDelete {
|
|||||||
modelName: string;
|
modelName: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface IWallItemResult {
|
interface IWallItemResult {
|
||||||
data?: Object;
|
data?: Object;
|
||||||
@@ -41,16 +45,18 @@ export const setWallItems = async (
|
|||||||
userId,
|
userId,
|
||||||
modelUuid,
|
modelUuid,
|
||||||
modelName,
|
modelName,
|
||||||
|
assetId,
|
||||||
position,
|
position,
|
||||||
type,
|
type,
|
||||||
csgposition,
|
csgposition,
|
||||||
csgscale,
|
csgscale,
|
||||||
quaternion,
|
quaternion,
|
||||||
assetId,
|
|
||||||
scale,
|
scale,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
organization,
|
organization,
|
||||||
} = data;
|
} = data;
|
||||||
|
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -59,13 +65,27 @@ export const setWallItems = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findvalue = await wallItemModel(organization).findOne({
|
const findvalue = await wallItemModel(organization).findOne({
|
||||||
modelUuid: modelUuid,isArchive:false
|
modelUuid: modelUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (findvalue) {
|
if (findvalue) {
|
||||||
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
|
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
|
||||||
{ modelUuid: modelUuid, projectId: projectId,isArchive:false },
|
{
|
||||||
|
modelUuid: modelUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
modelName,
|
modelName,
|
||||||
position,
|
position,
|
||||||
@@ -87,14 +107,15 @@ export const setWallItems = async (
|
|||||||
modelName,
|
modelName,
|
||||||
position,
|
position,
|
||||||
type,
|
type,
|
||||||
projectId,
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
csgposition,
|
csgposition,
|
||||||
csgscale,
|
csgscale,
|
||||||
quaternion,
|
quaternion,
|
||||||
scale,
|
scale,
|
||||||
|
userId,
|
||||||
assetId,
|
assetId,
|
||||||
});
|
});
|
||||||
console.log("newValue: ", newValue);
|
|
||||||
return {
|
return {
|
||||||
// status: "wall Item created successfully",
|
// status: "wall Item created successfully",
|
||||||
status: "Success",
|
status: "Success",
|
||||||
@@ -115,7 +136,7 @@ export const setWallItems = async (
|
|||||||
};
|
};
|
||||||
export const getWallItems = async (data: IWallGet) => {
|
export const getWallItems = async (data: IWallGet) => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId, projectId } = data;
|
const { organization, userId, projectId, versionId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -124,8 +145,17 @@ export const getWallItems = async (data: IWallGet) => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findValue = await wallItemModel(organization).find({
|
const findValue = await wallItemModel(organization).find({
|
||||||
projectId: projectId,isArchive:false
|
projectId: projectId,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!findValue) {
|
if (!findValue) {
|
||||||
return {
|
return {
|
||||||
@@ -154,7 +184,8 @@ export const deleteWallItems = async (
|
|||||||
data: IWallDelete
|
data: IWallDelete
|
||||||
): Promise<IWallItemResult> => {
|
): Promise<IWallItemResult> => {
|
||||||
try {
|
try {
|
||||||
const { modelUuid, modelName, organization, userId, projectId } = data;
|
const { modelUuid, modelName, organization, userId, versionId, projectId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -163,10 +194,18 @@ export const deleteWallItems = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findValue = await wallItemModel(organization).findOneAndDelete({
|
const findValue = await wallItemModel(organization).findOneAndDelete({
|
||||||
modelUuid: modelUuid,
|
modelUuid: modelUuid,
|
||||||
modelName: modelName,
|
modelName: modelName,
|
||||||
projectId: projectId,isArchive:false
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!findValue) {
|
if (!findValue) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
interface ISetZone {
|
interface ISetZone {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
zoneData: {
|
zoneData: {
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
points: [];
|
points: [];
|
||||||
@@ -24,12 +26,21 @@ interface ISetZone {
|
|||||||
interface IZone {
|
interface IZone {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
zoneUuid: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IZoneDel {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface IVizZone {
|
interface IVizZone {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface IResult {
|
interface IResult {
|
||||||
@@ -39,12 +50,13 @@ interface IResult {
|
|||||||
interface IGetZones {
|
interface IGetZones {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SetZone = async (data: ISetZone): Promise<IResult> => {
|
export const SetZone = async (data: ISetZone): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, zoneData, userId } = data;
|
const { organization, projectId, versionId, zoneData, userId } = data;
|
||||||
const zoneUuid = zoneData.zoneUuid;
|
const zoneUuid = zoneData.zoneUuid;
|
||||||
const points = zoneData.points;
|
const points = zoneData.points;
|
||||||
const zoneName = zoneData.zoneName;
|
const zoneName = zoneData.zoneName;
|
||||||
@@ -59,22 +71,35 @@ export const SetZone = async (data: ISetZone): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findZoneId = await zoneModel(organization).findOne({
|
const findZoneId = await zoneModel(organization).findOne({
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
});
|
});
|
||||||
if (findZoneId) {
|
if (findZoneId) {
|
||||||
const updateZone = await zoneModel(organization)
|
const updateZone = await zoneModel(organization)
|
||||||
.findOneAndUpdate(
|
.findOneAndUpdate(
|
||||||
{ zoneUuid: zoneUuid, projectId: projectId, isArchive: false },
|
{
|
||||||
{
|
zoneUuid: zoneUuid,
|
||||||
points: points,
|
projectId: projectId,
|
||||||
viewPortposition: viewPortposition,
|
versionId: versionId,
|
||||||
viewPortCenter: viewPortCenter,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
{ new: true }
|
{
|
||||||
)
|
zoneName: zoneName,
|
||||||
.select("-_id -__v");
|
points: points,
|
||||||
|
viewPortposition: viewPortposition,
|
||||||
|
viewPortCenter: viewPortCenter,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
)
|
||||||
|
.select("-_id -__v");
|
||||||
return { status: "zone updated", data: updateZone };
|
return { status: "zone updated", data: updateZone };
|
||||||
} else {
|
} else {
|
||||||
const zoneCreate = await zoneModel(organization).create({
|
const zoneCreate = await zoneModel(organization).create({
|
||||||
@@ -84,11 +109,12 @@ export const SetZone = async (data: ISetZone): Promise<IResult> => {
|
|||||||
zoneName: zoneName,
|
zoneName: zoneName,
|
||||||
points,
|
points,
|
||||||
layer,
|
layer,
|
||||||
|
versionId: versionId,
|
||||||
viewPortCenter,
|
viewPortCenter,
|
||||||
viewPortposition,
|
viewPortposition,
|
||||||
});
|
});
|
||||||
const createdZone = await zoneModel(organization)
|
const createdZone = await zoneModel(organization)
|
||||||
.findById(zoneCreate._id)
|
.findById({ _id: zoneCreate._id, isArchive: false })
|
||||||
.select("-_id -__v");
|
.select("-_id -__v");
|
||||||
return { status: "Success", data: createdZone };
|
return { status: "Success", data: createdZone };
|
||||||
}
|
}
|
||||||
@@ -104,9 +130,9 @@ export const SetZone = async (data: ISetZone): Promise<IResult> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const DelZone = async (data: IZone): Promise<IResult> => {
|
export const DelZone = async (data: IZoneDel): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId, zoneUuid, projectId } = data;
|
const { organization, userId, zoneUuid, versionId, projectId } = data;
|
||||||
const findZoneId = await zoneModel(organization).findOne({
|
const findZoneId = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
@@ -120,12 +146,19 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
if (findZoneId) {
|
if (findZoneId) {
|
||||||
const deleteZone = await zoneModel(organization)
|
const deleteZone = await zoneModel(organization)
|
||||||
.findOneAndUpdate(
|
.findOneAndUpdate(
|
||||||
{
|
{
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
@@ -136,6 +169,8 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
|
|||||||
if (deleteZone) {
|
if (deleteZone) {
|
||||||
const panels = await panelModel(organization).find({
|
const panels = await panelModel(organization).find({
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -149,21 +184,41 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await panelModel(organization).updateMany(
|
await panelModel(organization).updateMany(
|
||||||
{ zoneUuid, isArchive: false },
|
{
|
||||||
|
zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
);
|
);
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
widget3dModel(organization).updateMany(
|
widget3dModel(organization).updateMany(
|
||||||
{ zoneUuid, isArchive: false },
|
{
|
||||||
|
zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
),
|
),
|
||||||
templateModel(organization).updateMany(
|
templateModel(organization).updateMany(
|
||||||
{ zoneUuid, isArchive: false },
|
{
|
||||||
|
zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
),
|
),
|
||||||
floatWidgetModel(organization).updateMany(
|
floatWidgetModel(organization).updateMany(
|
||||||
{ zoneUuid, isArchive: false },
|
{
|
||||||
|
zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
@@ -192,11 +247,28 @@ export const DelZone = async (data: IZone): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const GetZones = async (data: IGetZones): Promise<IResult> => {
|
export const GetZones = async (data: IGetZones): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId, projectId } = data;
|
const { organization, userId, projectId, versionId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findZoneId = await zoneModel(organization)
|
const findZoneId = await zoneModel(organization)
|
||||||
.find({ projectId: projectId, isArchive: false })
|
.find({
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
.select(
|
.select(
|
||||||
"zoneUuid zoneName layer points viewPortCenter viewPortposition -_id"
|
"zoneUuid zoneName layer points viewPortCenter viewPortposition -_id"
|
||||||
);
|
);
|
||||||
@@ -219,7 +291,7 @@ export const GetZones = async (data: IGetZones): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const ZoneData = async (data: IZone): Promise<IResult> => {
|
export const ZoneData = async (data: IZone): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId, projectId, zoneUuid } = data;
|
const { organization, userId, projectId, zoneUuid, versionId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -228,9 +300,17 @@ export const ZoneData = async (data: IZone): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const findZone = await zoneModel(organization).findOne({
|
const findZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (findZone)
|
if (findZone)
|
||||||
@@ -255,7 +335,7 @@ export const ZoneData = async (data: IZone): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
|
export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId, projectId, zoneUuid } = data;
|
const { organization, userId, projectId, versionId, zoneUuid } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -264,10 +344,18 @@ export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization)
|
const existingZone = await zoneModel(organization)
|
||||||
.findOne({
|
.findOne({
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
})
|
})
|
||||||
.select(
|
.select(
|
||||||
@@ -278,6 +366,8 @@ export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
|
|||||||
} else {
|
} else {
|
||||||
const panelData = await panelModel(organization).find({
|
const panelData = await panelModel(organization).find({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
const zoneName = existingZone.zoneName as string;
|
const zoneName = existingZone.zoneName as string;
|
||||||
@@ -286,6 +376,8 @@ export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
|
|||||||
panelData.map(async (data) => {
|
panelData.map(async (data) => {
|
||||||
const widgetDataArray = await widgetModel(organization).find({
|
const widgetDataArray = await widgetModel(organization).find({
|
||||||
panelID: data._id,
|
panelID: data._id,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -329,7 +421,7 @@ export const SingleZonePanelData = async (data: IZone): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const VizZoneDatas = async (data: IVizZone): Promise<IResult> => {
|
export const VizZoneDatas = async (data: IVizZone): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId, projectId } = data;
|
const { organization, userId, projectId, versionId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -338,9 +430,17 @@ export const VizZoneDatas = async (data: IVizZone): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZones = await zoneModel(organization)
|
const existingZones = await zoneModel(organization)
|
||||||
.find({
|
.find({
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
})
|
})
|
||||||
.select(
|
.select(
|
||||||
@@ -353,6 +453,8 @@ export const VizZoneDatas = async (data: IVizZone): Promise<IResult> => {
|
|||||||
existingZones.map(async (zone) => {
|
existingZones.map(async (zone) => {
|
||||||
const panelData = await panelModel(organization).find({
|
const panelData = await panelModel(organization).find({
|
||||||
zoneUuid: zone._id,
|
zoneUuid: zone._id,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -360,6 +462,8 @@ export const VizZoneDatas = async (data: IVizZone): Promise<IResult> => {
|
|||||||
panelData.map(async (panel) => {
|
panelData.map(async (panel) => {
|
||||||
const widgetDataArray = await widgetModel(organization).find({
|
const widgetDataArray = await widgetModel(organization).find({
|
||||||
panelID: panel._id,
|
panelID: panel._id,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
231
src/shared/services/collaborative/lineService-collab.ts
Normal file
231
src/shared/services/collaborative/lineService-collab.ts
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
import * as Y from "yjs";
|
||||||
|
|
||||||
|
import lineModel from "../../V1Models/Builder/linesModel.ts";
|
||||||
|
import { existingUser,existingProjectById } from "../helpers/v1projecthelperFns.ts";
|
||||||
|
// import { lineMap } from "../yjs/yjsStore.ts";
|
||||||
|
import { getYDoc } from "../../../socket-server/utils/yjs/yjsRoomjoin.ts";
|
||||||
|
import { saveSnapshotService } from "../yjs/snapshot.ts";
|
||||||
|
|
||||||
|
interface ILinePoint {
|
||||||
|
position: {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
z: number;
|
||||||
|
};
|
||||||
|
uuid: string;
|
||||||
|
}
|
||||||
|
interface ILineItems {
|
||||||
|
organization: string;
|
||||||
|
layer: number;
|
||||||
|
line:ILinePoint[];
|
||||||
|
type: string;
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface ILineGet {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IPosition {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
z: number;
|
||||||
|
}
|
||||||
|
interface ILineUpdate {
|
||||||
|
organization: string;
|
||||||
|
uuid: number;
|
||||||
|
position: IPosition;
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface ILineDelete {
|
||||||
|
organization: string;
|
||||||
|
line: [];
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface ILinePointsDelete {
|
||||||
|
organization: string;
|
||||||
|
uuid: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface ILayerDelete {
|
||||||
|
organization: string;
|
||||||
|
layer: number;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
// const ydoc = new Y.Doc();
|
||||||
|
// const lineMap = ydoc.getMap("lines");
|
||||||
|
|
||||||
|
export const createLineService = async (
|
||||||
|
data: ILineItems
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
const { organization, line, type, layer, projectId,versionId, userId } = data;
|
||||||
|
console.log('data: ', 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 newLine = await lineModel(organization).create({
|
||||||
|
layer,
|
||||||
|
line,
|
||||||
|
type,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
const ydoc = await getYDoc(projectId?.toString(), versionId?.toString(),organization?.toString());
|
||||||
|
console.log('ydoc: ', ydoc);
|
||||||
|
const lineMap = ydoc.getMap("lines");
|
||||||
|
console.log('lineMap: ', lineMap);
|
||||||
|
|
||||||
|
const yLine = new Y.Map();
|
||||||
|
yLine.set("layer", layer);
|
||||||
|
yLine.set("type", type);
|
||||||
|
yLine.set("projectId", projectId?.toString());
|
||||||
|
yLine.set("userId", userId?.toString());
|
||||||
|
yLine.set("versionId", LivingProject?.Present_version?.toString());
|
||||||
|
|
||||||
|
const yLineArray = new Y.Array();
|
||||||
|
console.log('yLineArray: ', yLineArray);
|
||||||
|
for (const point of line) {
|
||||||
|
const yPoint = new Y.Map();
|
||||||
|
if (point?.position) {
|
||||||
|
yPoint.set("position", new Y.Map([
|
||||||
|
["x", point.position.x],
|
||||||
|
["y", point.position.y],
|
||||||
|
["z", point.position.z]
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
yPoint.set("uuid", point.uuid);
|
||||||
|
yLineArray.push([yPoint]);
|
||||||
|
}
|
||||||
|
yLine.set("line", yLineArray);
|
||||||
|
|
||||||
|
lineMap.set(`${newLine._id.toString()}`, yLine);
|
||||||
|
console.log("Line added to map:", lineMap.get(`${newLine._id.toString()}`));
|
||||||
|
|
||||||
|
await saveSnapshotService({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
versionId: versionId ,
|
||||||
|
createdBy: userId,
|
||||||
|
label: `Auto-snapshot after create line`, // ✅ Label
|
||||||
|
ydoc
|
||||||
|
});
|
||||||
|
|
||||||
|
return { status: "Success", data: newLine };
|
||||||
|
|
||||||
|
};
|
||||||
|
export const updateLineService = async (
|
||||||
|
data: ILineUpdate
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
const { uuid, position,projectId,versionId, userId,organization } = data;
|
||||||
|
console.log('data: ', data);
|
||||||
|
|
||||||
|
const updated = await lineModel(organization).findOneAndUpdate(
|
||||||
|
{ "line.uuid": uuid },
|
||||||
|
{ $set: { "line.$.position": position } },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('updated: ', updated);
|
||||||
|
if (updated) {
|
||||||
|
const ydoc =await getYDoc(projectId, versionId,organization);
|
||||||
|
const yLine = ydoc.getMap("lines").get(`${updated._id}`);
|
||||||
|
console.log('yLine: ', yLine);
|
||||||
|
|
||||||
|
if (yLine && yLine instanceof Y.Map) {
|
||||||
|
const yLineArray = yLine.get("line");
|
||||||
|
console.log('yLineArray: ', yLineArray);
|
||||||
|
if (yLineArray && yLineArray instanceof Y.Array) {
|
||||||
|
for (let i = 0; i < yLineArray.length; i++) {
|
||||||
|
const yPoint = yLineArray.get(i);
|
||||||
|
if (yPoint?.get("uuid") === uuid) {
|
||||||
|
const yPos = new Y.Map();
|
||||||
|
yPos.set("x", position.x);
|
||||||
|
yPos.set("y", position.y);
|
||||||
|
yPos.set("z", position.z);
|
||||||
|
yPoint.set("position", yPos);
|
||||||
|
console.log(`✅ Updated Yjs lineMap for uuid: ${uuid}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await saveSnapshotService({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
versionId: versionId ,
|
||||||
|
createdBy: userId,
|
||||||
|
label: `Auto-snapshot after update line`, // ✅ Label
|
||||||
|
ydoc
|
||||||
|
});
|
||||||
|
return { status: "Success", data: updated };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { status: "Update failed" };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DeleteLineItems = async (
|
||||||
|
data: ILineDelete
|
||||||
|
): Promise<{ status: string; data?: object }> => {
|
||||||
|
try {
|
||||||
|
const { organization, projectId, versionId, line, userId } = data;
|
||||||
|
console.log('data: ', 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 inputUuids = line.map((item: any) => item.uuid);
|
||||||
|
|
||||||
|
// 🧩 Delete in MongoDB
|
||||||
|
const findValue = await lineModel(organization).findOneAndDelete({
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
"line.uuid": { $all: inputUuids },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!findValue) {
|
||||||
|
return { status: "line not found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🧠 Delete from Y.Doc
|
||||||
|
const ydoc =await getYDoc(projectId, versionId ,organization);
|
||||||
|
const lineMap = ydoc.getMap("lines");
|
||||||
|
|
||||||
|
lineMap.delete(`${findValue._id}`); // same _id used while storing in Yjs map
|
||||||
|
|
||||||
|
console.log(`🧼 Yjs: line ${findValue._id} deleted`);
|
||||||
|
await saveSnapshotService({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
versionId: versionId ,
|
||||||
|
createdBy: userId,
|
||||||
|
label: `Auto-snapshot after update line`, // ✅ Label
|
||||||
|
ydoc
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: findValue,
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return { status: error.message };
|
||||||
|
} else {
|
||||||
|
return { status: "An unexpected error occurred" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
499
src/shared/services/dummyservice.ts
Normal file
499
src/shared/services/dummyservice.ts
Normal file
@@ -0,0 +1,499 @@
|
|||||||
|
import EventsDummyModel from "../V1Models/dummy/eventDummy.ts";
|
||||||
|
import ProductDummyModel from "../V1Models/dummy/productDumy.ts";
|
||||||
|
import {
|
||||||
|
existingProjectById,
|
||||||
|
existingUser,
|
||||||
|
} from "./helpers/v1projecthelperFns.ts";
|
||||||
|
import actionDummyModel, {
|
||||||
|
ConveyorActionSchema,
|
||||||
|
MachineActionSchema,
|
||||||
|
RoboticArmActionSchema,
|
||||||
|
StorageActionSchema,
|
||||||
|
VehicleActionSchema,
|
||||||
|
} from "../V1Models/dummy/actionDummy.ts";
|
||||||
|
interface IEventDatainterface {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
position: [number];
|
||||||
|
rotation: [number];
|
||||||
|
type: string;
|
||||||
|
speed: string;
|
||||||
|
point: {
|
||||||
|
uuid: string;
|
||||||
|
position: [number];
|
||||||
|
rotation: [number];
|
||||||
|
action: IActioninterface;
|
||||||
|
actions: IActionsinterface;
|
||||||
|
};
|
||||||
|
points: {
|
||||||
|
uuid: string;
|
||||||
|
position: [number];
|
||||||
|
rotation: [number];
|
||||||
|
action: IActioninterface;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
interface IActionsinterface {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
productUuid: string;
|
||||||
|
type: string;
|
||||||
|
actions: RoboticArmActionSchema[];
|
||||||
|
}
|
||||||
|
interface IActioninterface {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
productUuid: string;
|
||||||
|
type: string;
|
||||||
|
Action:
|
||||||
|
| VehicleActionSchema
|
||||||
|
| ConveyorActionSchema
|
||||||
|
| MachineActionSchema
|
||||||
|
| StorageActionSchema;
|
||||||
|
Actions: RoboticArmActionSchema[];
|
||||||
|
}
|
||||||
|
interface Iproduct {
|
||||||
|
productName: string;
|
||||||
|
productUuid: string;
|
||||||
|
eventDatas: IEventDatainterface;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IProductEvent {
|
||||||
|
productUuid: string;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IDelEvent {
|
||||||
|
productUuid: string;
|
||||||
|
modelUuid: string;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IProjectProducts {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IProductRename {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
productUuid: string;
|
||||||
|
productName: string;
|
||||||
|
}
|
||||||
|
interface IResult {
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const productAdddummy = async (data: Iproduct): Promise<any> => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
productName,
|
||||||
|
productUuid,
|
||||||
|
eventDatas,
|
||||||
|
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 existingProduct = await ProductAFind(
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
if (existingProduct) {
|
||||||
|
const existingEventData = await EventsDummyModel(organization).findOne({
|
||||||
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
modelUuid: eventDatas.modelUuid,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existingEventData) {
|
||||||
|
await EventUpdateFunction(
|
||||||
|
organization,
|
||||||
|
eventDatas,
|
||||||
|
productUuid,
|
||||||
|
projectId
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
status: "EventData updated successfully",
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
await EventCreateFunction(
|
||||||
|
organization,
|
||||||
|
eventDatas,
|
||||||
|
productUuid,
|
||||||
|
projectId
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
status: "EventData add successfully",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const newProduct = await ProductDummyModel(organization).create({
|
||||||
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
productName: productName,
|
||||||
|
});
|
||||||
|
if (newProduct) {
|
||||||
|
if (eventDatas) {
|
||||||
|
await EventCreateFunction(
|
||||||
|
organization,
|
||||||
|
eventDatas,
|
||||||
|
productUuid,
|
||||||
|
projectId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async function EventCreateFunction(
|
||||||
|
organization: string,
|
||||||
|
eventDatas: IEventDatainterface,
|
||||||
|
productUuid: string,
|
||||||
|
projectId: string
|
||||||
|
) {
|
||||||
|
await EventsDummyModel(organization).create({
|
||||||
|
projectId: projectId,
|
||||||
|
productUuid: productUuid,
|
||||||
|
modelUuid: eventDatas?.modelUuid as string,
|
||||||
|
modelName: eventDatas?.modelName,
|
||||||
|
position: eventDatas?.position,
|
||||||
|
rotation: eventDatas?.rotation,
|
||||||
|
type: eventDatas?.type,
|
||||||
|
speed: eventDatas?.speed,
|
||||||
|
point: {
|
||||||
|
uuid: eventDatas.point?.uuid,
|
||||||
|
},
|
||||||
|
points: eventDatas.points?.map((point) => ({
|
||||||
|
uuid: point.uuid,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
eventDatas.points;
|
||||||
|
await actionDummyModel(organization).create({
|
||||||
|
projectId: projectId,
|
||||||
|
productUuid: productUuid,
|
||||||
|
modelUuid: eventDatas?.modelUuid as string,
|
||||||
|
modelName: eventDatas?.modelName,
|
||||||
|
type: eventDatas?.type,
|
||||||
|
// Action: {
|
||||||
|
// uuid: eventDatas.point?.uuid,
|
||||||
|
// Action: eventDatas.point?.action || eventDatas.points?.action,
|
||||||
|
// },
|
||||||
|
// Actions: eventDatas.point?.actions.map((action) => ({
|
||||||
|
// uuid: action.uuid,
|
||||||
|
// Action: action.action,
|
||||||
|
// })),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function EventUpdateFunction(
|
||||||
|
organization: string,
|
||||||
|
eventDatas: IEventDatainterface,
|
||||||
|
productUuid: string,
|
||||||
|
projectId: string
|
||||||
|
) {
|
||||||
|
await EventsDummyModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
projectId: projectId,
|
||||||
|
modelUuid: eventDatas.modelUuid,
|
||||||
|
productUuid: productUuid,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
modelUuid: eventDatas?.modelUuid,
|
||||||
|
modelName: eventDatas?.modelName,
|
||||||
|
position: eventDatas?.position,
|
||||||
|
rotation: eventDatas?.rotation,
|
||||||
|
type: eventDatas?.type,
|
||||||
|
speed: eventDatas?.speed,
|
||||||
|
point: eventDatas?.point,
|
||||||
|
points: eventDatas?.points,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
async function ProductAFind(
|
||||||
|
productUuid: string,
|
||||||
|
projectId: string,
|
||||||
|
organization: string
|
||||||
|
) {
|
||||||
|
const existingProduct = await ProductDummyModel(organization).findOne({
|
||||||
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
return existingProduct;
|
||||||
|
}
|
||||||
|
export const getProductDatas = async (
|
||||||
|
data: IProductEvent
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { productUuid, 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 ExistingProduct = await ProductAFind(
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
|
|
||||||
|
const existingEventDatas = await EventsDummyModel(organization)
|
||||||
|
.find({
|
||||||
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("-productUuid");
|
||||||
|
if (!existingEventDatas) {
|
||||||
|
return { status: "Events not found", data: [] };
|
||||||
|
}
|
||||||
|
return { status: "Success", data: existingEventDatas };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const productDataDelete = async (
|
||||||
|
data: IProductEvent
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { productUuid, 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 ExistingProduct = await ProductAFind(
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
|
|
||||||
|
await ProductDummyModel(organization).findOneAndUpdate(
|
||||||
|
{ productUuid: productUuid, projectId: projectId, isArchive: false },
|
||||||
|
{
|
||||||
|
isArchive: true,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
const existingEventDatas = await EventsDummyModel(organization).find({
|
||||||
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existingEventDatas) {
|
||||||
|
await EventsDummyModel(organization).updateMany(
|
||||||
|
{ productUuid, projectId, isArchive: false },
|
||||||
|
{ $set: { isArchive: true } }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const EventDataDelete = async (data: IDelEvent): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { modelUuid, productUuid, 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 ExistingProduct = await ProductAFind(
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
|
const EventDel = await EventsDummyModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
modelUuid: modelUuid,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isArchive: true,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (!EventDel)
|
||||||
|
return {
|
||||||
|
status: "Event Delete Unsuccessful",
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const AllProductDatas = async (
|
||||||
|
data: IProjectProducts
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { 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 existingProduct = await ProductDummyModel(organization).find({
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingProduct) {
|
||||||
|
return {
|
||||||
|
status: "No products found",
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const result = [];
|
||||||
|
|
||||||
|
for (const product of existingProduct) {
|
||||||
|
const eventDatas = await EventsDummyModel(organization)
|
||||||
|
.find({
|
||||||
|
projectId: product.projectId,
|
||||||
|
productUuid: product.productUuid,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("-productUuid -isArchive -createdAt -updatedAt -__v -_id");
|
||||||
|
|
||||||
|
result.push({
|
||||||
|
projectId: product.projectId,
|
||||||
|
productName: product.productName,
|
||||||
|
productUuid: product.productUuid,
|
||||||
|
eventDatas,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: result,
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const productRename = async (data: IProductRename): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { productName, productUuid, 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 ExistingProduct = await ProductAFind(
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
|
|
||||||
|
const UpdateName = await ProductDummyModel(organization).findOneAndUpdate(
|
||||||
|
{ productUuid: productUuid, projectId: projectId, isArchive: false },
|
||||||
|
{
|
||||||
|
productName: productName,
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
if (!UpdateName) {
|
||||||
|
return {
|
||||||
|
status: "Rename Unsuccessful",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -26,7 +26,18 @@ export const existingUser = async (userId: string, organization: string) => {
|
|||||||
});
|
});
|
||||||
return userData;
|
return userData;
|
||||||
};
|
};
|
||||||
|
export async function LivingCurrentVersion(
|
||||||
|
organization: string,
|
||||||
|
projectId: string,
|
||||||
|
versionId: string
|
||||||
|
) {
|
||||||
|
const livingCurentVersion = await versionModel(organization).findOne({
|
||||||
|
_id: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
return livingCurentVersion;
|
||||||
|
}
|
||||||
export const archiveProject = async (
|
export const archiveProject = async (
|
||||||
projectId: string,
|
projectId: string,
|
||||||
organization: string
|
organization: string
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import ProductModel from "../../V1Models/Simulation/productModel.ts";
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
import versionModel from "../../V1Models/Version/versionModel.ts";
|
||||||
interface IEventDatainterface {
|
interface IEventDatainterface {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
modelName: string;
|
modelName: string;
|
||||||
@@ -31,12 +33,21 @@ interface Iproduct {
|
|||||||
userId: string;
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface IProductEvent {
|
interface IProductEvent {
|
||||||
productUuid: string;
|
productUuid: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
}
|
||||||
|
interface IProductEventDel {
|
||||||
|
productUuid: string;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface IDelEvent {
|
interface IDelEvent {
|
||||||
productUuid: string;
|
productUuid: string;
|
||||||
@@ -44,16 +55,19 @@ interface IDelEvent {
|
|||||||
userId: string;
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface IProjectProducts {
|
interface IProjectProducts {
|
||||||
userId: string;
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface IProductRename {
|
interface IProductRename {
|
||||||
userId: string;
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
productUuid: string;
|
productUuid: string;
|
||||||
productName: string;
|
productName: string;
|
||||||
}
|
}
|
||||||
@@ -69,6 +83,7 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
|||||||
productUuid,
|
productUuid,
|
||||||
eventDatas,
|
eventDatas,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
userId,
|
userId,
|
||||||
organization,
|
organization,
|
||||||
} = data;
|
} = data;
|
||||||
@@ -80,15 +95,23 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingProduct = await ProductAFind(
|
const existingProduct = await ProductAFind(
|
||||||
productUuid,
|
productUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
organization
|
organization
|
||||||
);
|
);
|
||||||
if (existingProduct) {
|
if (existingProduct) {
|
||||||
const existingEventData = await EventsDataModel(organization).findOne({
|
const existingEventData = await EventsDataModel(organization).findOne({
|
||||||
productUuid: productUuid,
|
productUuid: productUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
modelUuid: eventDatas.modelUuid,
|
modelUuid: eventDatas.modelUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
@@ -97,7 +120,8 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
|||||||
organization,
|
organization,
|
||||||
eventDatas,
|
eventDatas,
|
||||||
productUuid,
|
productUuid,
|
||||||
projectId
|
projectId,
|
||||||
|
versionId
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
status: "EventData updated successfully",
|
status: "EventData updated successfully",
|
||||||
@@ -107,7 +131,8 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
|||||||
organization,
|
organization,
|
||||||
eventDatas,
|
eventDatas,
|
||||||
productUuid,
|
productUuid,
|
||||||
projectId
|
projectId,
|
||||||
|
versionId
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
status: "EventData add successfully",
|
status: "EventData add successfully",
|
||||||
@@ -118,6 +143,7 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
|||||||
productUuid: productUuid,
|
productUuid: productUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
productName: productName,
|
productName: productName,
|
||||||
|
versionId: versionId,
|
||||||
});
|
});
|
||||||
if (newProduct) {
|
if (newProduct) {
|
||||||
if (eventDatas) {
|
if (eventDatas) {
|
||||||
@@ -125,7 +151,8 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
|||||||
organization,
|
organization,
|
||||||
eventDatas,
|
eventDatas,
|
||||||
productUuid,
|
productUuid,
|
||||||
projectId
|
projectId,
|
||||||
|
versionId
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,9 +177,11 @@ async function EventCreateFunction(
|
|||||||
organization: string,
|
organization: string,
|
||||||
eventDatas: IEventDatainterface,
|
eventDatas: IEventDatainterface,
|
||||||
productUuid: string,
|
productUuid: string,
|
||||||
projectId: string
|
projectId: string,
|
||||||
|
versionId: string
|
||||||
) {
|
) {
|
||||||
await EventsDataModel(organization).create({
|
await EventsDataModel(organization).create({
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
productUuid: productUuid,
|
productUuid: productUuid,
|
||||||
modelUuid: eventDatas?.modelUuid as string,
|
modelUuid: eventDatas?.modelUuid as string,
|
||||||
@@ -169,11 +198,13 @@ async function EventUpdateFunction(
|
|||||||
organization: string,
|
organization: string,
|
||||||
eventDatas: IEventDatainterface,
|
eventDatas: IEventDatainterface,
|
||||||
productUuid: string,
|
productUuid: string,
|
||||||
projectId: string
|
projectId: string,
|
||||||
|
versionId: string
|
||||||
) {
|
) {
|
||||||
await EventsDataModel(organization).findOneAndUpdate(
|
await EventsDataModel(organization).findOneAndUpdate(
|
||||||
{
|
{
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
modelUuid: eventDatas.modelUuid,
|
modelUuid: eventDatas.modelUuid,
|
||||||
productUuid: productUuid,
|
productUuid: productUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -193,11 +224,13 @@ async function EventUpdateFunction(
|
|||||||
async function ProductAFind(
|
async function ProductAFind(
|
||||||
productUuid: string,
|
productUuid: string,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
|
versionId: string,
|
||||||
organization: string
|
organization: string
|
||||||
) {
|
) {
|
||||||
const existingProduct = await ProductModel(organization).findOne({
|
const existingProduct = await ProductModel(organization).findOne({
|
||||||
productUuid: productUuid,
|
productUuid: productUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -207,7 +240,7 @@ export const getProductDatas = async (
|
|||||||
data: IProductEvent
|
data: IProductEvent
|
||||||
): Promise<IResult> => {
|
): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { productUuid, projectId, userId, organization } = data;
|
const { productUuid, projectId,versionId, userId, organization } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -216,9 +249,17 @@ export const getProductDatas = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const ExistingProduct = await ProductAFind(
|
const ExistingProduct = await ProductAFind(
|
||||||
productUuid,
|
productUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
ExistingVersion._id,
|
||||||
organization
|
organization
|
||||||
);
|
);
|
||||||
if (!ExistingProduct) return { status: "Product not found" };
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
@@ -227,6 +268,7 @@ export const getProductDatas = async (
|
|||||||
.find({
|
.find({
|
||||||
productUuid: productUuid,
|
productUuid: productUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
})
|
})
|
||||||
.select("-productUuid");
|
.select("-productUuid");
|
||||||
@@ -247,10 +289,10 @@ export const getProductDatas = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const productDataDelete = async (
|
export const productDataDelete = async (
|
||||||
data: IProductEvent
|
data: IProductEventDel
|
||||||
): Promise<IResult> => {
|
): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { productUuid, projectId, userId, organization } = data;
|
const { productUuid, projectId, versionId, userId, organization } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -259,15 +301,27 @@ export const productDataDelete = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const ExistingProduct = await ProductAFind(
|
const ExistingProduct = await ProductAFind(
|
||||||
productUuid,
|
productUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
organization
|
organization
|
||||||
);
|
);
|
||||||
if (!ExistingProduct) return { status: "Product not found" };
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
|
|
||||||
await ProductModel(organization).findOneAndUpdate(
|
await ProductModel(organization).findOneAndUpdate(
|
||||||
{ productUuid: productUuid, projectId: projectId, isArchive: false },
|
{
|
||||||
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
isArchive: true,
|
isArchive: true,
|
||||||
},
|
},
|
||||||
@@ -276,11 +330,17 @@ export const productDataDelete = async (
|
|||||||
const existingEventDatas = await EventsDataModel(organization).find({
|
const existingEventDatas = await EventsDataModel(organization).find({
|
||||||
productUuid: productUuid,
|
productUuid: productUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (existingEventDatas) {
|
if (existingEventDatas) {
|
||||||
await EventsDataModel(organization).updateMany(
|
await EventsDataModel(organization).updateMany(
|
||||||
{ productUuid, projectId, isArchive: false },
|
{
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -301,7 +361,14 @@ export const productDataDelete = async (
|
|||||||
};
|
};
|
||||||
export const EventDataDelete = async (data: IDelEvent): Promise<IResult> => {
|
export const EventDataDelete = async (data: IDelEvent): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { modelUuid, productUuid, projectId, userId, organization } = data;
|
const {
|
||||||
|
modelUuid,
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -310,9 +377,16 @@ export const EventDataDelete = async (data: IDelEvent): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const ExistingProduct = await ProductAFind(
|
const ExistingProduct = await ProductAFind(
|
||||||
productUuid,
|
productUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
organization
|
organization
|
||||||
);
|
);
|
||||||
if (!ExistingProduct) return { status: "Product not found" };
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
@@ -320,6 +394,7 @@ export const EventDataDelete = async (data: IDelEvent): Promise<IResult> => {
|
|||||||
{
|
{
|
||||||
productUuid: productUuid,
|
productUuid: productUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
modelUuid: modelUuid,
|
modelUuid: modelUuid,
|
||||||
},
|
},
|
||||||
@@ -351,7 +426,7 @@ export const AllProductDatas = async (
|
|||||||
data: IProjectProducts
|
data: IProjectProducts
|
||||||
): Promise<IResult> => {
|
): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { projectId, userId, organization } = data;
|
const { projectId, versionId ,userId, organization } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -360,8 +435,16 @@ export const AllProductDatas = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingProduct = await ProductModel(organization).find({
|
const existingProduct = await ProductModel(organization).find({
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingProduct) {
|
if (!existingProduct) {
|
||||||
@@ -375,6 +458,7 @@ export const AllProductDatas = async (
|
|||||||
for (const product of existingProduct) {
|
for (const product of existingProduct) {
|
||||||
const eventDatas = await EventsDataModel(organization)
|
const eventDatas = await EventsDataModel(organization)
|
||||||
.find({
|
.find({
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
projectId: product.projectId,
|
projectId: product.projectId,
|
||||||
productUuid: product.productUuid,
|
productUuid: product.productUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -383,6 +467,7 @@ export const AllProductDatas = async (
|
|||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
projectId: product.projectId,
|
projectId: product.projectId,
|
||||||
|
versionId: product.versionId,
|
||||||
productName: product.productName,
|
productName: product.productName,
|
||||||
productUuid: product.productUuid,
|
productUuid: product.productUuid,
|
||||||
eventDatas,
|
eventDatas,
|
||||||
@@ -407,7 +492,14 @@ export const AllProductDatas = async (
|
|||||||
};
|
};
|
||||||
export const productRename = async (data: IProductRename): Promise<IResult> => {
|
export const productRename = async (data: IProductRename): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { productName, productUuid, projectId, userId, organization } = data;
|
const {
|
||||||
|
productName,
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -416,15 +508,27 @@ export const productRename = async (data: IProductRename): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const ExistingProduct = await ProductAFind(
|
const ExistingProduct = await ProductAFind(
|
||||||
productUuid,
|
productUuid,
|
||||||
projectId,
|
projectId,
|
||||||
|
versionId,
|
||||||
organization
|
organization
|
||||||
);
|
);
|
||||||
if (!ExistingProduct) return { status: "Product not found" };
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
|
|
||||||
const UpdateName = await ProductModel(organization).findOneAndUpdate(
|
const UpdateName = await ProductModel(organization).findOneAndUpdate(
|
||||||
{ productUuid: productUuid, projectId: projectId, isArchive: false },
|
{
|
||||||
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
productName: productName,
|
productName: productName,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ export const TrashDatas = async (data: IOrg) => {
|
|||||||
Trash.DeletedAt.getTime() + 15 * 24 * 60 * 60 * 1000
|
Trash.DeletedAt.getTime() + 15 * 24 * 60 * 60 * 1000
|
||||||
);
|
);
|
||||||
if (now > deletedPlus15) {
|
if (now > deletedPlus15) {
|
||||||
console.log("now > deletedPlus15: ", now > deletedPlus15);
|
|
||||||
await projectModel(organization).updateOne(
|
await projectModel(organization).updateOne(
|
||||||
{ _id: Trash._id },
|
{ _id: Trash._id },
|
||||||
{ $set: { isDeleted: true } }
|
{ $set: { isDeleted: true } }
|
||||||
|
|||||||
@@ -5,8 +5,20 @@ import {
|
|||||||
existingUser,
|
existingUser,
|
||||||
previousVersion,
|
previousVersion,
|
||||||
generateUntitledProjectName,
|
generateUntitledProjectName,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
import UsersDataModel from "../../V1Models/Auth/user.ts";
|
import UsersDataModel from "../../V1Models/Auth/user.ts";
|
||||||
|
import assetModel from "../../V1Models/Builder/assetModel.ts";
|
||||||
|
import AisleModel from "../../V1Models/Builder/AisleModel.ts";
|
||||||
|
import cameraModel from "../../V1Models/Builder/cameraModel.ts";
|
||||||
|
import lineModel from "../../V1Models/Builder/linesModel.ts";
|
||||||
|
import wallItemModel from "../../V1Models/Builder/wallItemsModel.ts";
|
||||||
|
import zoneModel from "../../V1Models/Builder/zoneModel.ts";
|
||||||
|
import ProductModel from "../../V1Models/Simulation/productModel.ts";
|
||||||
|
import EventsDataModel from "../../V1Models/Simulation/eventsDataModel.ts";
|
||||||
|
import widget3dModel from "../../V1Models/Vizualization/3dwidget.ts";
|
||||||
|
import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
|
||||||
|
import templateModel from "../../V1Models/Vizualization/templatemodel.ts";
|
||||||
interface CreateProjectInput {
|
interface CreateProjectInput {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
projectUuid: string;
|
projectUuid: string;
|
||||||
@@ -86,15 +98,28 @@ export const createProject = async (data: CreateProjectInput) => {
|
|||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
const versionData = await previousVersion(project._id, organization);
|
const versionData = await previousVersion(project._id, organization);
|
||||||
|
|
||||||
|
const versionNameDesc = new Date().toLocaleString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "2-digit",
|
||||||
|
});
|
||||||
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.0,
|
version: 0.1,
|
||||||
|
versionName: versionNameDesc,
|
||||||
|
description: versionNameDesc,
|
||||||
});
|
});
|
||||||
await projectModel(organization).findByIdAndUpdate(
|
await projectModel(organization).findByIdAndUpdate(
|
||||||
{ _id: project._id, isArchive: false },
|
{ _id: project._id, isArchive: false },
|
||||||
{ total_versions: `v-${newVersion.version.toFixed(2)}` }
|
{
|
||||||
|
total_versions: `v-${newVersion.version.toFixed(1)}`,
|
||||||
|
Present_version: newVersion._id,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -102,7 +127,6 @@ export const createProject = async (data: CreateProjectInput) => {
|
|||||||
project: project,
|
project: project,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("error: ", error);
|
|
||||||
return {
|
return {
|
||||||
status: error,
|
status: error,
|
||||||
};
|
};
|
||||||
@@ -140,6 +164,7 @@ export const DeleteProject = async (data: ProjectDelInterface) => {
|
|||||||
{ isArchive: true, DeletedAt: new Date() },
|
{ isArchive: true, DeletedAt: new Date() },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
console.log("updateProject: ", updateProject);
|
||||||
if (updateProject) return { status: "Success", project: updateProject };
|
if (updateProject) return { status: "Success", project: updateProject };
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
return { status: error };
|
return { status: error };
|
||||||
@@ -150,15 +175,23 @@ export const updateProject = async (data: UpdateProjectInput) => {
|
|||||||
const { projectId, organization, userId, projectName, thumbnail } = data;
|
const { projectId, organization, userId, projectName, thumbnail } = data;
|
||||||
const ExistingUser = await existingUser(userId, organization);
|
const ExistingUser = await existingUser(userId, organization);
|
||||||
if (!ExistingUser) return { status: "User not found" };
|
if (!ExistingUser) return { status: "User not found" };
|
||||||
let filter = { _id: projectId, isArchive: false } as RoleFilter;
|
const existingProject = await projectModel(organization).findOne({
|
||||||
|
_id: projectId,
|
||||||
const existingProject = await projectModel(organization).findOne(filter);
|
isArchive: false,
|
||||||
|
});
|
||||||
if (!existingProject) return { status: "Project not found" };
|
if (!existingProject) return { status: "Project not found" };
|
||||||
|
// const currentVersion = await LivingCurrentVersion(
|
||||||
|
// organization,
|
||||||
|
// existingProject._id,
|
||||||
|
// existingProject.Present_version
|
||||||
|
// );
|
||||||
|
// if (!currentVersion) return { status: "CurrentVersion Data not found" };
|
||||||
if (projectName !== undefined) existingProject.projectName = projectName;
|
if (projectName !== undefined) existingProject.projectName = projectName;
|
||||||
if (thumbnail !== undefined) existingProject.thumbnail = thumbnail;
|
if (thumbnail !== undefined) existingProject.thumbnail = thumbnail;
|
||||||
const updateProject = await projectModel(organization)
|
const updateProject = await projectModel(organization)
|
||||||
.findOneAndUpdate(
|
.findOneAndUpdate(
|
||||||
filter,
|
// { _id: projectId, isArchive: false,versionId:currentVersion._id },
|
||||||
|
{ _id: projectId, isArchive: false },
|
||||||
{ projectName: projectName, thumbnail: thumbnail },
|
{ projectName: projectName, thumbnail: thumbnail },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
)
|
)
|
||||||
@@ -190,19 +223,27 @@ export const DuplicateProject = async (data: IProjectDuplicate) => {
|
|||||||
organization,
|
organization,
|
||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
|
|
||||||
if (projectExisting) {
|
if (projectExisting) {
|
||||||
return {
|
return {
|
||||||
status: "project_exists",
|
status: "project_exists",
|
||||||
project: projectExisting,
|
project: projectExisting,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
const OldprojectData = await projectModel(organization).findOne({
|
||||||
|
_id: projectUuid,
|
||||||
|
createdBy: userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
const oldprojectPresentVersion = await versionModel(organization).findOne({
|
||||||
|
_id: OldprojectData.Present_version,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
const uniqeName = await generateUniqueProjectName(
|
const uniqeName = await generateUniqueProjectName(
|
||||||
projectName,
|
projectName,
|
||||||
organization,
|
organization,
|
||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
const project = await projectModel(organization).create({
|
const newProject = await projectModel(organization).create({
|
||||||
projectName: uniqeName,
|
projectName: uniqeName,
|
||||||
projectUuid: projectUuid,
|
projectUuid: projectUuid,
|
||||||
createdBy: userId,
|
createdBy: userId,
|
||||||
@@ -210,20 +251,21 @@ export const DuplicateProject = async (data: IProjectDuplicate) => {
|
|||||||
sharedUsers: sharedUsers || [],
|
sharedUsers: sharedUsers || [],
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
await AllCloneForduplicate(projectUuid, newProject._id, organization);
|
||||||
const RecentUserDoc = await UsersDataModel(organization).findOne({
|
const RecentUserDoc = await UsersDataModel(organization).findOne({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
const newArr = RecentUserDoc?.recentlyViewed || [];
|
const newArr = RecentUserDoc?.recentlyViewed || [];
|
||||||
if (RecentUserDoc?.recentlyViewed.length === 0) {
|
if (RecentUserDoc?.recentlyViewed.length === 0) {
|
||||||
newArr.push(project._id);
|
newArr.push(newProject._id);
|
||||||
await RecentUserDoc.save();
|
await RecentUserDoc.save();
|
||||||
} else {
|
} else {
|
||||||
const index = newArr.indexOf(project._id);
|
const index = newArr.indexOf(newProject._id);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
newArr.splice(index, 1);
|
newArr.splice(index, 1);
|
||||||
}
|
}
|
||||||
newArr.unshift(project._id);
|
newArr.unshift(newProject._id);
|
||||||
|
|
||||||
if (newArr.length > maxLength) {
|
if (newArr.length > maxLength) {
|
||||||
newArr.pop();
|
newArr.pop();
|
||||||
@@ -234,21 +276,35 @@ export const DuplicateProject = async (data: IProjectDuplicate) => {
|
|||||||
{ recentlyViewed: newArr },
|
{ recentlyViewed: newArr },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
const versionData = await previousVersion(project._id, organization);
|
const oldVersions = await versionModel(organization).find({
|
||||||
if (!versionData || versionData.length === 0) {
|
projectId: projectUuid,
|
||||||
const newVersion = await versionModel(organization).create({
|
isArchive: false,
|
||||||
projectId: project._id,
|
});
|
||||||
createdBy: userId,
|
const clonedVersions = oldVersions.map((doc) => {
|
||||||
version: 0.0,
|
const { _id, __v, ...rest } = doc.toObject();
|
||||||
});
|
return {
|
||||||
await projectModel(organization).findByIdAndUpdate(
|
...rest,
|
||||||
{ _id: project._id, isArchive: false },
|
projectId: newProject._id,
|
||||||
{ total_versions: `v-${newVersion.version.toFixed(2)}` }
|
};
|
||||||
);
|
});
|
||||||
}
|
|
||||||
|
const createdversions = await versionModel(organization).create(
|
||||||
|
clonedVersions
|
||||||
|
);
|
||||||
|
const newPresentVersion = createdversions.find(
|
||||||
|
(v) => v.version === oldprojectPresentVersion?.version
|
||||||
|
);
|
||||||
|
|
||||||
|
await projectModel(organization).findByIdAndUpdate(
|
||||||
|
{ _id: newProject._id, isArchive: false },
|
||||||
|
{
|
||||||
|
total_versions: OldprojectData.total_versions,
|
||||||
|
Present_version: newPresentVersion._id,
|
||||||
|
}
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
status: "Success",
|
status: "Success",
|
||||||
project: project,
|
project: newProject,
|
||||||
};
|
};
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
return { status: error };
|
return { status: error };
|
||||||
@@ -295,6 +351,12 @@ export const viewProject = async (data: ProjectInterface) => {
|
|||||||
|
|
||||||
const existingProject = await projectModel(organization).findOne(filter);
|
const existingProject = await projectModel(organization).findOne(filter);
|
||||||
if (!existingProject) return { status: "Project not found" };
|
if (!existingProject) return { status: "Project not found" };
|
||||||
|
// const currentVersion = await LivingCurrentVersion(
|
||||||
|
// organization,
|
||||||
|
// existingProject._id,
|
||||||
|
// existingProject.Present_version
|
||||||
|
// );
|
||||||
|
// if (!currentVersion) return { status: "CurrentVersion Data not found" };
|
||||||
const newArr = RecentUserDoc?.recentlyViewed || [];
|
const newArr = RecentUserDoc?.recentlyViewed || [];
|
||||||
if (RecentUserDoc?.recentlyViewed.length === 0) {
|
if (RecentUserDoc?.recentlyViewed.length === 0) {
|
||||||
newArr.push(projectId);
|
newArr.push(projectId);
|
||||||
@@ -317,9 +379,47 @@ export const viewProject = async (data: ProjectInterface) => {
|
|||||||
);
|
);
|
||||||
const projectData = await projectModel(organization)
|
const projectData = await projectModel(organization)
|
||||||
.findOneAndUpdate(filter, { isViewed: Date.now() }, { new: true })
|
.findOneAndUpdate(filter, { isViewed: Date.now() }, { new: true })
|
||||||
.select("_id projectName createdBy thumbnail createdAt");
|
.select("_id projectName createdBy thumbnail createdAt isViewed");
|
||||||
return { status: "Success", data: projectData };
|
return { status: "Success", data: projectData };
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
return { status: error };
|
return { status: error };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const AllCloneForduplicate = async (
|
||||||
|
beforeCloneProjectId: string,
|
||||||
|
NewprojectId: string,
|
||||||
|
organization: string
|
||||||
|
) => {
|
||||||
|
async function cloneDocuments(model: any, label: string) {
|
||||||
|
const records = await model(organization).find({
|
||||||
|
projectId: beforeCloneProjectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!records.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cloned = records.map((doc: any) => {
|
||||||
|
const { _id, __v, ...rest } = doc.toObject();
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
projectId: NewprojectId,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const created = await model(organization).create(cloned);
|
||||||
|
}
|
||||||
|
await cloneDocuments(assetModel, "Asset");
|
||||||
|
await cloneDocuments(AisleModel, "Aisle");
|
||||||
|
await cloneDocuments(cameraModel, "Camera");
|
||||||
|
await cloneDocuments(lineModel, "Line");
|
||||||
|
await cloneDocuments(wallItemModel, "WallItem");
|
||||||
|
await cloneDocuments(zoneModel, "Zone");
|
||||||
|
await cloneDocuments(ProductModel, "Product");
|
||||||
|
await cloneDocuments(EventsDataModel, "Events");
|
||||||
|
await cloneDocuments(widget3dModel, "3DWidget");
|
||||||
|
await cloneDocuments(floatWidgetModel, "FloatWidget");
|
||||||
|
await cloneDocuments(templateModel, "Template");
|
||||||
|
};
|
||||||
|
|||||||
172
src/shared/services/version/README.md
Normal file
172
src/shared/services/version/README.md
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
DWINZO-BETA-BACKEND
|
||||||
|
|
||||||
|
Repository Structure:
|
||||||
|
DWINZO_BACKEND/
|
||||||
|
│
|
||||||
|
├── .gitignore
|
||||||
|
├── package.json
|
||||||
|
├── .env
|
||||||
|
│
|
||||||
|
└── src/
|
||||||
|
│
|
||||||
|
├── api-server/
|
||||||
|
│ │
|
||||||
|
│ └── controller/
|
||||||
|
│ ├─── Routes/
|
||||||
|
│ ├── V1
|
||||||
|
│ │ └── v1Controllers/
|
||||||
|
│ │ ├── v1Routes/
|
||||||
|
│ ├─── app.ts
|
||||||
|
│ ├─── main.ts
|
||||||
|
│
|
||||||
|
├── shared
|
||||||
|
│ │
|
||||||
|
│ └── connect/
|
||||||
|
│ ├─── middleware/
|
||||||
|
│ ├─── model/
|
||||||
|
│ ├─── redis/
|
||||||
|
│ ├─── services/
|
||||||
|
│ ├─── swagger/
|
||||||
|
│ ├─── utils/
|
||||||
|
│ ├─── V1Models/
|
||||||
|
│
|
||||||
|
├── socket-server
|
||||||
|
│ │
|
||||||
|
│ └── controllers/
|
||||||
|
│ ├─── manager/
|
||||||
|
│ ├─── services/
|
||||||
|
│ ├─── socket/
|
||||||
|
│ ├─── utils/
|
||||||
|
│ ├─── index.ts
|
||||||
|
|
||||||
|
VERSION CONTROL MODULE:
|
||||||
|
The Version Control Module is a backend system component designed to track, store, and manage multiple versions of data entities (such as scenes, assets, layouts, or entire projects). It enables developers and users to:
|
||||||
|
|
||||||
|
- View the historical state of an entity.
|
||||||
|
|
||||||
|
- Restore previous versions.
|
||||||
|
|
||||||
|
- Audit changes over time.
|
||||||
|
|
||||||
|
- Enable branching workflows like clone and rollback.
|
||||||
|
|
||||||
|
TECH STACK:
|
||||||
|
Language: Typescript
|
||||||
|
Framework: Express.js
|
||||||
|
Database: Mongodb
|
||||||
|
|
||||||
|
Architecture FOR API:
|
||||||
|
|
||||||
|
Entry Point:
|
||||||
|
|
||||||
|
- src/api-server/main.js starts the server and runs the main application.
|
||||||
|
- src/api-server/app.js sets up the Express app, middleware, and routes.
|
||||||
|
|
||||||
|
Components:
|
||||||
|
|
||||||
|
- src/api-server/V1/ (controllers, routes).
|
||||||
|
- src/shared/services/ (Service logics).
|
||||||
|
|
||||||
|
Utils:
|
||||||
|
|
||||||
|
- src/shared/utils/ contains Express middleware functions (e.g., hashing,tokenDatas).
|
||||||
|
|
||||||
|
Database:
|
||||||
|
|
||||||
|
- src/shared/connect/ handles database configuration and connection logic.
|
||||||
|
|
||||||
|
Models:
|
||||||
|
|
||||||
|
- src/shared/V1Models/ handles mongo schema structure and datatype.
|
||||||
|
|
||||||
|
|
||||||
|
Routing for Version:
|
||||||
|
|
||||||
|
|
||||||
|
________________________________________________________________________________________________
|
||||||
|
|Method | Routing | Description |
|
||||||
|
|__________|___________________________________|________________________________________________|
|
||||||
|
|POST | /generateVersion | Create New version |
|
||||||
|
|__________|___________________________________|________________________________________________|
|
||||||
|
|POST | /version/rollback | Version Rollback for the previous version |
|
||||||
|
|__________|___________________________________|________________________________________________|
|
||||||
|
|GET | /:projectId/versions | Project based Version histories |
|
||||||
|
|__________|___________________________________|________________________________________________|
|
||||||
|
|GET | /version/:versionId/:projectId | Get a Version Datas |
|
||||||
|
|__________|___________________________________|________________________________________________|
|
||||||
|
|
||||||
|
|
||||||
|
NEW VERSION instructions:
|
||||||
|
|
||||||
|
Request Datas:
|
||||||
|
- userId, organization from the User authenticationtoken.
|
||||||
|
- hierarchyVersion(parentVersion),description,projectId,createdBy(userId) from the body data.
|
||||||
|
|
||||||
|
LOGIC:
|
||||||
|
- checking for the valid userId,projectId and parentVersion.
|
||||||
|
- checking for the PreviousVersion based on the project.
|
||||||
|
- NewVersion Creation based on th PreviousVersion and parentVersion.
|
||||||
|
- Cloning for the previousVersion Datas(Scenes,asset,etc.) for the newVersion.
|
||||||
|
- Update the project data based on the latestVersion.
|
||||||
|
|
||||||
|
Response Datas:
|
||||||
|
- Http response with status code of 404 for User not found, Project not found and Parent Version not found.
|
||||||
|
- Http response with status code of 200 with Newversion unique Id(mongo _id).
|
||||||
|
- Http response with status code of 500 for Internal server error and Unknown error.
|
||||||
|
|
||||||
|
|
||||||
|
ROLL BACK instructions:
|
||||||
|
|
||||||
|
Request Datas:
|
||||||
|
- userId, organization from the User authenticationtoken.
|
||||||
|
- projectId,versionId from the body data.
|
||||||
|
|
||||||
|
LOGIC:
|
||||||
|
- checking for the valid userId,projectId and versionId(rollback versionId).
|
||||||
|
- checking for the PreviousVersion based on the project.
|
||||||
|
- NewVersion Creation based on th PreviousVersion and parentVersion(rollback versionId).
|
||||||
|
- Cloning for the parentVersion(rollback versionId) Datas(Scenes,asset,etc.) for the newVersion.
|
||||||
|
- Update the project data based on the latestVersion.
|
||||||
|
|
||||||
|
Response Datas:
|
||||||
|
- Http response with status code of 404 for User not found, Project not found and Mentioned Version not found for the Rollback.
|
||||||
|
- Http response with status code of 200 with Newversion unique Id(mongo _id) and message:"Rollback successfull".
|
||||||
|
- Http response with status code of 500 for Internal server error and Unknown error.
|
||||||
|
|
||||||
|
|
||||||
|
VERSION HISTORY instructions:
|
||||||
|
|
||||||
|
Request Datas:
|
||||||
|
- userId, organization from the User authenticationtoken.
|
||||||
|
- projectId params data.
|
||||||
|
- page,limit query data.
|
||||||
|
|
||||||
|
LOGIC:
|
||||||
|
- checking for the valid userId,projectId.
|
||||||
|
- fetching the allversions based on projectId for the Total count.
|
||||||
|
- filtering total project versions based on the sorting,limit and page.
|
||||||
|
- After filtering finalResponse with metaDatas like total count,page,limit and hasNextPage is provided
|
||||||
|
|
||||||
|
Response Datas:
|
||||||
|
- Http response with status code of 404 for User not found, Project not found and Mentioned Version not found for the Rollback.
|
||||||
|
- Http response with status code of 200 for Version History Datas.
|
||||||
|
- Http response with status code of 200 for Versions not found with empty Array[].
|
||||||
|
- Http response with status code of 500 for Internal server error and Unknown error.
|
||||||
|
|
||||||
|
|
||||||
|
PARTICULAR VERSION DATA instructions:
|
||||||
|
|
||||||
|
Request Datas:
|
||||||
|
- userId, organization from the User authenticationtoken.
|
||||||
|
- projectId,versionId params data.
|
||||||
|
|
||||||
|
LOGIC:
|
||||||
|
- checking for the valid userId,projectId.
|
||||||
|
- checking for the versionId based on the project.
|
||||||
|
- For existingVersion Fetching all the Builder, Simulation, RTViz datas based on the projectId and versionId
|
||||||
|
|
||||||
|
Response Datas:
|
||||||
|
- Http response with status code of 404 for User not found, Project not found and Mentioned Version not found for the Rollback.
|
||||||
|
- Http response with status code of 200 for Version based Datas.
|
||||||
|
- Http response with status code of 200 for Versions not found with empty Array[].
|
||||||
|
- Http response with status code of 500 for Internal server error and Unknown error.
|
||||||
@@ -1,124 +1,635 @@
|
|||||||
import projectModel from "../../model/project/project-model.ts";
|
import AisleModel, { Aisle } from "../../V1Models/Builder/AisleModel.ts";
|
||||||
import assetModel from "../../V1Models/Builder/assetModel.ts";
|
import assetModel, { AssetData } from "../../V1Models/Builder/assetModel.ts";
|
||||||
import versionModel from "../../model/version/versionModel.ts";
|
import cameraModel, { Camera } from "../../V1Models/Builder/cameraModel.ts";
|
||||||
|
import lineModel, { ILines } from "../../V1Models/Builder/linesModel.ts";
|
||||||
class VersionService {
|
import wallItemModel, {
|
||||||
async getCurrentVersion(db: string, projectId: string) {
|
WallItems,
|
||||||
const project = await projectModel(db).findById(projectId);
|
} from "../../V1Models/Builder/wallItemsModel.ts";
|
||||||
if (!project) throw new Error("Project not found");
|
import zoneModel, { Zone } from "../../V1Models/Builder/zoneModel.ts";
|
||||||
|
import environmentModel from "../../V1Models/Environment/environments-Model.ts";
|
||||||
return {
|
import versionModel from "../../V1Models/Version/versionModel.ts";
|
||||||
versionNumber: parseFloat(project.Present_version || "0.0"),
|
import widget3dModel, {
|
||||||
versionString: project.Present_version || "0.0",
|
Widget3d,
|
||||||
};
|
} from "../../V1Models/Vizualization/3dwidget.ts";
|
||||||
}
|
import panelModel, { Panel } from "../../V1Models/Vizualization/panelmodel.ts";
|
||||||
|
import widgetModel, {
|
||||||
async createNewVersion(
|
Widget,
|
||||||
db: string,
|
} from "../../V1Models/Vizualization/widgemodel.ts";
|
||||||
projectId: string,
|
import {
|
||||||
userId: string,
|
existingProjectById,
|
||||||
description?: string
|
existingUser,
|
||||||
) {
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
const project = await projectModel(db).findById(projectId);
|
import floatWidgetModel, {
|
||||||
if (!project) throw new Error("Project not found");
|
FloatingWidget,
|
||||||
|
} from "../../V1Models/Vizualization/floatWidget.ts";
|
||||||
const { versionNumber } = await this.getCurrentVersion(db, projectId);
|
import templateModel, {
|
||||||
const newVersion = parseFloat((versionNumber + 0.1).toFixed(1));
|
Template,
|
||||||
const versionName = `Version ${newVersion.toFixed(1)}`;
|
} from "../../V1Models/Vizualization/templatemodel.ts";
|
||||||
|
import ProductModel, {
|
||||||
const version = await versionModel(db).create({
|
Product,
|
||||||
versionName,
|
} from "../../V1Models/Simulation/productModel.ts";
|
||||||
version: newVersion,
|
import EventsDataModel, {
|
||||||
projectId: project._id,
|
IPointModel,
|
||||||
createdBy: userId,
|
} from "../../V1Models/Simulation/eventsDataModel.ts";
|
||||||
description,
|
import AuthModel from "../../V1Models/Auth/userAuthModel.ts";
|
||||||
});
|
type VersionData = {
|
||||||
|
Builder: {
|
||||||
await projectModel(db).findByIdAndUpdate(projectId, {
|
cameras: Camera[];
|
||||||
Present_version: newVersion.toFixed(1),
|
wallItems: WallItems[];
|
||||||
total_versions: newVersion.toFixed(1),
|
lines: ILines[];
|
||||||
});
|
zones: Zone[];
|
||||||
|
aisles: Aisle[];
|
||||||
return version;
|
assets: AssetData[];
|
||||||
}
|
};
|
||||||
|
Simulation: {
|
||||||
async saveCurrentStateAsVersion(
|
products: Product[];
|
||||||
db: string,
|
events: IPointModel[];
|
||||||
projectId: string,
|
};
|
||||||
userId: string,
|
RTViz: {
|
||||||
description?: string
|
panels: Panel[];
|
||||||
) {
|
widgets: Widget[];
|
||||||
const newVersion = await this.createNewVersion(
|
widget3ds: Widget3d[];
|
||||||
db,
|
floatWidgets: FloatingWidget[];
|
||||||
projectId,
|
templates: Template[];
|
||||||
userId,
|
};
|
||||||
description
|
};
|
||||||
);
|
interface IVersionSave {
|
||||||
|
organization: string;
|
||||||
const previousVersion = parseFloat((newVersion.version - 0.1).toFixed(1));
|
hierarchyVersion: string;
|
||||||
const previousVersionDoc = await versionModel(db).findOne({
|
versionName: string;
|
||||||
projectId,
|
projectId: string;
|
||||||
version: previousVersion,
|
userId: string;
|
||||||
});
|
createdBy: string;
|
||||||
console.log("previousVersionDoc: ", previousVersionDoc);
|
description?: string;
|
||||||
|
}
|
||||||
let previousAssets = [];
|
interface IVersionRollback {
|
||||||
if (previousVersionDoc) {
|
organization: string;
|
||||||
previousAssets = await assetModel(db).find({
|
versionId: string;
|
||||||
projectId,
|
projectId: string;
|
||||||
versionId: previousVersionDoc._id,
|
userId: string;
|
||||||
isArchive: false,
|
description?: string;
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const newAssets = await Promise.all(
|
|
||||||
previousAssets.map(async (asset) => {
|
|
||||||
console.log("previousAssets: ", previousAssets);
|
|
||||||
const newAsset = { ...asset.toObject(), versionId: newVersion._id };
|
|
||||||
delete newAsset._id;
|
|
||||||
return await assetModel(db).create(newAsset);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
version: newVersion,
|
|
||||||
assets: newAssets,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async getVersionHistory(db: string, projectId: string) {
|
|
||||||
const versions = await versionModel(db)
|
|
||||||
.find({ projectId, isArchive: false })
|
|
||||||
.sort({ version: 1 })
|
|
||||||
.populate("createdBy", "name email");
|
|
||||||
|
|
||||||
const versionHistory = await Promise.all(
|
|
||||||
versions.map(async (version) => {
|
|
||||||
const assets = await assetModel(db).find({
|
|
||||||
projectId,
|
|
||||||
versionId: version._id,
|
|
||||||
isArchive: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const assetCounts = assets.reduce((acc, asset) => {
|
|
||||||
acc[asset.type] = (acc[asset.type] || 0) + 1;
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
return {
|
|
||||||
version: version.version.toFixed(1),
|
|
||||||
versionName: version.versionName,
|
|
||||||
createdAt: version.createdAt,
|
|
||||||
createdBy: version.createdBy,
|
|
||||||
description: version.description,
|
|
||||||
assets: assetCounts,
|
|
||||||
totalAssets: assets.length,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
return versionHistory;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new VersionService();
|
interface IVersionHistory {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
page: number;
|
||||||
|
limit: number;
|
||||||
|
sortBy?: string;
|
||||||
|
sortOrder?: string;
|
||||||
|
}
|
||||||
|
interface IVersionUpdate {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
page: number;
|
||||||
|
versionId: string;
|
||||||
|
versionName?: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
interface IVersionById {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
userId: string;
|
||||||
|
}
|
||||||
|
interface IResult {
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}
|
||||||
|
export const CreateVersion = async (data: IVersionSave): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
hierarchyVersion,
|
||||||
|
projectId,
|
||||||
|
versionName,
|
||||||
|
description,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
createdBy,
|
||||||
|
} = data;
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) {
|
||||||
|
return {
|
||||||
|
status: "User not found",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const versionData = await versionModel(organization).findOne({
|
||||||
|
_id: hierarchyVersion,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!versionData) return { status: "Parent Version not found" };
|
||||||
|
const versionDataprevious = await versionModel(organization)
|
||||||
|
.findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.sort({ version: -1 });
|
||||||
|
const currentVersion = versionDataprevious?.version ?? 0;
|
||||||
|
const newVersion = parseFloat((currentVersion + 0.1).toFixed(2));
|
||||||
|
const saveVersion = await versionModel(organization).create({
|
||||||
|
versionName: versionName,
|
||||||
|
parentVersionID: versionData._id,
|
||||||
|
projectId: projectId,
|
||||||
|
description: description,
|
||||||
|
createdBy: createdBy,
|
||||||
|
previous_Version: currentVersion,
|
||||||
|
version: newVersion,
|
||||||
|
createdAt: new Date(),
|
||||||
|
});
|
||||||
|
const find_User = await AuthModel(organization).findById({
|
||||||
|
_id: saveVersion.createdBy,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
const responseVersionData = {
|
||||||
|
versionId: saveVersion._id,
|
||||||
|
version: saveVersion.version,
|
||||||
|
description: saveVersion.description,
|
||||||
|
versionName: saveVersion.versionName,
|
||||||
|
createdAt: saveVersion.createdAt,
|
||||||
|
createdBy: {
|
||||||
|
userId: find_User._id,
|
||||||
|
userName: find_User.userName,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
await LivingProject.updateOne({
|
||||||
|
Present_version: saveVersion._id,
|
||||||
|
total_versions: `v-${saveVersion.version.toFixed(1)}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
await AllCloneFornewVersions(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
saveVersion._id,
|
||||||
|
hierarchyVersion
|
||||||
|
);
|
||||||
|
return { status: "Success", data: responseVersionData };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GetVersionById = async (data: IVersionById): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { projectId, userId, organization, versionId } = data;
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) {
|
||||||
|
return {
|
||||||
|
status: "User not found",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingVersion = await versionModel(organization)
|
||||||
|
.findOne({
|
||||||
|
_id: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("version previous_Version");
|
||||||
|
if (!existingVersion) {
|
||||||
|
return { status: "Version not found for the project" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const [cameras, wallItems, lines, zones, aisles, assets] =
|
||||||
|
await Promise.all([
|
||||||
|
cameraModel(organization).find({
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
}),
|
||||||
|
wallItemModel(organization).find({
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
}),
|
||||||
|
lineModel(organization).find({
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
}),
|
||||||
|
zoneModel(organization)
|
||||||
|
.find({ versionId, projectId, isArchive: false })
|
||||||
|
.select(
|
||||||
|
"-_id zoneName layer panelOrder viewPortCenter lockedPanel points createdBy zoneUuid panelOrder"
|
||||||
|
),
|
||||||
|
AisleModel(organization).find({
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
}),
|
||||||
|
assetModel(organization).find({
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Simulation part
|
||||||
|
const [products, events] = await Promise.all([
|
||||||
|
ProductModel(organization).find({
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
}),
|
||||||
|
EventsDataModel(organization).find({
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// RTViz part
|
||||||
|
const templates = await templateModel(organization).find({
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
//RTVIZ zone based
|
||||||
|
let panels: Panel[] = [];
|
||||||
|
let widgets: Widget[] = [];
|
||||||
|
let widget3ds: Widget3d[] = [];
|
||||||
|
let floatWidgets: FloatingWidget[] = [];
|
||||||
|
|
||||||
|
for (const zone of zones) {
|
||||||
|
const zonePanels = await panelModel(organization)
|
||||||
|
.find({
|
||||||
|
zoneUuid: zone.zoneUuid,
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("panelName -_id");
|
||||||
|
panels.push(...zonePanels);
|
||||||
|
|
||||||
|
for (const panel of zonePanels) {
|
||||||
|
const panelWidgets = await widgetModel(organization)
|
||||||
|
.find({
|
||||||
|
panelID: panel._id,
|
||||||
|
zoneUuid: zone.zoneUuid,
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("widgetName widgetside widgetID elementType Data -_id");
|
||||||
|
widgets.push(...panelWidgets);
|
||||||
|
}
|
||||||
|
|
||||||
|
const zoneWidget3Ds = await widget3dModel(organization).find({
|
||||||
|
zoneUuid: zone.zoneUuid,
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
widget3ds.push(...zoneWidget3Ds);
|
||||||
|
|
||||||
|
const zoneFloatWidgets = await floatWidgetModel(organization).find({
|
||||||
|
zoneUuid: zone.zoneUuid,
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
floatWidgets.push(...zoneFloatWidgets);
|
||||||
|
}
|
||||||
|
|
||||||
|
const versionData: VersionData = {
|
||||||
|
Builder: {
|
||||||
|
cameras,
|
||||||
|
wallItems,
|
||||||
|
lines,
|
||||||
|
zones,
|
||||||
|
aisles,
|
||||||
|
assets,
|
||||||
|
},
|
||||||
|
Simulation: {
|
||||||
|
products,
|
||||||
|
events,
|
||||||
|
},
|
||||||
|
RTViz: {
|
||||||
|
panels,
|
||||||
|
widgets,
|
||||||
|
widget3ds,
|
||||||
|
floatWidgets,
|
||||||
|
templates,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: {
|
||||||
|
version: existingVersion,
|
||||||
|
entities: versionData,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RollBackversion = async (
|
||||||
|
data: IVersionRollback
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { versionId, projectId, userId, organization } = data;
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) {
|
||||||
|
return {
|
||||||
|
status: "User not found",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const rollbackversion = await versionModel(organization).findOne({
|
||||||
|
_id: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!rollbackversion)
|
||||||
|
return { status: "Mentioned Version not found for the Rollback" };
|
||||||
|
const versionDataprevious = await versionModel(organization)
|
||||||
|
.findOne({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.sort({ version: -1 });
|
||||||
|
const currentVersion = versionDataprevious?.version ?? 0;
|
||||||
|
const newVersion = parseFloat((currentVersion + 0.01).toFixed(2));
|
||||||
|
const saveVersion = await versionModel(organization).create({
|
||||||
|
parentVersionID: rollbackversion._id,
|
||||||
|
projectId: projectId,
|
||||||
|
createdBy: userId,
|
||||||
|
previous_Version: currentVersion,
|
||||||
|
version: newVersion,
|
||||||
|
createdAt: new Date(),
|
||||||
|
rollBackComment: `RollBack from the version ${rollbackversion.version}`,
|
||||||
|
});
|
||||||
|
LivingProject.Present_version = saveVersion._id;
|
||||||
|
LivingProject.total_versions = `v-${saveVersion.version.toFixed(2)}`;
|
||||||
|
await LivingProject.save();
|
||||||
|
|
||||||
|
await AllCloneFornewVersions(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
saveVersion._id,
|
||||||
|
rollbackversion._id
|
||||||
|
);
|
||||||
|
return { status: "Success", data: saveVersion._id };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const VersionHistory = async (
|
||||||
|
data: IVersionHistory
|
||||||
|
): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId, projectId, page, limit, sortOrder } = data;
|
||||||
|
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) return { status: "User not found" };
|
||||||
|
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
|
||||||
|
const filter: object = { projectId, isArchive: false };
|
||||||
|
const total = await versionModel(organization).countDocuments(filter);
|
||||||
|
const versiondatas = await versionModel(organization)
|
||||||
|
.find(filter)
|
||||||
|
.sort({ ["version"]: sortOrder === "asc" ? 1 : -1 })
|
||||||
|
.skip((page - 1) * limit)
|
||||||
|
.limit(limit)
|
||||||
|
.select("version createdBy createdAt description versionName")
|
||||||
|
.populate({
|
||||||
|
path: "createdBy",
|
||||||
|
model: AuthModel(organization),
|
||||||
|
select: "userName",
|
||||||
|
});
|
||||||
|
// .populate({
|
||||||
|
// path: "createdBy",
|
||||||
|
// model: UsersDataModel(organization),
|
||||||
|
// select: "profilePicture",
|
||||||
|
// });
|
||||||
|
// console.log('versiondatas: ', versiondatas);
|
||||||
|
if (!versiondatas)
|
||||||
|
return {
|
||||||
|
status: "Versions not found",
|
||||||
|
};
|
||||||
|
const versions = versiondatas.map((version) => {
|
||||||
|
return {
|
||||||
|
versionId: version._id,
|
||||||
|
version: version.version,
|
||||||
|
createdAt: version.createdAt,
|
||||||
|
description: version.description,
|
||||||
|
versionName: version.versionName,
|
||||||
|
createdBy: {
|
||||||
|
userId: version.createdBy._id,
|
||||||
|
userName: version.createdBy.userName,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: {
|
||||||
|
versions,
|
||||||
|
Metadatas: {
|
||||||
|
total,
|
||||||
|
page,
|
||||||
|
limit,
|
||||||
|
hasNextPage: page * limit < total,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const updateVersion = async (data: IVersionUpdate): Promise<IResult> => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
versionName,
|
||||||
|
description,
|
||||||
|
} = data;
|
||||||
|
|
||||||
|
const userExisting = await existingUser(userId, organization);
|
||||||
|
if (!userExisting) return { status: "User not found" };
|
||||||
|
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const existingVersionId = await versionModel(organization).findOne({
|
||||||
|
_id: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
});
|
||||||
|
if (!existingVersionId) {
|
||||||
|
return { status: "VersionId not match" };
|
||||||
|
} else {
|
||||||
|
existingVersionId.versionName = versionName;
|
||||||
|
existingVersionId.description = description;
|
||||||
|
await existingVersionId.save();
|
||||||
|
return { status: "Version Updated successfully" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AllCloneFornewVersions = async (
|
||||||
|
projectId: string,
|
||||||
|
organization: string,
|
||||||
|
versionId: string,
|
||||||
|
oldeVersionId: string
|
||||||
|
) => {
|
||||||
|
const cloneDocuments = async (model: any, modelName: string) => {
|
||||||
|
const docs = await model(organization).find({
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
versionId: oldeVersionId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!docs.length) return;
|
||||||
|
|
||||||
|
const clonedDocs = docs.map((doc: any) => {
|
||||||
|
const { _id, __v, ...rest } = doc.toObject();
|
||||||
|
return { ...rest, versionId };
|
||||||
|
});
|
||||||
|
|
||||||
|
const created = await model(organization).create(clonedDocs);
|
||||||
|
console.log(`Cloned ${modelName}:`, created.length);
|
||||||
|
};
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
cloneDocuments(assetModel, "Asset"),
|
||||||
|
cloneDocuments(AisleModel, "Aisle"),
|
||||||
|
cloneDocuments(cameraModel, "Camera"),
|
||||||
|
cloneDocuments(lineModel, "Line"),
|
||||||
|
cloneDocuments(wallItemModel, "WallItem"),
|
||||||
|
cloneDocuments(ProductModel, "Product"),
|
||||||
|
cloneDocuments(EventsDataModel, "Event"),
|
||||||
|
cloneDocuments(widget3dModel, "3D Widget"),
|
||||||
|
cloneDocuments(floatWidgetModel, "Float Widget"),
|
||||||
|
cloneDocuments(templateModel, "Template"),
|
||||||
|
cloneDocuments(environmentModel, "Environment"),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const zones = await zoneModel(organization).find({
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
versionId: oldeVersionId,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const zone of zones) {
|
||||||
|
const { _id: oldZoneId, __v, ...zoneData } = zone.toObject();
|
||||||
|
const newZone = await zoneModel(organization).create({
|
||||||
|
...zoneData,
|
||||||
|
versionId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const panels = await panelModel(organization).find({
|
||||||
|
zoneUuid: zone.zoneUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
versionId: oldeVersionId,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const panel of panels) {
|
||||||
|
const { _id: oldPanelId, widgets, __v, ...panelData } = panel.toObject();
|
||||||
|
const newPanel = await panelModel(organization).create({
|
||||||
|
...panelData,
|
||||||
|
versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
zoneUuid: newZone.zoneUuid,
|
||||||
|
});
|
||||||
|
|
||||||
|
const widgetsData = await widgetModel(organization).find({
|
||||||
|
panelID: oldPanelId,
|
||||||
|
projectId,
|
||||||
|
isArchive: false,
|
||||||
|
versionId: oldeVersionId,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const widget of widgetsData) {
|
||||||
|
const { _id, __v, ...widgetData } = widget.toObject();
|
||||||
|
const newWidget = await widgetModel(organization).create({
|
||||||
|
...widgetData,
|
||||||
|
projectId: projectId,
|
||||||
|
panelID: newPanel._id,
|
||||||
|
versionId,
|
||||||
|
zoneUuid: newZone.zoneUuid,
|
||||||
|
});
|
||||||
|
|
||||||
|
newPanel.widgets.push(newWidget._id);
|
||||||
|
}
|
||||||
|
|
||||||
|
await newPanel.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import zoneModel from "../../V1Models/Builder/zoneModel.ts";
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
|
||||||
interface IResult {
|
interface IResult {
|
||||||
@@ -31,6 +32,7 @@ interface IAddFloatData {
|
|||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
index: number;
|
index: number;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface IDelFloat {
|
interface IDelFloat {
|
||||||
userId: string;
|
userId: string;
|
||||||
@@ -38,6 +40,7 @@ interface IDelFloat {
|
|||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
floatWidgetID: string;
|
floatWidgetID: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface ISingleFloat {
|
interface ISingleFloat {
|
||||||
userId: string;
|
userId: string;
|
||||||
@@ -49,6 +52,7 @@ interface IGetZoneFloat {
|
|||||||
organization: string;
|
organization: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface IDuplicateFloatData {
|
interface IDuplicateFloatData {
|
||||||
userId: string;
|
userId: string;
|
||||||
@@ -72,10 +76,19 @@ interface IDuplicateFloatData {
|
|||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
index: number;
|
index: number;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, widget, zoneUuid, index, projectId, userId } = data;
|
const {
|
||||||
|
organization,
|
||||||
|
widget,
|
||||||
|
zoneUuid,
|
||||||
|
index,
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
userId,
|
||||||
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -84,10 +97,17 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||||
|
|
||||||
@@ -95,12 +115,17 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
|||||||
floatWidgetID: widget.id,
|
floatWidgetID: widget.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (existingFloatWidget) {
|
if (existingFloatWidget) {
|
||||||
const updateFloatWidget = await floatWidgetModel(
|
const updateFloatWidget = await floatWidgetModel(
|
||||||
organization
|
organization
|
||||||
).findOneAndUpdate(
|
).findOneAndUpdate(
|
||||||
{
|
{
|
||||||
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
floatWidgetID: widget.id,
|
floatWidgetID: widget.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
@@ -132,6 +157,8 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
|||||||
iconName: widget.iconName,
|
iconName: widget.iconName,
|
||||||
header: widget.header,
|
header: widget.header,
|
||||||
floatWidgetID: widget.id,
|
floatWidgetID: widget.id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
position: widget.position,
|
position: widget.position,
|
||||||
per: widget.per,
|
per: widget.per,
|
||||||
value: widget.value,
|
value: widget.value,
|
||||||
@@ -169,7 +196,14 @@ export const AddFloat = async (data: IAddFloatData): Promise<IResult> => {
|
|||||||
|
|
||||||
export const DelFloat = async (data: IDelFloat): Promise<IResult> => {
|
export const DelFloat = async (data: IDelFloat): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, floatWidgetID, zoneUuid, projectId, userId } = data;
|
const {
|
||||||
|
organization,
|
||||||
|
floatWidgetID,
|
||||||
|
versionId,
|
||||||
|
zoneUuid,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) {
|
if (!UserExists) {
|
||||||
return { status: "User not found" };
|
return { status: "User not found" };
|
||||||
@@ -182,20 +216,34 @@ export const DelFloat = async (data: IDelFloat): Promise<IResult> => {
|
|||||||
if (!LivingProject) {
|
if (!LivingProject) {
|
||||||
return { status: "Project not found" };
|
return { status: "Project not found" };
|
||||||
}
|
}
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||||
|
|
||||||
const findfloatWidget = await floatWidgetModel(organization).findOne({
|
const findfloatWidget = await floatWidgetModel(organization).findOne({
|
||||||
floatWidgetID: floatWidgetID,
|
floatWidgetID: floatWidgetID,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!findfloatWidget) return { status: "FloatWidget not found for the Id" };
|
if (!findfloatWidget) return { status: "FloatWidget not found for the Id" };
|
||||||
const widgetData = await floatWidgetModel(organization).findByIdAndUpdate(
|
const widgetData = await floatWidgetModel(organization).findByIdAndUpdate(
|
||||||
{ _id: findfloatWidget._id, isArchive: false },
|
{
|
||||||
|
_id: findfloatWidget._id,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{ isArchive: true },
|
{ isArchive: true },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
@@ -226,7 +274,15 @@ export const DuplicateFloat = async (
|
|||||||
data: IDuplicateFloatData
|
data: IDuplicateFloatData
|
||||||
): Promise<IResult> => {
|
): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, widget, zoneUuid, index, projectId, userId } = data;
|
const {
|
||||||
|
organization,
|
||||||
|
widget,
|
||||||
|
zoneUuid,
|
||||||
|
index,
|
||||||
|
versionId,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) {
|
if (!UserExists) {
|
||||||
return { status: "User not found" };
|
return { status: "User not found" };
|
||||||
@@ -239,10 +295,17 @@ export const DuplicateFloat = async (
|
|||||||
if (!LivingProject) {
|
if (!LivingProject) {
|
||||||
return { status: "Project not found" };
|
return { status: "Project not found" };
|
||||||
}
|
}
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||||
|
|
||||||
@@ -250,12 +313,16 @@ export const DuplicateFloat = async (
|
|||||||
floatWidgetID: widget.id,
|
floatWidgetID: widget.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
});
|
});
|
||||||
if (existingFloatWidget) {
|
if (existingFloatWidget) {
|
||||||
const updateFloatWidget = await floatWidgetModel(
|
const updateFloatWidget = await floatWidgetModel(
|
||||||
organization
|
organization
|
||||||
).findOneAndUpdate(
|
).findOneAndUpdate(
|
||||||
{
|
{
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
floatWidgetID: widget.id,
|
floatWidgetID: widget.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
@@ -292,6 +359,8 @@ export const DuplicateFloat = async (
|
|||||||
className: widget.className,
|
className: widget.className,
|
||||||
header: widget.header,
|
header: widget.header,
|
||||||
floatWidgetID: widget.id,
|
floatWidgetID: widget.id,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
position: widget.position,
|
position: widget.position,
|
||||||
per: widget.per,
|
per: widget.per,
|
||||||
value: widget.value,
|
value: widget.value,
|
||||||
@@ -338,7 +407,7 @@ export const DuplicateFloat = async (
|
|||||||
|
|
||||||
export const GetFloatWidget = async (data: IGetZoneFloat): Promise<IResult> => {
|
export const GetFloatWidget = async (data: IGetZoneFloat): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, zoneUuid, projectId, userId } = data;
|
const { organization, zoneUuid, projectId, userId,versionId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) {
|
if (!UserExists) {
|
||||||
return { status: "User not found" };
|
return { status: "User not found" };
|
||||||
@@ -351,15 +420,25 @@ export const GetFloatWidget = async (data: IGetZoneFloat): Promise<IResult> => {
|
|||||||
if (!LivingProject) {
|
if (!LivingProject) {
|
||||||
return { status: "Project not found" };
|
return { status: "Project not found" };
|
||||||
}
|
}
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found" };
|
if (!existingZone) return { status: "Zone not found" };
|
||||||
const widgetData = await floatWidgetModel(organization)
|
const widgetData = await floatWidgetModel(organization)
|
||||||
.find({
|
.find({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
})
|
})
|
||||||
.select("-_id -zoneUuid -createdAt -updatedAt -__v");
|
.select("-_id -zoneUuid -createdAt -updatedAt -__v");
|
||||||
@@ -393,6 +472,8 @@ export const GetFloatWidget = async (data: IGetZoneFloat): Promise<IResult> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//project and version based not changed
|
||||||
export const SingleFloatWidget = async (
|
export const SingleFloatWidget = async (
|
||||||
data: ISingleFloat
|
data: ISingleFloat
|
||||||
): Promise<IResult> => {
|
): Promise<IResult> => {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import widgetModel from "../../V1Models/Vizualization/widgemodel.ts";
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
interface IResult {
|
interface IResult {
|
||||||
status: string;
|
status: string;
|
||||||
@@ -15,13 +16,16 @@ interface IAddPanel {
|
|||||||
panelOrder: string[];
|
panelOrder: string[];
|
||||||
userId: string;
|
userId: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IPanel {
|
interface IPanel {
|
||||||
organization: string;
|
organization: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
panelName: string;
|
panelName: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
interface ILockedPanel {
|
interface ILockedPanel {
|
||||||
organization: string;
|
organization: string;
|
||||||
@@ -29,10 +33,12 @@ interface ILockedPanel {
|
|||||||
lockedPanel: string[];
|
lockedPanel: string[];
|
||||||
userId: string;
|
userId: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
}
|
}
|
||||||
export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, zoneUuid, panelOrder, userId, projectId } = data;
|
const { organization, zoneUuid, panelOrder, userId, versionId, projectId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -41,19 +47,33 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found" };
|
if (!existingZone) return { status: "Zone not found" };
|
||||||
await zoneModel(organization).findOneAndUpdate(
|
await zoneModel(organization).findOneAndUpdate(
|
||||||
{ zoneUuid: zoneUuid, isArchive: false },
|
{
|
||||||
|
zoneUuid: zoneUuid,
|
||||||
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
},
|
||||||
{ panelOrder: panelOrder },
|
{ panelOrder: panelOrder },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
const existingPanels = await panelModel(organization).find({
|
const existingPanels = await panelModel(organization).find({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -70,6 +90,8 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
|||||||
const newPanel = await panelModel(organization).create({
|
const newPanel = await panelModel(organization).create({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
panelName: panelName,
|
panelName: panelName,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
widgets: [],
|
widgets: [],
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
@@ -83,7 +105,8 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
|||||||
const zoneAndPanelData = await getZoneAndPanelData(
|
const zoneAndPanelData = await getZoneAndPanelData(
|
||||||
organization,
|
organization,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId
|
projectId,
|
||||||
|
versionId
|
||||||
);
|
);
|
||||||
if (!zoneAndPanelData) {
|
if (!zoneAndPanelData) {
|
||||||
return zoneAndPanelData;
|
return zoneAndPanelData;
|
||||||
@@ -103,7 +126,8 @@ export const AddPanel = async (data: IAddPanel): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, zoneUuid, panelName, userId, projectId } = data;
|
const { organization, zoneUuid, versionId, panelName, userId, projectId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -112,25 +136,41 @@ export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found" };
|
if (!existingZone) return { status: "Zone not found" };
|
||||||
const existingPanel = await panelModel(organization).findOne({
|
const existingPanel = await panelModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
panelName: panelName,
|
panelName: panelName,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!existingPanel) return { status: "Panel Already Deleted" };
|
if (!existingPanel) return { status: "Panel Already Deleted" };
|
||||||
|
|
||||||
await panelModel(organization).updateOne(
|
await panelModel(organization).updateOne(
|
||||||
{ _id: existingPanel._id, isArchive: false },
|
{
|
||||||
|
_id: existingPanel._id,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
);
|
);
|
||||||
const existingWidgets = await widgetModel(organization).find({
|
const existingWidgets = await widgetModel(organization).find({
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -141,14 +181,19 @@ export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
|||||||
|
|
||||||
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
||||||
await zoneModel(organization).updateOne(
|
await zoneModel(organization).updateOne(
|
||||||
{ _id: existingZone._id },
|
{
|
||||||
|
_id: existingZone._id,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
|
},
|
||||||
{ $pull: { panelOrder: existingPanel.panelName } }
|
{ $pull: { panelOrder: existingPanel.panelName } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const zoneAndPanelData = await getZoneAndPanelData(
|
const zoneAndPanelData = await getZoneAndPanelData(
|
||||||
organization,
|
organization,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId
|
projectId,
|
||||||
|
versionId
|
||||||
);
|
);
|
||||||
if (!zoneAndPanelData) {
|
if (!zoneAndPanelData) {
|
||||||
return zoneAndPanelData;
|
return zoneAndPanelData;
|
||||||
@@ -168,7 +213,8 @@ export const DelPanel = async (data: IPanel): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, zoneUuid, panelName, userId, projectId } = data;
|
const { organization, zoneUuid, panelName, versionId, userId, projectId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -177,8 +223,15 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
@@ -186,18 +239,27 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
|||||||
const existingPanel = await panelModel(organization).findOne({
|
const existingPanel = await panelModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
panelName: panelName,
|
panelName: panelName,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!existingPanel) return { status: "Requested Panel not found" };
|
if (!existingPanel) return { status: "Requested Panel not found" };
|
||||||
|
|
||||||
const existingWidgets = await widgetModel(organization).find({
|
const existingWidgets = await widgetModel(organization).find({
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (existingWidgets.length === 0) return { status: "No widgets to clear" };
|
if (existingWidgets.length === 0) return { status: "No widgets to clear" };
|
||||||
|
|
||||||
const clearWidgetsofPanel = await widgetModel(organization).updateMany(
|
const clearWidgetsofPanel = await widgetModel(organization).updateMany(
|
||||||
{ panelID: existingPanel._id, isArchive: false },
|
{
|
||||||
|
panelID: existingPanel._id,
|
||||||
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
},
|
||||||
{ isArchive: true }
|
{ isArchive: true }
|
||||||
);
|
);
|
||||||
const removeWidgetsInPanel = await panelModel(
|
const removeWidgetsInPanel = await panelModel(
|
||||||
@@ -213,7 +275,8 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
|||||||
const zoneAndPanelData = await getZoneAndPanelData(
|
const zoneAndPanelData = await getZoneAndPanelData(
|
||||||
organization,
|
organization,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId
|
projectId,
|
||||||
|
versionId
|
||||||
);
|
);
|
||||||
if (!zoneAndPanelData) {
|
if (!zoneAndPanelData) {
|
||||||
return zoneAndPanelData;
|
return zoneAndPanelData;
|
||||||
@@ -237,7 +300,14 @@ export const ClearPanel = async (data: IPanel): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, zoneUuid, lockedPanel, userId, projectId } = data;
|
const {
|
||||||
|
organization,
|
||||||
|
zoneUuid,
|
||||||
|
lockedPanel,
|
||||||
|
versionId,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -246,15 +316,27 @@ export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found" };
|
if (!existingZone) return { status: "Zone not found" };
|
||||||
else {
|
else {
|
||||||
const updateLockedPanel = await zoneModel(organization).findOneAndUpdate(
|
const updateLockedPanel = await zoneModel(organization).findOneAndUpdate(
|
||||||
{ zoneUuid: zoneUuid, isArchive: false },
|
{
|
||||||
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
lockedPanel: lockedPanel,
|
lockedPanel: lockedPanel,
|
||||||
},
|
},
|
||||||
@@ -263,7 +345,8 @@ export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
|||||||
const zoneAndPanelData = await getZoneAndPanelData(
|
const zoneAndPanelData = await getZoneAndPanelData(
|
||||||
organization,
|
organization,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
projectId
|
projectId,
|
||||||
|
versionId
|
||||||
);
|
);
|
||||||
if (!zoneAndPanelData) {
|
if (!zoneAndPanelData) {
|
||||||
return zoneAndPanelData;
|
return zoneAndPanelData;
|
||||||
@@ -291,16 +374,16 @@ export const LockedPanel = async (data: ILockedPanel): Promise<IResult> => {
|
|||||||
const getZoneAndPanelData = async (
|
const getZoneAndPanelData = async (
|
||||||
organization: string,
|
organization: string,
|
||||||
zoneUuid: string,
|
zoneUuid: string,
|
||||||
projectId: string
|
projectId: string,
|
||||||
|
versionId: string
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
const existingZone = await zoneModel(organization)
|
const existingZone = await zoneModel(organization)
|
||||||
.findOne({
|
.findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
})
|
})
|
||||||
.select(
|
.select(
|
||||||
"panelOrder zoneName zonePoints lockedPanel zoneUuid viewPortCenter viewPortposition"
|
"panelOrder zoneName zonePoints lockedPanel zoneUuid viewPortCenter viewPortposition"
|
||||||
@@ -311,6 +394,8 @@ const getZoneAndPanelData = async (
|
|||||||
const panelData = await panelModel(organization).find({
|
const panelData = await panelModel(organization).find({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
});
|
});
|
||||||
const zoneName = existingZone.zoneName as string;
|
const zoneName = existingZone.zoneName as string;
|
||||||
|
|
||||||
@@ -318,6 +403,8 @@ const getZoneAndPanelData = async (
|
|||||||
panelData.map(async (data) => {
|
panelData.map(async (data) => {
|
||||||
const widgetDataArray = await widgetModel(organization).find({
|
const widgetDataArray = await widgetModel(organization).find({
|
||||||
panelID: data._id,
|
panelID: data._id,
|
||||||
|
projectId: projectId,
|
||||||
|
versionId: versionId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import floatWidgetModel from "../../V1Models/Vizualization/floatWidget.ts";
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
interface IResult {
|
interface IResult {
|
||||||
status: string;
|
status: string;
|
||||||
@@ -23,12 +24,14 @@ interface IAddTemplate {
|
|||||||
Widgets3D: [];
|
Widgets3D: [];
|
||||||
};
|
};
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface ITemplateToZone {
|
interface ITemplateToZone {
|
||||||
organization: string;
|
organization: string;
|
||||||
templateID: string;
|
templateID: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
@@ -36,32 +39,47 @@ interface ITemplate {
|
|||||||
organization: string;
|
organization: string;
|
||||||
templateID: string;
|
templateID: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface IGetTemplate {
|
interface IGetTemplate {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
export const AddTemplate = async (data: IAddTemplate): Promise<IResult> => {
|
export const AddTemplate = async (data: IAddTemplate): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, template, projectId, userId } = data;
|
const { organization, template, projectId, versionId, userId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) {return { status: "User not found" }};
|
if (!UserExists) {
|
||||||
|
return { status: "User not found" };
|
||||||
|
}
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
projectId,
|
projectId,
|
||||||
organization,
|
organization,
|
||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) {return { status: "Project not found" }};
|
if (!LivingProject) {
|
||||||
|
return { status: "Project not found" };
|
||||||
|
}
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingTemplate = await templateModel(organization).findOne({
|
const existingTemplate = await templateModel(organization).findOne({
|
||||||
templateID: template.id,
|
templateID: template.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (existingTemplate) return { status: "TemplateID alreay exists" };
|
if (existingTemplate) return { status: "TemplateID alreay exists" };
|
||||||
const newTemplate = await templateModel(organization).create({
|
const newTemplate = await templateModel(organization).create({
|
||||||
templateID: template.id,
|
templateID: template.id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
templateName: template.name,
|
templateName: template.name,
|
||||||
panelOrder: template.panelOrder,
|
panelOrder: template.panelOrder,
|
||||||
widgets: template.widgets,
|
widgets: template.widgets,
|
||||||
@@ -71,7 +89,11 @@ export const AddTemplate = async (data: IAddTemplate): Promise<IResult> => {
|
|||||||
});
|
});
|
||||||
if (newTemplate) {
|
if (newTemplate) {
|
||||||
const allTemplateDatas = await templateModel(organization)
|
const allTemplateDatas = await templateModel(organization)
|
||||||
.find({ isArchive: false })
|
.find({
|
||||||
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
})
|
||||||
.select("-_id -__v -isArchive -createdAt -updatedAt");
|
.select("-_id -__v -isArchive -createdAt -updatedAt");
|
||||||
|
|
||||||
const formattedTemplates = allTemplateDatas.map(async (data) => ({
|
const formattedTemplates = allTemplateDatas.map(async (data) => ({
|
||||||
@@ -102,7 +124,8 @@ export const AddTemplateToZone = async (
|
|||||||
data: ITemplateToZone
|
data: ITemplateToZone
|
||||||
): Promise<IResult> => {
|
): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, templateID, projectId, zoneUuid, userId } = data;
|
const { organization, templateID, versionId, projectId, zoneUuid, userId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -111,9 +134,16 @@ export const AddTemplateToZone = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone)
|
if (!existingZone)
|
||||||
@@ -124,6 +154,7 @@ export const AddTemplateToZone = async (
|
|||||||
const existingTemplate = await templateModel(organization).findOne({
|
const existingTemplate = await templateModel(organization).findOne({
|
||||||
templateID: templateID,
|
templateID: templateID,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingTemplate)
|
if (!existingTemplate)
|
||||||
@@ -136,20 +167,28 @@ export const AddTemplateToZone = async (
|
|||||||
await existingZone.save();
|
await existingZone.save();
|
||||||
const archivePanelDatas = await panelModel(organization).find({
|
const archivePanelDatas = await panelModel(organization).find({
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
for (const panelData of archivePanelDatas) {
|
for (const panelData of archivePanelDatas) {
|
||||||
await widgetModel(organization).deleteMany({
|
await widgetModel(organization).deleteMany({
|
||||||
panelID: panelData._id,
|
panelID: panelData._id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await panelModel(organization).deleteMany({
|
await panelModel(organization).deleteMany({
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
await floatWidgetModel(organization).deleteMany({
|
await floatWidgetModel(organization).deleteMany({
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -157,6 +196,8 @@ export const AddTemplateToZone = async (
|
|||||||
await existingZone.save();
|
await existingZone.save();
|
||||||
const existingPanels = await panelModel(organization).find({
|
const existingPanels = await panelModel(organization).find({
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
const existingPanelNames = existingPanels.map(
|
const existingPanelNames = existingPanels.map(
|
||||||
@@ -170,6 +211,8 @@ export const AddTemplateToZone = async (
|
|||||||
missingPanels.map((panelName: any) =>
|
missingPanels.map((panelName: any) =>
|
||||||
panelModel(organization).create({
|
panelModel(organization).create({
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
panelName,
|
panelName,
|
||||||
widgets: [],
|
widgets: [],
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
@@ -180,6 +223,8 @@ export const AddTemplateToZone = async (
|
|||||||
for (const widgetData of existingTemplate.widgets) {
|
for (const widgetData of existingTemplate.widgets) {
|
||||||
const addedExistingPanel = await panelModel(organization).findOne({
|
const addedExistingPanel = await panelModel(organization).findOne({
|
||||||
panelName: widgetData.panel,
|
panelName: widgetData.panel,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
@@ -187,6 +232,8 @@ export const AddTemplateToZone = async (
|
|||||||
|
|
||||||
const existingWidget = await widgetModel(organization).findOne({
|
const existingWidget = await widgetModel(organization).findOne({
|
||||||
panelID: addedExistingPanel._id,
|
panelID: addedExistingPanel._id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
widgetID: widgetData.id,
|
widgetID: widgetData.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
@@ -194,6 +241,8 @@ export const AddTemplateToZone = async (
|
|||||||
|
|
||||||
const newWidget = await widgetModel(organization).create({
|
const newWidget = await widgetModel(organization).create({
|
||||||
widgetID: widgetData.id,
|
widgetID: widgetData.id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
elementType: widgetData.type,
|
elementType: widgetData.type,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
widgetName: widgetData.widgetName || "Widget",
|
widgetName: widgetData.widgetName || "Widget",
|
||||||
@@ -207,6 +256,8 @@ export const AddTemplateToZone = async (
|
|||||||
for (const floatData of existingTemplate.floatWidgets) {
|
for (const floatData of existingTemplate.floatWidgets) {
|
||||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||||
floatWidgetID: floatData.id,
|
floatWidgetID: floatData.id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
});
|
});
|
||||||
@@ -214,6 +265,8 @@ export const AddTemplateToZone = async (
|
|||||||
|
|
||||||
await floatWidgetModel(organization).create({
|
await floatWidgetModel(organization).create({
|
||||||
className: floatData.className,
|
className: floatData.className,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
header: floatData.header,
|
header: floatData.header,
|
||||||
floatWidgetID: floatData.id,
|
floatWidgetID: floatData.id,
|
||||||
position: floatData.position,
|
position: floatData.position,
|
||||||
@@ -250,7 +303,7 @@ export const AddTemplateToZone = async (
|
|||||||
};
|
};
|
||||||
export const TemplateDelete = async (data: ITemplate): Promise<IResult> => {
|
export const TemplateDelete = async (data: ITemplate): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { templateID, projectId, userId, organization } = data;
|
const { templateID, projectId, userId, organization, versionId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -259,14 +312,26 @@ export const TemplateDelete = async (data: ITemplate): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingTemplate = await templateModel(organization).findOne({
|
const existingTemplate = await templateModel(organization).findOne({
|
||||||
templateID: templateID,
|
templateID: templateID,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (existingTemplate) {
|
if (existingTemplate) {
|
||||||
const newTemplate = await templateModel(organization).updateOne(
|
const newTemplate = await templateModel(organization).updateOne(
|
||||||
{ templateID: templateID, isArchive: false, projectId: projectId },
|
{
|
||||||
|
templateID: templateID,
|
||||||
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
},
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
);
|
);
|
||||||
if (newTemplate) {
|
if (newTemplate) {
|
||||||
@@ -293,7 +358,7 @@ export const TemplateDelete = async (data: ITemplate): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const GetAllTemplates = async (data: IGetTemplate): Promise<IResult> => {
|
export const GetAllTemplates = async (data: IGetTemplate): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId, projectId } = data;
|
const { organization, userId, projectId,versionId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -302,8 +367,19 @@ export const GetAllTemplates = async (data: IGetTemplate): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const templateDatas = await templateModel(organization)
|
const templateDatas = await templateModel(organization)
|
||||||
.find({ projectId: projectId, isArchive: false })
|
.find({
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
.select("-_id -__v -isArchive -createdAt -updatedAt");
|
.select("-_id -__v -isArchive -createdAt -updatedAt");
|
||||||
if (!templateDatas) return { status: "All Datas" };
|
if (!templateDatas) return { status: "All Datas" };
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import widget3dModel from "../../V1Models/Vizualization/3dwidget.ts";
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
interface IResult {
|
interface IResult {
|
||||||
status: string;
|
status: string;
|
||||||
@@ -20,6 +21,7 @@ interface IWidget3DAdd {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
@@ -27,6 +29,7 @@ interface IWidget3dUpdate {
|
|||||||
organization: string;
|
organization: string;
|
||||||
id: string;
|
id: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
@@ -36,18 +39,21 @@ interface IWidgetUpdate {
|
|||||||
position: [];
|
position: [];
|
||||||
rotation: [];
|
rotation: [];
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
interface I3dWidgetGet {
|
interface I3dWidgetGet {
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, widget, userId, zoneUuid, projectId } = data;
|
const { organization, widget, userId, zoneUuid, projectId, versionId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -56,15 +62,24 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||||
|
|
||||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (existing3Dwidget) {
|
if (existing3Dwidget) {
|
||||||
@@ -72,6 +87,8 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
|||||||
{
|
{
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
{ position: widget.position },
|
{ position: widget.position },
|
||||||
@@ -87,6 +104,8 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
|||||||
type: widget.type,
|
type: widget.type,
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
position: widget.position,
|
position: widget.position,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
zoneUuid,
|
zoneUuid,
|
||||||
Data: {
|
Data: {
|
||||||
measurements: widget?.Data?.measurements || {},
|
measurements: widget?.Data?.measurements || {},
|
||||||
@@ -125,8 +144,16 @@ export const Add3DWidget = async (data: IWidget3DAdd): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, id, position, rotation, userId, zoneUuid, projectId } =
|
const {
|
||||||
data;
|
organization,
|
||||||
|
id,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
userId,
|
||||||
|
zoneUuid,
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
|
||||||
@@ -136,9 +163,16 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone)
|
if (!existingZone)
|
||||||
@@ -148,6 +182,8 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
|||||||
|
|
||||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||||
widgetID: id,
|
widgetID: id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
@@ -155,6 +191,8 @@ export const Update3Dwidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
|||||||
const update3dwidget = await widget3dModel(organization).findOneAndUpdate(
|
const update3dwidget = await widget3dModel(organization).findOneAndUpdate(
|
||||||
{
|
{
|
||||||
widgetID: id,
|
widgetID: id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
@@ -196,7 +234,7 @@ export const Delete3Dwidget = async (
|
|||||||
data: IWidget3dUpdate
|
data: IWidget3dUpdate
|
||||||
): Promise<IResult> => {
|
): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, id, userId, zoneUuid, projectId } = data;
|
const { organization, id, userId, zoneUuid, projectId, versionId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -205,9 +243,16 @@ export const Delete3Dwidget = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone)
|
if (!existingZone)
|
||||||
@@ -218,6 +263,8 @@ export const Delete3Dwidget = async (
|
|||||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||||
widgetID: id,
|
widgetID: id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
});
|
});
|
||||||
if (!existing3Dwidget) {
|
if (!existing3Dwidget) {
|
||||||
@@ -226,6 +273,8 @@ export const Delete3Dwidget = async (
|
|||||||
const updateWidget = await widget3dModel(organization).findOneAndUpdate(
|
const updateWidget = await widget3dModel(organization).findOneAndUpdate(
|
||||||
{
|
{
|
||||||
widgetID: id,
|
widgetID: id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
@@ -257,7 +306,7 @@ export const Delete3Dwidget = async (
|
|||||||
};
|
};
|
||||||
export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
|
export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, userId, zoneUuid, projectId } = data;
|
const { organization, userId, zoneUuid, versionId, projectId } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -266,9 +315,17 @@ export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone)
|
if (!existingZone)
|
||||||
@@ -277,6 +334,8 @@ export const Get3Dwidget = async (data: I3dWidgetGet): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
const widgetData = await widget3dModel(organization).find({
|
const widgetData = await widget3dModel(organization).find({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!widgetData || widgetData.length === 0) {
|
if (!widgetData || widgetData.length === 0) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import panelModel from "../../V1Models/Vizualization/panelmodel.ts";
|
|||||||
import {
|
import {
|
||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
|
LivingCurrentVersion,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
interface IResult {
|
interface IResult {
|
||||||
status: string;
|
status: string;
|
||||||
@@ -14,7 +15,9 @@ interface IWidgetCreate {
|
|||||||
userId: string;
|
userId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
widget: {
|
widget: {
|
||||||
|
widgetName: string;
|
||||||
type: string;
|
type: string;
|
||||||
title: string;
|
title: string;
|
||||||
panel: string;
|
panel: string;
|
||||||
@@ -30,6 +33,7 @@ interface IWidgetDelete {
|
|||||||
userId: string;
|
userId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
widgetID: string;
|
widgetID: string;
|
||||||
}
|
}
|
||||||
interface IWidgetUpdate {
|
interface IWidgetUpdate {
|
||||||
@@ -37,6 +41,7 @@ interface IWidgetUpdate {
|
|||||||
userId: string;
|
userId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
widgetID: string;
|
widgetID: string;
|
||||||
values: {
|
values: {
|
||||||
widgetName: string;
|
widgetName: string;
|
||||||
@@ -57,11 +62,13 @@ interface IGetWidget {
|
|||||||
userId: string;
|
userId: string;
|
||||||
zoneUuid: string;
|
zoneUuid: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
widgetID: string;
|
widgetID: string;
|
||||||
}
|
}
|
||||||
export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, widget, userId, zoneUuid, projectId } = data;
|
const { organization, widget, userId, zoneUuid, projectId, versionId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -70,15 +77,24 @@ export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||||
|
|
||||||
const existingPanel = await panelModel(organization).findOne({
|
const existingPanel = await panelModel(organization).findOne({
|
||||||
panelName: widget.panel,
|
panelName: widget.panel,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
@@ -87,6 +103,8 @@ export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
|||||||
if (existingPanel.panelName === widget.panel) {
|
if (existingPanel.panelName === widget.panel) {
|
||||||
const existingWidget = await widgetModel(organization).findOne({
|
const existingWidget = await widgetModel(organization).findOne({
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
@@ -94,11 +112,14 @@ export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
|||||||
const updateWidget = await widgetModel(organization).findOneAndUpdate(
|
const updateWidget = await widgetModel(organization).findOneAndUpdate(
|
||||||
{
|
{
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
|
widgetName: widget.widgetName || widget.title,
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
Data: {
|
Data: {
|
||||||
@@ -118,9 +139,11 @@ export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
|||||||
const newWidget = await widgetModel(organization).create({
|
const newWidget = await widgetModel(organization).create({
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
elementType: widget.type,
|
elementType: widget.type,
|
||||||
widgetName: widget.title,
|
widgetName: widget.title || widget.widgetName,
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
widgetside: widget.panel,
|
widgetside: widget.panel,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
Data: {
|
Data: {
|
||||||
measurements: widget?.Data?.measurements || {},
|
measurements: widget?.Data?.measurements || {},
|
||||||
@@ -164,7 +187,8 @@ export const AddWidget = async (data: IWidgetCreate): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, widgetID, userId, zoneUuid, projectId } = data;
|
const { organization, widgetID, userId, versionId, zoneUuid, projectId } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -173,9 +197,16 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||||
@@ -183,12 +214,20 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
|||||||
const findWidget = await widgetModel(organization).findOne({
|
const findWidget = await widgetModel(organization).findOne({
|
||||||
widgetID: widgetID,
|
widgetID: widgetID,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!findWidget) return { status: "Widget not found" };
|
if (!findWidget) return { status: "Widget not found" };
|
||||||
|
|
||||||
const widgetData = await widgetModel(organization).updateOne(
|
const widgetData = await widgetModel(organization).updateOne(
|
||||||
{ _id: findWidget._id, isArchive: false, zoneUuid: zoneUuid },
|
{
|
||||||
|
_id: findWidget._id,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
zoneUuid: zoneUuid,
|
||||||
|
},
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -196,11 +235,15 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
|||||||
await widgetModel(organization).find({
|
await widgetModel(organization).find({
|
||||||
panelID: findWidget.panelID,
|
panelID: findWidget.panelID,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const panelData = await panelModel(organization).findOne({
|
const panelData = await panelModel(organization).findOne({
|
||||||
_id: findWidget.panelID,
|
_id: findWidget.panelID,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
});
|
});
|
||||||
@@ -212,6 +255,8 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
|||||||
|
|
||||||
const activeWidgets = await widgetModel(organization).find({
|
const activeWidgets = await widgetModel(organization).find({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -247,7 +292,15 @@ export const WidgetDelete = async (data: IWidgetDelete): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const UpdateWidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
export const UpdateWidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, widgetID, userId, projectId, zoneUuid, values } = data;
|
const {
|
||||||
|
organization,
|
||||||
|
widgetID,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
zoneUuid,
|
||||||
|
values,
|
||||||
|
} = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -256,15 +309,24 @@ export const UpdateWidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
versionId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: versionId,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||||
|
|
||||||
const findWidget = await widgetModel(organization).findOne({
|
const findWidget = await widgetModel(organization).findOne({
|
||||||
widgetID: widgetID,
|
widgetID: widgetID,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
@@ -285,7 +347,12 @@ export const UpdateWidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await widgetModel(organization).findOneAndUpdate(
|
await widgetModel(organization).findOneAndUpdate(
|
||||||
{ widgetID: widgetID, isArchive: false },
|
{
|
||||||
|
widgetID: widgetID,
|
||||||
|
versionId: versionId,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
updateData,
|
updateData,
|
||||||
{
|
{
|
||||||
new: true,
|
new: true,
|
||||||
@@ -311,7 +378,8 @@ export const UpdateWidget = async (data: IWidgetUpdate): Promise<IResult> => {
|
|||||||
};
|
};
|
||||||
export const GetWidget = async (data: IGetWidget): Promise<IResult> => {
|
export const GetWidget = async (data: IGetWidget): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { organization, widgetID, userId, projectId, zoneUuid } = data;
|
const { organization, widgetID, userId, projectId, versionId, zoneUuid } =
|
||||||
|
data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -320,9 +388,17 @@ export const GetWidget = async (data: IGetWidget): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const VersionGetId = versionId ? versionId : LivingProject.Present_version;
|
||||||
|
const ExistingVersion = await LivingCurrentVersion(
|
||||||
|
organization,
|
||||||
|
LivingProject._id,
|
||||||
|
VersionGetId
|
||||||
|
);
|
||||||
|
if (!ExistingVersion) return { status: "Version Data not found" };
|
||||||
const existingZone = await zoneModel(organization).findOne({
|
const existingZone = await zoneModel(organization).findOne({
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
if (!existingZone) return { status: "Zone not found for the zoneUuid" };
|
||||||
@@ -331,6 +407,8 @@ export const GetWidget = async (data: IGetWidget): Promise<IResult> => {
|
|||||||
.findOne({
|
.findOne({
|
||||||
widgetID: widgetID,
|
widgetID: widgetID,
|
||||||
zoneUuid: zoneUuid,
|
zoneUuid: zoneUuid,
|
||||||
|
versionId: ExistingVersion._id,
|
||||||
|
projectId: projectId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
})
|
})
|
||||||
.select("Data widgetName -_id");
|
.select("Data widgetName -_id");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
|
import wallItemModel from "../../model/builder/assets/wallitems-Model.ts";
|
||||||
interface IWallSetupData {
|
interface IWallSetupData {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
modelName: string;
|
modelName: string;
|
||||||
@@ -45,7 +45,7 @@ export class WallItems {
|
|||||||
quaternion,
|
quaternion,
|
||||||
scale,
|
scale,
|
||||||
},
|
},
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
state: "Updated successfully",
|
state: "Updated successfully",
|
||||||
@@ -67,11 +67,13 @@ export class WallItems {
|
|||||||
data: newValue,
|
data: newValue,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
} catch (error:unknown) {
|
|
||||||
const err = error as Error;
|
const err = error as Error;
|
||||||
console.error("Error creating wallitems:", error);
|
console.error("Error creating wallitems:", error);
|
||||||
return { state: "Failed to create wallitems", data: { message: err.message } };
|
return {
|
||||||
|
state: "Failed to create wallitems",
|
||||||
|
data: { message: err.message },
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static async getWallItems(req: Request, res: Response) {
|
static async getWallItems(req: Request, res: Response) {
|
||||||
|
|||||||
92
src/shared/services/yjs/auto-save.ts
Normal file
92
src/shared/services/yjs/auto-save.ts
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import * as Y from "yjs";
|
||||||
|
import autoSaveModel from "../../V1Models/yjs/auto-saveModel.ts";
|
||||||
|
import { Request, Response } from "express";
|
||||||
|
|
||||||
|
import {
|
||||||
|
yDocStore,
|
||||||
|
observerAttached,
|
||||||
|
} from "../../../socket-server/utils/yjs/yjsRoomjoin.ts";
|
||||||
|
|
||||||
|
interface RestoreAutoSaveInput {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
}
|
||||||
|
interface clearAutoSaveInput {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const serializeYMap = (map: Y.Map<any>): Record<string, any> => {
|
||||||
|
const result: Record<string, any> = {};
|
||||||
|
for (const [key, value] of map.entries()) {
|
||||||
|
if (value instanceof Y.Map) {
|
||||||
|
result[key] = serializeYMap(value);
|
||||||
|
} else if (value instanceof Y.Array) {
|
||||||
|
result[key] = value
|
||||||
|
.toArray()
|
||||||
|
.map((item) => (item instanceof Y.Map ? serializeYMap(item) : item));
|
||||||
|
} else {
|
||||||
|
result[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const restoreYDocFromAutoSave = async (
|
||||||
|
data: RestoreAutoSaveInput
|
||||||
|
): Promise<{ status: string; data?: object }> => {
|
||||||
|
const { projectId, versionId, organization } = data;
|
||||||
|
const Model = autoSaveModel(organization);
|
||||||
|
const doc = await Model.findOne({ projectId, versionId });
|
||||||
|
|
||||||
|
if (!doc?.yjsData) {
|
||||||
|
return { status: "No auto-saved data found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const ydoc = new Y.Doc();
|
||||||
|
try {
|
||||||
|
const binary = Buffer.from(doc.yjsData, "base64");
|
||||||
|
Y.applyUpdateV2(ydoc, new Uint8Array(binary));
|
||||||
|
console.log(" Y.Doc restored from auto-saved data");
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(" Failed to apply Yjs update:", err.message);
|
||||||
|
return { status: "Corrupted Y.Doc data" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineMap = ydoc.getMap("lines");
|
||||||
|
|
||||||
|
const jsonData: Record<string, any> = {};
|
||||||
|
for (const [key, value] of lineMap.entries()) {
|
||||||
|
const yLine = value as Y.Map<any>;
|
||||||
|
jsonData[key] = serializeYMap(yLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { status: "Success", data: jsonData };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const clearSnapshotController = async (
|
||||||
|
data: clearAutoSaveInput
|
||||||
|
): Promise<{ status: string; data?: object }> => {
|
||||||
|
try {
|
||||||
|
const { projectId, versionId, organization } = data;
|
||||||
|
const key = `${projectId}-${versionId}`;
|
||||||
|
|
||||||
|
const Model = autoSaveModel(organization);
|
||||||
|
|
||||||
|
// 🗑️ Delete from MongoDB
|
||||||
|
await Model.deleteMany({ projectId, versionId });
|
||||||
|
|
||||||
|
// 🧠 Clear from in-memory Y.Doc store
|
||||||
|
yDocStore.delete(key);
|
||||||
|
observerAttached.delete(key);
|
||||||
|
|
||||||
|
console.log(`🧹 Cleared snapshot and Y.Doc from memory for: ${key}`);
|
||||||
|
|
||||||
|
return { status: "Success" };
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error("❌ Error clearing snapshot:", err.message);
|
||||||
|
return { status: "Error", data: { message: err.message } };
|
||||||
|
}
|
||||||
|
};
|
||||||
1
src/shared/services/yjs/clrearSnapshot.ts
Normal file
1
src/shared/services/yjs/clrearSnapshot.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
128
src/shared/services/yjs/snapshot.ts
Normal file
128
src/shared/services/yjs/snapshot.ts
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
import * as Y from "yjs";
|
||||||
|
import pako from "pako";
|
||||||
|
import { getYDoc } from "../../../socket-server/utils/yjs/yjsRoomjoin.ts";
|
||||||
|
import snapshotModel from "../../V1Models/yjs/snapshotModel.ts";
|
||||||
|
import autosaveModel from "../../V1Models/yjs/auto-saveModel.ts";
|
||||||
|
interface SnapshotInput {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
createdBy: string;
|
||||||
|
label: string;
|
||||||
|
ydoc: Y.Doc;
|
||||||
|
}
|
||||||
|
interface listSnapshotInput {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
interface RestoreSnapshotInput {
|
||||||
|
organization: string;
|
||||||
|
snapshotId: string; // MongoDB document _id
|
||||||
|
ydoc: Y.Doc;
|
||||||
|
}
|
||||||
|
export const saveSnapshotService = async ({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
createdBy,
|
||||||
|
label,
|
||||||
|
ydoc,
|
||||||
|
}: SnapshotInput): Promise<{ status: string; data?: object }> => {
|
||||||
|
try {
|
||||||
|
const snapshot = Y.encodeStateAsUpdate(ydoc); // 🧠 Convert Y.Doc to binary
|
||||||
|
|
||||||
|
const snapshotEntry = await snapshotModel(organization).create({
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
createdBy,
|
||||||
|
label,
|
||||||
|
snapshotData: Buffer.from(snapshot),
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: snapshotEntry,
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
status: "Failed to save snapshot",
|
||||||
|
data: error.message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const restoreSnapshotService = async ({
|
||||||
|
organization,
|
||||||
|
snapshotId,
|
||||||
|
ydoc,
|
||||||
|
}: RestoreSnapshotInput): Promise<{ status: string; data?: object }> => {
|
||||||
|
try {
|
||||||
|
const snapshot = await snapshotModel(organization).findById(snapshotId);
|
||||||
|
console.log('snapshotEntry: ', snapshot);
|
||||||
|
|
||||||
|
if (!snapshot) {
|
||||||
|
return { status: "Snapshot not found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ Create new Y.Doc and apply update
|
||||||
|
const ydoc = new Y.Doc();
|
||||||
|
Y.applyUpdate(ydoc, new Uint8Array(snapshot.snapshotData));
|
||||||
|
|
||||||
|
// ✅ Convert to JSON manually
|
||||||
|
const lineMap = ydoc.getMap('lines');
|
||||||
|
const jsonResult: any = {};
|
||||||
|
for (const [key, val] of lineMap.entries()) {
|
||||||
|
if (val instanceof Y.Map) {
|
||||||
|
const obj: any = {};
|
||||||
|
val.forEach((v, k) => {
|
||||||
|
if (v instanceof Y.Array) {
|
||||||
|
obj[k] = v.map((item: any) =>
|
||||||
|
item instanceof Y.Map
|
||||||
|
? Object.fromEntries(item.entries())
|
||||||
|
: item
|
||||||
|
);
|
||||||
|
} else if (v instanceof Y.Map) {
|
||||||
|
obj[k] = Object.fromEntries(v.entries());
|
||||||
|
} else {
|
||||||
|
obj[k] = v;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
jsonResult[key] = obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: {
|
||||||
|
snapshotId,
|
||||||
|
label: snapshot.label,
|
||||||
|
datas:jsonResult,
|
||||||
|
restoredAt: new Date(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
status: "Failed to restore snapshot",
|
||||||
|
data: error.message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const listSnapshotService = async (
|
||||||
|
data:listSnapshotInput
|
||||||
|
): Promise<{ status: string; data?: object }> => {
|
||||||
|
try {
|
||||||
|
|
||||||
|
const { projectId, versionId, organization } = data;
|
||||||
|
const SnapModel = snapshotModel(organization);
|
||||||
|
const snapshots = await SnapModel.find({ projectId, versionId })
|
||||||
|
.sort({ createdAt: -1 }) // latest first
|
||||||
|
.select("label createdAt _id");
|
||||||
|
|
||||||
|
return { status: "Success", data: snapshots };
|
||||||
|
} catch (error: any) {
|
||||||
|
return {
|
||||||
|
status: "Failed to save snapshot",
|
||||||
|
data: error.message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -26,7 +26,7 @@ USER root
|
|||||||
COPY . .
|
COPY . .
|
||||||
# Expose the port that the application listens on.
|
# Expose the port that the application listens on.
|
||||||
|
|
||||||
EXPOSE 7999
|
EXPOSE 1059
|
||||||
|
|
||||||
|
|
||||||
# Run the application.
|
# Run the application.
|
||||||
|
|||||||
@@ -20,7 +20,13 @@ export const SetAisleHandleEvent = async (
|
|||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.setAisleModel_v1 || !data?.organization) return;
|
if (event !== EVENTS.setAisleModel_v1 || !data?.organization) return;
|
||||||
const requiredFields = ["aisleUuid", "projectId", "userId", "organization"];
|
const requiredFields = [
|
||||||
|
"aisleUuid",
|
||||||
|
"projectId",
|
||||||
|
"versionId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
@@ -41,6 +47,9 @@ export const SetAisleHandleEvent = async (
|
|||||||
Success: { message: "Aisle Created Successfully" },
|
Success: { message: "Aisle Created Successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"Aisle Not Updated": { message: "Aisle Not Updated" },
|
"Aisle Not Updated": { message: "Aisle Not Updated" },
|
||||||
"Aisle Not Created": { message: "Aisle Not Created" },
|
"Aisle Not Created": { message: "Aisle Not Created" },
|
||||||
"Aisle Updated Successfully": { message: "Aisle Updated Successfully" },
|
"Aisle Updated Successfully": { message: "Aisle Updated Successfully" },
|
||||||
@@ -76,7 +85,13 @@ export const DeleteAisleHandleEvent = async (
|
|||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.delete_v1AisleModel || !data?.organization) return;
|
if (event !== EVENTS.delete_v1AisleModel || !data?.organization) return;
|
||||||
const requiredFields = ["aisleUuid", "projectId", "userId", "organization"];
|
const requiredFields = [
|
||||||
|
"aisleUuid",
|
||||||
|
"projectId",
|
||||||
|
"versionId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
@@ -97,6 +112,9 @@ export const DeleteAisleHandleEvent = async (
|
|||||||
Success: { message: "Aisle Deleted Successfully" },
|
Success: { message: "Aisle Deleted Successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"Aisle not found": { message: "Aisle not found" },
|
"Aisle not found": { message: "Aisle not found" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export const setAssetHandleEvent = async (
|
|||||||
"isLocked",
|
"isLocked",
|
||||||
"isVisible",
|
"isVisible",
|
||||||
"projectId",
|
"projectId",
|
||||||
|
"versionId",
|
||||||
"userId",
|
"userId",
|
||||||
"organization",
|
"organization",
|
||||||
];
|
];
|
||||||
@@ -54,6 +55,9 @@ export const setAssetHandleEvent = async (
|
|||||||
Success: { message: "Model created successfully" },
|
Success: { message: "Model created successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"Updated successfully": { message: "Updated successfully" },
|
"Updated successfully": { message: "Updated successfully" },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -87,10 +91,10 @@ export const deleteAssetHandleEvent = async (
|
|||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.delete_v1AssetModel || !data?.organization) return;
|
if (event !== EVENTS.delete_v1AssetModel || !data?.organization) return;
|
||||||
console.log('event: ', event);
|
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
"modelUuid",
|
"modelUuid",
|
||||||
"modelName",
|
"modelName",
|
||||||
|
"versionId",
|
||||||
"projectId",
|
"projectId",
|
||||||
"userId",
|
"userId",
|
||||||
"organization",
|
"organization",
|
||||||
@@ -115,6 +119,9 @@ export const deleteAssetHandleEvent = async (
|
|||||||
Success: { message: "Model deleted successfully" },
|
Success: { message: "Model deleted successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"model not found": { message: "model not found" },
|
"model not found": { message: "model not found" },
|
||||||
"Failed to archive asset": { message: "Failed to archive asset" },
|
"Failed to archive asset": { message: "Failed to archive asset" },
|
||||||
};
|
};
|
||||||
@@ -152,6 +159,7 @@ export const replaceEventDatasHandleEvent = async (
|
|||||||
"modelUuid",
|
"modelUuid",
|
||||||
"eventData",
|
"eventData",
|
||||||
"projectId",
|
"projectId",
|
||||||
|
"versionId",
|
||||||
"userId",
|
"userId",
|
||||||
"organization",
|
"organization",
|
||||||
];
|
];
|
||||||
@@ -174,6 +182,9 @@ export const replaceEventDatasHandleEvent = async (
|
|||||||
Success: { message: "Data updated successfully" },
|
Success: { message: "Data updated successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"Model not for this UUID": { message: "Model not for this UUID" },
|
"Model not for this UUID": { message: "Model not for this UUID" },
|
||||||
"Failed to archive asset": { message: "Failed to archive asset" },
|
"Failed to archive asset": { message: "Failed to archive asset" },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,54 +2,70 @@ import { Socket, Server } from "socket.io";
|
|||||||
import { EVENTS } from "../../socket/events.ts";
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
import { SetCamera } from "../../../shared/services/builder/cameraService.ts";
|
import { SetCamera } from "../../../shared/services/builder/cameraService.ts";
|
||||||
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
import {
|
||||||
|
ErrorResponse,
|
||||||
|
FinalResponse,
|
||||||
|
validateFields,
|
||||||
|
} from "../../utils/socketfunctionHelpers.ts";
|
||||||
export const SetCameraHandleEvent = async (
|
export const SetCameraHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.setCamera_v1 || !data?.organization) return;
|
if (event !== EVENTS.setCamera_v1 || !data?.organization) return;
|
||||||
console.log('event: ', event);
|
const requiredFields = [
|
||||||
const requiredFields = [
|
"position",
|
||||||
"position",
|
"target",
|
||||||
"target",
|
"rotation",
|
||||||
"rotation",
|
"projectId",
|
||||||
"projectId",
|
"userId",
|
||||||
"userId",
|
"organization",
|
||||||
"organization",
|
];
|
||||||
];
|
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.camera_v1CreateResponse,
|
|
||||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await SetCamera(data);
|
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
if (missingFields.length > 0) {
|
||||||
Success: { message: "Camera created successfully" },
|
emitToSenderAndAdmins(
|
||||||
"User not found": { message: "User not found" },
|
io,
|
||||||
"Project not found": { message: "Project not found" },
|
socket,
|
||||||
"Update Success": { message: "Update Success" },
|
data.organization,
|
||||||
|
EVENTS.camera_v1CreateResponse,
|
||||||
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("event: camera", event);
|
||||||
|
const result = await SetCamera(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Camera created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Update Success": { message: "Update Success" },
|
||||||
|
};
|
||||||
|
|
||||||
};
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Camera_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
const response = FinalResponse(
|
||||||
const Camera_Datas =
|
status,
|
||||||
status === "Success" && result?.data
|
socket,
|
||||||
|
data.organization,
|
||||||
|
messages,
|
||||||
|
Camera_Datas
|
||||||
|
);
|
||||||
|
|
||||||
? {
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
}
|
socket,
|
||||||
: undefined;
|
data.organization,
|
||||||
|
EVENTS.camera_v1CreateResponse,
|
||||||
const response = FinalResponse(status, socket, data.organization, messages, Camera_Datas);
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.camera_v1CreateResponse, response, connectedUsersByOrg)
|
};
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,51 +2,73 @@ import { Socket, Server } from "socket.io";
|
|||||||
import { EVENTS } from "../../socket/events.ts";
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
import { setEnvironment } from "../../../shared/services/builder/EnvironmentService.ts";
|
import { setEnvironment } from "../../../shared/services/builder/EnvironmentService.ts";
|
||||||
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
import {
|
||||||
|
ErrorResponse,
|
||||||
|
FinalResponse,
|
||||||
|
validateFields,
|
||||||
|
} from "../../utils/socketfunctionHelpers.ts";
|
||||||
|
|
||||||
export const setEnvironmentHandleEvent = async (
|
export const setEnvironmentHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.setenvironment_v1 || !data?.organization) return;
|
if (event !== EVENTS.setenvironment_v1 || !data?.organization) return;
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
"roofVisibility", "wallVisibility", "shadowVisibility",
|
"roofVisibility",
|
||||||
"projectId",
|
"wallVisibility",
|
||||||
"userId",
|
"shadowVisibility",
|
||||||
"organization",
|
"projectId",
|
||||||
];
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Environment_v1UpdateResponse,
|
|
||||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await setEnvironment(data);
|
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
if (missingFields.length > 0) {
|
||||||
Success: { message: "evironment created successfully" },
|
emitToSenderAndAdmins(
|
||||||
"User not found": { message: "User not found" },
|
io,
|
||||||
"Project not found": { message: "Project not found" },
|
socket,
|
||||||
'evironments updated': { message: 'evironments updated' },
|
data.organization,
|
||||||
|
EVENTS.Environment_v1UpdateResponse,
|
||||||
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await setEnvironment(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "evironment created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"CurrentVersion Data not found": {
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
},
|
||||||
|
"evironments updated": { message: "evironments updated" },
|
||||||
|
};
|
||||||
|
|
||||||
};
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const environment_Datas =
|
||||||
|
status === "Success" && result?.data ? {} : undefined;
|
||||||
|
const response = FinalResponse(
|
||||||
|
status,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
messages,
|
||||||
|
environment_Datas
|
||||||
|
);
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
emitToSenderAndAdmins(
|
||||||
const environment_Datas =
|
io,
|
||||||
status === "Success" && result?.data
|
socket,
|
||||||
|
data.organization,
|
||||||
? {
|
EVENTS.Environment_v1UpdateResponse,
|
||||||
|
response,
|
||||||
}
|
connectedUsersByOrg
|
||||||
: undefined;
|
);
|
||||||
const response = FinalResponse(status, socket, data.organization, messages, environment_Datas);
|
};
|
||||||
|
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Environment_v1UpdateResponse, response, connectedUsersByOrg)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const CreateLineHandleEvent = async (
|
|||||||
"line",
|
"line",
|
||||||
"type",
|
"type",
|
||||||
"layer",
|
"layer",
|
||||||
"projectId",
|
"projectId","versionId",
|
||||||
"userId",
|
"userId",
|
||||||
"organization",
|
"organization",
|
||||||
];
|
];
|
||||||
@@ -50,6 +50,9 @@ export const CreateLineHandleEvent = async (
|
|||||||
Success: { message: "line created successfully" },
|
Success: { message: "line created successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"Update Success": { message: "Update Success" },
|
"Update Success": { message: "Update Success" },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,7 +89,7 @@ export const UpdateLineHandleEvent = async (
|
|||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
"uuid",
|
"uuid",
|
||||||
"position",
|
"position",
|
||||||
"projectId",
|
"projectId","versionId",
|
||||||
"userId",
|
"userId",
|
||||||
"organization",
|
"organization",
|
||||||
];
|
];
|
||||||
@@ -110,6 +113,9 @@ export const UpdateLineHandleEvent = async (
|
|||||||
Success: { message: "line updated successfully" },
|
Success: { message: "line updated successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
@@ -142,8 +148,7 @@ export const DeleteLineHandleEvent = async (
|
|||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.deleteLine_v1 || !data?.organization) return;
|
if (event !== EVENTS.deleteLine_v1 || !data?.organization) return;
|
||||||
console.log("event: ", event);
|
const requiredFields = ["line", "projectId","versionId", "userId", "organization"];
|
||||||
const requiredFields = ["line", "projectId", "userId", "organization"];
|
|
||||||
|
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
@@ -165,6 +170,9 @@ export const DeleteLineHandleEvent = async (
|
|||||||
Success: { message: "line deleted successfully" },
|
Success: { message: "line deleted successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"line not found": { message: "line not found" },
|
"line not found": { message: "line not found" },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -198,8 +206,7 @@ export const DeleteLayerHandleEvent = async (
|
|||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.deleteLineLayer_v1 || !data?.organization) return;
|
if (event !== EVENTS.deleteLineLayer_v1 || !data?.organization) return;
|
||||||
console.log("event:-layer ", event);
|
const requiredFields = ["layer", "projectId","versionId", "userId", "organization"];
|
||||||
const requiredFields = ["layer", "projectId", "userId", "organization"];
|
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
@@ -220,6 +227,9 @@ export const DeleteLayerHandleEvent = async (
|
|||||||
Success: { message: "layer deleted successfully" },
|
Success: { message: "layer deleted successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"layer not found": { message: "layer not found" },
|
"layer not found": { message: "layer not found" },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -253,8 +263,7 @@ export const DeleteLinePointsHandleEvent = async (
|
|||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.deletePoint_v1 || !data?.organization) return;
|
if (event !== EVENTS.deletePoint_v1 || !data?.organization) return;
|
||||||
console.log("event:point ", event);
|
const requiredFields = ["uuid", "projectId","versionId", "userId", "organization"];
|
||||||
const requiredFields = ["uuid", "projectId", "userId", "organization"];
|
|
||||||
|
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
@@ -276,6 +285,9 @@ export const DeleteLinePointsHandleEvent = async (
|
|||||||
Success: { message: "point deleted successfully" },
|
Success: { message: "point deleted successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"Line not found": { message: "Line not found" },
|
"Line not found": { message: "Line not found" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ export const setWallItemsHandleEvent = async (
|
|||||||
"type",
|
"type",
|
||||||
"csgposition",
|
"csgposition",
|
||||||
"csgscale",
|
"csgscale",
|
||||||
"quaternion",
|
|
||||||
"assetId",
|
"assetId",
|
||||||
|
"quaternion","versionId",
|
||||||
"scale",
|
"scale",
|
||||||
"projectId",
|
"projectId",
|
||||||
"userId",
|
"userId",
|
||||||
@@ -56,9 +56,11 @@ export const setWallItemsHandleEvent = async (
|
|||||||
Success: { message: "wall Item created successfully" },
|
Success: { message: "wall Item created successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"Updated successfully": { message: "Updated successfully" },
|
"Updated successfully": { message: "Updated successfully" },
|
||||||
};
|
};
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
const wall_Datas = status === "Success" && result?.data ? {} : undefined;
|
const wall_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
@@ -92,7 +94,7 @@ export const deleteWallItemsHandleEvent = async (
|
|||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
"modelUuid",
|
"modelUuid",
|
||||||
"modelName",
|
"modelName",
|
||||||
"projectId",
|
"projectId","versionId",
|
||||||
"userId",
|
"userId",
|
||||||
"organization",
|
"organization",
|
||||||
];
|
];
|
||||||
@@ -116,6 +118,9 @@ export const deleteWallItemsHandleEvent = async (
|
|||||||
Success: { message: "wall Item deleted successfully" },
|
Success: { message: "wall Item deleted successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"model not found": { message: "model not found" },
|
"model not found": { message: "model not found" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,101 +1,138 @@
|
|||||||
import { Socket, Server } from "socket.io";
|
import { Socket, Server } from "socket.io";
|
||||||
import { EVENTS } from "../../socket/events.ts";
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
import { DelZone, SetZone } from "../../../shared/services/builder/zoneService.ts";
|
import {
|
||||||
import { ErrorResponse, FinalResponse, validateFields } from "../../utils/socketfunctionHelpers.ts";
|
DelZone,
|
||||||
|
SetZone,
|
||||||
|
} from "../../../shared/services/builder/zoneService.ts";
|
||||||
|
import {
|
||||||
|
ErrorResponse,
|
||||||
|
FinalResponse,
|
||||||
|
validateFields,
|
||||||
|
} from "../../utils/socketfunctionHelpers.ts";
|
||||||
|
|
||||||
export const SetZoneHandleEvent = async (
|
export const SetZoneHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.setZone_v1 || !data?.organization) return;
|
if (event !== EVENTS.setZone_v1 || !data?.organization) return;
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
"zoneData",
|
"zoneData",
|
||||||
"projectId",
|
"projectId",
|
||||||
"userId",
|
"versionId",
|
||||||
"organization",
|
"userId",
|
||||||
];
|
"organization",
|
||||||
const missingFields = validateFields(data, requiredFields);
|
];
|
||||||
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.zone_v1UpdateResponse,
|
emitToSenderAndAdmins(
|
||||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
io,
|
||||||
return;
|
socket,
|
||||||
}
|
data.organization,
|
||||||
const result = await SetZone(data);
|
EVENTS.zone_v1UpdateResponse,
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await SetZone(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
const messages: Record<string, { message: string }> = {
|
||||||
Success: { message: "zone created successfully" },
|
Success: { message: "zone created successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
"zone updated": { message: "zone updated" },
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
|
"zone updated": { message: "zone updated" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const zone_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
};
|
const response = FinalResponse(
|
||||||
|
status,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
messages,
|
||||||
|
zone_Datas
|
||||||
|
);
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
emitToSenderAndAdmins(
|
||||||
const zone_Datas =
|
io,
|
||||||
status === "Success" && result?.data
|
socket,
|
||||||
|
data.organization,
|
||||||
? {
|
EVENTS.zone_v1UpdateResponse,
|
||||||
|
response,
|
||||||
}
|
connectedUsersByOrg
|
||||||
: undefined;
|
);
|
||||||
|
};
|
||||||
const response = FinalResponse(status, socket, data.organization, messages, zone_Datas);
|
|
||||||
|
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.zone_v1UpdateResponse, response, connectedUsersByOrg)
|
|
||||||
}
|
|
||||||
export const DeleteZoneHandleEvent = async (
|
export const DeleteZoneHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.deleteZone_v1 || !data?.organization) return;
|
if (event !== EVENTS.deleteZone_v1 || !data?.organization) return;
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
"zoneUuid",
|
"zoneUuid",
|
||||||
"projectId",
|
"projectId",
|
||||||
"userId",
|
"versionId",
|
||||||
"organization",
|
"userId",
|
||||||
];
|
"organization",
|
||||||
|
];
|
||||||
|
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Zone_v1DeleteResponse,
|
emitToSenderAndAdmins(
|
||||||
ErrorResponse(missingFields, socket, data.organization), connectedUsersByOrg);
|
io,
|
||||||
return;
|
socket,
|
||||||
}
|
data.organization,
|
||||||
const result = await DelZone(data);
|
EVENTS.Zone_v1DeleteResponse,
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DelZone(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
const messages: Record<string, { message: string }> = {
|
||||||
Success: { message: "zone deleted created successfully" },
|
Success: { message: "zone deleted created successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const zone_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
|
const response = FinalResponse(
|
||||||
|
status,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
messages,
|
||||||
|
zone_Datas
|
||||||
|
);
|
||||||
|
|
||||||
};
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
const zone_Datas =
|
socket,
|
||||||
status === "Success" && result?.data
|
data.organization,
|
||||||
|
EVENTS.Zone_v1DeleteResponse,
|
||||||
? {
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
}
|
);
|
||||||
: undefined;
|
};
|
||||||
|
|
||||||
const response = FinalResponse(status, socket, data.organization, messages, zone_Datas);
|
|
||||||
|
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.Zone_v1DeleteResponse, response, connectedUsersByOrg)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,173 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import {
|
||||||
|
FinalResponse,
|
||||||
|
ErrorResponse,
|
||||||
|
validateFields,
|
||||||
|
} from "../../utils/socketfunctionHelpers.ts";
|
||||||
|
import {
|
||||||
|
createLineService,
|
||||||
|
DeleteLineItems,
|
||||||
|
updateLineService,
|
||||||
|
} from "../../../shared/services/collaborative/lineService-collab.ts";
|
||||||
|
import { getYDoc } from "../../utils/yjs/yjsRoomjoin.ts";
|
||||||
|
|
||||||
|
export const CreateLineHandleEventYjs = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: any
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.createLineYjs_v1 || !data?.organization) return;
|
||||||
|
|
||||||
|
const missingFields = validateFields(data, [
|
||||||
|
"line",
|
||||||
|
"type",
|
||||||
|
"layer",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
]);
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.createLineYjs_v1Response,
|
||||||
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await createLineService(data);
|
||||||
|
const status = result.status;
|
||||||
|
const response = FinalResponse(
|
||||||
|
status,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
{
|
||||||
|
Success: { message: "Line created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
},
|
||||||
|
result?.data
|
||||||
|
);
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.createLine_v1Response,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const UpdateLineHandleEventYjs = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: any
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.updateLineYjs_v1 || !data?.organization) return;
|
||||||
|
|
||||||
|
const missingFields = validateFields(data, [
|
||||||
|
"uuid",
|
||||||
|
"position",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
]);
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.updateLineYjs_v1Response,
|
||||||
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await updateLineService(data);
|
||||||
|
const status = result.status;
|
||||||
|
const response = FinalResponse(
|
||||||
|
status,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
{
|
||||||
|
Success: { message: "Line updated successfully" },
|
||||||
|
"Update failed": { message: "Update failed" },
|
||||||
|
},
|
||||||
|
result?.data
|
||||||
|
);
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.updateLineYjs_v1Response,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const DeleteLineHandleEventYjs = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deleteLineYjs_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["line", "projectId", "userId", "organization"];
|
||||||
|
|
||||||
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.deleteLineYjs_v1Response,
|
||||||
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteLineItems(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "line deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"line not found": { message: "line not found" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Line_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
|
const response = FinalResponse(
|
||||||
|
status,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
messages,
|
||||||
|
Line_Datas
|
||||||
|
);
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.deleteLineYjs_v1Response,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -23,7 +23,6 @@ export const projectHandleEvent = async (
|
|||||||
},
|
},
|
||||||
callback?: Function
|
callback?: Function
|
||||||
) => {
|
) => {
|
||||||
console.log("event: ", event);
|
|
||||||
if (event !== EVENTS.addProject || !data?.organization) return;
|
if (event !== EVENTS.addProject || !data?.organization) return;
|
||||||
const requiredFields = ["projectUuid", "userId", "thumbnail", "organization"];
|
const requiredFields = ["projectUuid", "userId", "thumbnail", "organization"];
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
@@ -82,7 +81,6 @@ export const projectDeleteHandleEvent = async (
|
|||||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
console.log("event: ", event);
|
|
||||||
|
|
||||||
if (event !== EVENTS.deleteProject || !data?.organization) return;
|
if (event !== EVENTS.deleteProject || !data?.organization) return;
|
||||||
const requiredFields = ["projectId", "userId", "organization"];
|
const requiredFields = ["projectId", "userId", "organization"];
|
||||||
@@ -106,6 +104,9 @@ export const projectDeleteHandleEvent = async (
|
|||||||
Success: { message: "Project Deleted Successfully" },
|
Success: { message: "Project Deleted Successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"CurrentVersion Data not found": {
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
@@ -145,7 +146,6 @@ export const projecUpdateHandleEvent = async (
|
|||||||
[org: string]: { socketId: string; userId: string; role: string }[];
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
console.log("event: ", event);
|
|
||||||
if (event !== EVENTS.ProjectUpdate || !data?.organization) return;
|
if (event !== EVENTS.ProjectUpdate || !data?.organization) return;
|
||||||
const requiredFields = ["projectId", "userId", "organization"];
|
const requiredFields = ["projectId", "userId", "organization"];
|
||||||
const missingFields = validateFields(data, requiredFields);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
@@ -168,6 +168,9 @@ export const projecUpdateHandleEvent = async (
|
|||||||
Success: { message: "Project updated Successfully" },
|
Success: { message: "Project updated Successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"CurrentVersion Data not found": {
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
@@ -207,7 +210,6 @@ export const DuplicateProjectHandleEvent = async (
|
|||||||
},
|
},
|
||||||
callback?: Function
|
callback?: Function
|
||||||
) => {
|
) => {
|
||||||
console.log("event: ", event);
|
|
||||||
if (event !== EVENTS.DuplicateProject || !data?.organization) return;
|
if (event !== EVENTS.DuplicateProject || !data?.organization) return;
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
"projectUuid",
|
"projectUuid",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export const productAddHandleEvent = async (
|
|||||||
"productName",
|
"productName",
|
||||||
"productUuid",
|
"productUuid",
|
||||||
"projectId",
|
"projectId",
|
||||||
|
"versionId",
|
||||||
"userId",
|
"userId",
|
||||||
"organization",
|
"organization",
|
||||||
];
|
];
|
||||||
@@ -52,6 +53,9 @@ export const productAddHandleEvent = async (
|
|||||||
Success: { message: "Product created successfully" },
|
Success: { message: "Product created successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"EventData updated successfully": {
|
"EventData updated successfully": {
|
||||||
message: "EventData updated successfully",
|
message: "EventData updated successfully",
|
||||||
},
|
},
|
||||||
@@ -89,7 +93,13 @@ export const productDataDeleteHandleEvent = async (
|
|||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.delete_v1ProductModel || !data?.organization) return;
|
if (event !== EVENTS.delete_v1ProductModel || !data?.organization) return;
|
||||||
const requiredFields = ["productUuid", "projectId", "userId", "organization"];
|
const requiredFields = [
|
||||||
|
"productUuid",
|
||||||
|
"versionId",
|
||||||
|
"projectId",
|
||||||
|
"userId",
|
||||||
|
"organization",
|
||||||
|
];
|
||||||
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
@@ -118,6 +128,9 @@ export const productDataDeleteHandleEvent = async (
|
|||||||
Success: { message: "Product deleted successfully" },
|
Success: { message: "Product deleted successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"Product not found": { message: "Product not found" },
|
"Product not found": { message: "Product not found" },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -168,6 +181,7 @@ export const EventDataDeleteHandleEvent = async (
|
|||||||
"modelUuid",
|
"modelUuid",
|
||||||
"productUuid",
|
"productUuid",
|
||||||
"projectId",
|
"projectId",
|
||||||
|
"versionId",
|
||||||
"userId",
|
"userId",
|
||||||
"organization",
|
"organization",
|
||||||
];
|
];
|
||||||
@@ -199,6 +213,9 @@ export const EventDataDeleteHandleEvent = async (
|
|||||||
Success: { message: "EventData deleted successfully" },
|
Success: { message: "EventData deleted successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"Product not found": { message: "Product not found" },
|
"Product not found": { message: "Product not found" },
|
||||||
"Event Delete Unsuccessful": { message: "Event Delete Unsuccessful" },
|
"Event Delete Unsuccessful": { message: "Event Delete Unsuccessful" },
|
||||||
};
|
};
|
||||||
@@ -249,6 +266,7 @@ export const productRenameHandleEvent = async (
|
|||||||
"productName",
|
"productName",
|
||||||
"productUuid",
|
"productUuid",
|
||||||
"projectId",
|
"projectId",
|
||||||
|
"versionId",
|
||||||
"userId",
|
"userId",
|
||||||
"organization",
|
"organization",
|
||||||
];
|
];
|
||||||
@@ -280,6 +298,9 @@ export const productRenameHandleEvent = async (
|
|||||||
Success: { message: "product Rename successfully" },
|
Success: { message: "product Rename successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Version Data not found": {
|
||||||
|
message: "Version Data not found",
|
||||||
|
},
|
||||||
"Product not found": { message: "Product not found" },
|
"Product not found": { message: "Product not found" },
|
||||||
"Rename Unsuccessful": { message: "Rename Unsuccessful" },
|
"Rename Unsuccessful": { message: "Rename Unsuccessful" },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,22 +1,50 @@
|
|||||||
import { Socket } from "socket.io";
|
import { Socket, Server } from "socket.io";
|
||||||
import { EVENTS } from "../../socket/events.ts";
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
import { emitEventResponse } from "../../utils/emitEventResponse.ts";
|
import {
|
||||||
import { addComments, createThread, deleteComments, deleteThread } from "../../../shared/services/Thread/ThreadService.ts";
|
emitEventResponse,
|
||||||
export const createThreadHandleEvent = async (event: string, socket: Socket, data: any,) => {
|
emitToSenderAndAdmins,
|
||||||
|
} from "../../utils/emitEventResponse.ts";
|
||||||
|
import {
|
||||||
|
addComments,
|
||||||
|
createThread,
|
||||||
|
deleteComments,
|
||||||
|
deleteThread,
|
||||||
|
findThreads,
|
||||||
|
updateThreadTitle,
|
||||||
|
} from "../../../shared/services/Thread/ThreadService.ts";
|
||||||
|
import {
|
||||||
|
ErrorResponse,
|
||||||
|
FinalResponse,
|
||||||
|
validateFields,
|
||||||
|
} from "../../utils/socketfunctionHelpers.ts";
|
||||||
|
export const createThreadHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
|
) => {
|
||||||
if (event !== EVENTS.createThread || !data?.organization) return;
|
if (event !== EVENTS.createThread || !data?.organization) return;
|
||||||
const requiredFields = ["userId", "position", "rotation", "organization", "projectId", "versionId"];
|
const requiredFields = [
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
"userId",
|
||||||
|
"position",
|
||||||
|
"rotation",
|
||||||
|
"organization",
|
||||||
|
"projectId",
|
||||||
|
];
|
||||||
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
const response = {
|
emitToSenderAndAdmins(
|
||||||
success: false,
|
io,
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
socket,
|
||||||
status: "MissingFields",
|
data.organization,
|
||||||
socketId: socket.id,
|
EVENTS.ThreadCreateResponse,
|
||||||
organization: data?.organization ?? "unknown",
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
};
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
emitEventResponse(socket, data?.organization, EVENTS.ThreadCreateResponse, response);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,38 +55,62 @@ export const createThreadHandleEvent = async (event: string, socket: Socket, dat
|
|||||||
Success: { message: "Thread created Successfully" },
|
Success: { message: "Thread created Successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"CurrentVersion Data not found": {
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
const threadDatas =
|
const threadDatas = status === "Success" && result?.data;
|
||||||
status === "Success" && result?.data
|
|
||||||
|
|
||||||
const response = {
|
// const response = {
|
||||||
success: status === "Success",
|
// success: status === "Success",
|
||||||
message: msg.message,
|
// message: msg.message,
|
||||||
|
// status,
|
||||||
|
// socketId: socket.id,
|
||||||
|
// organization: data.organization,
|
||||||
|
// ...(threadDatas ? { data: threadDatas } : {}),
|
||||||
|
// };
|
||||||
|
|
||||||
|
const response = FinalResponse(
|
||||||
status,
|
status,
|
||||||
socketId: socket.id,
|
socket,
|
||||||
organization: data.organization,
|
data.organization,
|
||||||
...(threadDatas ? { data: threadDatas } : {}),
|
messages,
|
||||||
};
|
threadDatas
|
||||||
|
);
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.ThreadCreateResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
|
||||||
|
// emitEventResponse(socket, data.organization, EVENTS.ThreadCreateResponse, response);
|
||||||
emitEventResponse(socket, data.organization, EVENTS.ThreadCreateResponse, response);
|
};
|
||||||
}
|
export const deleteThreadHandleEvent = async (
|
||||||
export const deleteThreadHandleEvent = async (event: string, socket: Socket, data: any,) => {
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
|
) => {
|
||||||
if (event !== EVENTS.deleteThread || !data?.organization) return;
|
if (event !== EVENTS.deleteThread || !data?.organization) return;
|
||||||
const requiredFields = ["userId", "threadId", "organization", "projectId", "versionId"];
|
const requiredFields = ["userId", "threadId", "organization", "projectId"];
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
const response = {
|
emitToSenderAndAdmins(
|
||||||
success: false,
|
io,
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
socket,
|
||||||
status: "MissingFields",
|
data.organization,
|
||||||
socketId: socket.id,
|
EVENTS.deleteThreadResponse,
|
||||||
organization: data?.organization ?? "unknown",
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
};
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
emitEventResponse(socket, data?.organization, EVENTS.deleteThreadResponse, response);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,39 +121,53 @@ export const deleteThreadHandleEvent = async (event: string, socket: Socket, dat
|
|||||||
Success: { message: "Thread deleted Successfully" },
|
Success: { message: "Thread deleted Successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"CurrentVersion Data not found": {
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
},
|
||||||
"can't deleted": { message: "Thread could not be deleted" },
|
"can't deleted": { message: "Thread could not be deleted" },
|
||||||
};
|
};
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
const threadDatas =
|
const threadDatas = status === "Success" && result?.data;
|
||||||
status === "Success" && result?.data
|
|
||||||
|
|
||||||
const response = {
|
const response = FinalResponse(
|
||||||
success: status === "Success",
|
|
||||||
message: msg.message,
|
|
||||||
status,
|
status,
|
||||||
socketId: socket.id,
|
socket,
|
||||||
organization: data.organization,
|
data.organization,
|
||||||
...(threadDatas ? { data: threadDatas } : {}),
|
messages,
|
||||||
};
|
threadDatas
|
||||||
|
);
|
||||||
|
emitToSenderAndAdmins(
|
||||||
emitEventResponse(socket, data.organization, EVENTS.deleteThreadResponse, response);
|
io,
|
||||||
}
|
socket,
|
||||||
export const addCommentHandleEvent = async (event: string, socket: Socket, data: any,) => {
|
data.organization,
|
||||||
|
EVENTS.deleteThreadResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const addCommentHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
|
) => {
|
||||||
if (event !== EVENTS.addComment || !data?.organization) return;
|
if (event !== EVENTS.addComment || !data?.organization) return;
|
||||||
const requiredFields = ["userId", "comments", "organization", "commentId", "projectId", "versionId"];
|
const requiredFields = ["userId", "organization", "threadId", "projectId"];
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
|
||||||
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
if (missingFields.length > 0) {
|
||||||
const response = {
|
emitToSenderAndAdmins(
|
||||||
success: false,
|
io,
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
socket,
|
||||||
status: "MissingFields",
|
data.organization,
|
||||||
socketId: socket.id,
|
EVENTS.addCommentResponse,
|
||||||
organization: data?.organization ?? "unknown",
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
};
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
emitEventResponse(socket, data?.organization, EVENTS.addCommentResponse, response);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,69 +175,144 @@ export const addCommentHandleEvent = async (event: string, socket: Socket, data:
|
|||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
const messages: Record<string, { message: string }> = {
|
||||||
Success: { message: "Thread created Successfully" },
|
Success: { message: "Thread comments add Successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
|
"CurrentVersion Data not found": {
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
},
|
||||||
|
updated: { message: "Comment updated successfully" },
|
||||||
};
|
};
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
const commentsData =
|
let commentsData;
|
||||||
status === "Success" && result?.data
|
if (status === "Success" || status === "updated") {
|
||||||
|
commentsData = result?.data;
|
||||||
|
|
||||||
const response = {
|
|
||||||
success: status === "Success",
|
|
||||||
message: msg.message,
|
|
||||||
status,
|
|
||||||
socketId: socket.id,
|
|
||||||
organization: data.organization,
|
|
||||||
...(commentsData ? { data: commentsData } : {}),
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
emitEventResponse(socket, data.organization, EVENTS.addCommentResponse, response);
|
|
||||||
}
|
|
||||||
export const deleteCommentHandleEvent = async (event: string, socket: Socket, data: any,) => {
|
|
||||||
if (event !== EVENTS.deleteComment || !data?.organization) return;
|
|
||||||
const requiredFields = ["userId", "organization", "commentId", "projectId", "versionId"];
|
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
|
||||||
const response = {
|
|
||||||
success: false,
|
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
|
||||||
status: "MissingFields",
|
|
||||||
socketId: socket.id,
|
|
||||||
organization: data?.organization ?? "unknown",
|
|
||||||
};
|
|
||||||
|
|
||||||
emitEventResponse(socket, data?.organization, EVENTS.deleteCommentResponse, response);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const response = FinalResponse(
|
||||||
|
status,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
messages,
|
||||||
|
commentsData
|
||||||
|
);
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.addCommentResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const deleteCommentHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.deleteComment || !data?.organization) return;
|
||||||
|
const requiredFields = ["userId", "organization", "commentId", "projectId"];
|
||||||
|
|
||||||
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.deleteCommentResponse,
|
||||||
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const result = await deleteComments(data);
|
const result = await deleteComments(data);
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
const messages: Record<string, { message: string }> = {
|
||||||
Success: { message: "Thread created Successfully" },
|
Success: { message: "Thread comment deleted Successfully" },
|
||||||
"User not found": { message: "User not found" },
|
"User not found": { message: "User not found" },
|
||||||
"Project not found": { message: "Project not found" },
|
"Project not found": { message: "Project not found" },
|
||||||
"unauthorized": { message: "You can only delete your own comment." },
|
"CurrentVersion Data not found": {
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
},
|
||||||
|
unauthorized: { message: "You can only delete your own comment." },
|
||||||
"thread not found": { message: "thread not found" },
|
"thread not found": { message: "thread not found" },
|
||||||
};
|
};
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
const commentsData =
|
const commentsData = status === "Success" && result?.data;
|
||||||
status === "Success" && result?.data
|
|
||||||
|
|
||||||
|
const response = FinalResponse(
|
||||||
const response = {
|
|
||||||
success: status === "Success",
|
|
||||||
message: msg.message,
|
|
||||||
status,
|
status,
|
||||||
socketId: socket.id,
|
socket,
|
||||||
organization: data.organization,
|
data.organization,
|
||||||
...(commentsData ? { data: commentsData } : {}),
|
messages,
|
||||||
|
commentsData
|
||||||
|
);
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.deleteCommentResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const threadUpdateHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.updateThreat || !data?.organization) return;
|
||||||
|
const requiredFields = ["userId", "organization", "threadId", "projectId"];
|
||||||
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.updateThreatResponse,
|
||||||
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await updateThreadTitle(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "ThreadTitle updated Successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"CurrentVersion Data not found": {
|
||||||
|
message: "CurrentVersion Data not found",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const commentsData = status === "Success" && result?.data;
|
||||||
|
|
||||||
|
const response = FinalResponse(
|
||||||
emitEventResponse(socket, data.organization, EVENTS.deleteCommentResponse, response);
|
status,
|
||||||
}
|
socket,
|
||||||
|
data.organization,
|
||||||
|
messages,
|
||||||
|
commentsData
|
||||||
|
);
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.updateThreatResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ export const TrashDeleteHandleEvent = async (
|
|||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] }, callback?: Function
|
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] }, callback?: Function
|
||||||
) => {
|
) => {
|
||||||
console.log('event: ', event);
|
|
||||||
if (event !== EVENTS.deleteTrash_v1 || !data?.organization) return;
|
if (event !== EVENTS.deleteTrash_v1 || !data?.organization) return;
|
||||||
const requiredFields = ["projectId","userId", "organization"];
|
const requiredFields = ["projectId","userId", "organization"];
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
const missingFields = requiredFields.filter(field => !data?.[field]);
|
||||||
|
|||||||
@@ -1,168 +1,232 @@
|
|||||||
import { Socket, Server } from "socket.io";
|
import { Socket, Server } from "socket.io";
|
||||||
import { EVENTS } from "../../socket/events.ts";
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
import { Add3DWidget, Delete3Dwidget, Update3Dwidget } from "../../../shared/services/visualization/widget3dService.ts";
|
import {
|
||||||
|
Add3DWidget,
|
||||||
|
Delete3Dwidget,
|
||||||
|
Update3Dwidget,
|
||||||
|
} from "../../../shared/services/visualization/widget3dService.ts";
|
||||||
export const add3DwidgetHandleEvent = async (
|
export const add3DwidgetHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.addWidget3D || !data?.organization) return;
|
if (event !== EVENTS.addWidget3D || !data?.organization) return;
|
||||||
const requiredFields = ["projectId", "userId", "organization", "zoneUuid", "widget"];
|
const requiredFields = [
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
"projectId",
|
||||||
|
"versionId",
|
||||||
if (missingFields.length > 0) {
|
"userId",
|
||||||
const response = {
|
"organization",
|
||||||
success: false,
|
"zoneUuid",
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
"widget",
|
||||||
status: "MissingFields",
|
];
|
||||||
socketId: socket.id,
|
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||||
organization: data?.organization ?? "unknown",
|
|
||||||
};
|
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.addWidget3DResponse, response, connectedUsersByOrg)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await Add3DWidget(data);
|
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
|
||||||
Success: { message: "Widget created successfully" },
|
|
||||||
"User not found": { message: "User not found" },
|
|
||||||
"Zone not found for the zoneUuid": { message: "Zone not found for the zoneUuid" },
|
|
||||||
"3dwidget update successfully": { message: "widget update successfully" },
|
|
||||||
"3dWidget not updated": { message: "3dWidget not updated" },
|
|
||||||
"Widget 3d not created": { message: "Widget 3d not created" },
|
|
||||||
};
|
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
|
||||||
const widgemodel3D_Datas =
|
|
||||||
status === "Success" && result?.data
|
|
||||||
|
|
||||||
? {
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
const response = {
|
const response = {
|
||||||
success: status === "Success",
|
success: false,
|
||||||
message: msg.message,
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
status,
|
status: "MissingFields",
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization: data.organization,
|
organization: data?.organization ?? "unknown",
|
||||||
...(widgemodel3D_Datas ? { data: widgemodel3D_Datas } : {}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.addWidget3DResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await Add3DWidget(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.addWidget3DResponse, response, connectedUsersByOrg)
|
const messages: Record<string, { message: string }> = {
|
||||||
}
|
Success: { message: "Widget created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found for the zoneUuid": {
|
||||||
|
message: "Zone not found for the zoneUuid",
|
||||||
|
},
|
||||||
|
"Version Data not found": { message: "Version Data not found" },
|
||||||
|
"3dwidget update successfully": { message: "widget update successfully" },
|
||||||
|
"3dWidget not updated": { message: "3dWidget not updated" },
|
||||||
|
"Widget 3d not created": { message: "Widget 3d not created" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const widgemodel3D_Datas =
|
||||||
|
status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(widgemodel3D_Datas ? { data: widgemodel3D_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.addWidget3DResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
export const update3DHandleEvent = async (
|
export const update3DHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.updateWidget3DPosition || !data?.organization) return;
|
if (event !== EVENTS.updateWidget3DPosition || !data?.organization) return;
|
||||||
const requiredFields = ["projectId", "id", "position", "rotation", "userId", "organization", "zoneUuid", "widget"];
|
const requiredFields = [
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
"projectId",
|
||||||
|
"versionId",
|
||||||
if (missingFields.length > 0) {
|
"id",
|
||||||
const response = {
|
"position",
|
||||||
success: false,
|
"rotation",
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
"userId",
|
||||||
status: "MissingFields",
|
"organization",
|
||||||
socketId: socket.id,
|
"zoneUuid",
|
||||||
organization: data?.organization ?? "unknown",
|
"widget",
|
||||||
};
|
];
|
||||||
|
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateWidget3DPositionResponse, response, connectedUsersByOrg)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await Update3Dwidget(data);
|
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
|
||||||
Success: { message: "widget update successfully" },
|
|
||||||
"User not found": { message: "User not found" },
|
|
||||||
"Zone not found": { message: "Zone not found" },
|
|
||||||
"Widget not updated": { message: "Widget not updated" },
|
|
||||||
"widget not found": { message: "widget not found" },
|
|
||||||
};
|
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
|
||||||
const widget3D_Datas =
|
|
||||||
status === "Success" && result?.data
|
|
||||||
|
|
||||||
? {
|
|
||||||
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
const response = {
|
const response = {
|
||||||
success: status === "Success",
|
success: false,
|
||||||
message: msg.message,
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
status,
|
status: "MissingFields",
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization: data.organization,
|
organization: data?.organization ?? "unknown",
|
||||||
...(widget3D_Datas ? { data: widget3D_Datas } : {}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.updateWidget3DPositionResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await Update3Dwidget(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.updateWidget3DPositionResponse, response, connectedUsersByOrg)
|
const messages: Record<string, { message: string }> = {
|
||||||
}
|
Success: { message: "widget update successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found": { message: "Zone not found" },
|
||||||
|
"Version Data not found": { message: "Version Data not found" },
|
||||||
|
"Widget not updated": { message: "Widget not updated" },
|
||||||
|
"widget not found": { message: "widget not found" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const widget3D_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(widget3D_Datas ? { data: widget3D_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.updateWidget3DPositionResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
export const Delete3DwidgetHandleEvent = async (
|
export const Delete3DwidgetHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.deleteWidget3D || !data?.organization) return;
|
if (event !== EVENTS.deleteWidget3D || !data?.organization) return;
|
||||||
const requiredFields = ["projectId", "id", "userId", "organization", "zoneUuid",];
|
const requiredFields = [
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
"projectId",
|
||||||
|
"versionId",
|
||||||
if (missingFields.length > 0) {
|
"id",
|
||||||
const response = {
|
"userId",
|
||||||
success: false,
|
"organization",
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
"zoneUuid",
|
||||||
status: "MissingFields",
|
];
|
||||||
socketId: socket.id,
|
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||||
organization: data?.organization ?? "unknown",
|
|
||||||
};
|
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletewidget3DResponse, response, connectedUsersByOrg)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await Delete3Dwidget(data);
|
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
|
||||||
Success: { message: "3DWidget delete unsuccessfull" },
|
|
||||||
"User not found": { message: "User not found" },
|
|
||||||
"Zone not found": { message: "Zone not found" },
|
|
||||||
"3D widget not found for the ID": { message: "3D widget not found for the ID" },
|
|
||||||
};
|
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
|
||||||
const widget3D_Datas =
|
|
||||||
status === "Success" && result?.data
|
|
||||||
|
|
||||||
? {
|
|
||||||
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
const response = {
|
const response = {
|
||||||
success: status === "Success",
|
success: false,
|
||||||
message: msg.message,
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
status,
|
status: "MissingFields",
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization: data.organization,
|
organization: data?.organization ?? "unknown",
|
||||||
...(widget3D_Datas ? { data: widget3D_Datas } : {}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.deletewidget3DResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await Delete3Dwidget(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.deletewidget3DResponse, response, connectedUsersByOrg)
|
const messages: Record<string, { message: string }> = {
|
||||||
}
|
Success: { message: "3DWidget delete unsuccessfull" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Zone not found": { message: "Zone not found" },
|
||||||
|
"Version Data not found": { message: "Version Data not found" },
|
||||||
|
"3D widget not found for the ID": {
|
||||||
|
message: "3D widget not found for the ID",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const widget3D_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(widget3D_Datas ? { data: widget3D_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.deletewidget3DResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user