Merge branch 'branch-1' into branch-v2
This commit is contained in:
@@ -3,7 +3,7 @@ ARG NODE_VERSION=lts
|
||||
FROM node:${NODE_VERSION}-alpine AS development
|
||||
# Use production node environment by default.
|
||||
|
||||
ENV NODE_ENV development
|
||||
ENV NODE_ENV = development
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as express from "express";
|
||||
import { assetsFloorservice } from "../controller/simulation/assetsFloorservice.ts";
|
||||
import { AssetsFloorService } from "../controller/simulation/assetsFloorservice.ts";
|
||||
const router = express.Router();
|
||||
router.post("/setasset", assetsFloorservice.setFloorassets);
|
||||
router.get("/floorAssets/:organization", assetsFloorservice.getFloorItems);
|
||||
router.post("/setasset", AssetsFloorService.setFloorassets);
|
||||
router.get("/floorAssets/:organization", AssetsFloorService.getFloorItems);
|
||||
router.patch(
|
||||
"/updateFloorAssets",
|
||||
assetsFloorservice.updateAssetPositionRotation
|
||||
AssetsFloorService.updateAssetPositionRotation
|
||||
);
|
||||
router.patch("/eventDataUpdate", assetsFloorservice.replaceEventDatas);
|
||||
// router.get("/pointData/:modelfileID/:organization", assetsFloorservice.gettypePoints);
|
||||
router.patch("/eventDataUpdate", AssetsFloorService.replaceEventDatas);
|
||||
// router.get("/pointData/:modelfileID/:organization", AssetsFloorService.gettypePoints);
|
||||
export default router;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as express from "express";
|
||||
import { pointService } from "../controller/assets/pointService.ts";
|
||||
import { PointService } from "../controller/assets/pointService.ts";
|
||||
const router = express.Router();
|
||||
router.post("/pointSchema", pointService.addPoints);
|
||||
router.get("/pointData/:modelfileID/:organization", pointService.gettypePoints);
|
||||
router.post("/pointSchema", PointService.addPoints);
|
||||
router.get("/pointData/:modelfileID/:organization", PointService.gettypePoints);
|
||||
export default router;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import express from 'express';
|
||||
import { camera } from '../controller/camera/camera-Services.ts';
|
||||
import { Camera } from '../controller/camera/camera-Services.ts';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/setCamera',camera.createCamera)
|
||||
router.get('/getCamera/:organization/:userId',camera.getCamera)
|
||||
router.get('/activeCameras/:organization',camera.onlineActiveDatas)
|
||||
router.post('/setCamera',Camera.createCamera)
|
||||
router.get('/getCamera/:organization/:userId',Camera.getCamera)
|
||||
router.get('/activeCameras/:organization',Camera.onlineActiveDatas)
|
||||
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import express from 'express';
|
||||
import { environment } from '../controller/environments/environments-Services.ts';
|
||||
import { Environment } from '../controller/environments/environments-Services.ts';
|
||||
|
||||
const router = express.Router();
|
||||
router.post('/setEvironments',environment.setEnvironment)
|
||||
router.get('/findEnvironments/:organization/:userId',environment.getEnvironment)
|
||||
router.post('/setEvironments',Environment.setEnvironment)
|
||||
router.get('/findEnvironments/:organization/:userId',Environment.getEnvironment)
|
||||
|
||||
|
||||
export default router;
|
||||
@@ -1,14 +1,14 @@
|
||||
import * as express from "express";
|
||||
import { floatWidgetService } from "../controller/visualization/floatWidgetService.ts";
|
||||
import { FloatWidgetService } from "../controller/visualization/FloatWidgetService.ts";
|
||||
const router = express.Router();
|
||||
router.post("/floatwidget/save", floatWidgetService.addfloatWidget);
|
||||
router.patch("/floatwidget/delete", floatWidgetService.deletefloatWidget);
|
||||
router.post("/floatwidget/save", FloatWidgetService.addfloatWidget);
|
||||
router.patch("/floatwidget/delete", FloatWidgetService.deletefloatWidget);
|
||||
router.get(
|
||||
"/floadData/:zoneId/:organization",
|
||||
floatWidgetService.getfloatWidget
|
||||
FloatWidgetService.getfloatWidget
|
||||
);
|
||||
router.get(
|
||||
"/A_floatWidget/:floatWidgetID/:organization",
|
||||
floatWidgetService.getsinglefloatWidget
|
||||
FloatWidgetService.getsinglefloatWidget
|
||||
);
|
||||
export default router;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import express from 'express';
|
||||
import { floorItems } from '../controller/assets/flooritem-Services.ts';
|
||||
import { assetsFloorservice } from '../controller/simulation/assetsFloorservice.ts';
|
||||
import express from "express";
|
||||
import { FloorItems } from "../controller/assets/flooritem-Services.ts";
|
||||
import { AssetsFloorService } from "../controller/simulation/assetsFloorservice.ts";
|
||||
|
||||
const router = express.Router();
|
||||
router.post('/setfloorItems',floorItems.setFloorItems)
|
||||
router.get('/findfloorItems/:organization',floorItems.getFloorItems)
|
||||
router.post("/setfloorItems", FloorItems.setFloorItems);
|
||||
router.get("/findfloorItems/:organization", FloorItems.getFloorItems);
|
||||
// router.delete('/deletefloorItem',floorItems.deleteFloorItems)
|
||||
router.delete('/deletefloorItem',assetsFloorservice.deleteFloorItems)
|
||||
router.delete("/deletefloorItem", AssetsFloorService.deleteFloorItems);
|
||||
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import express from 'express';
|
||||
import { lines } from '../controller/lines/line-Services.ts';
|
||||
|
||||
import express from "express";
|
||||
import { Lines } from "../controller/lines/line-Services.ts";
|
||||
|
||||
const router = express.Router();
|
||||
router.post('/setLine',lines.setLines)
|
||||
router.post('/updatePoint',lines.updateLines)
|
||||
router.get('/findLines/:organization',lines.getLines)
|
||||
router.delete('/deleteLine',lines.deleteLineItems)
|
||||
router.delete('/deletePoint',lines.deleteLinPoiteItems)
|
||||
router.post('/deleteLayer',lines.deleteLayer)
|
||||
router.post("/setLine", Lines.setLines);
|
||||
router.post("/updatePoint", Lines.updateLines);
|
||||
router.get("/findLines/:organization", Lines.getLines);
|
||||
router.delete("/deleteLine", Lines.deleteLineItems);
|
||||
router.delete("/deletePoint", Lines.deleteLinPoiteItems);
|
||||
router.post("/deleteLayer", Lines.deleteLayer);
|
||||
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as express from "express";
|
||||
import { panelService } from "../controller/visualization/panelService.ts";
|
||||
import { PanelService } from "../controller/visualization/PanelService.ts";
|
||||
const router = express.Router();
|
||||
/**
|
||||
* @swagger
|
||||
@@ -101,7 +101,7 @@ const router = express.Router();
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.post("/panel/save", panelService.AddPanel);
|
||||
router.post("/panel/save", PanelService.AddPanel);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -135,8 +135,8 @@ router.post("/panel/save", panelService.AddPanel);
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.patch("/panel/delete", panelService.deletePanel);
|
||||
router.patch("/clearpanel", panelService.clearPanel);
|
||||
router.patch("/panel/delete", PanelService.deletePanel);
|
||||
router.patch("/clearpanel", PanelService.clearPanel);
|
||||
|
||||
// router.get("/zone/:sceneID", Zoneservice.allZones);
|
||||
export default router;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
// import * as express from "express";
|
||||
// import { productFlowservice } from "../controller/simulation/productFlowservice.ts";
|
||||
// const router = express.Router();
|
||||
// router.post("/createProduct", productFlowservice.setproductFlow);
|
||||
// router.get("/productFlowList/:organization", productFlowservice.productpathsList);
|
||||
// export default router;
|
||||
@@ -1,11 +1,13 @@
|
||||
import * as express from "express";
|
||||
import { productFlowservice } from "../controller/simulation/productService.ts";
|
||||
import { ProductFlowservice } from "../controller/simulation/productService.ts";
|
||||
const productRouter = express.Router();
|
||||
productRouter.post("/UpsertProductOrEvent", productFlowservice.productAdd);
|
||||
productRouter.get("/productData", productFlowservice.getProductDatas);
|
||||
productRouter.patch("/EventDataDelete", productFlowservice.EventDataDelete);
|
||||
productRouter.patch("/productDataDelete", productFlowservice.productDataDelete);
|
||||
productRouter.get("/AllProducts/:organization", productFlowservice.AllProductDatas);
|
||||
productRouter.patch("/productRename", productFlowservice.productRename);
|
||||
productRouter.post("/UpsertProductOrEvent", ProductFlowservice.productAdd);
|
||||
productRouter.get("/productData", ProductFlowservice.getProductDatas);
|
||||
productRouter.patch("/EventDataDelete", ProductFlowservice.EventDataDelete);
|
||||
productRouter.patch("/productDataDelete", ProductFlowservice.productDataDelete);
|
||||
productRouter.get(
|
||||
"/AllProducts/:organization",
|
||||
ProductFlowservice.AllProductDatas
|
||||
);
|
||||
productRouter.patch("/productRename", ProductFlowservice.productRename);
|
||||
export default productRouter;
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import express from 'express';
|
||||
import { share } from '../controller/share/share-Controller.ts';
|
||||
import { Share } from '../controller/share/share-Controller.ts';
|
||||
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/shareUser',share.shareUser)
|
||||
router.get('/findshareUsers',share.findshareUser)
|
||||
router.post('/shareUser',Share.shareUser)
|
||||
router.get('/findshareUsers',Share.findshareUser)
|
||||
|
||||
|
||||
export default router;
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as express from "express";
|
||||
import { templateService } from "../controller/visualization/templateService.ts";
|
||||
import { TemplateService } from "../controller/visualization/templateService.ts";
|
||||
const router = express.Router();
|
||||
router.post("/template/save", templateService.AddTemplate);
|
||||
router.get("/templateData/:organization", templateService.GetAllTemplates);
|
||||
router.post("/TemplatetoZone", templateService.AddToZone);
|
||||
router.post("/template/save", TemplateService.AddTemplate);
|
||||
router.get("/templateData/:organization", TemplateService.GetAllTemplates);
|
||||
router.post("/TemplatetoZone", TemplateService.AddToZone);
|
||||
router.patch(
|
||||
"/TemplateDelete/:templateID/:organization",
|
||||
templateService.Deletezone
|
||||
TemplateService.Deletezone
|
||||
); //delete zone
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import express from 'express';
|
||||
import { user } from '../controller/user-Controller.ts';
|
||||
import express from "express";
|
||||
import { User } from "../controller/user-Controller.ts";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/signup',user.signup)
|
||||
router.post('/login',user.login)
|
||||
|
||||
router.post("/signup", User.signup);
|
||||
router.post("/login", User.login);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import express from 'express';
|
||||
import { wallItems } from '../controller/assets/wallitem-Services.ts';
|
||||
|
||||
import express from "express";
|
||||
import { WallItems } from "../controller/assets/wallitem-Services.ts";
|
||||
|
||||
const router = express.Router();
|
||||
router.post('/setWallItems',wallItems.setWallItems)
|
||||
router.get('/findWallItems/:organization',wallItems.getWallItems)
|
||||
router.delete('/deleteWallItem',wallItems.deleteWallItems)
|
||||
router.post("/setWallItems", WallItems.setWallItems);
|
||||
router.get("/findWallItems/:organization", WallItems.getWallItems);
|
||||
router.delete("/deleteWallItem", WallItems.deleteWallItems);
|
||||
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as express from "express";
|
||||
import { widget3dService } from "../controller/visualization/3dWidgetService.ts";
|
||||
import { Widget3dService } from "../controller/visualization/3dWidgetService.ts";
|
||||
const router = express.Router();
|
||||
router.post("/3dwidget/save", widget3dService.add3Dwidget);
|
||||
router.get("/3dwidgetData/:zoneId/:organization", widget3dService.get3Dwiget);
|
||||
router.get("/widget3D/:id/:organization", widget3dService.getSingle3Dwidget);
|
||||
router.patch("/widget3D/delete", widget3dService.delete3Dwidget);
|
||||
router.patch("/modifyPR/widget3D", widget3dService.update3DpositionRotation);
|
||||
router.post("/3dwidget/save", Widget3dService.add3Dwidget);
|
||||
router.get("/3dwidgetData/:zoneId/:organization", Widget3dService.get3Dwiget);
|
||||
router.get("/widget3D/:id/:organization", Widget3dService.getSingle3Dwidget);
|
||||
router.patch("/widget3D/delete", Widget3dService.delete3Dwidget);
|
||||
router.patch("/modifyPR/widget3D", Widget3dService.update3DpositionRotation);
|
||||
export default router;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as express from "express";
|
||||
import { widgetService } from "../controller/visualization/widgetService.ts";
|
||||
import { WidgetService } from "../controller/visualization/widgetService.ts";
|
||||
const router = express.Router();
|
||||
/**
|
||||
* @swagger
|
||||
@@ -134,11 +134,11 @@ const router = express.Router();
|
||||
* 500:
|
||||
* description: Server error
|
||||
*/
|
||||
router.post("/widget/save", widgetService.addWidget);
|
||||
router.patch("/widget/:widgetID", widgetService.updatewidget);
|
||||
router.patch("/delete/widget", widgetService.deleteWidget);
|
||||
router.post("/widget/save", WidgetService.addWidget);
|
||||
router.patch("/widget/:widgetID", WidgetService.updatewidget);
|
||||
router.patch("/delete/widget", WidgetService.deleteWidget);
|
||||
router.get(
|
||||
"/WidgetData/:widgetID/:organization",
|
||||
widgetService.getDatafromWidget
|
||||
WidgetService.getDatafromWidget
|
||||
);
|
||||
export default router;
|
||||
|
||||
@@ -1,14 +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)
|
||||
// router.get('/A_zone/:zoneId/:organization',zone.ZoneData)
|
||||
|
||||
|
||||
|
||||
export default router;
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as express from "express";
|
||||
import { Zoneservice } from "../controller/lines/zoneService.ts";
|
||||
import { ZoneService } from "../controller/lines/zoneService.ts";
|
||||
|
||||
const router = express.Router();
|
||||
/**
|
||||
* @swagger
|
||||
@@ -245,7 +246,7 @@ const router = express.Router();
|
||||
* type: string
|
||||
* example: "Internal server error"
|
||||
*/
|
||||
router.post("/zone/save", Zoneservice.addandUpdateZone); //Zone create and update for the points
|
||||
router.post("/zone/save", ZoneService.addandUpdateZone); //Zone create and update for the points
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -318,9 +319,9 @@ router.post("/zone/save", Zoneservice.addandUpdateZone); //Zone create and updat
|
||||
* value:
|
||||
* message: "Zone not found for the UUID"
|
||||
*/
|
||||
router.get("/zones/:sceneID", Zoneservice.allZones);
|
||||
router.get("/zones/:sceneID", ZoneService.allZones);
|
||||
|
||||
router.get("/pageZodeData", Zoneservice.vizAllDatas);
|
||||
router.get("/pageZodeData", ZoneService.vizAllDatas);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -414,7 +415,7 @@ router.get("/pageZodeData", Zoneservice.vizAllDatas);
|
||||
* example:
|
||||
* error: "Internal Server Error"
|
||||
*/
|
||||
router.get("/ZoneVisualization/:zoneId", Zoneservice.singleZonePanelDatas);
|
||||
router.get("/ZoneVisualization/:zoneId", ZoneService.singleZonePanelDatas);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -483,7 +484,7 @@ router.get("/ZoneVisualization/:zoneId", Zoneservice.singleZonePanelDatas);
|
||||
* value:
|
||||
* message: "Zone not found"
|
||||
*/
|
||||
router.get("/A_zone/:zoneId/:organization", Zoneservice.ZoneData);
|
||||
router.get("/A_zone/:zoneId/:organization", ZoneService.ZoneData);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -536,7 +537,6 @@ router.get("/A_zone/:zoneId/:organization", Zoneservice.ZoneData);
|
||||
* type: string
|
||||
* example: "Internal Server Error"
|
||||
*/
|
||||
router.patch("/zone/:zoneId", Zoneservice.deleteAZone); //delete Zone
|
||||
// router.get("/zone/:sceneID", Zoneservice.allZones);
|
||||
router.patch("/zones/lockedPanels", Zoneservice.lockedPanel);
|
||||
router.patch("/zone/:zoneId", ZoneService.deleteAZone); //delete Zone
|
||||
router.patch("/zones/lockedPanels", ZoneService.lockedPanel);
|
||||
export default router;
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
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 {
|
||||
console.log("req.body: ", req.body);
|
||||
const { userName, Email, Password, profilePicture } = 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;
|
||||
console.log("req.body: ", 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,115 @@
|
||||
import { Request, Response } from "express";
|
||||
|
||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||
import {
|
||||
GetCamers,
|
||||
SetCamera,
|
||||
} from "../../../../shared/services/builder/cameraService.ts";
|
||||
|
||||
export const SetNewCamera = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { organization, role, userId } = req.user || {};
|
||||
const { position, target, rotation, projectId, versionId } = req.body;
|
||||
if (
|
||||
!organization ||
|
||||
!role ||
|
||||
!userId ||
|
||||
!position ||
|
||||
!target ||
|
||||
!rotation ||
|
||||
!projectId ||
|
||||
!versionId
|
||||
) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const data = {
|
||||
position,
|
||||
target,
|
||||
rotation,
|
||||
projectId,
|
||||
versionId,
|
||||
organization,
|
||||
role,
|
||||
userId,
|
||||
};
|
||||
const result = await SetCamera(data);
|
||||
|
||||
switch (result.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
TrashDatas: [],
|
||||
});
|
||||
break;
|
||||
|
||||
case "Update Success":
|
||||
res.status(200).json({
|
||||
TrashDatas: result.data,
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
TrashDatas: result.data,
|
||||
});
|
||||
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 CameraList = 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 GetCamers({
|
||||
organization,
|
||||
role,
|
||||
userId,
|
||||
});
|
||||
|
||||
switch (result.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
TrashDatas: [],
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
TrashDatas: 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,151 @@
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
RecentlyAdded,
|
||||
searchProject,
|
||||
searchTrashProject,
|
||||
} from "../../../../shared/services/v1home/v1homeservice.ts";
|
||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||
|
||||
export const recentDataController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<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: 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;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,270 @@
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
createProject,
|
||||
DeleteProject,
|
||||
GetAllProjects,
|
||||
updateProject,
|
||||
viewProject,
|
||||
} from "../../../../shared/services/v1Project/v1projectservice.ts";
|
||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||
|
||||
export const createProjectController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.user || {};
|
||||
console.log("req.user: ", req.user);
|
||||
const { projectUuid, thumbnail } = req.body;
|
||||
if (!req.user || !req.user.userId || !req.user.organization) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (!projectUuid || !thumbnail) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await createProject({ ...req.body, userId, organization });
|
||||
|
||||
switch (result.status) {
|
||||
case "project_exists":
|
||||
res.status(403).json({
|
||||
message: "Project already exists",
|
||||
});
|
||||
break;
|
||||
|
||||
case "user_not_found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
|
||||
case "Success":
|
||||
res.status(201).json({
|
||||
message: "Project created Successfully",
|
||||
projectId: result.project._id,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const GetProjects = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization, role } = req.user || {};
|
||||
// const { userId, organization } = req.params;
|
||||
if (!userId || !organization || !role) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await GetAllProjects({ userId, organization, role });
|
||||
switch (result?.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
|
||||
case "Success":
|
||||
res.status(201).json({
|
||||
Projects: result?.Datas,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const RemoveProject = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { projectId } = req.params;
|
||||
// const { organization, userId } = req.body;
|
||||
const { organization, userId, role } = req.user || {};
|
||||
if (
|
||||
!req.user ||
|
||||
!req.user.userId ||
|
||||
!req.user.organization ||
|
||||
!req.user.role
|
||||
) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (!projectId || !organization || !userId || !role) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await DeleteProject({
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
role,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(201).json({
|
||||
message: "Project Deleted Successfully",
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const updateProjectController = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<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 ||
|
||||
!req.user.userId ||
|
||||
!req.user.organization ||
|
||||
!req.user.role
|
||||
) {
|
||||
res.status(401).json({ message: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
const { projectId } = req.params as {
|
||||
projectId: string;
|
||||
};
|
||||
if (!userId || !organization || !projectId || !role) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await viewProject({
|
||||
projectId,
|
||||
organization,
|
||||
userId,
|
||||
role,
|
||||
});
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
message: "Project not found",
|
||||
});
|
||||
break;
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
projectData: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,99 @@
|
||||
import { Request, Response } from "express";
|
||||
import {
|
||||
TrashDatas,
|
||||
RestoreTrashData,
|
||||
} from "../../../../shared/services/v1trash/v1trashservice.ts";
|
||||
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||
|
||||
export const GetTrashList = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<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 "Trash is Empty":
|
||||
res.status(200).json({
|
||||
message: "Trash is Empty",
|
||||
TrashDatas: [],
|
||||
});
|
||||
break;
|
||||
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
TrashDatas: result.ListDatas,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const RestoreTrash = async (
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<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 "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",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Request, Response } from "express";
|
||||
import versionService from "../../../../shared/services/version/versionService.ts";
|
||||
|
||||
export const versioncontroller = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const { projectId, userId, description, db } = req.body;
|
||||
// if (!userName || !Email || !description) {
|
||||
// res.status(400).json({
|
||||
// message: "All fields are required",
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
const result = await versionService.saveCurrentStateAsVersion(
|
||||
db,
|
||||
projectId,
|
||||
userId,
|
||||
description
|
||||
);
|
||||
|
||||
console.log(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "An unexpected error occurred",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
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;
|
||||
16
src/api-server/V1/v1Routes/v1-homeRoutes.ts
Normal file
16
src/api-server/V1/v1Routes/v1-homeRoutes.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import express from "express";
|
||||
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||
import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
|
||||
import { recentDataController } from "../../V1/v1Controllers/homeController/v1homeController.ts";
|
||||
|
||||
const v1homeRoutes = express.Router();
|
||||
|
||||
//home-Page
|
||||
v1homeRoutes.get(
|
||||
"/RecentlyViewed",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
recentDataController
|
||||
);
|
||||
|
||||
export default v1homeRoutes;
|
||||
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,
|
||||
RemoveProject,
|
||||
updateProjectController,
|
||||
ViewData,
|
||||
} from "../../V1/v1Controllers/projectController/v1projectController.ts";
|
||||
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||
import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
|
||||
|
||||
const v1projectRouter = express.Router();
|
||||
|
||||
// project
|
||||
v1projectRouter.post("/upsertProject", tokenValidator, createProjectController);
|
||||
v1projectRouter.get(
|
||||
"/Projects",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
GetProjects
|
||||
);
|
||||
v1projectRouter.patch(
|
||||
"/Project/archive/:projectId",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
RemoveProject
|
||||
);
|
||||
|
||||
v1projectRouter.patch(
|
||||
"/Project/:projectId",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
updateProjectController
|
||||
);
|
||||
v1projectRouter.get(
|
||||
"/Project/:projectId",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
ViewData
|
||||
);
|
||||
|
||||
export default v1projectRouter;
|
||||
25
src/api-server/V1/v1Routes/v1-trashRoutes.ts
Normal file
25
src/api-server/V1/v1Routes/v1-trashRoutes.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import express from "express";
|
||||
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||
import authorizedRoles from "../../../shared/middleware/rbacMiddleware.ts";
|
||||
import {
|
||||
GetTrashList,
|
||||
RestoreTrash,
|
||||
} from "../../V1/v1Controllers/trashController/v1trashController.ts";
|
||||
|
||||
const v1TrashRoutes = express.Router();
|
||||
|
||||
//trash
|
||||
v1TrashRoutes.get(
|
||||
"/TrashItems ",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
GetTrashList
|
||||
);
|
||||
|
||||
v1TrashRoutes.patch(
|
||||
"/Trash/restore",
|
||||
tokenValidator,
|
||||
authorizedRoles("Admin", "User"),
|
||||
RestoreTrash
|
||||
);
|
||||
export default v1TrashRoutes;
|
||||
@@ -1,6 +1,5 @@
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import connectDB from "../shared/connect/mongoose.ts";
|
||||
import dotenv from "dotenv";
|
||||
import cameraRoutes from "./Routes/camera-Routes.ts";
|
||||
import environmentsRoutes from "./Routes/environments-Routes.ts";
|
||||
@@ -9,8 +8,7 @@ import flooritemRoutes from "./Routes/flooritem-Routes.ts";
|
||||
import WallitemRoutes from "./Routes/wallItems-Routes.ts";
|
||||
import userRoutes from "./Routes/user-Routes.ts";
|
||||
import shareRoutes from "./Routes/share-Routes.ts";
|
||||
import zoneRoutes from "./Routes/zone-Routes.ts";
|
||||
import zoneRoutes2 from "./Routes/zoneRoutes.ts"; //update
|
||||
import zoneRoutes from "./Routes/zoneRoutes.ts"; //update
|
||||
import panelRouter from "./Routes/panelRoutes.ts";
|
||||
import widgetRouter from "./Routes/widgetRoute.ts";
|
||||
import assetpointRouter from "./Routes/assetpointRoutes.ts";
|
||||
@@ -22,8 +20,13 @@ import productRouter from "./Routes/productRoutes.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 v1TrashRoutes from "./V1/v1Routes/v1-trashRoutes.ts";
|
||||
import v1homeRoutes from "./V1/v1Routes/v1-homeRoutes.ts";
|
||||
import v1projectRouter from "./V1/v1Routes/v1-projectRoutes.ts";
|
||||
// import productFlowRoutes from "./Routes/productFlowRouts.ts";
|
||||
|
||||
redis;
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
// const allowedOriginsDev = [
|
||||
@@ -64,7 +67,6 @@ dotenv.config();
|
||||
app.get("/", (req, res) => {
|
||||
res.send("Hello, I am Major-Dwinzo API!");
|
||||
});
|
||||
// connectDB();
|
||||
app.get("/health", (req, res) => {
|
||||
res.status(200).json({ message: "Server is running" });
|
||||
});
|
||||
@@ -76,9 +78,8 @@ app.use("/api/v1", flooritemRoutes);
|
||||
app.use("/api/v1", WallitemRoutes);
|
||||
app.use("/api/v1", userRoutes);
|
||||
app.use("/api/v1", shareRoutes);
|
||||
app.use("/api/v2", zoneRoutes);
|
||||
//update
|
||||
app.use("/api/v2", zoneRoutes2); //updates
|
||||
app.use("/api/v2", zoneRoutes); //updates
|
||||
app.use("/api/v2", panelRouter);
|
||||
app.use("/api/v2", widgetRouter);
|
||||
app.use("/api/v2", assetpointRouter);
|
||||
@@ -91,4 +92,11 @@ app.use("/api/v2", productRouter);
|
||||
app.use("/api/v1", projectRouter);
|
||||
app.use("/api/v1", trashRouter);
|
||||
app.use("/api/v1", homePageRouter);
|
||||
|
||||
//New versions--based on the token and role based
|
||||
app.use("/api/v2", Authrouter);
|
||||
app.use("/api/v2", v1projectRouter);
|
||||
app.use("/api/v2", v1TrashRoutes);
|
||||
app.use("/api/v2", v1homeRoutes);
|
||||
|
||||
export default app;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Request, Response } from "express";
|
||||
import floorItemsModel from "../../../shared/model/assets/flooritems-Model.ts";
|
||||
|
||||
export class floorItems {
|
||||
export class FloorItems {
|
||||
static async setFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const {
|
||||
@@ -57,7 +57,6 @@ export class floorItems {
|
||||
static async getFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
// console.log('req.params: ', req.params);
|
||||
|
||||
const findValue = await floorItemsModel(organization).find();
|
||||
if (!findValue) {
|
||||
|
||||
@@ -74,7 +74,7 @@ interface IPointStaticMachine extends IPointBase {
|
||||
targets: { modelUUID: string; pointUUID: string }[];
|
||||
};
|
||||
}
|
||||
export class pointService {
|
||||
export class PointService {
|
||||
static async addPoints(req: Request, res: Response): Promise<any> {
|
||||
const { type, modelfileID, organization } = req.body;
|
||||
|
||||
|
||||
@@ -1,80 +1,92 @@
|
||||
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 {
|
||||
static async setWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const {
|
||||
modelUuid,
|
||||
modelName,
|
||||
position,
|
||||
type,
|
||||
csgposition,
|
||||
csgscale,
|
||||
quaternion,
|
||||
scale,
|
||||
organization,
|
||||
} = req.body;
|
||||
|
||||
export class wallItems {
|
||||
static async setWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modelUuid, modelName, position, type, csgposition,csgscale,quaternion,scale,organization } = req.body
|
||||
|
||||
const findvalue = await wallItemModel(organization).findOne({
|
||||
modelUuid: modelUuid,
|
||||
});
|
||||
|
||||
const findvalue = await wallItenmModel(organization).findOne({ modelUuid: modelUuid})
|
||||
|
||||
if (findvalue) {
|
||||
const updatevalue = await wallItenmModel(organization).findOneAndUpdate(
|
||||
{ modelUuid: modelUuid },
|
||||
{
|
||||
modelName,
|
||||
position,
|
||||
type,
|
||||
csgposition,
|
||||
csgscale,
|
||||
quaternion,
|
||||
scale,
|
||||
},
|
||||
{ new: true } // Return the updated document
|
||||
);
|
||||
res.status(201).json(updatevalue);
|
||||
|
||||
if (findvalue) {
|
||||
const updatevalue = await wallItemModel(organization).findOneAndUpdate(
|
||||
{ modelUuid: modelUuid },
|
||||
{
|
||||
modelName,
|
||||
position,
|
||||
type,
|
||||
csgposition,
|
||||
csgscale,
|
||||
quaternion,
|
||||
scale,
|
||||
},
|
||||
{ new: true } // Return the updated document
|
||||
);
|
||||
res.status(201).json(updatevalue);
|
||||
} else {
|
||||
const newValue = await wallItemModel(organization).create({
|
||||
modelUuid,
|
||||
modelName,
|
||||
position,
|
||||
type,
|
||||
csgposition,
|
||||
csgscale,
|
||||
quaternion,
|
||||
scale,
|
||||
});
|
||||
|
||||
} else {
|
||||
const newValue = await wallItenmModel(organization).create({ modelUuid,modelName, position, type, csgposition,csgscale,quaternion,scale });
|
||||
res.status(201).json(newValue);
|
||||
}
|
||||
|
||||
|
||||
res.status(201).json(newValue);
|
||||
|
||||
}
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating wallitems:', error);
|
||||
res.status(500).json({ message: "Failed to create wallitems" });
|
||||
}
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error("Error creating wallitems:", error);
|
||||
res.status(500).json({ message: "Failed to create wallitems" });
|
||||
}
|
||||
static async getWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
|
||||
}
|
||||
static async getWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
|
||||
const findValue = await wallItenmModel
|
||||
(organization).find()
|
||||
if (!findValue) {
|
||||
res.status(200).json("wallitems not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get wallitems:', error);
|
||||
res.status(500).json({ error: "Failed to get wallitems" });
|
||||
}
|
||||
const findValue = await wallItemModel(organization).find();
|
||||
if (!findValue) {
|
||||
res.status(200).json("wallitems not found");
|
||||
} else {
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get wallitems:", error);
|
||||
res.status(500).json({ error: "Failed to get wallitems" });
|
||||
}
|
||||
static async deleteWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modelUuid,modelName,organization } = req.body;
|
||||
|
||||
}
|
||||
static async deleteWallItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modelUuid, modelName, organization } = req.body;
|
||||
|
||||
const findValue = await wallItenmModel
|
||||
(organization).findOneAndDelete({modelUuid:modelUuid,modelName:modelName})
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get wallitems:', error);
|
||||
res.status(500).json({ error: "Failed to get wallitems" });
|
||||
}
|
||||
const findValue = await wallItemModel(organization).findOneAndDelete({
|
||||
modelUuid: modelUuid,
|
||||
modelName: modelName,
|
||||
});
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get wallitems:", error);
|
||||
res.status(500).json({ error: "Failed to get wallitems" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,88 +2,96 @@ import { Request, Response } from "express";
|
||||
import cameraModel from "../../../shared/model/camera/camera-Model.ts";
|
||||
import userModel from "../../../shared/model/user-Model.ts";
|
||||
|
||||
export class camera {
|
||||
static async createCamera(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId, position, target, rotation,organization } = req.body
|
||||
|
||||
export class Camera {
|
||||
static async createCamera(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId, position, target, rotation, organization } = req.body;
|
||||
|
||||
const findCamera = await cameraModel(organization).findOne({ userId: userId })
|
||||
|
||||
if (findCamera) {
|
||||
const updateCamera = await cameraModel(organization).findOneAndUpdate(
|
||||
{ userId: userId }, { position: position, target: target,rotation:rotation }, { new: true });
|
||||
res.status(201).json(updateCamera);
|
||||
const findCamera = await cameraModel(organization).findOne({
|
||||
userId: userId,
|
||||
});
|
||||
|
||||
} else {
|
||||
const newCamera = await cameraModel(organization).create({ userId, position, target,rotation });
|
||||
|
||||
res.status(201).json(newCamera);
|
||||
|
||||
}
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating camera:', error);
|
||||
res.status(500).json({message:"Failed to create camera"});
|
||||
}
|
||||
}
|
||||
static async getCamera(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId, organization } = req.params;
|
||||
|
||||
// if (!userId) {
|
||||
// res.status(201).json("User data is insufficient");
|
||||
// }
|
||||
const findCamera = await cameraModel(organization).findOne({ userId: userId })
|
||||
if (!findCamera) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findCamera);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get camera:', error);
|
||||
res.status(500).json({ error: "Failed to get camera" });
|
||||
}
|
||||
}
|
||||
|
||||
static async onlineActiveDatas(req: Request, res: Response) {
|
||||
const {organization } = req.params;
|
||||
try {
|
||||
const findactiveUsers = await userModel(organization).find({activeStatus:"online"})
|
||||
|
||||
|
||||
const cameraDataPromises = findactiveUsers.map(async (activeUser:any) => {
|
||||
const cameraData = await cameraModel(organization)
|
||||
.findOne({ userId: activeUser._id })
|
||||
.select("position target rotation -_id");
|
||||
|
||||
if (cameraData) {
|
||||
return {
|
||||
position: cameraData.position,
|
||||
target: cameraData.target,
|
||||
rotation:cameraData.rotation,
|
||||
userData: {
|
||||
_id: activeUser._id,
|
||||
userName: activeUser.userName,
|
||||
email: activeUser.email,
|
||||
activeStatus: activeUser.activeStatus,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Return null if no camera data is found for the user
|
||||
return null;
|
||||
if (findCamera) {
|
||||
const updateCamera = await cameraModel(organization).findOneAndUpdate(
|
||||
{ userId: userId },
|
||||
{ position: position, target: target, rotation: rotation },
|
||||
{ new: true }
|
||||
);
|
||||
res.status(201).json(updateCamera);
|
||||
} else {
|
||||
const newCamera = await cameraModel(organization).create({
|
||||
userId,
|
||||
position,
|
||||
target,
|
||||
rotation,
|
||||
});
|
||||
|
||||
const cameraDatas = (await Promise.all(cameraDataPromises)).filter((singledata:any) => singledata !== null);
|
||||
res.status(201).json(newCamera);
|
||||
}
|
||||
|
||||
|
||||
res.status(200).send({ cameraDatas });
|
||||
|
||||
} catch (error:any) {
|
||||
res.status(500).send(error);
|
||||
}
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error("Error creating camera:", error);
|
||||
res.status(500).json({ message: "Failed to create camera" });
|
||||
}
|
||||
}
|
||||
static async getCamera(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId, organization } = req.params;
|
||||
|
||||
const findCamera = await cameraModel(organization).findOne({
|
||||
userId: userId,
|
||||
});
|
||||
if (!findCamera) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
res.status(201).json(findCamera);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get camera:", error);
|
||||
res.status(500).json({ error: "Failed to get camera" });
|
||||
}
|
||||
}
|
||||
|
||||
static async onlineActiveDatas(req: Request, res: Response) {
|
||||
const { organization } = req.params;
|
||||
try {
|
||||
const findactiveUsers = await userModel(organization).find({
|
||||
activeStatus: "online",
|
||||
});
|
||||
|
||||
const cameraDataPromises = findactiveUsers.map(
|
||||
async (activeUser: any) => {
|
||||
const cameraData = await cameraModel(organization)
|
||||
.findOne({ userId: activeUser._id })
|
||||
.select("position target rotation -_id");
|
||||
|
||||
if (cameraData) {
|
||||
return {
|
||||
position: cameraData.position,
|
||||
target: cameraData.target,
|
||||
rotation: cameraData.rotation,
|
||||
userData: {
|
||||
_id: activeUser._id,
|
||||
userName: activeUser.userName,
|
||||
email: activeUser.email,
|
||||
activeStatus: activeUser.activeStatus,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Return null if no camera data is found for the user
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
const cameraDatas = (await Promise.all(cameraDataPromises)).filter(
|
||||
(singledata: any) => singledata !== null
|
||||
);
|
||||
|
||||
res.status(200).send({ cameraDatas });
|
||||
} catch (error: any) {
|
||||
res.status(500).send(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Request, Response } from "express";
|
||||
import environmentModel from "../../../shared/model/environments/environments-Model.ts";
|
||||
|
||||
export class environment {
|
||||
export class Environment {
|
||||
static async setEnvironment(req: Request, res: Response) {
|
||||
try {
|
||||
const {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { Request, Response } from "express";
|
||||
import { RecentlyAdded, searchProject, searchTrashProject } from "../../../shared/services/home/homeService.ts";
|
||||
import {
|
||||
RecentlyAdded,
|
||||
searchProject,
|
||||
searchTrashProject,
|
||||
} from "../../../shared/services/home/homeService.ts";
|
||||
|
||||
export const recentDataController = async (
|
||||
req: Request,
|
||||
@@ -44,7 +48,10 @@ export const recentDataController = async (
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const searchProjectController = async (req: Request, res: Response): Promise<void> => {
|
||||
export const searchProjectController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { searchName, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
@@ -91,7 +98,10 @@ export const searchProjectController = async (req: Request, res: Response): Prom
|
||||
return;
|
||||
}
|
||||
};
|
||||
export const searchTrashProjectController = async (req: Request, res: Response): Promise<void> => {
|
||||
export const searchTrashProjectController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { searchName, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
@@ -137,4 +147,4 @@ export const searchTrashProjectController = async (req: Request, res: Response):
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,125 +1,116 @@
|
||||
import { Request, Response } from "express";
|
||||
import lineModel from "../../../shared/model/lines/lines-Model.ts";
|
||||
|
||||
export class lines {
|
||||
static async setLines(req: Request, res: Response) {
|
||||
try {
|
||||
const {organization,layer,line,type}=req.body
|
||||
const newLine = await lineModel(organization).create({ layer,line,type });
|
||||
|
||||
|
||||
res.status(201).json(newLine);
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating Lines:', error);
|
||||
res.status(500).json({message:"Failed to create Lines"});
|
||||
}
|
||||
export class Lines {
|
||||
static async setLines(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization, layer, line, type } = req.body;
|
||||
const newLine = await lineModel(organization).create({
|
||||
layer,
|
||||
line,
|
||||
type,
|
||||
});
|
||||
|
||||
res.status(201).json(newLine);
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error("Error creating Lines:", error);
|
||||
res.status(500).json({ message: "Failed to create Lines" });
|
||||
}
|
||||
static async updateLines(req: Request, res: Response) {
|
||||
try {
|
||||
const {organization,uuid,position,}=req.body
|
||||
// const findLine = await lineModel(organization).find({ 'line.uuid': uuid });
|
||||
// Update the position of the line matching the uuid
|
||||
}
|
||||
static async updateLines(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization, uuid, position } = req.body;
|
||||
// const findLine = await lineModel(organization).find({ 'line.uuid': uuid });
|
||||
// Update the position of the line matching the uuid
|
||||
const updateResult = await lineModel(organization).updateMany(
|
||||
{ "line.uuid": uuid }, // Filter: Find the line with the given uuid
|
||||
{ $set: { "line.$.position": position } } // Update the position and type
|
||||
);
|
||||
|
||||
res.status(201).json(updateResult);
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error("Error creating Lines:", error);
|
||||
res.status(500).json({ message: "Failed to create Lines" });
|
||||
}
|
||||
}
|
||||
static async getLines(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
|
||||
const findValue = await lineModel(organization).find();
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get Lines:", error);
|
||||
res.status(500).json({ error: "Failed to get Lines" });
|
||||
}
|
||||
}
|
||||
static async deleteLineItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization, layer, line, type } = req.body;
|
||||
|
||||
const inputUuids = line.map((item: any) => item.uuid);
|
||||
const findValue = await lineModel(organization).findOneAndDelete({
|
||||
"line.uuid": { $all: inputUuids },
|
||||
});
|
||||
|
||||
if (!findValue) {
|
||||
res.status(200).json("data not found");
|
||||
} else {
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error delete Lines:", error);
|
||||
res.status(500).json({ error: "Failed to delete Lines" });
|
||||
}
|
||||
}
|
||||
static async deleteLinPoiteItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization, layer, uuid, type } = req.body;
|
||||
|
||||
const findValue = await lineModel(organization).deleteMany({
|
||||
"line.uuid": uuid,
|
||||
});
|
||||
|
||||
if (!findValue) {
|
||||
res.status(200).json("data not found");
|
||||
} else {
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error delete Lines:", error);
|
||||
res.status(500).json({ error: "Failed to delete Lines" });
|
||||
}
|
||||
}
|
||||
|
||||
static async deleteLayer(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization, layer } = req.body;
|
||||
|
||||
const findValue = await lineModel(organization).find({ layer: layer });
|
||||
|
||||
if (!findValue) {
|
||||
res.status(200).json("data not found");
|
||||
} else {
|
||||
await lineModel(organization).deleteMany({ layer: layer });
|
||||
|
||||
const updateResult = await lineModel(organization).updateMany(
|
||||
{ 'line.uuid': uuid }, // Filter: Find the line with the given uuid
|
||||
{ $set: { 'line.$.position': position } } // Update the position and type
|
||||
{ layer: { $gt: layer } },
|
||||
{ $inc: { layer: -1 } }
|
||||
);
|
||||
|
||||
res.status(201).json(updateResult);
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating Lines:', error);
|
||||
res.status(500).json({message:"Failed to create Lines"});
|
||||
}
|
||||
}
|
||||
static async getLines(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
|
||||
|
||||
const findValue = await lineModel(organization).find()
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get Lines:', error);
|
||||
res.status(500).json({ error: "Failed to get Lines" });
|
||||
}
|
||||
}
|
||||
static async deleteLineItems(req: Request, res: Response) {
|
||||
try {
|
||||
const {organization,layer,line,type}=req.body
|
||||
|
||||
const inputUuids = line.map((item: any) => item.uuid);
|
||||
|
||||
|
||||
// const findValue = await lineModel(organization).findOneAndDelete({
|
||||
|
||||
// line: { $elemMatch: { uuid: { $in: inputUuids } } },
|
||||
// });
|
||||
const findValue = await lineModel(organization).findOneAndDelete({
|
||||
"line.uuid": { $all: inputUuids } // Ensure all UUIDs are present in the `line` key
|
||||
});
|
||||
|
||||
if (!findValue) {
|
||||
res.status(200).json("data not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error delete Lines:', error);
|
||||
res.status(500).json({ error: "Failed to delete Lines" });
|
||||
}
|
||||
}
|
||||
static async deleteLinPoiteItems(req: Request, res: Response) {
|
||||
try {
|
||||
const {organization,layer,uuid,type}=req.body
|
||||
|
||||
const findValue = await lineModel(organization).deleteMany({ 'line.uuid': uuid })
|
||||
|
||||
if (!findValue) {
|
||||
res.status(200).json("data not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error delete Lines:', error);
|
||||
res.status(500).json({ error: "Failed to delete Lines" });
|
||||
}
|
||||
}
|
||||
|
||||
static async deleteLayer(req: Request, res: Response) {
|
||||
try {
|
||||
const {organization,layer}=req.body
|
||||
|
||||
// Fetch the documents with the specified layer value
|
||||
const findValue = await lineModel(organization).find({ layer: layer });
|
||||
|
||||
if (!findValue) {
|
||||
res.status(200).json("data not found");
|
||||
} else {
|
||||
await lineModel(organization).deleteMany({ layer: layer });
|
||||
// console.log(`Documents with layer ${layer} have been deleted.`);
|
||||
|
||||
// Update documents with layer greater than -1
|
||||
const updateResult = await lineModel(organization).updateMany(
|
||||
{ layer: { $gt:layer} },
|
||||
{ $inc: { layer: -1 } } // Example operation: decrementing layer by 1
|
||||
);
|
||||
|
||||
|
||||
res.status(201).json(updateResult);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error delete Lines:', error);
|
||||
res.status(500).json({ error: "Failed to delete Lines" });
|
||||
}
|
||||
|
||||
res.status(201).json(updateResult);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error delete Lines:", error);
|
||||
res.status(500).json({ error: "Failed to delete Lines" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
import { Request, Response } from "express";
|
||||
import zoneModel from "../../../shared/model/lines/zone-Model.ts";
|
||||
export class zone {
|
||||
static async setZone(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization, userId, zoneData } = req.body
|
||||
// console.log('req.body: ', req.body);
|
||||
const zoneId = zoneData.zoneId
|
||||
const points = zoneData.points
|
||||
const zoneName = zoneData.zoneName
|
||||
const layer = zoneData.layer
|
||||
const viewPortCenter = zoneData.viewPortCenter
|
||||
const viewPortposition = zoneData.viewPortposition
|
||||
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
|
||||
if (findZoneId) {
|
||||
const updateZone = await zoneModel(organization).findOneAndUpdate(
|
||||
{ zoneId: zoneId }, { points: points, viewPortposition: viewPortposition, viewPortCenter: viewPortCenter }, { new: true }
|
||||
).select("-_id -__v")
|
||||
res.status(201).json({ message: 'zone updated', data: updateZone, organization: organization })
|
||||
} else {
|
||||
const zoneCreate = await zoneModel(organization).create({
|
||||
zoneId, createBy: userId, zoneName: zoneName, points, layer, viewPortCenter, viewPortposition
|
||||
})
|
||||
const createdZone = await zoneModel(organization)
|
||||
.findById(zoneCreate._id)
|
||||
.select('-_id -__v')
|
||||
.lean();
|
||||
res.status(201).json({ message: 'zone created', data: createdZone, organization: organization })
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('error: ', error);
|
||||
res.status(500).json({ message: 'Zone not found', error })
|
||||
}
|
||||
}
|
||||
static async deleteZone(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization, userId, zoneId } = req.body
|
||||
|
||||
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
|
||||
if (findZoneId) {
|
||||
const deleteZone = await zoneModel(organization).findOneAndDelete(
|
||||
{ zoneId: zoneId, createBy: userId }
|
||||
).select("-_id -__v")
|
||||
res.status(201).json({ message: 'zone deleted', data: deleteZone, organization: organization })
|
||||
} else {
|
||||
|
||||
res.status(500).json({ message: 'Invalid zone ID' })
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('error: ', error);
|
||||
res.status(500).json({ message: 'Zone not found', error })
|
||||
}
|
||||
}
|
||||
static async getZones(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization, userId } = req.params
|
||||
|
||||
|
||||
const findZoneId = await zoneModel(organization)
|
||||
.find()
|
||||
.select("zoneId zoneName layer points viewPortCenter viewPortposition -_id");
|
||||
|
||||
if (!findZoneId) {
|
||||
res.status(500).json({ message: 'Invalid zone' })
|
||||
|
||||
}
|
||||
res.status(201).json({ data: findZoneId, organization: organization })
|
||||
} catch (error) {
|
||||
console.log('error: ', error);
|
||||
res.status(500).json({ message: 'Zone not found', error })
|
||||
}
|
||||
}
|
||||
|
||||
static async ZoneData(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const organization = req.params.organization;
|
||||
const zoneId = req.params.zoneId;
|
||||
const findZone = await zoneModel(organization)
|
||||
.findOne({ zoneId: zoneId })
|
||||
// .select("zoneName");
|
||||
console.log("findZone: ", findZone);
|
||||
if (findZone) return res.status(200).json(findZone);
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { Request, Response } from "express";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export class Zoneservice {
|
||||
export class ZoneService {
|
||||
static async addandUpdateZone(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const organization = req.body.organization;
|
||||
|
||||
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,43 +1,46 @@
|
||||
import { Request, Response } from "express";
|
||||
import userModel from "../../../shared/model/user-Model.ts";
|
||||
|
||||
export class Share {
|
||||
static async shareUser(req: Request, res: Response) {
|
||||
try {
|
||||
const { email, isShare, organization } = req.body;
|
||||
|
||||
export class share {
|
||||
static async shareUser(req: Request, res: Response) {
|
||||
try {
|
||||
const { email, isShare, organization } = req.body
|
||||
|
||||
const findValue = await userModel(organization).findOneAndUpdate(
|
||||
{ email: email },
|
||||
{ isShare: isShare },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
const findValue = await userModel(organization).findOneAndUpdate({email:email},{isShare:isShare},{new:true})
|
||||
|
||||
res.status(201).json({message:"scene shared successfully",data:findValue});
|
||||
if (!findValue) {
|
||||
res.status(404).json({message:"Not found"})
|
||||
}
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating Share:', error);
|
||||
res.status(500).json({message:"Failed to create Share"});
|
||||
}
|
||||
res
|
||||
.status(201)
|
||||
.json({ message: "scene shared successfully", data: findValue });
|
||||
if (!findValue) {
|
||||
res.status(404).json({ message: "Not found" });
|
||||
}
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error("Error creating Share:", error);
|
||||
res.status(500).json({ message: "Failed to create Share" });
|
||||
}
|
||||
|
||||
static async findshareUser(req: Request, res: Response) {
|
||||
try {
|
||||
const organization = req.query.organization as string;
|
||||
|
||||
|
||||
const findValue = await userModel(organization).find({}).select("isShare email userName -_id")
|
||||
// console.log('findValue: ', findValue);
|
||||
|
||||
res.status(201).json({message:"scene shared datas",data:findValue});
|
||||
if (!findValue) {
|
||||
res.status(404).json({message:"Not found"})
|
||||
}
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error Share:', error);
|
||||
res.status(500).json({message:"Failed to Share datas "});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static async findshareUser(req: Request, res: Response) {
|
||||
try {
|
||||
const organization = req.query.organization as string;
|
||||
|
||||
const findValue = await userModel(organization)
|
||||
.find({})
|
||||
.select("isShare email userName -_id");
|
||||
|
||||
res.status(201).json({ message: "scene shared datas", data: findValue });
|
||||
if (!findValue) {
|
||||
res.status(404).json({ message: "Not found" });
|
||||
}
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error("Error Share:", error);
|
||||
res.status(500).json({ message: "Failed to Share datas " });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,182 +1,9 @@
|
||||
import { Request, Response } from "express";
|
||||
import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
|
||||
import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||
import pointModel from "../../../shared/model/builder/assets/assetPoint-Model.ts";
|
||||
import EventsDataModel from "../../../shared/model/simulation/eventsDataModel.ts";
|
||||
|
||||
export class assetsFloorservice {
|
||||
// static async setFloorassets(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const {
|
||||
// modelUuid,
|
||||
// modelName,
|
||||
// position,
|
||||
// modelfileID,
|
||||
// rotation,
|
||||
// isLocked,
|
||||
// isVisible,
|
||||
// organization,
|
||||
// eventData,
|
||||
// } = req.body;
|
||||
// console.log("req.body: ", req.body);
|
||||
|
||||
// const findvalue = await assetModel(organization).findOne({
|
||||
// modelUuid,
|
||||
// // modelName,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// const checkpointType = await pointModel(organization).findOne({
|
||||
// modelfileID: modelfileID,
|
||||
// isArchive: false,
|
||||
// });
|
||||
|
||||
// if (findvalue) {
|
||||
// const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
// { modelUuid, isArchive: false },
|
||||
// {
|
||||
// modelName: modelName,
|
||||
// position,
|
||||
// rotation,
|
||||
// isVisible,
|
||||
// isLocked,
|
||||
// },
|
||||
// { new: true }
|
||||
// );
|
||||
// return res.status(201).json(updatevalue);
|
||||
// } else {
|
||||
// let assetData: any = {
|
||||
// modelUuid,
|
||||
// modelName,
|
||||
// position,
|
||||
// modelfileID,
|
||||
// rotation,
|
||||
// isLocked,
|
||||
// isVisible,
|
||||
// };
|
||||
|
||||
// console.log("eventData: ", eventData);
|
||||
// if (eventData) {
|
||||
// if (eventData.type === "Conveyor") {
|
||||
// assetData.speed = eventData.speed;
|
||||
// } else if (eventData.type === "Vehicle") {
|
||||
// assetData.speed = eventData.points.speed;
|
||||
// if (!eventData.points) {
|
||||
// return res
|
||||
// .status(400)
|
||||
// .json({ message: "Vehicle points must be a single object" });
|
||||
// }
|
||||
// // if (eventData.points.rotation) {
|
||||
// // return res.status(400).json({
|
||||
// // message: "Rotation is not allowed for Vehicle points",
|
||||
// // });
|
||||
// // }
|
||||
|
||||
// if (eventData.points.triggers) {
|
||||
// return res.status(400).json({
|
||||
// message: "triggers is not allowed for Vehicle points",
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// // else if(eventData.type === "ArmBot"){
|
||||
// // assetData.speed = eventData.position;
|
||||
// // }else if(eventData.type === "StaticMachine"){
|
||||
// // assetData.speed = eventData.position;
|
||||
// // }
|
||||
|
||||
// assetData.points = eventData.points;
|
||||
// assetData.type = eventData.type;
|
||||
// }
|
||||
// const assetDoc = await assetModel(organization).create(assetData);
|
||||
// await assetDoc.save();
|
||||
|
||||
// return res.status(201).json({
|
||||
// message: "Model stored successfully",
|
||||
// modelId: assetDoc._id,
|
||||
// });
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error("Error creating flooritems:", error);
|
||||
// res.status(500).json({ message: "Failed to create flooritems" });
|
||||
// }
|
||||
// }
|
||||
// static async getFloorItems(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const { organization } = req.params;
|
||||
// const findValues = await assetModel(organization)
|
||||
// .find({ isArchive: false })
|
||||
// .select("-_id -isArchive");
|
||||
|
||||
// if (!findValues || findValues.length === 0) {
|
||||
// return res.status(200).json({ message: "floorItems not found" });
|
||||
// }
|
||||
|
||||
// const response = findValues.map((item) => {
|
||||
// // console.log("item: ", item);
|
||||
// // console.log("item: ", item.type);
|
||||
// // console.log('findValues: ', findValues);
|
||||
// // console.log("item.points: ", item.points);
|
||||
// const responseItem: any = {
|
||||
// modelUuid: item.modelUuid,
|
||||
// modelName: item.modelName,
|
||||
// position: item.position,
|
||||
// rotation: item.rotation,
|
||||
// modelfileID: item.modelfileID,
|
||||
// isLocked: item.isLocked,
|
||||
// isVisible: item.isVisible,
|
||||
// };
|
||||
// if (item.type === "Conveyor" && item.points.length > 0) {
|
||||
// responseItem.eventData = {
|
||||
// speed: item.speed,
|
||||
// points: item.points,
|
||||
// type: item.type,
|
||||
// };
|
||||
// }
|
||||
|
||||
// if (item.type === "Vehicle" && item.points) {
|
||||
// responseItem.eventData = {
|
||||
// type: item.type,
|
||||
// points: item.points,
|
||||
// };
|
||||
// }
|
||||
// if (item.type === "ArmBot" && item.points) {
|
||||
// responseItem.eventData = {
|
||||
// type: item.type,
|
||||
// points: item.points,
|
||||
// };
|
||||
// }
|
||||
// if (item.type === "StaticMachine" && item.points) {
|
||||
// responseItem.eventData = {
|
||||
// type: item.type,
|
||||
// points: item.points,
|
||||
// };
|
||||
// }
|
||||
// return responseItem;
|
||||
// });
|
||||
|
||||
// return res.status(200).json(response);
|
||||
// } catch (error) {
|
||||
// res.status(500).json({ error: "Failed to get flooritems" });
|
||||
// }
|
||||
// }
|
||||
// static async deleteFloorItems(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const { modelUuid, modelName, organization } = req.body;
|
||||
|
||||
// const findValue = await assetModel(organization).findOneAndDelete({
|
||||
// modelUuid: modelUuid,
|
||||
// modelName: modelName,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (!findValue) {
|
||||
// res.status(200).json("user not found");
|
||||
// } else {
|
||||
// res.status(201).json(findValue);
|
||||
// }
|
||||
// } catch (error) {
|
||||
// res.status(500).json({ error: "Failed to get flooritems" });
|
||||
// }
|
||||
// }
|
||||
export class AssetsFloorService {
|
||||
static async updateAssetPositionRotation(
|
||||
req: Request,
|
||||
res: Response
|
||||
@@ -186,11 +13,11 @@ export class assetsFloorservice {
|
||||
modelUuid,
|
||||
modelName,
|
||||
position,
|
||||
modelfileID,
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
organization,
|
||||
// modelfileID, //optional
|
||||
// eventData, // Optional
|
||||
} = req.body;
|
||||
|
||||
@@ -244,7 +71,6 @@ export class assetsFloorservice {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
//update setfoolrassets//getFloorItems//deleteFloorItems.........
|
||||
static async setFloorassets(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const {
|
||||
@@ -265,7 +91,7 @@ export class assetsFloorservice {
|
||||
// modelName,
|
||||
isArchive: false,
|
||||
});
|
||||
const checkpointType = await pointModel(organization).findOne({
|
||||
await pointModel(organization).findOne({
|
||||
modelfileID: modelfileID,
|
||||
isArchive: false,
|
||||
});
|
||||
@@ -292,10 +118,9 @@ export class assetsFloorservice {
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
eventData
|
||||
eventData,
|
||||
};
|
||||
|
||||
console.log("eventData: ", eventData);
|
||||
if (eventData) {
|
||||
if (eventData.type === "Conveyor") {
|
||||
assetData.speed = eventData.speed;
|
||||
@@ -306,24 +131,12 @@ export class assetsFloorservice {
|
||||
.status(400)
|
||||
.json({ message: "Vehicle points must be a single object" });
|
||||
}
|
||||
// if (eventData.points.rotation) {
|
||||
// return res.status(400).json({
|
||||
// message: "Rotation is not allowed for Vehicle points",
|
||||
// });
|
||||
// }
|
||||
|
||||
if (eventData.points.triggers) {
|
||||
return res.status(400).json({
|
||||
message: "triggers is not allowed for Vehicle points",
|
||||
});
|
||||
}
|
||||
}
|
||||
// else if(eventData.type === "ArmBot"){
|
||||
// assetData.speed = eventData.position;
|
||||
// }else if(eventData.type === "StaticMachine"){
|
||||
// assetData.speed = eventData.position;
|
||||
// }
|
||||
|
||||
assetData.points = eventData.points;
|
||||
assetData.type = eventData.type;
|
||||
}
|
||||
@@ -352,10 +165,6 @@ export class assetsFloorservice {
|
||||
}
|
||||
|
||||
const response = findValues.map((item) => {
|
||||
// console.log("item: ", item);
|
||||
// console.log("item: ", item.type);
|
||||
// console.log('findValues: ', findValues);
|
||||
// console.log("item.points: ", item.points);
|
||||
const responseItem: any = {
|
||||
modelUuid: item.modelUuid,
|
||||
modelName: item.modelName,
|
||||
@@ -366,36 +175,9 @@ export class assetsFloorservice {
|
||||
isVisible: item.isVisible,
|
||||
eventData: item.eventData,
|
||||
};
|
||||
// if (item.type === "Conveyor" && item.points.length > 0) {
|
||||
// responseItem.eventData = {
|
||||
// speed: item.speed,
|
||||
// points: item.points,
|
||||
// type: item.type,
|
||||
// };
|
||||
// }
|
||||
|
||||
// if (item.type === "Vehicle" && item.points) {
|
||||
// responseItem.eventData = {
|
||||
// type: item.type,
|
||||
// points: item.points,
|
||||
// };
|
||||
// }
|
||||
// if (item.type === "ArmBot" && item.points) {
|
||||
// responseItem.eventData = {
|
||||
// type: item.type,
|
||||
// points: item.points,
|
||||
// };
|
||||
// }
|
||||
// if (item.type === "StaticMachine" && item.points) {
|
||||
// responseItem.eventData = {
|
||||
// type: item.type,
|
||||
// points: item.points,
|
||||
// };
|
||||
// }
|
||||
return responseItem;
|
||||
});
|
||||
|
||||
// console.log('response: ', response);
|
||||
return res.status(200).json(response);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Failed to get flooritems" });
|
||||
@@ -404,36 +186,35 @@ export class assetsFloorservice {
|
||||
static async deleteFloorItems(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { modelUuid, modelName, organization } = req.body;
|
||||
console.log('req.body:', req.body);
|
||||
|
||||
|
||||
const asset = await assetModel(organization).findOne({
|
||||
modelUuid,
|
||||
modelName,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
|
||||
if (!asset) {
|
||||
return res.status(404).json({ message: "Model not found" });
|
||||
}
|
||||
|
||||
|
||||
const archivedAsset = await assetModel(organization).findOneAndUpdate(
|
||||
{ modelUuid, modelName },
|
||||
{ $set: { isArchive: true } },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
|
||||
if (!archivedAsset) {
|
||||
return res.status(500).json({ message: "Failed to archive asset" });
|
||||
}
|
||||
|
||||
|
||||
const updatedEvents = await EventsDataModel(organization).updateMany(
|
||||
{ modelUuid },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
|
||||
|
||||
console.log("Archived asset:", archivedAsset);
|
||||
console.log("Updated events:", updatedEvents.modifiedCount);
|
||||
|
||||
|
||||
return res.status(200).json({ message: "delete Asset successfully" });
|
||||
} catch (error) {
|
||||
console.error("Error deleting floor items:", error);
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
// import { Request, Response } from "express";
|
||||
// // import assetModel from "../../../shared/model/assets/flooritems-Model.ts";
|
||||
// import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
|
||||
// import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||
// import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||
// import productFlowModel from "../../../shared/model/simulation/ProductFlowmodel.ts";
|
||||
|
||||
// export class productFlowservice {
|
||||
// static async setproductFlow(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const {
|
||||
// productName,
|
||||
// modelUuid,
|
||||
// modelName,
|
||||
// eventData,
|
||||
// organization,
|
||||
// productID,
|
||||
// } = req.body;
|
||||
|
||||
// // Validate required fields
|
||||
// if (!modelUuid || !modelName || !organization) {
|
||||
// return res.status(400).json({ message: "Missing required fields" });
|
||||
// }
|
||||
|
||||
// // Check if asset exists
|
||||
// const existingAsset = await assetModel(organization).findOne({
|
||||
// modelUuid: modelUuid,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (!existingAsset) {
|
||||
// return res.status(404).json({ message: "Asset not found for the ID" });
|
||||
// }
|
||||
|
||||
// // Prepare point references
|
||||
// let pointRefs: any[] = [];
|
||||
// if (eventData?.points && Array.isArray(eventData.points)) {
|
||||
// for (const point of eventData.points) {
|
||||
// let actionRefs: any[] = [];
|
||||
// let triggerRefs: any[] = [];
|
||||
|
||||
// // Process actions
|
||||
// if (Array.isArray(point.actions)) {
|
||||
// for (const action of point.actions) {
|
||||
// const actionDoc = await actionModel(organization).create({
|
||||
// pointsUUID: point.uuid,
|
||||
// isArchive: false,
|
||||
// uuid: action.uuid,
|
||||
// name: action.name,
|
||||
// type: action.type,
|
||||
// material: action.material || null,
|
||||
// delay: action.delay || null,
|
||||
// spawn_Interval: action.spawn_Interval || null,
|
||||
// });
|
||||
// actionRefs.push({
|
||||
// _id: actionDoc._id,
|
||||
// ...action,
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Process triggers
|
||||
// if (Array.isArray(point.triggers)) {
|
||||
// for (const trigger of point.triggers) {
|
||||
// const triggerDoc = await triggerModel(organization).create({
|
||||
// pointsUUID: point.uuid,
|
||||
// isArchive: false,
|
||||
// uuid: trigger.uuid,
|
||||
// name: trigger.name,
|
||||
// type: trigger.type,
|
||||
// bufferTime: trigger.bufferTime || null,
|
||||
// });
|
||||
// triggerRefs.push({
|
||||
// _id: triggerDoc._id,
|
||||
// ...trigger,
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// pointRefs.push({
|
||||
// pointuuid: point.uuid,
|
||||
// position: point.position || [],
|
||||
// rotation: point.rotation || [],
|
||||
// actions: actionRefs,
|
||||
// triggers: triggerRefs,
|
||||
// connections: point.connections || null,
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Check if product flow exists
|
||||
// const existingproductData = await productFlowModel(organization).findOne({
|
||||
// _id: productID,
|
||||
// });
|
||||
|
||||
// let result;
|
||||
// if (existingproductData) {
|
||||
// // Update existing product flow
|
||||
// result = await productFlowModel(organization).findOneAndUpdate(
|
||||
// { _id: productID },
|
||||
// {
|
||||
// $push: {
|
||||
// ProductData: {
|
||||
// AssetName: modelName,
|
||||
// Assetuuid: modelUuid,
|
||||
// paths: {
|
||||
// Points: pointRefs,
|
||||
// },
|
||||
// isArchive: false,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// { new: true }
|
||||
// );
|
||||
// } else {
|
||||
// // Create new product flow
|
||||
// result = await productFlowModel(organization).create({
|
||||
// _id: productID,
|
||||
// productName: productName,
|
||||
// ProductData: [
|
||||
// {
|
||||
// AssetName: modelName,
|
||||
// Assetuuid: modelUuid,
|
||||
// paths: {
|
||||
// Points: pointRefs,
|
||||
// },
|
||||
// isArchive: false,
|
||||
// },
|
||||
// ],
|
||||
// eventType: eventData?.type || null,
|
||||
// speed: eventData?.speed || null,
|
||||
// });
|
||||
// }
|
||||
|
||||
// res.status(201).json({
|
||||
// message: "Product flow processed successfully",
|
||||
// data: result,
|
||||
// });
|
||||
// } catch (error) {
|
||||
// console.error("Error creating flooritems:", error);
|
||||
// res.status(500).json({ message: "Failed to create flooritems" });
|
||||
// }
|
||||
// }
|
||||
// static async pointActionList(req: Request, res: Response): Promise<any> {}
|
||||
// static async productpathsList(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const { organization } = req.params;
|
||||
// const productFlowList = await productFlowModel(organization)
|
||||
// .find()
|
||||
// .select("ProductData productName -_id")
|
||||
// .exec();
|
||||
|
||||
// const formattedData = await Promise.all(
|
||||
// productFlowList.map(async (item) => ({
|
||||
// productName: item.productName,
|
||||
// paths: await Promise.all(
|
||||
// item.ProductData.map(async (data: any) => ({
|
||||
// Points: await Promise.all(
|
||||
// data.paths.Points.map(async (point: any) => {
|
||||
// const actions = await actionModel(organization)
|
||||
// .find({ _id: { $in: point.actions } })
|
||||
// .select(
|
||||
// "-_id -pointsUUID -isArchive -createdAt -updatedAt -__v"
|
||||
// )
|
||||
// .lean();
|
||||
// const triggers = await triggerModel(organization)
|
||||
// .find({ _id: { $in: point.triggers } })
|
||||
// .select(
|
||||
// "-_id -pointsUUID -isArchive -createdAt -updatedAt -__v"
|
||||
// )
|
||||
// .lean();
|
||||
// return {
|
||||
// connections: point.connections || null,
|
||||
// pointuuid: point.pointuuid,
|
||||
// actions: actions,
|
||||
// triggers: triggers,
|
||||
// position: point.position,
|
||||
// rotation: point.rotation,
|
||||
// };
|
||||
// })
|
||||
// ),
|
||||
// }))
|
||||
// ),
|
||||
// }))
|
||||
// );
|
||||
|
||||
// return res.status(200).json(formattedData);
|
||||
// } catch (error) {
|
||||
// console.error("Error get flooritems:", error);
|
||||
// res.status(500).json({ error: "Failed to get flooritems" });
|
||||
// }
|
||||
// }
|
||||
// // static async deleteFloorItems(req: Request, res: Response): Promise<any> {
|
||||
// // try {
|
||||
// // const { modelUuid, modelName, organization } = req.body;
|
||||
|
||||
// // const findValue = await assetModel(organization).findOneAndDelete({
|
||||
// // modelUuid: modelUuid,
|
||||
// // modelName: modelName,
|
||||
// // isArchive: false,
|
||||
// // });
|
||||
// // if (!findValue) {
|
||||
// // res.status(200).json("user not found");
|
||||
// // } else {
|
||||
// // res.status(201).json(findValue);
|
||||
// // }
|
||||
// // } catch (error) {
|
||||
// // console.error("Error get flooritems:", error);
|
||||
// // res.status(500).json({ error: "Failed to get flooritems" });
|
||||
// // }
|
||||
// // }
|
||||
// // static async updateAssetPositionRotation(
|
||||
// // req: Request,
|
||||
// // res: Response
|
||||
// // ): Promise<any> {
|
||||
// // try {
|
||||
// // const {
|
||||
// // modelUuid,
|
||||
// // modelName,
|
||||
// // position,
|
||||
// // modelfileID,
|
||||
// // rotation,
|
||||
// // isLocked,
|
||||
// // isVisible,
|
||||
// // organization,
|
||||
// // // eventData, // Optional
|
||||
// // } = req.body;
|
||||
|
||||
// // const existingAsset = await assetModel(organization).findOne({
|
||||
// // modelUuid: modelUuid,
|
||||
// // isArchive: false,
|
||||
// // });
|
||||
// // if (!existingAsset) return res.send("Asset not found");
|
||||
// // const updateAsset = await assetModel(organization).updateMany(
|
||||
// // { modelUuid: modelUuid, modelName: modelName, isArchive: false },
|
||||
// // {
|
||||
// // position: position,
|
||||
// // rotation: rotation,
|
||||
// // isVisible: isVisible,
|
||||
// // isLocked: isLocked,
|
||||
// // }
|
||||
// // );
|
||||
// // if (updateAsset)
|
||||
// // return res.status(200).json({ message: "Asset updated successfully" });
|
||||
// // } catch (error: any) {
|
||||
// // return res.send(error.message);
|
||||
// // }
|
||||
// // }
|
||||
// // static async updateActionsDatas(req: Request, res: Response) {}
|
||||
// }
|
||||
@@ -2,256 +2,237 @@ import { Request, Response } from "express";
|
||||
import ProductModel from "../../../shared/model/simulation/productModel.ts";
|
||||
import EventsDataModel from "../../../shared/model/simulation/eventsDataModel.ts";
|
||||
|
||||
export class productFlowservice {
|
||||
|
||||
static async productAdd(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { productName, productId, eventDatas, organization } = req.body;
|
||||
if (!organization) {
|
||||
return res
|
||||
.json({ message: "organization not found" });
|
||||
export class ProductFlowservice {
|
||||
static async productAdd(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { productName, productId, eventDatas, organization } = req.body;
|
||||
if (!organization) {
|
||||
return res.json({ message: "organization not found" });
|
||||
}
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingProduct) {
|
||||
const existingEventData = await EventsDataModel(organization).findOne({
|
||||
productId: productId,
|
||||
modelUuid: eventDatas.modelUuid,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingEventData) {
|
||||
await EventsDataModel(organization).findOneAndUpdate(
|
||||
{
|
||||
modelUuid: eventDatas.modelUuid,
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
modelUuid: eventDatas?.modelUuid,
|
||||
modelName: eventDatas?.modelName,
|
||||
position: eventDatas?.position,
|
||||
rotation: eventDatas?.rotation,
|
||||
type: eventDatas?.type,
|
||||
speed: eventDatas?.speed,
|
||||
point: eventDatas?.point,
|
||||
points: eventDatas?.points,
|
||||
}
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
})
|
||||
if (existingProduct) {
|
||||
const existingEventData = await EventsDataModel(organization).findOne(
|
||||
{
|
||||
productId: productId,
|
||||
modelUuid: eventDatas.modelUuid,
|
||||
isArchive: false,
|
||||
})
|
||||
if (existingEventData) {
|
||||
const updateEventData = await EventsDataModel(organization).findOneAndUpdate(
|
||||
{
|
||||
modelUuid: eventDatas.modelUuid,
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
}
|
||||
, {
|
||||
modelUuid: eventDatas?.modelUuid,
|
||||
modelName: eventDatas?.modelName,
|
||||
position: eventDatas?.position,
|
||||
rotation: eventDatas?.rotation,
|
||||
type: eventDatas?.type,
|
||||
speed: eventDatas?.speed,
|
||||
point: eventDatas?.point,
|
||||
points: eventDatas?.points,
|
||||
})
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "EventData updated successfully" });
|
||||
} else {
|
||||
const addEventData = await EventsDataModel(organization).create({
|
||||
productId: productId,
|
||||
modelUuid: eventDatas?.modelUuid,
|
||||
modelName: eventDatas?.modelName,
|
||||
position: eventDatas?.position,
|
||||
rotation: eventDatas?.rotation,
|
||||
type: eventDatas?.type,
|
||||
speed: eventDatas?.speed,
|
||||
point: eventDatas?.point,
|
||||
points: eventDatas?.points
|
||||
})
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: "EventData add successfully" });
|
||||
}
|
||||
} else {
|
||||
const newProduct = await ProductModel(organization).create({
|
||||
productId: productId,
|
||||
productName: productName
|
||||
|
||||
})
|
||||
if (newProduct) {
|
||||
|
||||
if (eventDatas) {
|
||||
const addEventData = await EventsDataModel(organization).create({
|
||||
productId: productId,
|
||||
modelUuid: eventDatas?.modelUuid,
|
||||
modelName: eventDatas?.modelName,
|
||||
position: eventDatas?.position,
|
||||
rotation: eventDatas?.rotation,
|
||||
type: eventDatas?.type,
|
||||
speed: eventDatas?.speed,
|
||||
point: eventDatas?.point,
|
||||
points: eventDatas?.points,
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: "Product created successfully" });
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to create product" });
|
||||
);
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "EventData updated successfully" });
|
||||
} else {
|
||||
await EventsDataModel(organization).create({
|
||||
productId: productId,
|
||||
modelUuid: eventDatas?.modelUuid,
|
||||
modelName: eventDatas?.modelName,
|
||||
position: eventDatas?.position,
|
||||
rotation: eventDatas?.rotation,
|
||||
type: eventDatas?.type,
|
||||
speed: eventDatas?.speed,
|
||||
point: eventDatas?.point,
|
||||
points: eventDatas?.points,
|
||||
});
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: "EventData add successfully" });
|
||||
}
|
||||
}
|
||||
static async getProductDatas(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { productId, organization } = req.query
|
||||
if (typeof productId !== "string" || typeof organization !== "string") {
|
||||
return res.status(400).json({ message: "Missing or invalid query parameters" });
|
||||
}
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
})
|
||||
|
||||
if (!existingProduct)
|
||||
return res.status(404).json({ message: "Product not found" });
|
||||
|
||||
|
||||
const existingEventDatas = await EventsDataModel(organization).find({ productId: productId }).select("-productId")
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
.json(existingEventDatas);
|
||||
} catch (error) {
|
||||
|
||||
res.status(500).json({ message: "Failed to get product" });
|
||||
} else {
|
||||
const newProduct = await ProductModel(organization).create({
|
||||
productId: productId,
|
||||
productName: productName,
|
||||
});
|
||||
if (newProduct) {
|
||||
if (eventDatas) {
|
||||
await EventsDataModel(organization).create({
|
||||
productId: productId,
|
||||
modelUuid: eventDatas?.modelUuid,
|
||||
modelName: eventDatas?.modelName,
|
||||
position: eventDatas?.position,
|
||||
rotation: eventDatas?.rotation,
|
||||
type: eventDatas?.type,
|
||||
speed: eventDatas?.speed,
|
||||
point: eventDatas?.point,
|
||||
points: eventDatas?.points,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: "Product created successfully" });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to create product" });
|
||||
}
|
||||
static async productDataDelete(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { productId, organization } = req.query
|
||||
if (typeof productId !== "string" || typeof organization !== "string") {
|
||||
return res.status(400).json({ message: "Missing or invalid query parameters" });
|
||||
}
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
})
|
||||
}
|
||||
static async getProductDatas(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { productId, organization } = req.query;
|
||||
if (typeof productId !== "string" || typeof organization !== "string") {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ message: "Missing or invalid query parameters" });
|
||||
}
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProduct)
|
||||
return res.status(404).json({ message: "Product not found" });
|
||||
if (!existingProduct)
|
||||
return res.status(404).json({ message: "Product not found" });
|
||||
|
||||
const productDelete = await ProductModel(organization).findOneAndUpdate(
|
||||
{ productId: productId },
|
||||
{
|
||||
isArchive: true,
|
||||
}, { new: true }
|
||||
|
||||
)
|
||||
const existingEventDatas = await EventsDataModel(organization).find({ productId: productId })
|
||||
if (existingEventDatas) {
|
||||
for (const event of existingEventDatas) {
|
||||
|
||||
await EventsDataModel(organization).updateMany(
|
||||
{ productId },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
return res.status(201).json({ message: "product deleted successfully" });
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to delete product" });
|
||||
}
|
||||
const existingEventDatas = await EventsDataModel(organization)
|
||||
.find({ productId: productId })
|
||||
.select("-productId");
|
||||
|
||||
return res.status(200).json(existingEventDatas);
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to get product" });
|
||||
}
|
||||
static async EventDataDelete(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { productId, organization, modelUuid } = req.body
|
||||
}
|
||||
static async productDataDelete(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { productId, organization } = req.query;
|
||||
if (typeof productId !== "string" || typeof organization !== "string") {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ message: "Missing or invalid query parameters" });
|
||||
}
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
})
|
||||
|
||||
if (!existingProduct)
|
||||
return res.status(404).json({ message: "Product not found" });
|
||||
|
||||
|
||||
const existingEventDatas = await EventsDataModel(organization).findOneAndUpdate(
|
||||
{ productId: productId, modelUuid: modelUuid }, {
|
||||
isArchive: true,
|
||||
}, { new: true }
|
||||
|
||||
)
|
||||
|
||||
return res.status(201).json({ message: "EventData deleted successfully" });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to delete Eventdata" });
|
||||
}
|
||||
if (!existingProduct)
|
||||
return res.status(404).json({ message: "Product not found" });
|
||||
|
||||
await ProductModel(organization).findOneAndUpdate(
|
||||
{ productId: productId },
|
||||
{
|
||||
isArchive: true,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
const existingEventDatas = await EventsDataModel(organization).find({
|
||||
productId: productId,
|
||||
});
|
||||
if (existingEventDatas) {
|
||||
// for (const event of existingEventDatas) {
|
||||
await EventsDataModel(organization).updateMany(
|
||||
{ productId },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
// }
|
||||
}
|
||||
return res.status(201).json({ message: "product deleted successfully" });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to delete product" });
|
||||
}
|
||||
static async AllProductDatas(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization } = req.params
|
||||
}
|
||||
static async EventDataDelete(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { productId, organization, modelUuid } = req.body;
|
||||
|
||||
if (!organization) {
|
||||
return res
|
||||
.json({ message: "organization not found" });
|
||||
}
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
const existingProduct = await ProductModel(organization).find({
|
||||
isArchive: false,
|
||||
})
|
||||
if (!existingProduct) {
|
||||
return res.status(404).json({ message: 'No products found' });
|
||||
}
|
||||
const result = [];
|
||||
if (!existingProduct)
|
||||
return res.status(404).json({ message: "Product not found" });
|
||||
|
||||
for (const product of existingProduct) {
|
||||
|
||||
|
||||
// Fetch events data for each product, excluding productId field
|
||||
const eventDatas = await EventsDataModel(organization)
|
||||
.find({ productId: product.productId, isArchive: false })
|
||||
.select("-productId -isArchive -createdAt -updatedAt -__v -_id");
|
||||
|
||||
|
||||
|
||||
// Combine product and event data
|
||||
result.push({
|
||||
// product: {
|
||||
productName: product.productName,
|
||||
productId: product.productId,
|
||||
eventDatas,
|
||||
// },
|
||||
});
|
||||
}
|
||||
|
||||
// Return combined data
|
||||
return res.status(200).json(result);
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to get Allproduct" });
|
||||
}
|
||||
await EventsDataModel(organization).findOneAndUpdate(
|
||||
{ productId: productId, modelUuid: modelUuid },
|
||||
{
|
||||
isArchive: true,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: "EventData deleted successfully" });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to delete Eventdata" });
|
||||
}
|
||||
static async productRename(req: Request, res: Response): Promise<any> {
|
||||
}
|
||||
static async AllProductDatas(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
|
||||
try {
|
||||
const { productId, productName, organization } = req.body
|
||||
if (!organization) {
|
||||
return res.json({ message: "organization not found" });
|
||||
}
|
||||
|
||||
const existingProduct = await ProductModel(organization).find({
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingProduct) {
|
||||
return res.status(404).json({ message: "No products found" });
|
||||
}
|
||||
const result = [];
|
||||
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
})
|
||||
for (const product of existingProduct) {
|
||||
const eventDatas = await EventsDataModel(organization)
|
||||
.find({ productId: product.productId, isArchive: false })
|
||||
.select("-productId -isArchive -createdAt -updatedAt -__v -_id");
|
||||
|
||||
if (!existingProduct)
|
||||
return res.status(404).json({ message: "Product not found" });
|
||||
|
||||
const productDelete = await ProductModel(organization).findOneAndUpdate(
|
||||
{ productId: productId },
|
||||
{
|
||||
productName: productName,
|
||||
}, { new: true }
|
||||
|
||||
)
|
||||
|
||||
return res.status(201).json({ message: "product Rename successfully" });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to product Rename" });
|
||||
}
|
||||
result.push({
|
||||
// product: {
|
||||
productName: product.productName,
|
||||
productId: product.productId,
|
||||
eventDatas,
|
||||
// },
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to get Allproduct" });
|
||||
}
|
||||
}
|
||||
static async productRename(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { productId, productName, organization } = req.body;
|
||||
|
||||
const existingProduct = await ProductModel(organization).findOne({
|
||||
productId: productId,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (!existingProduct)
|
||||
return res.status(404).json({ message: "Product not found" });
|
||||
|
||||
await ProductModel(organization).findOneAndUpdate(
|
||||
{ productId: productId },
|
||||
{
|
||||
productName: productName,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
return res.status(201).json({ message: "product Rename successfully" });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to product Rename" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { Request, Response } from "express";
|
||||
import { Server } from 'http';
|
||||
import userModel from "../../shared/model/user-Model.ts";
|
||||
import { isSharedArrayBuffer } from "util/types";
|
||||
import {hashGenerate,hashValidator} from "../../shared/security/Hasing.ts"
|
||||
// import {hashGenerate} from '../security/Hasing'
|
||||
import {hashGenerate,hashValidator} from "../../shared/utils/Hasing.ts"
|
||||
|
||||
let serverAlive = true;
|
||||
export class user {
|
||||
export class User {
|
||||
static async signup(req: Request, res: Response) {
|
||||
try {
|
||||
let role;
|
||||
@@ -43,7 +40,6 @@ export class user {
|
||||
try {
|
||||
let role;
|
||||
const { email, password,organization } = req.body;
|
||||
// console.log(' req.body: ', req.body);
|
||||
|
||||
const existingMail = await userModel(organization).findOne({
|
||||
email:email
|
||||
@@ -57,7 +53,6 @@ export class user {
|
||||
password,
|
||||
hashedpassword
|
||||
)
|
||||
// console.log('checkpassword: ', checkpassword);
|
||||
if (checkpassword) {
|
||||
// const tokenValidation=await tokenGenerator(existingMail.email)
|
||||
res.status(200).send({
|
||||
@@ -77,27 +72,5 @@ export class user {
|
||||
res.status(500).send(error);
|
||||
}
|
||||
}
|
||||
|
||||
// static async checkserverHealth(server:Server,organization: string){
|
||||
// try {
|
||||
// if (server.listening) {
|
||||
// console.log('Server is running');
|
||||
// serverAlive = true;
|
||||
// // Update all users to online status
|
||||
// } else {
|
||||
// // await userModel(organization).updateMany({}, { activeStatus: "offline" }); // Replace `activeStatus` with your actual field
|
||||
// throw new Error('Server is not running');
|
||||
// }
|
||||
// } catch (error:any) {
|
||||
// console.error('Server health check failed:', error.message);
|
||||
// serverAlive = false;
|
||||
|
||||
// // Update all users to offline status
|
||||
// // await userModel(organization).updateMany({}, { activeStatus: "offline" });
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
// export const startHealthCheck = (server: Server, organization: string) => {
|
||||
// setInterval(() => user.checkserverHealth(server, organization), 5000);
|
||||
// };
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Request, Response } from "express";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||
export class widget3dService {
|
||||
export class Widget3dService {
|
||||
static async add3Dwidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization, widget, zoneId } = req.body;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Request, Response } from "express";
|
||||
import floatWidgetModel from "../../../shared/model/vizualization/floatWidget.ts";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
export class floatWidgetService {
|
||||
export class FloatWidgetService {
|
||||
static async addfloatWidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization, widget, zoneId } = req.body;
|
||||
@@ -19,9 +19,7 @@ export class floatWidgetService {
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
const updateFloatWidget = await floatWidgetModel(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
await floatWidgetModel(organization).findOneAndUpdate(
|
||||
{
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
@@ -141,65 +139,4 @@ export class floatWidgetService {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
// static async updatewidget(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const { organization, widgetID, values } = req.body;
|
||||
// const findwidget = await widgetSchema(organization).findOne({
|
||||
// widgetID: widgetID,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (!findwidget)
|
||||
// return res.status(404).send({ message: "Data not found" });
|
||||
// const updateData = {
|
||||
// widgetName: values.widgetName,
|
||||
// widgetSide: values.widgetSide, // Fixed typo from widgetside to widgetSide
|
||||
// elementType: values.type,
|
||||
// Data: {
|
||||
// measurement: values.Data.measurement,
|
||||
// duration: values.Data.duration,
|
||||
// },
|
||||
// elementColor: values.color,
|
||||
// fontFamily: values.fontFamily,
|
||||
// fontStyle: values.fontStyle,
|
||||
// fontWeight: values.fontWeight,
|
||||
// isArchive: false,
|
||||
// };
|
||||
|
||||
// const changedWidget = await widgetSchema(organization).findOneAndUpdate(
|
||||
// { widgetID: widgetID, isArchive: false },
|
||||
// updateData,
|
||||
// {
|
||||
// new: true,
|
||||
// upsert: true,
|
||||
// setDefaultsOnInsert: true,
|
||||
// }
|
||||
// );
|
||||
|
||||
// return res.status(200).json({
|
||||
// message: "Widget updated successfully",
|
||||
// });
|
||||
// } catch (error: any) {
|
||||
// return res.status(500).send(error.message);
|
||||
// }
|
||||
// }
|
||||
|
||||
// static async getDatafromWidget(req: Request, res: Response): Promise<any> {
|
||||
// const { organization, widgetID } = req.params;
|
||||
// try {
|
||||
// const existingWidget = await widgetSchema(organization)
|
||||
// .findOne({
|
||||
// widgetID: widgetID,
|
||||
// isArchive: false,
|
||||
// })
|
||||
// .select("Data -_id");
|
||||
// const Datastructure = {
|
||||
// measurements: existingWidget.Data.measurements || {},
|
||||
// duration: existingWidget.Data.duration || "1h",
|
||||
// };
|
||||
|
||||
// if (existingWidget) return res.status(200).json({ Data: Datastructure });
|
||||
// } catch (error: any) {
|
||||
// return res.status(500).send(error.message);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
|
||||
export class panelService {
|
||||
export class PanelService {
|
||||
static async AddPanel(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const organization = req.body.organization;
|
||||
const zoneId = req.body.zoneId;
|
||||
const panelName = req.body.panelName;
|
||||
// const panelName = req.body.panelName;
|
||||
const panelOrder = req.body.panelOrder;
|
||||
const findZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
@@ -18,7 +18,7 @@ export class panelService {
|
||||
if (!findZone) {
|
||||
return res.status(404).json({ message: "Zone not found" });
|
||||
}
|
||||
const updatezone = await zoneSchema(organization).findOneAndUpdate(
|
||||
await zoneSchema(organization).findOneAndUpdate(
|
||||
{ zoneId: zoneId, isArchive: false },
|
||||
{ panelOrder: panelOrder },
|
||||
{ new: true }
|
||||
@@ -52,10 +52,6 @@ export class panelService {
|
||||
message: "No new panels were created. All panels already exist.",
|
||||
});
|
||||
}
|
||||
// const IDdata = createdPanels.map((ID: any) => {
|
||||
// return ID._id;
|
||||
// });
|
||||
createdPanels;
|
||||
return res.status(201).json({
|
||||
message: "Panels created successfully",
|
||||
panelID: createdPanels,
|
||||
@@ -66,7 +62,6 @@ export class panelService {
|
||||
}
|
||||
static async deletePanel(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const { organization, panelName, zoneId } = req.body;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
@@ -81,7 +76,7 @@ export class panelService {
|
||||
});
|
||||
if (!existingPanel)
|
||||
return res.status(409).json({ message: "Panel Already Deleted" });
|
||||
const updatePanel = await panelSchema(organization).findOneAndUpdate(
|
||||
await panelSchema(organization).findOneAndUpdate(
|
||||
{ _id: existingPanel._id, isArchive: false },
|
||||
{ isArchive: true },
|
||||
{ new: true }
|
||||
@@ -96,12 +91,11 @@ export class panelService {
|
||||
}
|
||||
|
||||
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
||||
const index1 = existingZone.panelOrder.indexOf(existingPanel.panelName);
|
||||
existingZone.panelOrder.indexOf(existingPanel.panelName);
|
||||
const zonepanelname = await zoneSchema(organization).updateOne(
|
||||
{ _id: existingZone._id },
|
||||
{ $pull: { panelOrder: existingPanel.panelName } }
|
||||
);
|
||||
console.log("zonepanelname: ", zonepanelname);
|
||||
}
|
||||
|
||||
return res.status(200).json({ message: "Panel deleted successfully" });
|
||||
@@ -111,7 +105,6 @@ export class panelService {
|
||||
}
|
||||
static async clearPanel(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.body;: ", req.body);
|
||||
const { organization, panelName, zoneId } = req.body;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
|
||||
@@ -5,7 +5,7 @@ import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
import floatWidgetModel from "../../../shared/model/vizualization/floatWidget.ts";
|
||||
|
||||
export class templateService {
|
||||
export class TemplateService {
|
||||
static async AddTemplate(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const {
|
||||
@@ -18,7 +18,6 @@ export class templateService {
|
||||
// snapshot,
|
||||
// floatWidgets,
|
||||
} = req.body;
|
||||
// console.log("req.body: ", req.body);
|
||||
const existingTemplate = await templateModel(organization).findOne({
|
||||
templateID: template.id,
|
||||
isArchive: false,
|
||||
@@ -181,7 +180,6 @@ export class templateService {
|
||||
}
|
||||
static async Deletezone(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.params: ", req.params);
|
||||
const { organization, templateID } = req.params;
|
||||
const existingTemplate = await templateModel(organization).findOne({
|
||||
templateID: templateID,
|
||||
|
||||
@@ -2,11 +2,9 @@ import { Request, Response } from "express";
|
||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export class widgetService {
|
||||
export class WidgetService {
|
||||
static async addWidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
// console.log("req.body: ", req.body);
|
||||
console.log("req.body: ", req.body);
|
||||
const {
|
||||
organization,
|
||||
// panel,
|
||||
@@ -34,7 +32,6 @@ export class widgetService {
|
||||
isArchive: false,
|
||||
// widgetOrder: widget.widgetOrder,
|
||||
});
|
||||
// console.log('existingWidget: ', widget.data.measurements);
|
||||
if (existingWidget) {
|
||||
const updateWidget = await widgetSchema(
|
||||
organization
|
||||
@@ -58,16 +55,13 @@ export class widgetService {
|
||||
},
|
||||
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
||||
);
|
||||
console.log("updateWidget: ", updateWidget);
|
||||
if (!updateWidget) {
|
||||
return res.json({ message: "Widget update unsuccessful" });
|
||||
}
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "Widget updated successfully" });
|
||||
// return res
|
||||
// .status(409)
|
||||
// .json({ message: "Widget already exist for the widgetID" });
|
||||
|
||||
}
|
||||
const newWidget = await widgetSchema(organization).create({
|
||||
widgetID: widget.id,
|
||||
@@ -100,7 +94,6 @@ export class widgetService {
|
||||
static async deleteWidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { widgetID, organization, zoneId } = req.body;
|
||||
console.log(" req.body: ", req.body);
|
||||
const findWidget = await widgetSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
widgetID: widgetID,
|
||||
@@ -115,7 +108,7 @@ export class widgetService {
|
||||
|
||||
if (widgetData) {
|
||||
// Find all widgets in the same panel and sort them by widgetOrder
|
||||
const widgets = await widgetSchema(organization).find({
|
||||
await widgetSchema(organization).find({
|
||||
panelID: findWidget.panelID,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
@@ -146,7 +139,6 @@ export class widgetService {
|
||||
|
||||
static async updatewidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const { organization, widgetID, values } = req.body;
|
||||
const findwidget = await widgetSchema(organization).findOne({
|
||||
widgetID: widgetID,
|
||||
@@ -169,7 +161,7 @@ export class widgetService {
|
||||
isArchive: false,
|
||||
};
|
||||
|
||||
const changedWidget = await widgetSchema(organization).findOneAndUpdate(
|
||||
await widgetSchema(organization).findOneAndUpdate(
|
||||
{ widgetID: widgetID, isArchive: false },
|
||||
updateData,
|
||||
{
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import app from './app.ts';
|
||||
import http from 'http';
|
||||
import ip from 'ip';
|
||||
|
||||
// import { startHealthCheck } from './controller/user-Controller';
|
||||
import swaggerUi from 'swagger-ui-express';
|
||||
import mongoAdminCreation from '../shared/security/mongosecurity.ts';
|
||||
import fs from 'fs';
|
||||
const server = http.createServer(app);
|
||||
|
||||
@@ -34,6 +32,5 @@ const PORT = process.env.API_PORT
|
||||
server.listen(PORT, () => {
|
||||
console.log(`API-Server running on http://localhost:${PORT}`);
|
||||
console.log(`Swagger UI available at http://localhost:${PORT}/api-docs`);
|
||||
// console.log(`Server is also accessible on IP address: ${ip.address()}`);
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user