Compare commits
55 Commits
Main-dupli
...
branch-v2
| Author | SHA1 | Date | |
|---|---|---|---|
| 9eed968b03 | |||
| d53c66de77 | |||
| 18965b8a20 | |||
| 5216ee190a | |||
| 591d86c274 | |||
| 118f65d688 | |||
| 673d07ce37 | |||
| d5fa507617 | |||
| f9083175da | |||
| e6f3e26353 | |||
| 245959ef88 | |||
| 09ea99098f | |||
| 17727c1281 | |||
| 66ccde6110 | |||
| fc53a859f0 | |||
| 73a531c843 | |||
| cb4c2b414d | |||
| efe986502d | |||
| 2a7d465424 | |||
| bb9813a09f | |||
| 2bb3814d75 | |||
| 11d38e645f | |||
| 72faf6782e | |||
| 1609f64695 | |||
| 4331f88c9a | |||
| c38a698692 | |||
| bea6044b25 | |||
| 7fb2a6bd2d | |||
| 6b5bee879b | |||
| 694d50b278 | |||
| 2c28ffe9aa | |||
| fdfc7a983c | |||
| 7603c1b64a | |||
| 9b4f8c0841 | |||
| fd578df59f | |||
| 089c6af1b6 | |||
| ac8de5d33d | |||
| d863465030 | |||
| 9be63d3459 | |||
| 2aa8c479fa | |||
| f62ccd1ea9 | |||
| 611bffdaa9 | |||
| 1c55013c2b | |||
| 5566b74633 | |||
| 0b30a8aeaa | |||
| c64e5ea8b5 | |||
| 6c17ba4590 | |||
| 0e7db2af8d | |||
| bd0c5013a9 | |||
| 46dafd4417 | |||
| 79b6a4fa75 | |||
| e2be6deb0a | |||
| af8510ad90 | |||
| 2997967899 | |||
| ca8e8b66f4 |
17
.env
17
.env
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
MONGO_URI=mongodb://mongo/
|
MONGO_URI=mongodb://mongo/
|
||||||
MONGO_USER=admin
|
MONGO_USER=admin
|
||||||
MONGO_PASSWORD=admin321
|
MONGO_PASSWORD=admin321
|
||||||
@@ -7,3 +8,19 @@ API_PORT=5000
|
|||||||
SOCKET_PORT=8000
|
SOCKET_PORT=8000
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
FRONTEND_ORIGIN_PROD=http://185.100.212.76:8200
|
FRONTEND_ORIGIN_PROD=http://185.100.212.76:8200
|
||||||
|
|
||||||
|
|
||||||
|
MinIO_URL=185.100.212.76
|
||||||
|
MinIO_PORT=9999
|
||||||
|
MinIO_accessKey=sabarinathan
|
||||||
|
MinIO_secretKey=sabarinathan
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JWT_SECRET="DwinzoProject"
|
||||||
|
REFRESH_JWT_SECRET="RefreshDwinzoProject"
|
||||||
|
|
||||||
|
|
||||||
|
REDIS_ENV= true
|
||||||
|
REDIS_DOCKER =185.100.212.76
|
||||||
|
REDIS_PORT=6666
|
||||||
766
package-lock.json
generated
766
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -18,9 +18,13 @@
|
|||||||
"express": "^4.21.1",
|
"express": "^4.21.1",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"http": "^0.0.1-security",
|
"http": "^0.0.1-security",
|
||||||
|
"ioredis": "^5.6.1",
|
||||||
"ip": "^2.0.1",
|
"ip": "^2.0.1",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
|
"minio": "^8.0.5",
|
||||||
"mongoose": "^8.8.1",
|
"mongoose": "^8.8.1",
|
||||||
|
"multer": "^1.4.5-lts.2",
|
||||||
|
"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"
|
||||||
@@ -31,7 +35,10 @@
|
|||||||
"@types/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
"@types/ip": "^1.1.3",
|
"@types/ip": "^1.1.3",
|
||||||
"@types/jsonwebtoken": "^9.0.7",
|
"@types/jsonwebtoken": "^9.0.7",
|
||||||
|
"@types/mime-types": "^2.1.4",
|
||||||
|
"@types/multer": "^1.4.12",
|
||||||
"@types/node": "^22.9.0",
|
"@types/node": "^22.9.0",
|
||||||
|
"@types/nodemailer": "^6.4.17",
|
||||||
"@types/swagger-ui-express": "^4.1.7",
|
"@types/swagger-ui-express": "^4.1.7",
|
||||||
"nodemon": "^3.1.7",
|
"nodemon": "^3.1.7",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
|
|||||||
@@ -11,10 +11,8 @@ RUN npm install -g tsx --ignore-scripts
|
|||||||
|
|
||||||
COPY package.json ./
|
COPY package.json ./
|
||||||
COPY package-lock.json ./
|
COPY package-lock.json ./
|
||||||
RUN npm install --ignore-scripts
|
RUN npm install --ignore-scripts && \
|
||||||
|
addgroup -S appgroup && \
|
||||||
|
|
||||||
RUN addgroup -S appgroup && \
|
|
||||||
adduser -S appuser -G appgroup && \
|
adduser -S appuser -G appgroup && \
|
||||||
chown -R appuser:appgroup /usr/src/app
|
chown -R appuser:appgroup /usr/src/app
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,4 @@ router.post('/setfloorItems',FloorItems.setFloorItems)
|
|||||||
router.get('/findfloorItems/:organization',FloorItems.getFloorItems)
|
router.get('/findfloorItems/:organization',FloorItems.getFloorItems)
|
||||||
router.delete('/deletefloorItem',AssetsFloorService.deleteFloorItems)
|
router.delete('/deletefloorItem',AssetsFloorService.deleteFloorItems)
|
||||||
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
18
src/api-server/Routes/homepageRoutes.ts
Normal file
18
src/api-server/Routes/homepageRoutes.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import * as express from "express";
|
||||||
|
import {
|
||||||
|
recentDataController,
|
||||||
|
searchProjectController,
|
||||||
|
searchTrashProjectController,
|
||||||
|
} from "../controller/home/homeControllers.ts";
|
||||||
|
import { tutorialsDataController } from "../controller/home/tutorialControllers.ts";
|
||||||
|
|
||||||
|
const homePageRouter = express.Router();
|
||||||
|
|
||||||
|
homePageRouter.get(
|
||||||
|
"/RecentlyViewed/:userId/:organization",
|
||||||
|
recentDataController
|
||||||
|
);
|
||||||
|
homePageRouter.get("/searchProjects", searchProjectController);
|
||||||
|
homePageRouter.get("/searchTrashProjects", searchTrashProjectController);
|
||||||
|
homePageRouter.get("/tutorials", tutorialsDataController);
|
||||||
|
export default homePageRouter;
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
import express from 'express';
|
import express from "express";
|
||||||
import { Lines } from '../controller/lines/line-Services.ts';
|
import { Lines } from "../controller/lines/line-Services.ts";
|
||||||
|
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
router.post('/setLine',Lines.setLines)
|
router.post("/setLine", Lines.setLines);
|
||||||
router.post('/updatePoint',Lines.updateLines)
|
router.post("/updatePoint", Lines.updateLines);
|
||||||
router.get('/findLines/:organization',Lines.getLines)
|
router.get("/findLines/:organization", Lines.getLines);
|
||||||
router.delete('/deleteLine',Lines.deleteLineItems)
|
router.delete("/deleteLine", Lines.deleteLineItems);
|
||||||
router.delete('/deletePoint',Lines.deleteLinPoiteItems)
|
router.delete("/deletePoint", Lines.deleteLinPoiteItems);
|
||||||
router.post('/deleteLayer',Lines.deleteLayer)
|
router.post("/deleteLayer", Lines.deleteLayer);
|
||||||
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -5,7 +5,9 @@ productRouter.post("/UpsertProductOrEvent", ProductFlowService.productAdd);
|
|||||||
productRouter.get("/productData", ProductFlowService.getProductDatas);
|
productRouter.get("/productData", ProductFlowService.getProductDatas);
|
||||||
productRouter.patch("/EventDataDelete", ProductFlowService.EventDataDelete);
|
productRouter.patch("/EventDataDelete", ProductFlowService.EventDataDelete);
|
||||||
productRouter.patch("/productDataDelete", ProductFlowService.productDataDelete);
|
productRouter.patch("/productDataDelete", ProductFlowService.productDataDelete);
|
||||||
productRouter.get("/AllProducts/:organization", ProductFlowService.AllProductDatas);
|
productRouter.get(
|
||||||
|
"/AllProducts/:organization",
|
||||||
|
ProductFlowService.AllProductDatas
|
||||||
|
);
|
||||||
productRouter.patch("/productRename", ProductFlowService.productRename);
|
productRouter.patch("/productRename", ProductFlowService.productRename);
|
||||||
export default productRouter;
|
export default productRouter;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
import * as express from "express";
|
import * as express from "express";
|
||||||
import { createProjectController } from "../controller/project/projectController.ts";
|
import {
|
||||||
|
createProjectController,
|
||||||
|
GetProjects,
|
||||||
|
RemoveProject,
|
||||||
|
updateProjectController,
|
||||||
|
ViewData,
|
||||||
|
} from "../controller/project/projectController.ts";
|
||||||
|
|
||||||
const projectRouter = express.Router();
|
const projectRouter = express.Router();
|
||||||
projectRouter.post("/upsertProject",createProjectController)
|
projectRouter.post("/upsertProject", createProjectController);
|
||||||
export default projectRouter
|
projectRouter.get("/Projects/:userId/:organization", GetProjects);
|
||||||
|
projectRouter.patch("/Project/archive/:projectId", RemoveProject);
|
||||||
|
projectRouter.patch("/Project/modify", updateProjectController);
|
||||||
|
projectRouter.get("/Project/view", ViewData);
|
||||||
|
export default projectRouter;
|
||||||
|
|||||||
8
src/api-server/Routes/trashRoutes.ts
Normal file
8
src/api-server/Routes/trashRoutes.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import * as express from "express";
|
||||||
|
import { GetTrashList, RestoreTrash } from "../controller/trash/trashcontrollers.ts";
|
||||||
|
|
||||||
|
const trashRouter = express.Router();
|
||||||
|
trashRouter.get("/Trash/Lists", GetTrashList);
|
||||||
|
trashRouter.patch("/restore",RestoreTrash)
|
||||||
|
|
||||||
|
export default trashRouter;
|
||||||
@@ -7,5 +7,4 @@ router.post('/setWallItems',WallItems.setWallItems)
|
|||||||
router.get('/findWallItems/:organization',WallItems.getWallItems)
|
router.get('/findWallItems/:organization',WallItems.getWallItems)
|
||||||
router.delete('/deleteWallItem',WallItems.deleteWallItems)
|
router.delete('/deleteWallItem',WallItems.deleteWallItems)
|
||||||
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import express from 'express';
|
|
||||||
|
|
||||||
import { Zone } from '../controller/lines/zone-Services.ts';
|
|
||||||
|
|
||||||
|
|
||||||
const router = express.Router();
|
|
||||||
router.post('/setZone',Zone.setZone)
|
|
||||||
router.delete('/deleteZone',Zone.deleteZone)
|
|
||||||
router.get('/findZones/:organization',Zone.getZones)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default router;
|
|
||||||
@@ -537,5 +537,7 @@ router.get("/A_zone/:zoneId/:organization", ZoneService.ZoneData);
|
|||||||
* example: "Internal Server Error"
|
* example: "Internal Server Error"
|
||||||
*/
|
*/
|
||||||
router.patch("/zone/:zoneId", ZoneService.deleteAZone);
|
router.patch("/zone/:zoneId", ZoneService.deleteAZone);
|
||||||
|
router.get("/findZones/:organization", ZoneService.getZones);
|
||||||
|
|
||||||
router.patch("/zones/lockedPanels", ZoneService.lockedPanel);
|
router.patch("/zones/lockedPanels", ZoneService.lockedPanel);
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@@ -0,0 +1,245 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import {
|
||||||
|
AuthLogin,
|
||||||
|
AuthLogout,
|
||||||
|
AuthSignup,
|
||||||
|
forgetPassword,
|
||||||
|
} from "../../../../shared/services/auth/authServices.ts";
|
||||||
|
|
||||||
|
export const SignupController = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userName, Email, Password } = req.body;
|
||||||
|
if (!userName || !Email || !Password) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AuthSignup(req.body);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User already exists":
|
||||||
|
res.status(403).json({
|
||||||
|
message: "User already exists",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "New User created",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "An unexpected error occurred",
|
||||||
|
});
|
||||||
|
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 AuthLogin(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 "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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const SignOutController = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { Email } = req.body;
|
||||||
|
if (!Email) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "Email field is Mandatory",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AuthLogout(req.body);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Token not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Token not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Logout Successfull",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "An unexpected error occurred",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ForgetPasswordController = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { Email } = req.body;
|
||||||
|
if (!Email) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "Email field is Mandatory",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await forgetPassword(req.body);
|
||||||
|
switch (result.status) {
|
||||||
|
case "You can only reset your password once every 24 hours.":
|
||||||
|
res.status(400).json({
|
||||||
|
message: "You can only reset your password once every 24 hours.",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Email not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Email not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Password reset link sent successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "An unexpected error occurred",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ResetPasswordController = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { newPassword, resetToken, confirmPassword } = req.body;
|
||||||
|
if (!newPassword || !resetToken || !confirmPassword) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are Mandatory",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await forgetPassword(req.body);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "Invalid token payload.":
|
||||||
|
res.status(400).json({
|
||||||
|
message: "Invalid token payload.",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Password mismatch":
|
||||||
|
res.status(400).json({
|
||||||
|
message: "Password mismatch",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Token is invalid or expired.":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Token is invalid or expired.",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Password reset successfull!!",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "An unexpected error occurred",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
DeleteAisle,
|
||||||
|
GetProjectAisles,
|
||||||
|
SetAisle,
|
||||||
|
} from "../../../../shared/services/builder/AisleService.ts";
|
||||||
|
|
||||||
|
export const UpsertAisleController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { aisleUuid, points, type, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !aisleUuid || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
points,
|
||||||
|
type,
|
||||||
|
aisleUuid,
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await SetAisle(data);
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle Not Updated":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle Not Updated",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle Updated Successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle Updated Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle Not Created":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle Not Created",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle Created Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle validation failed":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle validation failed",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteAisleController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { aisleUuid, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !aisleUuid || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
aisleUuid,
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await DeleteAisle(data);
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle Deleted Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const AllAisleController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await GetProjectAisles(data);
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle 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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
getEnvironment,
|
||||||
|
setEnvironment,
|
||||||
|
} from "../../../../shared/services/builder/EnvironmentService.ts";
|
||||||
|
|
||||||
|
export const SetEnvironmentController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const {
|
||||||
|
roofVisibility,
|
||||||
|
renderDistance,
|
||||||
|
limitDistance,
|
||||||
|
wallVisibility,
|
||||||
|
shadowVisibility,
|
||||||
|
projectId,
|
||||||
|
} = req.body;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
roofVisibility,
|
||||||
|
wallVisibility,
|
||||||
|
shadowVisibility,
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
renderDistance,
|
||||||
|
limitDistance,
|
||||||
|
};
|
||||||
|
const result = await setEnvironment(req.body);
|
||||||
|
|
||||||
|
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 "environments updated":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetEnvironmentController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await getEnvironment(data);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Environment Not found for the User":
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,309 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
CreateLineItems,
|
||||||
|
DeleteLayer,
|
||||||
|
DeleteLineItems,
|
||||||
|
DeleteLinePoints,
|
||||||
|
GetLinesService,
|
||||||
|
UpdateLineItems,
|
||||||
|
} from "../../../../shared/services/builder/lineService.ts";
|
||||||
|
|
||||||
|
export const NewLineController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { line, type, layer, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !line || !type || !layer || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
line,
|
||||||
|
type,
|
||||||
|
layer,
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await CreateLineItems(data);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const UpdateLineController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { uuid, position, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !uuid || !position || projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await UpdateLineItems({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
uuid,
|
||||||
|
position,
|
||||||
|
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 "Success":
|
||||||
|
res.status(201).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteLineController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, line } = req.body;
|
||||||
|
if (!organization || !userId || !projectId || !line) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteLineItems({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
line,
|
||||||
|
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 "line not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "data not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteLayerController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, layer } = req.body;
|
||||||
|
if (!organization || !userId || !projectId || !layer) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteLayer({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
layer,
|
||||||
|
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 "layer not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "data not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DeleteLinePointsController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, uuid } = req.body;
|
||||||
|
if (!organization || !userId || !projectId || !uuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteLinePoints({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
uuid,
|
||||||
|
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 "Line not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "data not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetLinesController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await GetLinesService({
|
||||||
|
organization,
|
||||||
|
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 "Line 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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,324 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
deleteAssetModel,
|
||||||
|
getFloorItems,
|
||||||
|
replaceEventDatas,
|
||||||
|
setAssetModel,
|
||||||
|
updateAssetPositionRotation,
|
||||||
|
} from "../../../../shared/services/builder/assetService.ts";
|
||||||
|
|
||||||
|
export const CreateAssetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const {
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
eventData,
|
||||||
|
modelfileID,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
projectId,
|
||||||
|
} = req.body;
|
||||||
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!isLocked ||
|
||||||
|
!isVisible ||
|
||||||
|
!position ||
|
||||||
|
!rotation ||
|
||||||
|
!modelfileID ||
|
||||||
|
!modelName ||
|
||||||
|
!projectId ||
|
||||||
|
!modelUuid
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
eventData,
|
||||||
|
modelfileID,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
projectId,
|
||||||
|
};
|
||||||
|
const result = await setAssetModel(data);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Updated successfully":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Model stored successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteAssetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { modelUuid, modelName, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !modelUuid || !projectId || !modelName) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await deleteAssetModel({
|
||||||
|
organization,
|
||||||
|
modelName,
|
||||||
|
modelUuid,
|
||||||
|
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 "model not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Model not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Failed to archive asset":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Failed to archive asset",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Asset Deleted successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetAssetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await getFloorItems({
|
||||||
|
organization,
|
||||||
|
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 "floorItems 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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ReplaceEventDataController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { modelUuid, eventData, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !projectId || !modelUuid || !eventData) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await replaceEventDatas({
|
||||||
|
modelUuid,
|
||||||
|
organization,
|
||||||
|
eventData,
|
||||||
|
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 "Model not for this UUID":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Model not for this UUID",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({ message: "Data updated successfully" });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const AssetUpdatePosRotController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const {
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
projectId,
|
||||||
|
} = req.body;
|
||||||
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!isLocked ||
|
||||||
|
!isVisible ||
|
||||||
|
!position ||
|
||||||
|
!rotation ||
|
||||||
|
!modelName ||
|
||||||
|
!projectId ||
|
||||||
|
!modelUuid
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await updateAssetPositionRotation({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
isLocked,
|
||||||
|
isVisible,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
|
||||||
|
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 "Asset not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Asset not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({ message: "Asset updated successfully" });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
GetCamers,
|
||||||
|
onlineActiveDatas,
|
||||||
|
SetCamera,
|
||||||
|
} from "../../../../shared/services/builder/cameraService.ts";
|
||||||
|
|
||||||
|
export const SetNewCamera = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { position, target, rotation, projectId } = req.body;
|
||||||
|
if (
|
||||||
|
!organization ||
|
||||||
|
!userId ||
|
||||||
|
!position ||
|
||||||
|
!target ||
|
||||||
|
!rotation ||
|
||||||
|
!projectId
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
position,
|
||||||
|
target,
|
||||||
|
rotation,
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await SetCamera(data);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Update Success":
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const CameraList = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await GetCamers({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
|
||||||
|
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 "Camera 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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ActiveOnlineController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
if (!organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await onlineActiveDatas({
|
||||||
|
organization,
|
||||||
|
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 "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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import {
|
||||||
|
deleteWallItems,
|
||||||
|
getWallItems,
|
||||||
|
setWallItems,
|
||||||
|
} from "../../../../shared/services/builder/wallService.ts";
|
||||||
|
import { error } from "console";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
export const WallSetup = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const {
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
type,
|
||||||
|
csgposition,
|
||||||
|
csgscale,
|
||||||
|
quaternion,
|
||||||
|
scale,
|
||||||
|
projectId,
|
||||||
|
} = req.body;
|
||||||
|
if (
|
||||||
|
!modelUuid ||
|
||||||
|
!modelName ||
|
||||||
|
!position ||
|
||||||
|
!type ||
|
||||||
|
!projectId ||
|
||||||
|
!csgscale ||
|
||||||
|
!csgposition ||
|
||||||
|
!quaternion ||
|
||||||
|
!scale ||
|
||||||
|
!organization ||
|
||||||
|
!userId
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required!",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await setWallItems({
|
||||||
|
projectId,
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
type,
|
||||||
|
csgposition,
|
||||||
|
csgscale,
|
||||||
|
quaternion,
|
||||||
|
scale,
|
||||||
|
organization,
|
||||||
|
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 "Updated successfully":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
case "wall Item created successfully":
|
||||||
|
res.status(201).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json(error);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const WallGet = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await getWallItems({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
|
||||||
|
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 "wallitems 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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const WallDelete = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, modelName, modelUuid } = req.body;
|
||||||
|
if (!organization || !userId || !projectId || !modelName || !modelUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await deleteWallItems({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
modelName,
|
||||||
|
modelUuid,
|
||||||
|
});
|
||||||
|
|
||||||
|
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 "model not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "model not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,321 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
DelZone,
|
||||||
|
GetZones,
|
||||||
|
SetZone,
|
||||||
|
SingleZonePanelData,
|
||||||
|
VizZoneDatas,
|
||||||
|
ZoneData,
|
||||||
|
} from "../../../../shared/services/builder/zoneService.ts";
|
||||||
|
|
||||||
|
export const CreateZoneController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { zoneData, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !zoneData || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
zoneData,
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await SetZone(data);
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "zone updated":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "zone updated",
|
||||||
|
ZoneData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "zone created",
|
||||||
|
ZoneData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteZoneController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { zoneUuid, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !zoneUuid || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DelZone({
|
||||||
|
organization,
|
||||||
|
zoneUuid,
|
||||||
|
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 "Invalid zone ID":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the UUID",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Zone deleted successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetZoneController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await GetZones({
|
||||||
|
organization,
|
||||||
|
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 "Invalid zone":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the UUID",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const VizZoneController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await VizZoneDatas({
|
||||||
|
organization,
|
||||||
|
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 "Zone not found for the UUID":
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ZoneDataController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, zoneUuid } = req.params;
|
||||||
|
if (!organization || !userId || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await ZoneData({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
zoneUuid,
|
||||||
|
});
|
||||||
|
|
||||||
|
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 "Zone not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const SingleZonePanelController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId, zoneUuid } = req.params;
|
||||||
|
if (!organization || !userId || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await SingleZonePanelData({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
zoneUuid,
|
||||||
|
});
|
||||||
|
|
||||||
|
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 "Zone not found for the UUID":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the UUID",
|
||||||
|
});
|
||||||
|
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",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import {
|
||||||
|
RecentlyAdded,
|
||||||
|
searchProject,
|
||||||
|
searchTrashProject,
|
||||||
|
} from "../../../../shared/services/v1home/v1homeservice.ts";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
|
||||||
|
export const recentDataController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization, role } = req.user || {};
|
||||||
|
if (!userId || !organization || !role) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await RecentlyAdded({ userId, organization, role });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Datas were empty":
|
||||||
|
res.status(200).json({
|
||||||
|
RecentlyViewed: [],
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
RecentlyViewed: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const searchProjectController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization, role } = req.user || {};
|
||||||
|
if (!userId || !organization || !role) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { searchName } = req.query as {
|
||||||
|
searchName: string;
|
||||||
|
};
|
||||||
|
const result = await searchProject({
|
||||||
|
searchName,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
projectData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const searchTrashProjectController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization, role } = req.user || {};
|
||||||
|
if (!userId || !organization || !role) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { searchName } = req.query as {
|
||||||
|
searchName: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await searchTrashProject({
|
||||||
|
searchName,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
projectData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,313 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import {
|
||||||
|
createProject,
|
||||||
|
DeleteProject,
|
||||||
|
DuplicateProject,
|
||||||
|
GetAllProjects,
|
||||||
|
updateProject,
|
||||||
|
viewProject,
|
||||||
|
} from "../../../../shared/services/v1Project/v1projectservice.ts";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
|
||||||
|
export const createProjectController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectUuid, thumbnail } = req.body;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!projectUuid || !thumbnail) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await createProject({ ...req.body, userId, organization });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "project_exists":
|
||||||
|
res.status(403).json({
|
||||||
|
message: "Project already exists",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "user_not_found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Project created Successfully",
|
||||||
|
projectId: result.project._id,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetProjects = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization, role } = req.user || {};
|
||||||
|
if (!userId || !organization || !role) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await GetAllProjects({ userId, organization, role });
|
||||||
|
switch (result?.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
Projects: result?.Datas,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const RemoveProject = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { projectId } = req.params;
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
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 DeleteProject({
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Project Deleted Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const updateProjectController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization, role } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
const { projectName, thumbnail } = req.body;
|
||||||
|
if (!userId || !organization || !projectId || !role) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await updateProject({
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectName,
|
||||||
|
thumbnail,
|
||||||
|
role,
|
||||||
|
});
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project updated Successfully",
|
||||||
|
projectData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ViewData = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId, role } = req.user || {};
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { projectId } = req.params as {
|
||||||
|
projectId: string;
|
||||||
|
};
|
||||||
|
if (!userId || !organization || !projectId || !role) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await viewProject({
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
role,
|
||||||
|
});
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
projectData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ProjectDuplicateController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectUuid, thumbnail, projectName } = req.body;
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!projectUuid || !thumbnail || !projectName) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DuplicateProject({
|
||||||
|
...req.body,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "project_exists":
|
||||||
|
res.status(403).json({
|
||||||
|
message: "Project already exists",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "user_not_found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Project Duplicated Successfully",
|
||||||
|
projectId: result.project._id,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,395 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AllProductDatas,
|
||||||
|
EventDataDelete,
|
||||||
|
getProductDatas,
|
||||||
|
productAdd,
|
||||||
|
productDataDelete,
|
||||||
|
productRename,
|
||||||
|
} from "../../../../shared/services/simulation/productService.ts";
|
||||||
|
|
||||||
|
export const AddProductController = 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 productAdd({
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import {
|
||||||
|
TrashDatas,
|
||||||
|
RestoreTrashData,
|
||||||
|
TrashDelete,
|
||||||
|
} from "../../../../shared/services/v1trash/v1trashservice.ts";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
|
||||||
|
export const GetTrashList = 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 result = await TrashDatas({ organization, role, userId });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Trash is Empty":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Trash is Empty",
|
||||||
|
TrashDatas: [],
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
TrashDatas: result.ListDatas,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RestoreTrash = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, role, userId } = req.user || {};
|
||||||
|
const { projectId } = req.query as {
|
||||||
|
projectId: string;
|
||||||
|
};
|
||||||
|
if (!organization || !projectId || !role || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await RestoreTrashData({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
role,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "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 "Project Restore unsuccessfull":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project Restore unsuccessfull",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project Restored successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project Restored successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteTrashData = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, role, userId } = req.user || {};
|
||||||
|
const { projectId } = req.query as {
|
||||||
|
projectId: string;
|
||||||
|
};
|
||||||
|
if (!organization || !projectId || !role || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await TrashDelete({
|
||||||
|
organization,
|
||||||
|
projectId,
|
||||||
|
role,
|
||||||
|
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 "Project Already Deleted":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project Already Deleted",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Trash Project Delete successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import versionService from "../../../../shared/services/version/versionService.ts";
|
||||||
|
|
||||||
|
export const versioncontroller = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { projectId, userId, description, db } = req.body;
|
||||||
|
|
||||||
|
const result = await versionService.saveCurrentStateAsVersion(
|
||||||
|
db,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
description
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "An unexpected error occurred",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,326 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddFloat,
|
||||||
|
DelFloat,
|
||||||
|
DuplicateFloat,
|
||||||
|
GetFloatWidget,
|
||||||
|
SingleFloatWidget,
|
||||||
|
} from "../../../../shared/services/visualization/floatWidgetService.ts";
|
||||||
|
|
||||||
|
export const FloatAddController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { widget, zoneUuid, index, projectId } = req.body;
|
||||||
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!widget ||
|
||||||
|
!zoneUuid ||
|
||||||
|
!index ||
|
||||||
|
!projectId
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AddFloat({
|
||||||
|
organization,
|
||||||
|
widget,
|
||||||
|
zoneUuid,
|
||||||
|
index,
|
||||||
|
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 "Zone not found for the zoneUuid":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the zoneUuid",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Widget updated successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget updated successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Failed to create FloatWidget":
|
||||||
|
res.status(400).json({
|
||||||
|
message: "Failed to create FloatWidget",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "FloatWidget 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 DeleteFloatController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { floatWidgetID, projectId, zoneUuid } = req.body;
|
||||||
|
if (!userId || !organization || !floatWidgetID || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DelFloat({
|
||||||
|
organization,
|
||||||
|
floatWidgetID,
|
||||||
|
zoneUuid,
|
||||||
|
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 "Zone not found for the zoneUuid":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the zoneUuid",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "FloatWidget not found for the Id":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "FloatWidget not found for the Id",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "FloatWidget not deleted":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "FloatWidget not deleted",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "FloatingWidget 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 DuplicateFloatController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { widget, projectId, zoneUuid, index } = req.body;
|
||||||
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!widget ||
|
||||||
|
!projectId ||
|
||||||
|
!zoneUuid ||
|
||||||
|
!index
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DuplicateFloat({
|
||||||
|
organization,
|
||||||
|
widget,
|
||||||
|
zoneUuid,
|
||||||
|
index,
|
||||||
|
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 "Zone not found for the zoneUuid":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the zoneUuid",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "FloatWidget update unsuccessfull":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "FloatWidget update unsuccessfull",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Widget updated successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget updated successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Failed to duplicate FloatWidget":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Failed to duplicate FloatWidget",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Duplicate FloatWidget 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 GetFloatController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId, zoneUuid } = req.params;
|
||||||
|
if (!userId || !organization || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await GetFloatWidget({
|
||||||
|
organization,
|
||||||
|
zoneUuid,
|
||||||
|
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 "Zone not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "All Datas":
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const SingleFloatController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { floatWidgetID } = req.params;
|
||||||
|
if (!userId || !organization || !floatWidgetID) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await SingleFloatWidget({
|
||||||
|
organization,
|
||||||
|
floatWidgetID,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Widget not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Widget not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
Data: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddPanel,
|
||||||
|
ClearPanel,
|
||||||
|
DelPanel,
|
||||||
|
LockedPanel,
|
||||||
|
} from "../../../../shared/services/visualization/panelService.ts";
|
||||||
|
|
||||||
|
export const AddPanelController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { panelOrder, zoneUuid, projectId } = req.body;
|
||||||
|
if (!userId || !organization || !panelOrder || !zoneUuid || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AddPanel({
|
||||||
|
organization,
|
||||||
|
panelOrder,
|
||||||
|
zoneUuid,
|
||||||
|
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 "Zone not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "No new panels were created. All panels already exist":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "No new panels were created. All panels already exist",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Panels created successfully",
|
||||||
|
panelID: 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 DeletePanelController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { panelName, projectId, zoneUuid } = req.body;
|
||||||
|
if (!userId || !organization || !panelName || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DelPanel({
|
||||||
|
organization,
|
||||||
|
panelName,
|
||||||
|
zoneUuid,
|
||||||
|
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 "Zone not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Panel Already Deleted":
|
||||||
|
res.status(409).json({
|
||||||
|
message: "Panel Already Deleted",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Panel 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 ClearPanelController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { panelName, projectId, zoneUuid } = req.body;
|
||||||
|
if (!userId || !organization || !panelName || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await ClearPanel({
|
||||||
|
organization,
|
||||||
|
panelName,
|
||||||
|
zoneUuid,
|
||||||
|
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 "Zone not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Requested Panel not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Requested Panel not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "No widgets to clear":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "No widgets to clear",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "PanelWidgets cleared successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const LockedPanelController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId, zoneUuid, lockedPanel } = req.body;
|
||||||
|
if (!userId || !organization || !projectId || !zoneUuid || !lockedPanel) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await LockedPanel({
|
||||||
|
organization,
|
||||||
|
zoneUuid,
|
||||||
|
lockedPanel,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
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 "Zone not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "locked panel not updated":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "locked panel not updated",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "locked panel updated successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddTemplate,
|
||||||
|
AddTemplateToZone,
|
||||||
|
GetAllTemplates,
|
||||||
|
TemplateDelete,
|
||||||
|
} from "../../../../shared/services/visualization/templateService.ts";
|
||||||
|
|
||||||
|
export const AddTemplateController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { template, projectId } = req.body;
|
||||||
|
if (!userId || !organization || !template || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AddTemplate({
|
||||||
|
organization,
|
||||||
|
template,
|
||||||
|
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 "TemplateID alreay exists":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "TemplateID alreay exists",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Template not saved":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Template not saved",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Template saved successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const AddTemToZoneController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { templateID, projectId, zoneUuid } = req.body;
|
||||||
|
if (!userId || !organization || !templateID || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AddTemplateToZone({
|
||||||
|
organization,
|
||||||
|
templateID,
|
||||||
|
zoneUuid,
|
||||||
|
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 "Zone not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "TemplateID not found":
|
||||||
|
res.status(409).json({
|
||||||
|
message: "TemplateID not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Template placed in Zone",
|
||||||
|
data: 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 TemplateDeleteController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { templateID, projectId } = req.body;
|
||||||
|
if (!userId || !organization || !templateID || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await TemplateDelete({
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
templateID,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
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 "Template not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Template not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Template not Deleted":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Template not Deleted",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Template 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 GetTemplateController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!userId || !organization || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await GetAllTemplates({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
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 "All Datas":
|
||||||
|
res.status(404).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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,271 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddWidget,
|
||||||
|
GetWidget,
|
||||||
|
UpdateWidget,
|
||||||
|
WidgetDelete,
|
||||||
|
} from "../../../../shared/services/visualization/widgetService.ts";
|
||||||
|
|
||||||
|
export const AddWidgetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { widget, projectId, zoneUuid } = req.body;
|
||||||
|
if (!userId || !organization || !widget || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AddWidget({
|
||||||
|
organization,
|
||||||
|
widget,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
zoneUuid,
|
||||||
|
});
|
||||||
|
|
||||||
|
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 "Zone not found for the zoneUuid":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "panelName not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "panelName not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Widget update unsuccessfull":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget update unsuccessfull",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Widget update successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget updated successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget created successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Type mismatch":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Type mismatch",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const WidgetDeleteController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { widgetID, projectId, zoneUuid } = req.body;
|
||||||
|
if (!userId || !organization || !widgetID || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await WidgetDelete({
|
||||||
|
organization,
|
||||||
|
widgetID,
|
||||||
|
zoneUuid,
|
||||||
|
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 "Zone not found for the zoneUuid":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the zoneUuid",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Widget not found":
|
||||||
|
res.status(409).json({
|
||||||
|
message: "Widget not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget 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 WidgetUpdateController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { values, projectId, zoneUuid, widgetID } = req.body;
|
||||||
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!widgetID ||
|
||||||
|
!values ||
|
||||||
|
!projectId ||
|
||||||
|
!zoneUuid
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await UpdateWidget({
|
||||||
|
organization,
|
||||||
|
values,
|
||||||
|
zoneUuid,
|
||||||
|
widgetID,
|
||||||
|
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 "Zone not found for the zoneUuid":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the zoneUuid",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Data not found":
|
||||||
|
res.status(409).json({
|
||||||
|
message: "Data not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget updated successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetWidgetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId, zoneUuid, widgetID } = req.query as {
|
||||||
|
projectId: string;
|
||||||
|
zoneUuid: string;
|
||||||
|
widgetID: string;
|
||||||
|
};
|
||||||
|
if (!userId || !organization || !widgetID || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await GetWidget({
|
||||||
|
organization,
|
||||||
|
zoneUuid,
|
||||||
|
widgetID,
|
||||||
|
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 "Zone not found for the zoneUuid":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found for the zoneUuid",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Widget not found for the widgetID":
|
||||||
|
res.status(409).json({
|
||||||
|
message: "Widget not found for the widgetID",
|
||||||
|
});
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,272 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
Add3DWidget,
|
||||||
|
Delete3Dwidget,
|
||||||
|
Get3Dwidget,
|
||||||
|
Update3Dwidget,
|
||||||
|
} from "../../../../shared/services/visualization/widget3dService.ts";
|
||||||
|
|
||||||
|
export const Add3dWidgetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { widget, projectId, zoneUuid } = req.body;
|
||||||
|
if (!userId || !organization || !widget || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await Add3DWidget({
|
||||||
|
organization,
|
||||||
|
widget,
|
||||||
|
userId,
|
||||||
|
zoneUuid,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
|
||||||
|
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 "Zone not found for the zoneUuid":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Widget not updated":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget not updated",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "widget update successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "widget update successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Widget 3d not created":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget 3d not created",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget 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 Update3DwidgetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { id, position, rotation, projectId, zoneUuid } = req.body;
|
||||||
|
if (
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!id ||
|
||||||
|
!position ||
|
||||||
|
!rotation ||
|
||||||
|
!projectId ||
|
||||||
|
!zoneUuid
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await Update3Dwidget({
|
||||||
|
organization,
|
||||||
|
id,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
userId,
|
||||||
|
zoneUuid,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
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 "Zone not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "widget3D update successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Widget not updated":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Widget not updated",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "widget not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "widget not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const Delete3DwidgetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { id, projectId, zoneUuid } = req.body;
|
||||||
|
if (!userId || !organization || !id || !projectId || !zoneUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await Delete3Dwidget({
|
||||||
|
organization,
|
||||||
|
id,
|
||||||
|
userId,
|
||||||
|
zoneUuid,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
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 "Zone not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "3D widget not found for the ID":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "3D widget not found for the ID",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "3DWidget delete unsuccessfull":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "3DWidget delete unsuccessfull",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "3DWidget 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 Get3DWidgetController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId, zoneUuid } = req.params;
|
||||||
|
if (!userId || !organization || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await Get3Dwidget({
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
zoneUuid,
|
||||||
|
projectId,
|
||||||
|
});
|
||||||
|
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 "Zone not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Zone not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "All 3Dwidgets":
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
15
src/api-server/V1/v1Routes/BuilderRoutes/V1-AisleRoutes.ts
Normal file
15
src/api-server/V1/v1Routes/BuilderRoutes/V1-AisleRoutes.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AllAisleController,
|
||||||
|
DeleteAisleController,
|
||||||
|
UpsertAisleController,
|
||||||
|
} from "../../v1Controllers/builderController/v1AisleController.ts";
|
||||||
|
|
||||||
|
const V1Aisle = express.Router();
|
||||||
|
|
||||||
|
V1Aisle.post("/UpsertAisle", tokenValidator, UpsertAisleController);
|
||||||
|
V1Aisle.patch("/DeleteAisle", tokenValidator, DeleteAisleController);
|
||||||
|
V1Aisle.get("/Aisles/:projectId", tokenValidator, AllAisleController);
|
||||||
|
|
||||||
|
export default V1Aisle;
|
||||||
34
src/api-server/V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts
Normal file
34
src/api-server/V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
CreateZoneController,
|
||||||
|
DeleteZoneController,
|
||||||
|
GetZoneController,
|
||||||
|
SingleZonePanelController,
|
||||||
|
VizZoneController,
|
||||||
|
ZoneDataController,
|
||||||
|
} from "../../v1Controllers/builderController/v1zoneController.ts";
|
||||||
|
|
||||||
|
const V1Zone = express.Router();
|
||||||
|
|
||||||
|
V1Zone.post("/zones", tokenValidator, CreateZoneController);
|
||||||
|
V1Zone.patch("/zones/delete", tokenValidator, DeleteZoneController);
|
||||||
|
|
||||||
|
V1Zone.get(
|
||||||
|
"/zones/visualization/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
VizZoneController
|
||||||
|
);
|
||||||
|
|
||||||
|
V1Zone.get(
|
||||||
|
"/zones/:projectId/:zoneUuid",
|
||||||
|
tokenValidator,
|
||||||
|
ZoneDataController
|
||||||
|
);
|
||||||
|
V1Zone.get(
|
||||||
|
"/zones/panel/:projectId/:zoneUuid",
|
||||||
|
tokenValidator,
|
||||||
|
SingleZonePanelController
|
||||||
|
);
|
||||||
|
V1Zone.get("/zones/:projectId", tokenValidator, GetZoneController);
|
||||||
|
export default V1Zone;
|
||||||
32
src/api-server/V1/v1Routes/BuilderRoutes/v1-assetRoutes.ts
Normal file
32
src/api-server/V1/v1Routes/BuilderRoutes/v1-assetRoutes.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AssetUpdatePosRotController,
|
||||||
|
CreateAssetController,
|
||||||
|
GetAssetController,
|
||||||
|
ReplaceEventDataController,
|
||||||
|
} from "../../v1Controllers/builderController/v1assetController.ts";
|
||||||
|
|
||||||
|
const V1Asset = express.Router();
|
||||||
|
|
||||||
|
V1Asset.post(
|
||||||
|
"/setAsset",
|
||||||
|
tokenValidator,
|
||||||
|
CreateAssetController
|
||||||
|
);
|
||||||
|
V1Asset.patch(
|
||||||
|
"/updateFloorAssetPositions",
|
||||||
|
tokenValidator,
|
||||||
|
AssetUpdatePosRotController
|
||||||
|
);
|
||||||
|
V1Asset.get(
|
||||||
|
"/floorAssets/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
GetAssetController
|
||||||
|
);
|
||||||
|
V1Asset.patch(
|
||||||
|
"/updateEventData",
|
||||||
|
tokenValidator,
|
||||||
|
ReplaceEventDataController
|
||||||
|
);
|
||||||
|
export default V1Asset;
|
||||||
27
src/api-server/V1/v1Routes/BuilderRoutes/v1-cameraRoutes.ts
Normal file
27
src/api-server/V1/v1Routes/BuilderRoutes/v1-cameraRoutes.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
ActiveOnlineController,
|
||||||
|
CameraList,
|
||||||
|
SetNewCamera,
|
||||||
|
} from "../../v1Controllers/builderController/v1cameraController.ts";
|
||||||
|
|
||||||
|
const V1Camera = express.Router();
|
||||||
|
|
||||||
|
V1Camera.post(
|
||||||
|
"/setCamera",
|
||||||
|
tokenValidator,
|
||||||
|
SetNewCamera
|
||||||
|
);
|
||||||
|
V1Camera.get(
|
||||||
|
"/activeCameras",
|
||||||
|
tokenValidator,
|
||||||
|
ActiveOnlineController
|
||||||
|
);
|
||||||
|
V1Camera.get(
|
||||||
|
"/cameras/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
CameraList
|
||||||
|
);
|
||||||
|
|
||||||
|
export default V1Camera;
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
GetEnvironmentController,
|
||||||
|
SetEnvironmentController,
|
||||||
|
} from "../../v1Controllers/builderController/v1EnvironmentController.ts";
|
||||||
|
|
||||||
|
const V1Environment = express.Router();
|
||||||
|
|
||||||
|
V1Environment.post("/SetEnvironments", tokenValidator, SetEnvironmentController);
|
||||||
|
|
||||||
|
V1Environment.get(
|
||||||
|
"/Environments/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
GetEnvironmentController
|
||||||
|
);
|
||||||
|
|
||||||
|
export default V1Environment;
|
||||||
20
src/api-server/V1/v1Routes/BuilderRoutes/v1-linesRoutes.ts
Normal file
20
src/api-server/V1/v1Routes/BuilderRoutes/v1-linesRoutes.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
DeleteLayerController,
|
||||||
|
DeleteLineController,
|
||||||
|
DeleteLinePointsController,
|
||||||
|
GetLinesController,
|
||||||
|
NewLineController,
|
||||||
|
UpdateLineController,
|
||||||
|
} from "../../v1Controllers/builderController/v1LineController.ts";
|
||||||
|
|
||||||
|
const V1Line = express.Router();
|
||||||
|
|
||||||
|
V1Line.post("/lines", tokenValidator, NewLineController);
|
||||||
|
V1Line.post("/points", tokenValidator, UpdateLineController);
|
||||||
|
V1Line.patch("/layers/delete", tokenValidator, DeleteLayerController);
|
||||||
|
V1Line.patch("/lines/delete", tokenValidator, DeleteLineController);
|
||||||
|
V1Line.patch("/points/delete", tokenValidator, DeleteLinePointsController);
|
||||||
|
V1Line.get("/lines/:projectId", tokenValidator, GetLinesController);
|
||||||
|
export default V1Line;
|
||||||
26
src/api-server/V1/v1Routes/BuilderRoutes/v1-wallRoutes.ts
Normal file
26
src/api-server/V1/v1Routes/BuilderRoutes/v1-wallRoutes.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
WallDelete,
|
||||||
|
WallGet,
|
||||||
|
WallSetup,
|
||||||
|
} from "../../v1Controllers/builderController/v1wallController.ts";
|
||||||
|
|
||||||
|
const V1Wall = express.Router();
|
||||||
|
|
||||||
|
V1Wall.post(
|
||||||
|
"/walls",
|
||||||
|
tokenValidator,
|
||||||
|
WallSetup
|
||||||
|
);
|
||||||
|
V1Wall.patch(
|
||||||
|
"/walls/delete",
|
||||||
|
tokenValidator,
|
||||||
|
WallDelete
|
||||||
|
);
|
||||||
|
V1Wall.get(
|
||||||
|
"/walls/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
WallGet
|
||||||
|
);
|
||||||
|
export default V1Wall;
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddProductController,
|
||||||
|
DeleteEventsController,
|
||||||
|
DeleteProductController,
|
||||||
|
GetProductEventDatas,
|
||||||
|
ProjectBasedProductsController,
|
||||||
|
RenameProductController,
|
||||||
|
} from "../../v1Controllers/simulationController/v1productController.ts";
|
||||||
|
|
||||||
|
const V1Product = express.Router();
|
||||||
|
|
||||||
|
V1Product.post("/ProductUpsert", tokenValidator, AddProductController);
|
||||||
|
V1Product.get("/EventsByProduct", tokenValidator, GetProductEventDatas);
|
||||||
|
V1Product.patch("/DeleteEvent", tokenValidator, DeleteEventsController);
|
||||||
|
V1Product.patch("/DeleteProduct", tokenValidator, DeleteProductController);
|
||||||
|
V1Product.get(
|
||||||
|
"/ProjectProducts/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
ProjectBasedProductsController
|
||||||
|
);
|
||||||
|
V1Product.patch("/RenameProduct", tokenValidator, RenameProductController);
|
||||||
|
export default V1Product;
|
||||||
19
src/api-server/V1/v1Routes/authRoutes.ts
Normal file
19
src/api-server/V1/v1Routes/authRoutes.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import express from "express";
|
||||||
|
import {
|
||||||
|
ForgetPasswordController,
|
||||||
|
ResetPasswordController,
|
||||||
|
SignInController,
|
||||||
|
SignOutController,
|
||||||
|
SignupController,
|
||||||
|
} from "../v1Controllers/authController/authControllers.ts";
|
||||||
|
import { versioncontroller } from "../v1Controllers/versionController/versioncontroller.ts";
|
||||||
|
|
||||||
|
const Authrouter = express.Router();
|
||||||
|
Authrouter.post("/Auth/signup", SignupController);
|
||||||
|
Authrouter.post("/Auth/login", SignInController);
|
||||||
|
Authrouter.post("/Auth/logout", SignOutController);
|
||||||
|
Authrouter.post("/Auth/forgetPassword", ForgetPasswordController);
|
||||||
|
Authrouter.post("/Auth/reset-password/:resetToken", ResetPasswordController);
|
||||||
|
Authrouter.post("/Auth/versionData", versioncontroller);
|
||||||
|
|
||||||
|
export default Authrouter;
|
||||||
27
src/api-server/V1/v1Routes/v1-homeRoutes.ts
Normal file
27
src/api-server/V1/v1Routes/v1-homeRoutes.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
recentDataController,
|
||||||
|
searchProjectController,
|
||||||
|
searchTrashProjectController,
|
||||||
|
} from "../../V1/v1Controllers/homeController/v1homeController.ts";
|
||||||
|
|
||||||
|
const V1homeRoutes = express.Router();
|
||||||
|
|
||||||
|
V1homeRoutes.get(
|
||||||
|
"/RecentlyViewed",
|
||||||
|
tokenValidator,
|
||||||
|
recentDataController
|
||||||
|
);
|
||||||
|
V1homeRoutes.get(
|
||||||
|
"/search/searchProjects",
|
||||||
|
tokenValidator,
|
||||||
|
searchProjectController
|
||||||
|
);
|
||||||
|
V1homeRoutes.get(
|
||||||
|
"/search/searchTrashProjects",
|
||||||
|
tokenValidator,
|
||||||
|
searchTrashProjectController
|
||||||
|
);
|
||||||
|
|
||||||
|
export default V1homeRoutes;
|
||||||
42
src/api-server/V1/v1Routes/v1-projectRoutes.ts
Normal file
42
src/api-server/V1/v1Routes/v1-projectRoutes.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import express from "express";
|
||||||
|
import {
|
||||||
|
createProjectController,
|
||||||
|
GetProjects,
|
||||||
|
ProjectDuplicateController,
|
||||||
|
RemoveProject,
|
||||||
|
updateProjectController,
|
||||||
|
ViewData,
|
||||||
|
} from "../../V1/v1Controllers/projectController/v1projectController.ts";
|
||||||
|
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||||
|
|
||||||
|
const V1projectRouter = express.Router();
|
||||||
|
|
||||||
|
V1projectRouter.post("/NewProject", tokenValidator, createProjectController);
|
||||||
|
V1projectRouter.post(
|
||||||
|
"/project/Duplicate",
|
||||||
|
tokenValidator,
|
||||||
|
ProjectDuplicateController
|
||||||
|
);
|
||||||
|
V1projectRouter.get(
|
||||||
|
"/Projects",
|
||||||
|
tokenValidator,
|
||||||
|
GetProjects
|
||||||
|
);
|
||||||
|
V1projectRouter.patch(
|
||||||
|
"/Projects/Archive/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
RemoveProject
|
||||||
|
);
|
||||||
|
|
||||||
|
V1projectRouter.patch(
|
||||||
|
"/Projects/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
updateProjectController
|
||||||
|
);
|
||||||
|
V1projectRouter.get(
|
||||||
|
"/Project/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
ViewData
|
||||||
|
);
|
||||||
|
|
||||||
|
export default V1projectRouter;
|
||||||
26
src/api-server/V1/v1Routes/v1-trashRoutes.ts
Normal file
26
src/api-server/V1/v1Routes/v1-trashRoutes.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
DeleteTrashData,
|
||||||
|
GetTrashList,
|
||||||
|
RestoreTrash,
|
||||||
|
} from "../../V1/v1Controllers/trashController/v1trashController.ts";
|
||||||
|
|
||||||
|
const V1TrashRoutes = express.Router();
|
||||||
|
V1TrashRoutes.get(
|
||||||
|
"/TrashItems",
|
||||||
|
tokenValidator,
|
||||||
|
GetTrashList
|
||||||
|
);
|
||||||
|
|
||||||
|
V1TrashRoutes.patch(
|
||||||
|
"/Trash/restore",
|
||||||
|
tokenValidator,
|
||||||
|
RestoreTrash
|
||||||
|
);
|
||||||
|
V1TrashRoutes.patch(
|
||||||
|
"/Trash/Delete",
|
||||||
|
tokenValidator,
|
||||||
|
DeleteTrashData
|
||||||
|
);
|
||||||
|
export default V1TrashRoutes;
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
DeleteFloatController,
|
||||||
|
DuplicateFloatController,
|
||||||
|
FloatAddController,
|
||||||
|
GetFloatController,
|
||||||
|
SingleFloatController,
|
||||||
|
} from "../../v1Controllers/vizualizationController/v1floatWidgetController.ts";
|
||||||
|
|
||||||
|
const V1FloatWidget = express.Router();
|
||||||
|
|
||||||
|
V1FloatWidget.post(
|
||||||
|
"/floatWidget/save",
|
||||||
|
tokenValidator,
|
||||||
|
FloatAddController
|
||||||
|
);
|
||||||
|
V1FloatWidget.patch(
|
||||||
|
"/floatWidget/delete",
|
||||||
|
tokenValidator,
|
||||||
|
DeleteFloatController
|
||||||
|
);
|
||||||
|
V1FloatWidget.get(
|
||||||
|
"/floatWidgets/:zoneUuid/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
GetFloatController
|
||||||
|
);
|
||||||
|
V1FloatWidget.get(
|
||||||
|
"/floatWidget/:floatWidgetId",
|
||||||
|
tokenValidator,
|
||||||
|
SingleFloatController
|
||||||
|
);
|
||||||
|
V1FloatWidget.post(
|
||||||
|
"/floatWidget/duplicate",
|
||||||
|
tokenValidator,
|
||||||
|
DuplicateFloatController
|
||||||
|
);
|
||||||
|
export default V1FloatWidget;
|
||||||
32
src/api-server/V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts
Normal file
32
src/api-server/V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddTemplateController,
|
||||||
|
AddTemToZoneController,
|
||||||
|
GetTemplateController,
|
||||||
|
TemplateDeleteController,
|
||||||
|
} from "../../v1Controllers/vizualizationController/v1templateController.ts";
|
||||||
|
|
||||||
|
const V1Template = express.Router();
|
||||||
|
|
||||||
|
V1Template.post(
|
||||||
|
"/template/save",
|
||||||
|
tokenValidator,
|
||||||
|
AddTemplateController
|
||||||
|
);
|
||||||
|
V1Template.post(
|
||||||
|
"/template/toZone",
|
||||||
|
tokenValidator,
|
||||||
|
AddTemToZoneController
|
||||||
|
);
|
||||||
|
V1Template.get(
|
||||||
|
"/template/data/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
GetTemplateController
|
||||||
|
);
|
||||||
|
V1Template.patch(
|
||||||
|
"/template/delete",
|
||||||
|
tokenValidator,
|
||||||
|
TemplateDeleteController
|
||||||
|
);
|
||||||
|
export default V1Template;
|
||||||
27
src/api-server/V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts
Normal file
27
src/api-server/V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddPanelController,
|
||||||
|
ClearPanelController,
|
||||||
|
DeletePanelController,
|
||||||
|
} from "../../v1Controllers/vizualizationController/v1panelController.ts";
|
||||||
|
|
||||||
|
const V1PanelRoutes = express.Router();
|
||||||
|
|
||||||
|
V1PanelRoutes.post(
|
||||||
|
"/panel/save",
|
||||||
|
tokenValidator,
|
||||||
|
AddPanelController
|
||||||
|
);
|
||||||
|
V1PanelRoutes.patch(
|
||||||
|
"/panel/delete",
|
||||||
|
tokenValidator,
|
||||||
|
DeletePanelController
|
||||||
|
);
|
||||||
|
V1PanelRoutes.patch(
|
||||||
|
"/panel/clear",
|
||||||
|
tokenValidator,
|
||||||
|
ClearPanelController
|
||||||
|
);
|
||||||
|
|
||||||
|
export default V1PanelRoutes;
|
||||||
35
src/api-server/V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts
Normal file
35
src/api-server/V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Add3dWidgetController,
|
||||||
|
Delete3DwidgetController,
|
||||||
|
Get3DWidgetController,
|
||||||
|
Update3DwidgetController,
|
||||||
|
} from "../../v1Controllers/vizualizationController/widget3Dcontroller.ts";
|
||||||
|
|
||||||
|
const V1Widget3d = express.Router();
|
||||||
|
|
||||||
|
|
||||||
|
V1Widget3d.post(
|
||||||
|
"/widget3d/save",
|
||||||
|
tokenValidator,
|
||||||
|
|
||||||
|
Add3dWidgetController
|
||||||
|
);
|
||||||
|
V1Widget3d.patch(
|
||||||
|
"/widget3d/update",
|
||||||
|
tokenValidator,
|
||||||
|
Update3DwidgetController
|
||||||
|
);
|
||||||
|
V1Widget3d.get(
|
||||||
|
"/widget3d/data/:zoneUuid/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
Get3DWidgetController
|
||||||
|
);
|
||||||
|
V1Widget3d.patch(
|
||||||
|
"/widget3d/delete",
|
||||||
|
tokenValidator,
|
||||||
|
Delete3DwidgetController
|
||||||
|
);
|
||||||
|
export default V1Widget3d;
|
||||||
32
src/api-server/V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts
Normal file
32
src/api-server/V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddWidgetController,
|
||||||
|
GetWidgetController,
|
||||||
|
WidgetDeleteController,
|
||||||
|
WidgetUpdateController,
|
||||||
|
} from "../../v1Controllers/vizualizationController/v1widgetController.ts";
|
||||||
|
|
||||||
|
const V1Widget = express.Router();
|
||||||
|
|
||||||
|
V1Widget.post(
|
||||||
|
"/widget/save",
|
||||||
|
tokenValidator,
|
||||||
|
AddWidgetController
|
||||||
|
);
|
||||||
|
V1Widget.patch(
|
||||||
|
"/widget/:widgetID",
|
||||||
|
tokenValidator,
|
||||||
|
WidgetUpdateController
|
||||||
|
);
|
||||||
|
V1Widget.get(
|
||||||
|
"/widget/data",
|
||||||
|
tokenValidator,
|
||||||
|
GetWidgetController
|
||||||
|
);
|
||||||
|
V1Widget.patch(
|
||||||
|
"/widget/delete",
|
||||||
|
tokenValidator,
|
||||||
|
WidgetDeleteController
|
||||||
|
);
|
||||||
|
export default V1Widget;
|
||||||
@@ -8,7 +8,6 @@ import flooritemRoutes from "./Routes/flooritem-Routes.ts";
|
|||||||
import WallitemRoutes from "./Routes/wallItems-Routes.ts";
|
import WallitemRoutes from "./Routes/wallItems-Routes.ts";
|
||||||
import userRoutes from "./Routes/user-Routes.ts";
|
import userRoutes from "./Routes/user-Routes.ts";
|
||||||
import shareRoutes from "./Routes/share-Routes.ts";
|
import shareRoutes from "./Routes/share-Routes.ts";
|
||||||
import zoneRoutes from "./Routes/zone-Routes.ts";
|
|
||||||
import zoneRoutes2 from "./Routes/zoneRoutes.ts";
|
import zoneRoutes2 from "./Routes/zoneRoutes.ts";
|
||||||
import panelRouter from "./Routes/panelRoutes.ts";
|
import panelRouter from "./Routes/panelRoutes.ts";
|
||||||
import widgetRouter from "./Routes/widgetRoute.ts";
|
import widgetRouter from "./Routes/widgetRoute.ts";
|
||||||
@@ -19,11 +18,35 @@ import templateRoutes from "./Routes/templateRoutes.ts";
|
|||||||
import widget3dRoutes from "./Routes/widget3dRoutes.ts";
|
import widget3dRoutes from "./Routes/widget3dRoutes.ts";
|
||||||
import productRouter from "./Routes/productRoutes.ts";
|
import productRouter from "./Routes/productRoutes.ts";
|
||||||
import projectRouter from "./Routes/projectRoutes.ts";
|
import projectRouter from "./Routes/projectRoutes.ts";
|
||||||
|
import trashRouter from "./Routes/trashRoutes.ts";
|
||||||
|
import homePageRouter from "./Routes/homepageRoutes.ts";
|
||||||
|
import redis from "../shared/redis/redis.ts";
|
||||||
|
import Authrouter from "./V1/v1Routes/authRoutes.ts";
|
||||||
|
import V1projectRouter from "./V1/v1Routes/v1-projectRoutes.ts";
|
||||||
|
import V1TrashRoutes from "./V1/v1Routes/v1-trashRoutes.ts";
|
||||||
|
import V1homeRoutes from "./V1/v1Routes/v1-homeRoutes.ts";
|
||||||
|
import V1Asset from "./V1/v1Routes/BuilderRoutes/v1-assetRoutes.ts";
|
||||||
|
import V1Camera from "./V1/v1Routes/BuilderRoutes/v1-cameraRoutes.ts";
|
||||||
|
import V1Environment from "./V1/v1Routes/BuilderRoutes/v1-environmentRoutes.ts";
|
||||||
|
import V1Line from "./V1/v1Routes/BuilderRoutes/v1-linesRoutes.ts";
|
||||||
|
import V1Wall from "./V1/v1Routes/BuilderRoutes/v1-wallRoutes.ts";
|
||||||
|
import V1Zone from "./V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts";
|
||||||
|
import V1FloatWidget from "./V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts";
|
||||||
|
import V1PanelRoutes from "./V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts";
|
||||||
|
import V1Template from "./V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts";
|
||||||
|
import V1Widget from "./V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts";
|
||||||
|
import V1Widget3d from "./V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts";
|
||||||
|
import V1Product from "./V1/v1Routes/SimulationRoutes/v1-ProductRoutes.ts";
|
||||||
|
import V1Aisle from "./V1/v1Routes/BuilderRoutes/V1-AisleRoutes.ts";
|
||||||
|
redis;
|
||||||
const app = express();
|
const app = express();
|
||||||
app.disable("x-powered-by");
|
|
||||||
dotenv.config();
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
|
app.use(express.json({ limit: "50mb" }));
|
||||||
|
app.use(
|
||||||
|
express.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 })
|
||||||
|
);
|
||||||
|
dotenv.config();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
res.send("Hello, I am Major-Dwinzo API!");
|
res.send("Hello, I am Major-Dwinzo API!");
|
||||||
@@ -36,7 +59,6 @@ app.use("/api/v1", flooritemRoutes);
|
|||||||
app.use("/api/v1", WallitemRoutes);
|
app.use("/api/v1", WallitemRoutes);
|
||||||
app.use("/api/v1", userRoutes);
|
app.use("/api/v1", userRoutes);
|
||||||
app.use("/api/v1", shareRoutes);
|
app.use("/api/v1", shareRoutes);
|
||||||
app.use("/api/v2", zoneRoutes);
|
|
||||||
|
|
||||||
app.use("/api/v2", zoneRoutes2);
|
app.use("/api/v2", zoneRoutes2);
|
||||||
app.use("/api/v2", panelRouter);
|
app.use("/api/v2", panelRouter);
|
||||||
@@ -48,4 +70,25 @@ app.use("/api/v2", templateRoutes);
|
|||||||
app.use("/api/v2", widget3dRoutes);
|
app.use("/api/v2", widget3dRoutes);
|
||||||
app.use("/api/v2", productRouter);
|
app.use("/api/v2", productRouter);
|
||||||
app.use("/api/v1", projectRouter);
|
app.use("/api/v1", projectRouter);
|
||||||
|
app.use("/api/v1", trashRouter);
|
||||||
|
app.use("/api/v1", homePageRouter);
|
||||||
|
|
||||||
|
app.use("/api/V1", Authrouter);
|
||||||
|
app.use("/api/V1", V1projectRouter);
|
||||||
|
app.use("/api/V1", V1TrashRoutes);
|
||||||
|
app.use("/api/V1", V1homeRoutes);
|
||||||
|
app.use("/api/V1", V1Asset);
|
||||||
|
app.use("/api/V1", V1Camera);
|
||||||
|
app.use("/api/V1", V1Line);
|
||||||
|
app.use("/api/V1", V1Environment);
|
||||||
|
app.use("/api/V1", V1Wall);
|
||||||
|
app.use("/api/V1", V1Zone);
|
||||||
|
app.use("/api/V1", V1FloatWidget);
|
||||||
|
app.use("/api/V1", V1PanelRoutes);
|
||||||
|
app.use("/api/V1", V1Template);
|
||||||
|
app.use("/api/V1", V1Widget);
|
||||||
|
app.use("/api/V1", V1Widget3d);
|
||||||
|
app.use("/api/V1", V1Product);
|
||||||
|
app.use("/api/V1", V1Aisle);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import wallItenmModel from "../../../shared/model/assets/wallitems-Model.ts";
|
import wallItemModel from "../../../shared/model/builder/assets/wallitems-Model.ts";
|
||||||
|
|
||||||
export class WallItems {
|
export class WallItems {
|
||||||
static async setWallItems(req: Request, res: Response) {
|
static async setWallItems(req: Request, res: Response) {
|
||||||
@@ -16,12 +16,12 @@ export class WallItems {
|
|||||||
organization,
|
organization,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
const findvalue = await wallItenmModel(organization).findOne({
|
const findvalue = await wallItemModel(organization).findOne({
|
||||||
modelUuid: modelUuid,
|
modelUuid: modelUuid,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (findvalue) {
|
if (findvalue) {
|
||||||
const updatevalue = await wallItenmModel(organization).findOneAndUpdate(
|
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
|
||||||
{ modelUuid: modelUuid },
|
{ modelUuid: modelUuid },
|
||||||
{
|
{
|
||||||
modelName,
|
modelName,
|
||||||
@@ -36,7 +36,7 @@ export class WallItems {
|
|||||||
);
|
);
|
||||||
res.status(201).json(updatevalue);
|
res.status(201).json(updatevalue);
|
||||||
} else {
|
} else {
|
||||||
const newValue = await wallItenmModel(organization).create({
|
const newValue = await wallItemModel(organization).create({
|
||||||
modelUuid,
|
modelUuid,
|
||||||
modelName,
|
modelName,
|
||||||
position,
|
position,
|
||||||
@@ -58,7 +58,7 @@ export class WallItems {
|
|||||||
try {
|
try {
|
||||||
const { organization } = req.params;
|
const { organization } = req.params;
|
||||||
|
|
||||||
const findValue = await wallItenmModel(organization).find();
|
const findValue = await wallItemModel(organization).find();
|
||||||
if (!findValue) {
|
if (!findValue) {
|
||||||
res.status(200).json("wallitems not found");
|
res.status(200).json("wallitems not found");
|
||||||
} else {
|
} else {
|
||||||
@@ -73,7 +73,7 @@ export class WallItems {
|
|||||||
try {
|
try {
|
||||||
const { modelUuid, modelName, organization } = req.body;
|
const { modelUuid, modelName, organization } = req.body;
|
||||||
|
|
||||||
const findValue = await wallItenmModel(organization).findOneAndDelete({
|
const findValue = await wallItemModel(organization).findOneAndDelete({
|
||||||
modelUuid: modelUuid,
|
modelUuid: modelUuid,
|
||||||
modelName: modelName,
|
modelName: modelName,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ export class Environment {
|
|||||||
renderDistance,
|
renderDistance,
|
||||||
limitDistance,
|
limitDistance,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
const findvalue = await environmentModel(organization).findOne({
|
const findvalue = await environmentModel(organization).findOne({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
});
|
});
|
||||||
|
|||||||
150
src/api-server/controller/home/homeControllers.ts
Normal file
150
src/api-server/controller/home/homeControllers.ts
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import {
|
||||||
|
RecentlyAdded,
|
||||||
|
searchProject,
|
||||||
|
searchTrashProject,
|
||||||
|
} from "../../../shared/services/home/homeService.ts";
|
||||||
|
|
||||||
|
export const recentDataController = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.params;
|
||||||
|
if (!userId || !organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await RecentlyAdded({ userId, organization });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Datas were empty":
|
||||||
|
res.status(200).json({
|
||||||
|
RecentlyViewed: [],
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
RecentlyViewed: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const searchProjectController = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { searchName, organization, userId } = req.query as {
|
||||||
|
organization: string;
|
||||||
|
searchName: string;
|
||||||
|
userId: string;
|
||||||
|
};
|
||||||
|
if (!userId || !organization || !searchName) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await searchProject({
|
||||||
|
searchName,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
projectData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const searchTrashProjectController = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { searchName, organization, userId } = req.query as {
|
||||||
|
organization: string;
|
||||||
|
searchName: string;
|
||||||
|
userId: string;
|
||||||
|
};
|
||||||
|
if (!userId || !organization || !searchName) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await searchTrashProject({
|
||||||
|
searchName,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
projectData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
37
src/api-server/controller/home/tutorialControllers.ts
Normal file
37
src/api-server/controller/home/tutorialControllers.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { getTutorials } from "../../../shared/services/home/tutorialsService.ts";
|
||||||
|
import { Request, Response } from "express";
|
||||||
|
|
||||||
|
export const tutorialsDataController = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization = "tutorials" } = req.body;
|
||||||
|
if (!organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "Organization is required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const result = await getTutorials({ organization });
|
||||||
|
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
tutorials: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -238,7 +238,6 @@ export class ZoneService {
|
|||||||
return res.status(500).send(error.message);
|
return res.status(500).send(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async lockedPanel(req: Request, res: Response): Promise<any> {
|
static async lockedPanel(req: Request, res: Response): Promise<any> {
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
const organization = req.body.organization;
|
const organization = req.body.organization;
|
||||||
@@ -272,4 +271,24 @@ export class ZoneService {
|
|||||||
return res.status(500).send(error.message);
|
return res.status(500).send(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getZones(req: Request, res: Response) {
|
||||||
|
try {
|
||||||
|
const { organization } = req.params;
|
||||||
|
|
||||||
|
const findZoneId = await zoneSchema(organization)
|
||||||
|
.find({ isArchive: false })
|
||||||
|
.select(
|
||||||
|
"zoneId zoneName layer points viewPortCenter viewPortposition -_id"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!findZoneId) {
|
||||||
|
res.status(500).json({ message: "Invalid zone" });
|
||||||
|
}
|
||||||
|
res.status(200).json({ data: findZoneId, organization: organization });
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({ message: "Zone not found", error });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
59
src/api-server/controller/newassets/wallcontroller.ts
Normal file
59
src/api-server/controller/newassets/wallcontroller.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import { WallItems } from "../../../shared/services/wall/wallItemservice.ts";
|
||||||
|
import { error } from "console";
|
||||||
|
|
||||||
|
export const WallSetup = async (req: Request, res: Response): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
type,
|
||||||
|
csgposition,
|
||||||
|
csgscale,
|
||||||
|
quaternion,
|
||||||
|
scale,
|
||||||
|
organization,
|
||||||
|
} = req.body;
|
||||||
|
if (
|
||||||
|
!modelUuid ||
|
||||||
|
!modelName ||
|
||||||
|
!position ||
|
||||||
|
!type ||
|
||||||
|
!csgscale ||
|
||||||
|
!csgposition ||
|
||||||
|
!quaternion ||
|
||||||
|
!scale ||
|
||||||
|
!organization
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required!",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await WallItems.setWallItems({
|
||||||
|
modelUuid,
|
||||||
|
modelName,
|
||||||
|
position,
|
||||||
|
type,
|
||||||
|
csgposition,
|
||||||
|
csgscale,
|
||||||
|
quaternion,
|
||||||
|
scale,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
switch (result.state) {
|
||||||
|
case "Updated successfully":
|
||||||
|
res.status(201).json(result.data);
|
||||||
|
break;
|
||||||
|
case "wall Item created successfully":
|
||||||
|
res.status(201).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json(error);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
res.status(500).json({ message: "Unknown error" });
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,45 +1,233 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import { createProject } from "../../../shared/services/project/project-Serivices.ts";
|
import {
|
||||||
|
createProject,
|
||||||
|
DeleteProject,
|
||||||
|
GetAllProjects,
|
||||||
|
updateProject,
|
||||||
|
viewProject,
|
||||||
|
} from "../../../shared/services/project/project-Services.ts";
|
||||||
|
|
||||||
export const createProjectController = async (req: Request, res: Response): Promise<void> => {
|
export const createProjectController = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
|
const { projectUuid, userId, thumbnail, organization } = req.body;
|
||||||
|
if (!projectUuid || !userId || !thumbnail || !organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const result = await createProject(req.body);
|
const result = await createProject(req.body);
|
||||||
|
|
||||||
switch (result.status) {
|
switch (result.status) {
|
||||||
case "project_exists":
|
case "project_exists":
|
||||||
res.status(409).json({
|
res.status(403).json({
|
||||||
success: false,
|
|
||||||
message: "Project already exists",
|
message: "Project already exists",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "user_not_found":
|
case "user_not_found":
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
success: false,
|
|
||||||
message: "User not found",
|
message: "User not found",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "success":
|
case "Success":
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
success: true,
|
message: "Project created Successfully",
|
||||||
message: "Project created successfully",
|
projectId: result.project._id,
|
||||||
data: result.project,
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
success: false,
|
|
||||||
message: "Internal server error",
|
message: "Internal server error",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error in controller:", error);
|
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
success: false,
|
message: "Unknown error",
|
||||||
message: "Internal server error",
|
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetProjects = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.params;
|
||||||
|
if (!userId || !organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await GetAllProjects({ userId, organization });
|
||||||
|
switch (result?.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
Projects: result?.Datas,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const RemoveProject = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { projectId } = req.params;
|
||||||
|
const { organization, userId } = req.body;
|
||||||
|
if (!projectId || !organization || !userId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteProject({ projectId, organization, userId });
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Project Deleted Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const updateProjectController = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { projectId, organization, projectName, thumbnail, userId } =
|
||||||
|
req.body;
|
||||||
|
if (!userId || !organization || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await updateProject({
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
projectName,
|
||||||
|
thumbnail,
|
||||||
|
});
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project updated Successfully",
|
||||||
|
projectData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ViewData = async (req: Request, res: Response): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { projectId, organization, userId } = req.query as {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
userId: string;
|
||||||
|
};
|
||||||
|
if (!userId || !organization || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await viewProject({
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
switch (result?.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
projectData: result.data,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ export class AssetsFloorService {
|
|||||||
return res.status(500).send(error.message);
|
return res.status(500).send(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setFloorassets(req: Request, res: Response): Promise<any> {
|
static async setFloorassets(req: Request, res: Response): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
@@ -128,14 +127,12 @@ export class AssetsFloorService {
|
|||||||
.status(400)
|
.status(400)
|
||||||
.json({ message: "Vehicle points must be a single object" });
|
.json({ message: "Vehicle points must be a single object" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventData.points.triggers) {
|
if (eventData.points.triggers) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
message: "triggers is not allowed for Vehicle points",
|
message: "triggers is not allowed for Vehicle points",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assetData.points = eventData.points;
|
assetData.points = eventData.points;
|
||||||
assetData.type = eventData.type;
|
assetData.type = eventData.type;
|
||||||
}
|
}
|
||||||
@@ -174,7 +171,6 @@ export class AssetsFloorService {
|
|||||||
isVisible: item.isVisible,
|
isVisible: item.isVisible,
|
||||||
eventData: item.eventData,
|
eventData: item.eventData,
|
||||||
};
|
};
|
||||||
|
|
||||||
return responseItem;
|
return responseItem;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
94
src/api-server/controller/trash/trashcontrollers.ts
Normal file
94
src/api-server/controller/trash/trashcontrollers.ts
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import { Request, Response } from "express";
|
||||||
|
import {
|
||||||
|
TrashDatas,
|
||||||
|
RestoreTrashData,
|
||||||
|
} from "../../../shared/services/trash/trashService.ts";
|
||||||
|
|
||||||
|
export const GetTrashList = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization } = req.query as { organization: string };
|
||||||
|
if (!organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await TrashDatas({ organization });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "Trash is Empty":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Trash is Empty",
|
||||||
|
TrashDatas: [],
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
TrashDatas: result.ListDatas,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RestoreTrash = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, projectId } = req.query as {
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
};
|
||||||
|
console.log("organization: ", organization);
|
||||||
|
if (!organization || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await RestoreTrashData({ organization, projectId });
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project Restore unsuccessfull":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project Restore unsuccessfull",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project Restored successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Project Restored successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import userModel from "../../shared/model/user-Model.ts";
|
import userModel from "../../shared/model/user-Model.ts";
|
||||||
import { hashGenerate, hashValidator } from "../../shared/security/Hasing.ts";
|
import { hashGenerate, hashValidator } from "../../shared/utils/Hasing.ts";
|
||||||
|
|
||||||
export class User {
|
export class User {
|
||||||
static async signup(req: Request, res: Response) {
|
static async signup(req: Request, res: Response) {
|
||||||
|
|||||||
@@ -129,7 +129,8 @@ export class Widget3dService {
|
|||||||
widgetID: id,
|
widgetID: id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!widgetData) return res.status(204).json({ message: "Widget not found" });
|
if (!widgetData)
|
||||||
|
return res.status(204).json({ message: "Widget not found" });
|
||||||
const structureData = {
|
const structureData = {
|
||||||
measurements: widgetData?.Data?.measurements,
|
measurements: widgetData?.Data?.measurements,
|
||||||
duration: widgetData?.Data?.duration,
|
duration: widgetData?.Data?.duration,
|
||||||
|
|||||||
@@ -170,7 +170,6 @@ export class TemplateService {
|
|||||||
}
|
}
|
||||||
static async Deletezone(req: Request, res: Response): Promise<any> {
|
static async Deletezone(req: Request, res: Response): Promise<any> {
|
||||||
try {
|
try {
|
||||||
console.log("req.params: ", req.params);
|
|
||||||
const { organization, templateID } = req.params;
|
const { organization, templateID } = req.params;
|
||||||
const existingTemplate = await templateModel(organization).findOne({
|
const existingTemplate = await templateModel(organization).findOne({
|
||||||
templateID: templateID,
|
templateID: templateID,
|
||||||
|
|||||||
24
src/shared/V1Models/Auth/tokenModel.ts
Normal file
24
src/shared/V1Models/Auth/tokenModel.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "./userAuthModel.ts";
|
||||||
|
export interface Token extends Document {
|
||||||
|
userId: User["_id"];
|
||||||
|
isArchive: boolean;
|
||||||
|
refreshToken: string;
|
||||||
|
resetTokenExpiry?: Date;
|
||||||
|
resetToken: string;
|
||||||
|
}
|
||||||
|
const tokenSchema: Schema = new Schema({
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
token: { type: String },
|
||||||
|
refreshToken: { type: String },
|
||||||
|
tokenCreatedAt: { type: Date },
|
||||||
|
resetToken: { type: String },
|
||||||
|
resetTokenExpiry: { type: Date },
|
||||||
|
});
|
||||||
|
|
||||||
|
const tokenType = (db: any) => {
|
||||||
|
return MainModel(db, "Token", tokenSchema, "Token");
|
||||||
|
};
|
||||||
|
export default tokenType;
|
||||||
48
src/shared/V1Models/Auth/user.ts
Normal file
48
src/shared/V1Models/Auth/user.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "./userAuthModel.ts";
|
||||||
|
export interface UserData extends Document {
|
||||||
|
userId: User["_id"];
|
||||||
|
isShare: boolean;
|
||||||
|
activeStatus: string;
|
||||||
|
notificationEnable: boolean;
|
||||||
|
About: string;
|
||||||
|
isArchive: boolean;
|
||||||
|
role: string;
|
||||||
|
profilePicture: string;
|
||||||
|
recentlyViewed: string[];
|
||||||
|
}
|
||||||
|
const UserDataSchema: Schema = new Schema({
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
notificationEnable: { type: Boolean, default: false },
|
||||||
|
About: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
role: {
|
||||||
|
type: String,
|
||||||
|
default: "User",
|
||||||
|
enum: ["User", "Admin"],
|
||||||
|
},
|
||||||
|
isShare: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
activeStatus: {
|
||||||
|
type: String,
|
||||||
|
enum: ["online", "offline"],
|
||||||
|
default: "offline",
|
||||||
|
},
|
||||||
|
recentlyViewed: {
|
||||||
|
type: [String],
|
||||||
|
default: [],
|
||||||
|
},
|
||||||
|
profilePicture: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const UsersDataModel = (db: any) => {
|
||||||
|
return MainModel(db, "UsersData", UserDataSchema, "UsersData");
|
||||||
|
};
|
||||||
|
export default UsersDataModel;
|
||||||
32
src/shared/V1Models/Auth/userAuthModel.ts
Normal file
32
src/shared/V1Models/Auth/userAuthModel.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
export interface User extends Document {
|
||||||
|
userName: string;
|
||||||
|
Email: string;
|
||||||
|
Password: string;
|
||||||
|
isArchive: boolean;
|
||||||
|
visitorBrowserID: string;
|
||||||
|
lastPasswordReset: number;
|
||||||
|
}
|
||||||
|
const AuthSchema: Schema = new Schema({
|
||||||
|
userName: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
Email: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
Password: {
|
||||||
|
type: String,
|
||||||
|
min: 8,
|
||||||
|
},
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
lastPasswordReset: { type: Number },
|
||||||
|
visitorBrowserID: { type: String },
|
||||||
|
});
|
||||||
|
|
||||||
|
const AuthModel = (db: any) => {
|
||||||
|
return MainModel(db, "UserAuth", AuthSchema, "UserAuth");
|
||||||
|
};
|
||||||
|
export default AuthModel;
|
||||||
161
src/shared/V1Models/Builder/AisleModel.ts
Normal file
161
src/shared/V1Models/Builder/AisleModel.ts
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
|
||||||
|
type PointTypes = "Aisle";
|
||||||
|
|
||||||
|
export interface Point {
|
||||||
|
pointUuid: string;
|
||||||
|
pointType: PointTypes;
|
||||||
|
position: [number, number, number];
|
||||||
|
layer: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ValidAisleTypes = [
|
||||||
|
"solid-aisle",
|
||||||
|
"dashed-aisle",
|
||||||
|
"stripped-aisle",
|
||||||
|
"dotted-aisle",
|
||||||
|
"arrow-aisle",
|
||||||
|
"arrows-aisle",
|
||||||
|
"arc-aisle",
|
||||||
|
"circle-aisle",
|
||||||
|
"junction-aisle",
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
const ValidAisleColors = [
|
||||||
|
"gray",
|
||||||
|
"yellow",
|
||||||
|
"green",
|
||||||
|
"orange",
|
||||||
|
"blue",
|
||||||
|
"purple",
|
||||||
|
"red",
|
||||||
|
"#66FF00",
|
||||||
|
"yellow-black",
|
||||||
|
"white-black",
|
||||||
|
] as const;
|
||||||
|
type AisleTypes =
|
||||||
|
| "solid-aisle"
|
||||||
|
| "dashed-aisle"
|
||||||
|
| "stripped-aisle"
|
||||||
|
| "dotted-aisle"
|
||||||
|
| "arrow-aisle"
|
||||||
|
| "arrows-aisle"
|
||||||
|
| "arc-aisle"
|
||||||
|
| "circle-aisle"
|
||||||
|
| "junction-aisle";
|
||||||
|
|
||||||
|
type AisleColors =
|
||||||
|
| "gray"
|
||||||
|
| "yellow"
|
||||||
|
| "green"
|
||||||
|
| "orange"
|
||||||
|
| "blue"
|
||||||
|
| "purple"
|
||||||
|
| "red"
|
||||||
|
| "#66FF00"
|
||||||
|
| "yellow-black"
|
||||||
|
| "white-black";
|
||||||
|
|
||||||
|
interface ForAisle {
|
||||||
|
aisleType: AisleTypes;
|
||||||
|
aisleColor: AisleColors;
|
||||||
|
}
|
||||||
|
interface SolidAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DashedAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
dashLength: number;
|
||||||
|
gapLength: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DottedAisle extends ForAisle {
|
||||||
|
dotRadius: number;
|
||||||
|
gapLength: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ArrowAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ArrowsAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
aisleLength: number;
|
||||||
|
gapLength: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ArcAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
isFlipped: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CircleAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JunctionAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
isFlipped: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AisleType =
|
||||||
|
| SolidAisle
|
||||||
|
| DashedAisle
|
||||||
|
| DottedAisle
|
||||||
|
| ArrowAisle
|
||||||
|
| ArrowsAisle
|
||||||
|
| ArcAisle
|
||||||
|
| CircleAisle
|
||||||
|
| JunctionAisle;
|
||||||
|
|
||||||
|
export interface Aisle extends Document {
|
||||||
|
aisleUuid: string;
|
||||||
|
points: [Point, Point];
|
||||||
|
projectId: Project["_id"];
|
||||||
|
createdBy: User["_id"];
|
||||||
|
type: AisleType;
|
||||||
|
isArchive: boolean;
|
||||||
|
}
|
||||||
|
type Aisles = Aisle[];
|
||||||
|
const AisleSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
aisleUuid: { type: String, required: true },
|
||||||
|
createdBy: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
points: {
|
||||||
|
type: [
|
||||||
|
{
|
||||||
|
pointUuid: String,
|
||||||
|
pointType: { type: String, enum: ["Aisle"] },
|
||||||
|
position: [Number],
|
||||||
|
layer: Number,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: Object,
|
||||||
|
validate: {
|
||||||
|
validator: function (value: any) {
|
||||||
|
return (
|
||||||
|
value &&
|
||||||
|
ValidAisleTypes.includes(value.aisleType) &&
|
||||||
|
ValidAisleColors.includes(value.aisleColor)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
message: (props: any) =>
|
||||||
|
`Invalid aisleType or aisleColor: ${JSON.stringify(props.value)}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const AisleModel = (db: any) => {
|
||||||
|
return MainModel(db, "Aisle", AisleSchema, "Aisle");
|
||||||
|
};
|
||||||
|
export default AisleModel;
|
||||||
71
src/shared/V1Models/Builder/assetModel.ts
Normal file
71
src/shared/V1Models/Builder/assetModel.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { Document, Schema } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
interface ICommonBase {
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
interface IPointsConveyor extends ICommonBase {
|
||||||
|
points?: {
|
||||||
|
Uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
interface IPoint extends ICommonBase {
|
||||||
|
point?: {
|
||||||
|
Uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export interface AssetData extends Document {
|
||||||
|
userId: User["_id"];
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
|
modelUuid: string;
|
||||||
|
modelfileID: string;
|
||||||
|
modelName: string;
|
||||||
|
isLocked: boolean;
|
||||||
|
type: string;
|
||||||
|
isVisible: boolean;
|
||||||
|
isArchive: false;
|
||||||
|
|
||||||
|
position: [];
|
||||||
|
rotation: {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
z: number;
|
||||||
|
};
|
||||||
|
speed: number | string;
|
||||||
|
eventData: IPoint | IPointsConveyor;
|
||||||
|
}
|
||||||
|
|
||||||
|
const assetDataSchema: Schema = new Schema({
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
modelUuid: { type: String },
|
||||||
|
modelfileID: { type: String },
|
||||||
|
modelName: { type: String },
|
||||||
|
type: { type: String },
|
||||||
|
position: { type: Array },
|
||||||
|
rotation: {
|
||||||
|
x: { type: Number },
|
||||||
|
y: { type: Number },
|
||||||
|
z: { type: Number },
|
||||||
|
},
|
||||||
|
speed: { type: Schema.Types.Mixed },
|
||||||
|
isLocked: { type: Boolean },
|
||||||
|
isVisible: { type: Boolean },
|
||||||
|
eventData: {
|
||||||
|
type: Schema.Types.Mixed,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const assetModel = (db: string) => {
|
||||||
|
return MainModel(db, "Assets", assetDataSchema, "Assets");
|
||||||
|
};
|
||||||
|
export default assetModel;
|
||||||
53
src/shared/V1Models/Builder/cameraModel.ts
Normal file
53
src/shared/V1Models/Builder/cameraModel.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { Document, Schema } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
export interface Camera extends Document {
|
||||||
|
userId: User["_id"];
|
||||||
|
projectId: Project["_id"];
|
||||||
|
isArchive: boolean;
|
||||||
|
versionId: Version["_id"];
|
||||||
|
position: {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
z: number;
|
||||||
|
};
|
||||||
|
target: {
|
||||||
|
x: { type: number; required: true };
|
||||||
|
y: { type: number; required: true };
|
||||||
|
z: { type: number; required: true };
|
||||||
|
};
|
||||||
|
rotation: {
|
||||||
|
x: { type: number; required: true };
|
||||||
|
y: { type: number; required: true };
|
||||||
|
z: { type: number; required: true };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const cameraSchema: Schema = new Schema({
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
position: {
|
||||||
|
x: { type: Number, required: true },
|
||||||
|
y: { type: Number, required: true },
|
||||||
|
z: { type: Number, required: true },
|
||||||
|
},
|
||||||
|
target: {
|
||||||
|
x: { type: Number, required: true },
|
||||||
|
y: { type: Number, required: true },
|
||||||
|
z: { type: Number, required: true },
|
||||||
|
},
|
||||||
|
rotation: {
|
||||||
|
x: { type: Number, required: true },
|
||||||
|
y: { type: Number, required: true },
|
||||||
|
z: { type: Number, required: true },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const cameraModel = (db: string) => {
|
||||||
|
return MainModel(db, "Camera", cameraSchema, "Camera");
|
||||||
|
};
|
||||||
|
export default cameraModel;
|
||||||
27
src/shared/V1Models/Builder/linesModel.ts
Normal file
27
src/shared/V1Models/Builder/linesModel.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import mongoose, { Schema } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
const positionSchema = new mongoose.Schema({
|
||||||
|
x: { type: Number },
|
||||||
|
y: { type: Number },
|
||||||
|
z: { type: Number },
|
||||||
|
});
|
||||||
|
|
||||||
|
const Vector3 = new mongoose.Schema({
|
||||||
|
position: { type: positionSchema, required: false },
|
||||||
|
uuid: { type: String, required: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
const LineSchema = new mongoose.Schema({
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
|
layer: { type: Number, required: true },
|
||||||
|
line: { type: [Vector3], required: true },
|
||||||
|
type: { type: String, required: false },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
const lineModel = (db: string) => {
|
||||||
|
return MainModel(db, "lines", LineSchema, "lines");
|
||||||
|
};
|
||||||
|
export default lineModel;
|
||||||
37
src/shared/V1Models/Builder/wallItemsModel.ts
Normal file
37
src/shared/V1Models/Builder/wallItemsModel.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { Document, Schema } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
export interface WallItems extends Document {
|
||||||
|
userId: User["_id"];
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
type: string;
|
||||||
|
csgposition: [];
|
||||||
|
csgscale: [];
|
||||||
|
position: [];
|
||||||
|
quaternion: [];
|
||||||
|
scale: [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const wallItemsSchema: Schema = new Schema({
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
|
modelUuid: { type: String, unique: true },
|
||||||
|
modelName: { type: String },
|
||||||
|
type: { type: String },
|
||||||
|
csgposition: { type: Array },
|
||||||
|
csgscale: { type: Array },
|
||||||
|
position: { type: Array },
|
||||||
|
quaternion: { type: Array },
|
||||||
|
scale: { type: Array },
|
||||||
|
});
|
||||||
|
|
||||||
|
const wallItemModel = (db: string) => {
|
||||||
|
return MainModel(db, "wallitems", wallItemsSchema, "wallitems");
|
||||||
|
};
|
||||||
|
export default wallItemModel;
|
||||||
48
src/shared/V1Models/Builder/zoneModel.ts
Normal file
48
src/shared/V1Models/Builder/zoneModel.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
export interface Zone extends Document {
|
||||||
|
zoneName: string;
|
||||||
|
zoneUuid: string;
|
||||||
|
points: [];
|
||||||
|
viewPortCenter: [];
|
||||||
|
viewPortposition: [];
|
||||||
|
isArchive: boolean;
|
||||||
|
panelOrder: string[];
|
||||||
|
lockedPanel: string[];
|
||||||
|
createdBy: User["_id"];
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
|
layer: number;
|
||||||
|
}
|
||||||
|
const zoneSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
zoneName: { type: String },
|
||||||
|
zoneUuid: { type: String },
|
||||||
|
createdBy: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
|
layer: { type: Number },
|
||||||
|
points: { type: Array },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
panelOrder: {
|
||||||
|
type: [String],
|
||||||
|
enum: ["left", "right", "top", "bottom"],
|
||||||
|
},
|
||||||
|
viewPortCenter: { type: Array, required: true },
|
||||||
|
viewPortposition: { type: Array, required: true },
|
||||||
|
lockedPanel: {
|
||||||
|
type: [String],
|
||||||
|
default: [],
|
||||||
|
enum: ["left", "right", "top", "bottom"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const zoneModel = (db: any) => {
|
||||||
|
return MainModel(db, "zones", zoneSchema, "zones");
|
||||||
|
};
|
||||||
|
export default zoneModel;
|
||||||
30
src/shared/V1Models/Environment/environments-Model.ts
Normal file
30
src/shared/V1Models/Environment/environments-Model.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { Document, Schema } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
export interface Environment extends Document {
|
||||||
|
userId: User["_id"];
|
||||||
|
projectId: Project["_id"];
|
||||||
|
roofVisibility: boolean;
|
||||||
|
wallVisibility: boolean;
|
||||||
|
renderDistance: number;
|
||||||
|
shadowVisibility: boolean;
|
||||||
|
limitDistance: boolean;
|
||||||
|
isArchive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const environmentSchema: Schema = new Schema({
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
roofVisibility: { type: Boolean, default: false },
|
||||||
|
wallVisibility: { type: Boolean, default: false },
|
||||||
|
shadowVisibility: { type: Boolean, default: false },
|
||||||
|
renderDistance: { type: Number, default: 40 },
|
||||||
|
limitDistance: { type: Boolean, default: true },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
const environmentModel = (db: string) => {
|
||||||
|
return MainModel(db, "Environments", environmentSchema, "Environments");
|
||||||
|
};
|
||||||
|
export default environmentModel;
|
||||||
39
src/shared/V1Models/Project/project-model.ts
Normal file
39
src/shared/V1Models/Project/project-model.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
|
||||||
|
export interface Project extends Document {
|
||||||
|
projectUuid: string;
|
||||||
|
projectName: string;
|
||||||
|
createdBy: User["_id"];
|
||||||
|
isArchive: boolean;
|
||||||
|
isDeleted: boolean;
|
||||||
|
thumbnail: string;
|
||||||
|
sharedUsers: [];
|
||||||
|
DeletedAt: Date;
|
||||||
|
isViewed: number;
|
||||||
|
total_versions: string;
|
||||||
|
Present_version: string;
|
||||||
|
}
|
||||||
|
const projectSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
projectUuid: { type: String },
|
||||||
|
projectName: { type: String },
|
||||||
|
thumbnail: { type: String },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
|
||||||
|
sharedUsers: [{ type: Schema.Types.ObjectId, ref: "user" }],
|
||||||
|
DeletedAt: { type: Date, default: null },
|
||||||
|
isDeleted: { type: Boolean, default: false },
|
||||||
|
isViewed: { type: Number },
|
||||||
|
total_versions: { type: String },
|
||||||
|
Present_version: { type: String },
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const projectModel = (db: string) => {
|
||||||
|
return MainModel(db, "Projects", projectSchema, "Projects");
|
||||||
|
};
|
||||||
|
|
||||||
|
export default projectModel;
|
||||||
52
src/shared/V1Models/Project/share-model.ts
Normal file
52
src/shared/V1Models/Project/share-model.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import mongoose, { Document, Schema } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
|
||||||
|
export interface IShare extends Document {
|
||||||
|
Createdby: {
|
||||||
|
userId: mongoose.Types.ObjectId;
|
||||||
|
Email: string;
|
||||||
|
};
|
||||||
|
isActive: boolean;
|
||||||
|
Share_People: [
|
||||||
|
{
|
||||||
|
userId: mongoose.Types.ObjectId;
|
||||||
|
Email: string;
|
||||||
|
AccessPoint: string;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
Description: string;
|
||||||
|
createdAt: number;
|
||||||
|
projectId: mongoose.Types.ObjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
const shareSchema: Schema = new Schema({
|
||||||
|
CreatedBy: {
|
||||||
|
userId: {
|
||||||
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
|
ref: "User",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
Email: { type: String, ref: "User", required: true },
|
||||||
|
},
|
||||||
|
isActive: { type: Boolean, default: false },
|
||||||
|
Share_People: [
|
||||||
|
{
|
||||||
|
userId: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
|
||||||
|
Email: { type: String, ref: "User", required: true },
|
||||||
|
AccessPoint: {
|
||||||
|
type: String,
|
||||||
|
default: "Can view",
|
||||||
|
enum: ["Can view", "Can edit", "Can comment"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
createdAt: {
|
||||||
|
type: Number,
|
||||||
|
default: Date.now(),
|
||||||
|
},
|
||||||
|
projectId: { type: mongoose.Schema.Types.ObjectId, ref: "Scene" },
|
||||||
|
});
|
||||||
|
const shareModel = (db: any) => {
|
||||||
|
return MainModel(db, "Shared", shareSchema, "Shared");
|
||||||
|
};
|
||||||
|
export default shareModel;
|
||||||
180
src/shared/V1Models/Simulation/eventsDataModel.ts
Normal file
180
src/shared/V1Models/Simulation/eventsDataModel.ts
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
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;
|
||||||
|
actionName: string;
|
||||||
|
actionType: "default" | "spawn" | "swap" | "despawn";
|
||||||
|
material: string;
|
||||||
|
delay: number | "inherit";
|
||||||
|
spawnInterval: number | "inherit";
|
||||||
|
spawnCount: number | "inherit";
|
||||||
|
triggers: TriggerSchema[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface VehiclePointSchema {
|
||||||
|
uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
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 RoboticArmPointSchema {
|
||||||
|
uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
actions: {
|
||||||
|
actionUuid: string;
|
||||||
|
actionName: string;
|
||||||
|
actionType: "pickAndPlace";
|
||||||
|
process: {
|
||||||
|
startPoint: [number, number, number];
|
||||||
|
endPoint: [number, number, number];
|
||||||
|
};
|
||||||
|
triggers: TriggerSchema[];
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MachinePointSchema {
|
||||||
|
uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
action: {
|
||||||
|
actionUuid: string;
|
||||||
|
actionName: string;
|
||||||
|
actionType: "process";
|
||||||
|
processTime: number;
|
||||||
|
swapMaterial: string;
|
||||||
|
triggers: TriggerSchema[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StoragePointSchema {
|
||||||
|
uuid: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
action: {
|
||||||
|
actionUuid: string;
|
||||||
|
actionName: string;
|
||||||
|
actionType: "storage";
|
||||||
|
materials: { materialName: string; materialId: string }[];
|
||||||
|
storageCapacity: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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/Simulation/productModel.ts
Normal file
28
src/shared/V1Models/Simulation/productModel.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;
|
||||||
54
src/shared/V1Models/Thread/thread-Model.ts
Normal file
54
src/shared/V1Models/Thread/thread-Model.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { Document, Schema } from "mongoose";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
interface IComment {
|
||||||
|
userId: User["_id"];
|
||||||
|
comment: string;
|
||||||
|
timestamp:number
|
||||||
|
}
|
||||||
|
export interface IThread extends Document {
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
|
state: string;
|
||||||
|
commentId: string;
|
||||||
|
createdBy: User["_id"];
|
||||||
|
createdAt: number;
|
||||||
|
lastUpdatedAt: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
replies: IComment[];
|
||||||
|
|
||||||
|
}
|
||||||
|
const CommentSchema = new Schema<IComment>(
|
||||||
|
{
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },
|
||||||
|
comment: { type: String,},
|
||||||
|
timestamp:{
|
||||||
|
type: Number,
|
||||||
|
default:Date.now()}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const threadSchema = new Schema<IThread>({
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: 'Project', required: true },
|
||||||
|
state: { type: String, enum: ['active', 'inactive'], required: true },
|
||||||
|
commentId: { type: String, },
|
||||||
|
createdBy: { type: Schema.Types.ObjectId, ref: 'User', required: true },
|
||||||
|
createdAt: { type: Number,},
|
||||||
|
lastUpdatedAt: { type: String, },
|
||||||
|
position: {
|
||||||
|
type: [Number],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
rotation: {
|
||||||
|
type: [Number],
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
replies: { type: [CommentSchema ], default: [] },
|
||||||
|
});
|
||||||
|
|
||||||
|
const ThreadModel = (db: string) => {
|
||||||
|
return MainModel(db, "Threads", threadSchema, "Threads");
|
||||||
|
};
|
||||||
|
export default ThreadModel;
|
||||||
27
src/shared/V1Models/Version/versionModel.ts
Normal file
27
src/shared/V1Models/Version/versionModel.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
export interface Version extends Document {
|
||||||
|
versionName: string;
|
||||||
|
projectId: Project["_id"];
|
||||||
|
createdBy: User["_id"];
|
||||||
|
isArchive: boolean;
|
||||||
|
version: number;
|
||||||
|
}
|
||||||
|
const versionSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
versionName: { type: String },
|
||||||
|
version: { type: Number },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "project" },
|
||||||
|
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const versionModel = (db: string) => {
|
||||||
|
return MainModel(db, "Versions", versionSchema, "Versions");
|
||||||
|
};
|
||||||
|
|
||||||
|
export default versionModel;
|
||||||
36
src/shared/V1Models/Vizualization/3dwidget.ts
Normal file
36
src/shared/V1Models/Vizualization/3dwidget.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
export interface Widget3d extends Document {
|
||||||
|
type: string;
|
||||||
|
widgetID: string;
|
||||||
|
widgetName: string;
|
||||||
|
position: [];
|
||||||
|
rotation: [];
|
||||||
|
isArchive: boolean;
|
||||||
|
zoneUuid:string
|
||||||
|
Data: {
|
||||||
|
measurements: {};
|
||||||
|
duration: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const Widget3dSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
type: { type: String },
|
||||||
|
widgetID: { type: String },
|
||||||
|
widgetName: { type: String, default: "Widget3D" },
|
||||||
|
position: { type: Array },
|
||||||
|
rotation: { type: Array },
|
||||||
|
zoneUuid:{ type: String },
|
||||||
|
Data: {
|
||||||
|
measurements: { type: Object, default: {} },
|
||||||
|
duration: { type: String, default: "1h" },
|
||||||
|
},
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const widget3dModel = (db: any) => {
|
||||||
|
return MainModel(db, "3dWidget", Widget3dSchema, "3dWidget");
|
||||||
|
};
|
||||||
|
export default widget3dModel;
|
||||||
45
src/shared/V1Models/Vizualization/floatWidget.ts
Normal file
45
src/shared/V1Models/Vizualization/floatWidget.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
export interface FloatingWidget extends Document {
|
||||||
|
className: string;
|
||||||
|
iconName: string;
|
||||||
|
header: string;
|
||||||
|
floatWidgetID: string;
|
||||||
|
position: {};
|
||||||
|
per: string;
|
||||||
|
value: string;
|
||||||
|
isArchive: boolean;
|
||||||
|
zoneUuid: string
|
||||||
|
Data: {
|
||||||
|
measurements: {};
|
||||||
|
duration: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const floatingWidgetSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
className: { type: String },
|
||||||
|
iconName: { type: String },
|
||||||
|
header: { type: String },
|
||||||
|
floatWidgetID: { type: String },
|
||||||
|
position: { type: Object },
|
||||||
|
per: { type: String },
|
||||||
|
value: { type: String },
|
||||||
|
zoneUuid: { type: String },
|
||||||
|
Data: {
|
||||||
|
measurements: { type: Object, default: {} },
|
||||||
|
duration: { type: String, default: "1h" },
|
||||||
|
},
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const floatWidgetModel = (db: any) => {
|
||||||
|
return MainModel(
|
||||||
|
db,
|
||||||
|
"FloatingWidget",
|
||||||
|
floatingWidgetSchema,
|
||||||
|
"FloatingWidget"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default floatWidgetModel;
|
||||||
22
src/shared/V1Models/Vizualization/panelmodel.ts
Normal file
22
src/shared/V1Models/Vizualization/panelmodel.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import mongoose, { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
export interface Panel extends Document {
|
||||||
|
zoneUuid: string
|
||||||
|
panelName: string;
|
||||||
|
widgets: [mongoose.Types.ObjectId];
|
||||||
|
isArchive: boolean;
|
||||||
|
}
|
||||||
|
const panelSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
zoneUuid: { type: String },
|
||||||
|
panelName: { type: String },
|
||||||
|
widgets: [{ type: mongoose.Schema.Types.ObjectId, ref: "Widget" }],
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const panelModel = (db: any) => {
|
||||||
|
return MainModel(db, "Panel", panelSchema, "Panel");
|
||||||
|
};
|
||||||
|
export default panelModel;
|
||||||
39
src/shared/V1Models/Vizualization/templatemodel.ts
Normal file
39
src/shared/V1Models/Vizualization/templatemodel.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
export interface Template extends Document {
|
||||||
|
userId: User["_id"];
|
||||||
|
projectId: Project["_id"];
|
||||||
|
versionId: Version["_id"];
|
||||||
|
templateName: string;
|
||||||
|
templateID: string;
|
||||||
|
snapshot: string;
|
||||||
|
panelOrder: [];
|
||||||
|
widgets: [];
|
||||||
|
floatWidgets: [];
|
||||||
|
Widgets3D: [];
|
||||||
|
isArchive: boolean;
|
||||||
|
}
|
||||||
|
const templateSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
|
templateName: { type: String },
|
||||||
|
templateID: { type: String },
|
||||||
|
snapshot: { type: String },
|
||||||
|
panelOrder: { type: Array },
|
||||||
|
widgets: { type: Array },
|
||||||
|
floatWidgets: { type: Array },
|
||||||
|
Widgets3D: { type: Array },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const templateModel = (db: any) => {
|
||||||
|
return MainModel(db, "Template", templateSchema, "Template");
|
||||||
|
};
|
||||||
|
export default templateModel;
|
||||||
46
src/shared/V1Models/Vizualization/widgemodel.ts
Normal file
46
src/shared/V1Models/Vizualization/widgemodel.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import mongoose, { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
export interface Widget extends Document {
|
||||||
|
widgetName: string;
|
||||||
|
widgetside: string;
|
||||||
|
widgetID: string;
|
||||||
|
widgetOrder: string;
|
||||||
|
elementType: string;
|
||||||
|
elementColor: string;
|
||||||
|
fontFamily: string;
|
||||||
|
fontStyle: string;
|
||||||
|
fontWeight: string;
|
||||||
|
isArchive: boolean;
|
||||||
|
panelID: mongoose.Types.ObjectId;
|
||||||
|
Data: {
|
||||||
|
measurements: {};
|
||||||
|
duration: string;
|
||||||
|
};
|
||||||
|
zoneUuid: string
|
||||||
|
}
|
||||||
|
const widgetSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
widgetName: { type: String, default: "Widget" },
|
||||||
|
widgetside: { type: String },
|
||||||
|
widgetID: { type: String },
|
||||||
|
widgetOrder: { type: String },
|
||||||
|
elementType: { type: String },
|
||||||
|
elementColor: { type: String },
|
||||||
|
fontFamily: { type: String },
|
||||||
|
fontStyle: { type: String },
|
||||||
|
Data: {
|
||||||
|
measurements: { type: Object, default: {} },
|
||||||
|
duration: { type: String, default: "1h" },
|
||||||
|
},
|
||||||
|
fontWeight: { type: String },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
panelID: { type: mongoose.Schema.Types.ObjectId, ref: "Panel" },
|
||||||
|
zoneUuid: { type: String }
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const widgetModel = (db: any) => {
|
||||||
|
return MainModel(db, "Widget", widgetSchema, "Widget");
|
||||||
|
};
|
||||||
|
export default widgetModel;
|
||||||
10
src/shared/connect/blobConnection.ts
Normal file
10
src/shared/connect/blobConnection.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { Client } from 'minio';
|
||||||
|
const minioClient = new Client({
|
||||||
|
endPoint: process.env.MinIO_URL!,
|
||||||
|
port: parseInt(process.env.MinIO_PORT!, 10),
|
||||||
|
useSSL: false,
|
||||||
|
accessKey: process.env.MinIO_accessKey!,
|
||||||
|
secretKey: process.env.MinIO_secretKey!,
|
||||||
|
});
|
||||||
|
|
||||||
|
export { minioClient}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import mongoose, { Schema, Connection, Model } from "mongoose";
|
import mongoose, { Schema, Connection, Model } from "mongoose";
|
||||||
|
|
||||||
interface ConnectionCache {
|
interface ConnectionCache {
|
||||||
[key: string]: Connection;
|
[key: string]: Connection;
|
||||||
}
|
}
|
||||||
@@ -47,4 +46,5 @@ const MainModel = <T>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default MainModel;
|
export default MainModel;
|
||||||
|
|||||||
13
src/shared/middleware/rbacMiddleware.ts
Normal file
13
src/shared/middleware/rbacMiddleware.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { Response, NextFunction } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../shared/utils/token.ts";
|
||||||
|
type Role = "Admin" | "User";
|
||||||
|
const authorizedRoles = (...allowedRoles: Role[]) => {
|
||||||
|
return (req: AuthenticatedRequest, res: Response, next: NextFunction) => {
|
||||||
|
if (!req.user || !allowedRoles.includes(req.user.role as Role)) {
|
||||||
|
res.status(403).json({ message: "Access Denied" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export default authorizedRoles;
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { Document, Schema } from "mongoose";
|
|
||||||
import MainModel from "../../connect/mongoose.ts";
|
|
||||||
export interface WallItems extends Document {
|
|
||||||
modelUuid: string;
|
|
||||||
modelName: string;
|
|
||||||
modelfileID: string;
|
|
||||||
type: string;
|
|
||||||
csgposition: [];
|
|
||||||
csgscale: [];
|
|
||||||
position: [];
|
|
||||||
quaternion: [];
|
|
||||||
scale: [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const wallItemsSchema: Schema = new Schema({
|
|
||||||
modelUuid: { type: String },
|
|
||||||
modelfileID: { type: String },
|
|
||||||
modelName: { type: String },
|
|
||||||
type: { type: String },
|
|
||||||
csgposition: { type: Array },
|
|
||||||
csgscale: { type: Array },
|
|
||||||
position: { type: Array },
|
|
||||||
quaternion: { type: Array },
|
|
||||||
scale: { type: Array },
|
|
||||||
});
|
|
||||||
|
|
||||||
const wallItenmModel = (db: string) => {
|
|
||||||
return MainModel(db, "wallitems", wallItemsSchema, "wallitems");
|
|
||||||
};
|
|
||||||
export default wallItenmModel;
|
|
||||||
@@ -18,7 +18,7 @@ interface IPoint extends ICommonBase {
|
|||||||
rotation: [number, number, number];
|
rotation: [number, number, number];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export interface assetData extends Document {
|
export interface AssetData extends Document {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
modelfileID: string;
|
modelfileID: string;
|
||||||
modelName: string;
|
modelName: string;
|
||||||
|
|||||||
@@ -102,10 +102,8 @@ const PointSchema = new Schema<IPointModel>(
|
|||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const pointModel = (db: string) => {
|
const pointModel = (db: string) => {
|
||||||
return MainModel(db, "Points", PointSchema, "Points");
|
return MainModel(db, "Points", PointSchema, "Points");
|
||||||
};
|
};
|
||||||
|
|
||||||
export default pointModel;
|
export default pointModel;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const wallItemsSchema: Schema = new Schema({
|
|||||||
scale: { type: Array },
|
scale: { type: Array },
|
||||||
});
|
});
|
||||||
|
|
||||||
const wallItenmModel = (db: string) => {
|
const wallItemModel = (db: string) => {
|
||||||
return MainModel(db, "wallitems", wallItemsSchema, "wallitems");
|
return MainModel(db, "wallitems", wallItemsSchema, "wallitems");
|
||||||
};
|
};
|
||||||
export default wallItenmModel;
|
export default wallItemModel;
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import { Document, Schema } from "mongoose";
|
|
||||||
import MainModel from "../../../connect/mongoose.ts";
|
|
||||||
export interface Environment extends Document {
|
|
||||||
userId: string;
|
|
||||||
roofVisibility: boolean;
|
|
||||||
wallVisibility: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const environmentSchema: Schema = new Schema({
|
|
||||||
userId: { type: String, unique: true },
|
|
||||||
roofVisibility: { type: Boolean, default: false },
|
|
||||||
wallVisibility: { type: Boolean, default: false },
|
|
||||||
shadowVisibility: { type: Boolean, default: false },
|
|
||||||
});
|
|
||||||
|
|
||||||
const environmentModel = (db: string) => {
|
|
||||||
return MainModel(db, "environments", environmentSchema, "environments");
|
|
||||||
};
|
|
||||||
export default environmentModel;
|
|
||||||
@@ -4,7 +4,7 @@ import MainModel from "../../../connect/mongoose.ts";
|
|||||||
export interface Zone extends Document {
|
export interface Zone extends Document {
|
||||||
zoneName: string;
|
zoneName: string;
|
||||||
zoneId: string;
|
zoneId: string;
|
||||||
zonePoints: [];
|
points: [];
|
||||||
viewPortCenter: [];
|
viewPortCenter: [];
|
||||||
viewPortposition: [];
|
viewPortposition: [];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export interface User extends Document {
|
|||||||
userName: String;
|
userName: String;
|
||||||
email: String;
|
email: String;
|
||||||
password: String;
|
password: String;
|
||||||
|
recentlyViewed: string[];
|
||||||
role: String;
|
role: String;
|
||||||
profilePicture: String;
|
profilePicture: String;
|
||||||
isShare: Boolean;
|
isShare: Boolean;
|
||||||
|
|||||||
27
src/shared/model/version/versionModel.ts
Normal file
27
src/shared/model/version/versionModel.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../project/project-model.ts";
|
||||||
|
import { User } from "../user-Model.ts";
|
||||||
|
export interface Version extends Document {
|
||||||
|
versionName: string;
|
||||||
|
projectId: Project["_id"];
|
||||||
|
createdBy: User["_id"];
|
||||||
|
isArchive: boolean;
|
||||||
|
version: number;
|
||||||
|
}
|
||||||
|
const versionSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
versionName: { type: String },
|
||||||
|
version: { type: Number },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "project" },
|
||||||
|
createdBy: { type: Schema.Types.ObjectId, ref: "user" },
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const versionModel = (db: string) => {
|
||||||
|
return MainModel(db, "Versions", versionSchema, "Versions");
|
||||||
|
};
|
||||||
|
|
||||||
|
export default versionModel;
|
||||||
21
src/shared/redis/redis.ts
Normal file
21
src/shared/redis/redis.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import Redis from "ioredis";
|
||||||
|
import * as dotenv from "dotenv";
|
||||||
|
dotenv.config();
|
||||||
|
const redis = new Redis.default({
|
||||||
|
host:
|
||||||
|
process.env.REDIS_ENV === "true"
|
||||||
|
? process.env.REDIS_DOCKER
|
||||||
|
: process.env.REDIS_LOCAL,
|
||||||
|
port: parseInt(process.env.REDIS_PORT || "6379"),
|
||||||
|
password: "",
|
||||||
|
db: 0,
|
||||||
|
});
|
||||||
|
redis.on("connect", () => {
|
||||||
|
console.log(`Connected to Redis to ${redis.options.port}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
redis.on("error", (err: unknown) => {
|
||||||
|
console.error("Redis connection error:", err);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default redis;
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
|
||||||
import * as Jwt from "jsonwebtoken";
|
|
||||||
|
|
||||||
interface AuthenticatedRequest extends Request {
|
|
||||||
user?: {
|
|
||||||
email: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const tokenGenerator = (email: string) => {
|
|
||||||
const token = Jwt.sign({ email: email }, "Milestone", {
|
|
||||||
expiresIn: "3hours",
|
|
||||||
});
|
|
||||||
return token;
|
|
||||||
};
|
|
||||||
|
|
||||||
const tokenValidator = (
|
|
||||||
req: AuthenticatedRequest,
|
|
||||||
res: Response,
|
|
||||||
next: NextFunction
|
|
||||||
): void => {
|
|
||||||
const token: string | undefined = req.headers.token as string | undefined;
|
|
||||||
if (!token) {
|
|
||||||
res.status(403).json({
|
|
||||||
msg: "No token present",
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const decoded = Jwt.verify(token, "Milestone") as { email: string };
|
|
||||||
req.user = decoded;
|
|
||||||
next();
|
|
||||||
} catch (err) {
|
|
||||||
res.status(401).json({
|
|
||||||
msg: "Invalid Token",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export { tokenValidator, tokenGenerator };
|
|
||||||
172
src/shared/services/Thread/ThreadService.ts
Normal file
172
src/shared/services/Thread/ThreadService.ts
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
import ThreadModel from "../../V1Models/Thread/thread-Model.ts";
|
||||||
|
import { existingProjectByIdWithoutUser, existingUser } from "../helpers/v1projecthelperFns.ts";
|
||||||
|
|
||||||
|
|
||||||
|
interface IThread {
|
||||||
|
projectId: string;
|
||||||
|
versionId: string;
|
||||||
|
state: string
|
||||||
|
commentId: string;
|
||||||
|
threadId: string;
|
||||||
|
userId: string;
|
||||||
|
createdAt: string;
|
||||||
|
lastUpdatedAt: string;
|
||||||
|
position: [number, number, number];
|
||||||
|
rotation: [number, number, number];
|
||||||
|
comments: string
|
||||||
|
timestamp: number;
|
||||||
|
|
||||||
|
organization: string;
|
||||||
|
}
|
||||||
|
export const createThread = async (data: IThread) => {
|
||||||
|
try {
|
||||||
|
const { projectId, state, userId, position, rotation, comments, 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 newThread = await ThreadModel(organization).create({
|
||||||
|
projectId,
|
||||||
|
state,
|
||||||
|
createdBy: userId,
|
||||||
|
position,
|
||||||
|
rotation,
|
||||||
|
comments,
|
||||||
|
createdAt: Date.now()
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: newThread,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
status: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const deleteThread = async (data: IThread) => {
|
||||||
|
try {
|
||||||
|
const { projectId, userId, organization, threadId } = 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 findThreadId = await ThreadModel(organization).findOne({ _id: threadId, createdBy: userId })
|
||||||
|
if (!findThreadId) {
|
||||||
|
return { status: "can't deleted" };
|
||||||
|
}
|
||||||
|
const deleteThread = await ThreadModel(organization).findOneAndDelete({ _id: threadId, createdBy: userId })
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: deleteThread,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
return {
|
||||||
|
status: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const addComments = async (data: IThread) => {
|
||||||
|
try {
|
||||||
|
const { projectId, userId, comments, organization, threadId } = 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 findThreadId = await ThreadModel(organization).findById(threadId)
|
||||||
|
|
||||||
|
const newComment = { userId, comment: comments, timestamp: Date.now() };
|
||||||
|
findThreadId?.replies.push(newComment)
|
||||||
|
await findThreadId?.save()
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: newComment.comment,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
return {
|
||||||
|
status: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const deleteComments = async (data: IThread) => {
|
||||||
|
try {
|
||||||
|
const { projectId, userId, commentId, organization, threadId } = 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 findThreadId = await ThreadModel(organization).findOne({ _id: threadId })
|
||||||
|
if (!findThreadId) {
|
||||||
|
return { status: "thread not found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleted = await ThreadModel(organization).updateOne(
|
||||||
|
{ _id: threadId },
|
||||||
|
{
|
||||||
|
$pull: {
|
||||||
|
replies: {
|
||||||
|
_id: commentId,
|
||||||
|
userId: userId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (deleted.modifiedCount === 0) {
|
||||||
|
return { status: "unauthorized" };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: deleted
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error: ", error);
|
||||||
|
return {
|
||||||
|
status: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
62
src/shared/services/User/userService.ts
Normal file
62
src/shared/services/User/userService.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import UsersDataModel from "../../V1Models/Auth/user.ts";
|
||||||
|
import AuthModel from "../../V1Models/Auth/userAuthModel.ts";
|
||||||
|
import {
|
||||||
|
existingProjectById,
|
||||||
|
existingUser,
|
||||||
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
interface ISearchUser {
|
||||||
|
searchName: string;
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface ShareUserResult {
|
||||||
|
userName: string;
|
||||||
|
Email: string;
|
||||||
|
profilePicture?: string;
|
||||||
|
}
|
||||||
|
export const ShareUserSearch = async (
|
||||||
|
data: ISearchUser
|
||||||
|
): Promise<{
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}> => {
|
||||||
|
const { userId, organization, searchName, projectId } = data;
|
||||||
|
try {
|
||||||
|
if (!(await existingUser(userId, organization)))
|
||||||
|
return { status: "User not found" };
|
||||||
|
|
||||||
|
if (!(await existingProjectById(projectId, organization, userId)))
|
||||||
|
return { status: "Project not found" };
|
||||||
|
|
||||||
|
const UsersData = await AuthModel(organization).find({
|
||||||
|
Email: { $regex: `${searchName}`, $options: "i" },
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!UsersData || UsersData.length === 0)
|
||||||
|
return { status: "Project not found" };
|
||||||
|
const results = await Promise.all(
|
||||||
|
UsersData.map(async (user) => {
|
||||||
|
const profile = await UsersDataModel(organization)
|
||||||
|
.findOne({ userId: user._id, isArchive: false })
|
||||||
|
.select("profilePicture");
|
||||||
|
return {
|
||||||
|
userName: user.userName,
|
||||||
|
Email: user.Email,
|
||||||
|
profilePicture: profile?.profilePicture,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return { status: "Success", data: results };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
465
src/shared/services/auth/authServices.ts
Normal file
465
src/shared/services/auth/authServices.ts
Normal file
@@ -0,0 +1,465 @@
|
|||||||
|
import AuthModel from "../../V1Models/Auth/userAuthModel.ts";
|
||||||
|
import UsersDataModel from "../../V1Models/Auth/user.ts";
|
||||||
|
import nodemailer from "nodemailer";
|
||||||
|
import tokenType from "../../V1Models/Auth/tokenModel.ts";
|
||||||
|
import Jwt from "jsonwebtoken";
|
||||||
|
|
||||||
|
import { hashValidator, hashGenerate } from "../../utils/Hasing.ts";
|
||||||
|
import redis from "../../redis/redis.ts";
|
||||||
|
import { tokenGenerator, tokenRefreshGenerator } from "../../utils/token.ts";
|
||||||
|
interface Iserviceuser {
|
||||||
|
userName: string;
|
||||||
|
Email: string;
|
||||||
|
Password: string;
|
||||||
|
profilePicture?: string;
|
||||||
|
}
|
||||||
|
interface IloginUser {
|
||||||
|
Email: string;
|
||||||
|
Password: string;
|
||||||
|
fingerprint: string;
|
||||||
|
}
|
||||||
|
interface IresetToken {
|
||||||
|
resetToken: string;
|
||||||
|
newPassword: string;
|
||||||
|
confirmPassword: string;
|
||||||
|
}
|
||||||
|
interface IUser {
|
||||||
|
Email: string;
|
||||||
|
userName: string;
|
||||||
|
_id: string;
|
||||||
|
}
|
||||||
|
const jwt_secret = process.env.JWT_SECRET as string;
|
||||||
|
export function extractOrg(Email: string) {
|
||||||
|
return Email.split("@")[1].split(".")[0];
|
||||||
|
}
|
||||||
|
async function findExistingUserEmail(Email: string) {
|
||||||
|
const organization = extractOrg(Email);
|
||||||
|
const existingUser = await AuthModel(organization).findOne({
|
||||||
|
Email: Email,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
return existingUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AuthSignup = async (
|
||||||
|
data: Iserviceuser
|
||||||
|
): Promise<{
|
||||||
|
status: string;
|
||||||
|
}> => {
|
||||||
|
const { userName, Email, Password, profilePicture } = data;
|
||||||
|
try {
|
||||||
|
let role;
|
||||||
|
const caseChange = Email.toLowerCase();
|
||||||
|
const organization = extractOrg(caseChange);
|
||||||
|
const Existing_User = await findExistingUserEmail(caseChange);
|
||||||
|
if (Existing_User) {
|
||||||
|
return { status: "User already exists" };
|
||||||
|
} else {
|
||||||
|
const hashPassword = await hashGenerate(Password);
|
||||||
|
const userCount = await AuthModel(organization).countDocuments({});
|
||||||
|
role = userCount === 0 ? "Admin" : "User";
|
||||||
|
const isShare = "true";
|
||||||
|
const newuser = await AuthModel(organization).create({
|
||||||
|
userName: userName,
|
||||||
|
Email: caseChange,
|
||||||
|
Password: hashPassword,
|
||||||
|
});
|
||||||
|
await UsersDataModel(organization).create({
|
||||||
|
userId: newuser._id,
|
||||||
|
role: role,
|
||||||
|
isShare: isShare,
|
||||||
|
profilePicture: profilePicture,
|
||||||
|
});
|
||||||
|
return { status: "Success" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AuthLogin = async (
|
||||||
|
data: IloginUser
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { Email, Password, fingerprint } = data;
|
||||||
|
const caseChange = Email.toLowerCase();
|
||||||
|
const organization = extractOrg(caseChange);
|
||||||
|
const Existing_User = await findExistingUserEmail(caseChange);
|
||||||
|
if (!Existing_User) return { status: "User Not Found!!! Kindly signup..." };
|
||||||
|
else {
|
||||||
|
const existingMail = await getUserFromCacheOrDB(caseChange);
|
||||||
|
const checkPassword = await hashValidator(
|
||||||
|
Password,
|
||||||
|
existingMail.Password
|
||||||
|
);
|
||||||
|
if (!checkPassword)
|
||||||
|
return {
|
||||||
|
status: "Email & Password is invalid...Check the credentials",
|
||||||
|
};
|
||||||
|
|
||||||
|
const browserID = existingMail.visitorBrowserID;
|
||||||
|
if (browserID && browserID !== fingerprint) {
|
||||||
|
await Promise.all([
|
||||||
|
redis.del(`token:${caseChange}`),
|
||||||
|
redis.del(`user:${caseChange}`),
|
||||||
|
]);
|
||||||
|
await AuthModel(organization).updateOne(
|
||||||
|
{ Email: caseChange },
|
||||||
|
{ visitorBrowserID: "" }
|
||||||
|
);
|
||||||
|
await tokenType(organization).updateOne(
|
||||||
|
{ userId: Existing_User._id },
|
||||||
|
{ refreshToken: "" }
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
status: "Already LoggedIn on another browser....Please logout!!!",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const UserData = await UsersDataModel(organization).findOne({
|
||||||
|
userId: existingMail._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!UserData)
|
||||||
|
return {
|
||||||
|
status: "User_Datas not found",
|
||||||
|
};
|
||||||
|
const redisTokenRaw = await redis.get(`token:${caseChange}`);
|
||||||
|
if (redisTokenRaw) {
|
||||||
|
const cachedTokens = JSON.parse(redisTokenRaw);
|
||||||
|
try {
|
||||||
|
Jwt.verify(cachedTokens.token, jwt_secret);
|
||||||
|
return {
|
||||||
|
status: "Success",
|
||||||
|
data: {
|
||||||
|
message: "login successfull",
|
||||||
|
email: existingMail.Email,
|
||||||
|
name: existingMail.userName,
|
||||||
|
userId: existingMail._id,
|
||||||
|
isShare: UserData.isShare,
|
||||||
|
token: cachedTokens.token,
|
||||||
|
refreshToken: cachedTokens.refreshToken,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
console.log("Access token expired. Generating new...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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: "Success",
|
||||||
|
data: finalResult,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const AuthLogout = async ({
|
||||||
|
Email,
|
||||||
|
}: Iserviceuser): Promise<{ status: string }> => {
|
||||||
|
try {
|
||||||
|
const caseChange = Email.toLowerCase();
|
||||||
|
const organization = extractOrg(caseChange);
|
||||||
|
const Existing_User = await findExistingUserEmail(caseChange);
|
||||||
|
if (!Existing_User) return { status: "User not found" };
|
||||||
|
|
||||||
|
const tokenData = await tokenType(organization).findOne({
|
||||||
|
userId: Existing_User._id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!tokenData) return { status: "Token not found" };
|
||||||
|
await Promise.all([
|
||||||
|
redis.del(`token:${caseChange}`),
|
||||||
|
redis.del(`user:${caseChange}`),
|
||||||
|
]);
|
||||||
|
tokenData.refreshToken = "";
|
||||||
|
await tokenData.save();
|
||||||
|
Existing_User.visitorBrowserID = "";
|
||||||
|
await Existing_User.save();
|
||||||
|
return { status: "Success" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const forgetPassword = async ({
|
||||||
|
Email,
|
||||||
|
}: Iserviceuser): Promise<{ status: string }> => {
|
||||||
|
try {
|
||||||
|
const caseChange = Email.toLowerCase();
|
||||||
|
const organization = extractOrg(caseChange);
|
||||||
|
const Existing_User = await findExistingUserEmail(caseChange);
|
||||||
|
if (Existing_User) {
|
||||||
|
if (Existing_User.lastPasswordReset) {
|
||||||
|
const lastPasswordReset = Existing_User.lastPasswordReset;
|
||||||
|
const now = Date.now();
|
||||||
|
const timeDiff = now - lastPasswordReset;
|
||||||
|
const diffInHours = Math.floor(timeDiff / (1000 * 60 * 60));
|
||||||
|
if (diffInHours < 24)
|
||||||
|
return {
|
||||||
|
status: "You can only reset your password once every 24 hours.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const transport = nodemailer.createTransport({
|
||||||
|
service: "gmail",
|
||||||
|
secure: true,
|
||||||
|
auth: {
|
||||||
|
user: process.env.EMAIL_USER,
|
||||||
|
pass: process.env.EMAIL_PASS,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const resetToken = tokenGenerator(
|
||||||
|
Email,
|
||||||
|
Existing_User.Role as string,
|
||||||
|
Existing_User._id as string,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
const userTokenData = await tokenType(organization).findOne({
|
||||||
|
Email: Email,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!userTokenData) {
|
||||||
|
await tokenType(organization).create({
|
||||||
|
Email: Existing_User.Email,
|
||||||
|
userId: Existing_User._id,
|
||||||
|
resetToken: resetToken,
|
||||||
|
resetTokenExpiry: Date.now(),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
userTokenData.resetToken = resetToken;
|
||||||
|
userTokenData.resetTokenExpiry = new Date();
|
||||||
|
await userTokenData.save();
|
||||||
|
}
|
||||||
|
const Receiver = {
|
||||||
|
from: process.env.EMAIL_USER,
|
||||||
|
to: Email,
|
||||||
|
subject: "Password Reset Request",
|
||||||
|
text: `Click the below link to generate the new password \n ${
|
||||||
|
process.env.CLIENT_URL
|
||||||
|
}/reset-password/${tokenGenerator(
|
||||||
|
Email,
|
||||||
|
Existing_User.Role as string,
|
||||||
|
Existing_User._id as string,
|
||||||
|
organization
|
||||||
|
)}`,
|
||||||
|
};
|
||||||
|
await transport.sendMail(Receiver);
|
||||||
|
|
||||||
|
return { status: "Success" };
|
||||||
|
} else {
|
||||||
|
return { status: "Email not found" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const resetPassword = async ({
|
||||||
|
resetToken,
|
||||||
|
newPassword,
|
||||||
|
confirmPassword,
|
||||||
|
}: IresetToken): Promise<{ status: string }> => {
|
||||||
|
try {
|
||||||
|
const decoded = Jwt.verify(resetToken, "Milestone");
|
||||||
|
if (typeof decoded === "string" || !("email" in decoded))
|
||||||
|
return { status: "Invalid token payload." };
|
||||||
|
|
||||||
|
const Email = decoded.email;
|
||||||
|
const organization = extractOrg(Email);
|
||||||
|
if (newPassword !== confirmPassword) return { status: "Password mismatch" };
|
||||||
|
|
||||||
|
const userData = await AuthModel(organization).findOne({
|
||||||
|
Email: Email,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
const userTokenData = await tokenType(organization).findOne({
|
||||||
|
Email: Email,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!userData || !userTokenData) return { status: "User not found" };
|
||||||
|
else {
|
||||||
|
const tokenexpiry = userTokenData.resetTokenExpiry as Date;
|
||||||
|
const now = Date.now();
|
||||||
|
const tokenAge = tokenexpiry ? now - tokenexpiry.getTime() : 0;
|
||||||
|
const TOKEN_EXPIRATION_TIME = 15 * 60 * 1000;
|
||||||
|
|
||||||
|
if (!tokenexpiry || tokenAge > TOKEN_EXPIRATION_TIME)
|
||||||
|
return { status: "Token is invalid or expired." };
|
||||||
|
const hashPassword = await hashGenerate(newPassword);
|
||||||
|
const lastPasswordReset = Date.now();
|
||||||
|
await AuthModel(organization).findByIdAndUpdate(
|
||||||
|
userData._id,
|
||||||
|
{ Password: hashPassword, lastPasswordReset: lastPasswordReset },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
userTokenData.resetToken = "";
|
||||||
|
userTokenData.resetTokenExpiry = undefined;
|
||||||
|
await userTokenData.save();
|
||||||
|
await ResetFromCacheOrDB(Email);
|
||||||
|
return { status: "Success" };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async function getUserFromCacheOrDB(Email: string) {
|
||||||
|
const redisUserKey = `user:${Email}`;
|
||||||
|
try {
|
||||||
|
const cachedUser = await redis.get(redisUserKey);
|
||||||
|
if (cachedUser) return JSON.parse(cachedUser);
|
||||||
|
|
||||||
|
const Existing_User = await findExistingUserEmail(Email);
|
||||||
|
|
||||||
|
if (Existing_User) {
|
||||||
|
await redis.setex(redisUserKey, 3600, JSON.stringify(Existing_User));
|
||||||
|
}
|
||||||
|
return Existing_User;
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ResetFromCacheOrDB(Email: string) {
|
||||||
|
const redisUserKey = `user:${Email}`;
|
||||||
|
try {
|
||||||
|
const organization = extractOrg(Email);
|
||||||
|
const cachedUser = await redis.get(redisUserKey);
|
||||||
|
if (cachedUser) {
|
||||||
|
const user = await AuthModel(organization)
|
||||||
|
.findOne({
|
||||||
|
Email: Email,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.lean()
|
||||||
|
.select("-__v -Profilepicture");
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
await redis.setex(redisUserKey, 3600, JSON.stringify(user));
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleTokenCache(
|
||||||
|
userId: string,
|
||||||
|
Email: string,
|
||||||
|
token: string,
|
||||||
|
refreshToken: string
|
||||||
|
) {
|
||||||
|
const redisTokenKey = `token:${Email}`;
|
||||||
|
try {
|
||||||
|
const organization = extractOrg(Email);
|
||||||
|
const tokenPayload = {
|
||||||
|
token,
|
||||||
|
refreshToken,
|
||||||
|
userId,
|
||||||
|
Email,
|
||||||
|
};
|
||||||
|
await redis.setex(redisTokenKey, 3600, JSON.stringify(tokenPayload));
|
||||||
|
|
||||||
|
let tokenDoc = await tokenType(organization).findOne({
|
||||||
|
userId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!tokenDoc) {
|
||||||
|
await tokenType(organization).create({ userId, refreshToken });
|
||||||
|
} else {
|
||||||
|
await tokenType(organization).findByIdAndUpdate(
|
||||||
|
tokenDoc._id,
|
||||||
|
{ refreshToken },
|
||||||
|
{ new: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokenPayload;
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
66
src/shared/services/blob/blobServices.ts
Normal file
66
src/shared/services/blob/blobServices.ts
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import { minioClient } from "../../connect/blobConnection.ts";
|
||||||
|
|
||||||
|
type MulterFile = {
|
||||||
|
fieldname: string;
|
||||||
|
originalname: string;
|
||||||
|
encoding: string;
|
||||||
|
mimetype: string;
|
||||||
|
size: number;
|
||||||
|
buffer: Buffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
const bucketName = "assets-public-bucket";
|
||||||
|
|
||||||
|
const publicReadPolicy = {
|
||||||
|
Version: "2012-10-17",
|
||||||
|
Statement: [
|
||||||
|
{
|
||||||
|
Effect: "Allow",
|
||||||
|
Principal: { AWS: "*" },
|
||||||
|
Action: ["s3:GetObject"],
|
||||||
|
Resource: [`arn:aws:s3:::${bucketName}/*`],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
async function ensureBucketExists() {
|
||||||
|
const exists = await minioClient.bucketExists(bucketName);
|
||||||
|
if (!exists) {
|
||||||
|
await minioClient.makeBucket(bucketName, "local-region");
|
||||||
|
console.log("Bucket created");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureFolderExists(folderName: string) {
|
||||||
|
const folderPrefix = folderName.endsWith("/") ? folderName : `${folderName}/`;
|
||||||
|
const objects = minioClient.listObjects(bucketName, folderPrefix, true);
|
||||||
|
for await (const _ of objects) return;
|
||||||
|
await minioClient.putObject(bucketName, folderPrefix, Buffer.from(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setPublicPolicy() {
|
||||||
|
await minioClient.setBucketPolicy(bucketName, JSON.stringify(publicReadPolicy));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function uploadProjectThumbnail(file: MulterFile, folderName: string): Promise<string> {
|
||||||
|
try {
|
||||||
|
const folderName = "models";
|
||||||
|
const objectName = `${folderName}/${Date.now()}_${file.originalname}`;
|
||||||
|
|
||||||
|
|
||||||
|
await ensureBucketExists();
|
||||||
|
await ensureFolderExists(folderName);
|
||||||
|
await minioClient.putObject(bucketName, objectName, file.buffer, file.size, {
|
||||||
|
"Content-Type": file.mimetype,
|
||||||
|
});
|
||||||
|
await setPublicPolicy();
|
||||||
|
|
||||||
|
const encodedName = encodeURIComponent(objectName);
|
||||||
|
const blobUrl = `${process.env.MinIO_USESSL === "true" ? "https" : "http"}://${process.env.MinIO_URL}:${process.env.MINIO_PORT}/${bucketName}/${encodedName}`;
|
||||||
|
|
||||||
|
return blobUrl;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Upload failed:", err);
|
||||||
|
throw new Error("Thumbnail upload failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
154
src/shared/services/builder/AisleService.ts
Normal file
154
src/shared/services/builder/AisleService.ts
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
import AisleModel, {
|
||||||
|
AisleType,
|
||||||
|
Point,
|
||||||
|
} from "../../V1Models/Builder/AisleModel.ts";
|
||||||
|
import {
|
||||||
|
existingProjectById,
|
||||||
|
existingUser,
|
||||||
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
interface IAisleDatas {
|
||||||
|
userId: string;
|
||||||
|
aisleUuid: string;
|
||||||
|
points?: [Point, Point];
|
||||||
|
type?: AisleType;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IAisleDelete {
|
||||||
|
userId: string;
|
||||||
|
aisleUuid: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IProjectAisles {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
export const SetAisle = async (
|
||||||
|
data: IAisleDatas
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { aisleUuid, points, type, organization, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingAisle = await AisleModel(organization).findOne({
|
||||||
|
aisleUuid: aisleUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (ExistingAisle) {
|
||||||
|
const UpdateAisle = await AisleModel(organization).findOneAndUpdate(
|
||||||
|
{ aisleUuid: aisleUuid, projectId: projectId, isArchive: false },
|
||||||
|
{ type: type, points: points },
|
||||||
|
{ new: true, runValidators: true }
|
||||||
|
);
|
||||||
|
if (!UpdateAisle) return { status: "Aisle Not Updated" };
|
||||||
|
return { status: "Aisle Updated Successfully", data: UpdateAisle };
|
||||||
|
} else {
|
||||||
|
const NewAisle = await AisleModel(organization).create({
|
||||||
|
aisleUuid,
|
||||||
|
projectId,
|
||||||
|
type: type,
|
||||||
|
points: points,
|
||||||
|
createdBy: userId,
|
||||||
|
});
|
||||||
|
if (!NewAisle) return { status: "Aisle Not Created" };
|
||||||
|
return { status: "Success", data: NewAisle };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
if (error.name === "ValidationError") {
|
||||||
|
return {
|
||||||
|
status: "Aisle validation failed",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteAisle = async (
|
||||||
|
data: IAisleDelete
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { aisleUuid, organization, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingAisle = await AisleModel(organization).findOne({
|
||||||
|
aisleUuid: aisleUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (ExistingAisle) {
|
||||||
|
await AisleModel(organization).updateOne(
|
||||||
|
{ aisleUuid: aisleUuid, projectId: projectId, isArchive: false },
|
||||||
|
{ isArchive: true }
|
||||||
|
);
|
||||||
|
return { status: "Success" };
|
||||||
|
}
|
||||||
|
return { status: "Aisle not found" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetProjectAisles = async (
|
||||||
|
data: IProjectAisles
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { organization, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingAisle = await AisleModel(organization)
|
||||||
|
.find({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("aisleUuid points type");
|
||||||
|
if (ExistingAisle) {
|
||||||
|
return { status: "Success", data: ExistingAisle };
|
||||||
|
}
|
||||||
|
return { status: "Aisle not found", data: [] };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user