Aisle and Simulation Product API and socket Completed
This commit is contained in:
@@ -5,6 +5,9 @@ productRouter.post("/UpsertProductOrEvent", ProductFlowService.productAdd);
|
|||||||
productRouter.get("/productData", ProductFlowService.getProductDatas);
|
productRouter.get("/productData", ProductFlowService.getProductDatas);
|
||||||
productRouter.patch("/EventDataDelete", ProductFlowService.EventDataDelete);
|
productRouter.patch("/EventDataDelete", ProductFlowService.EventDataDelete);
|
||||||
productRouter.patch("/productDataDelete", ProductFlowService.productDataDelete);
|
productRouter.patch("/productDataDelete", ProductFlowService.productDataDelete);
|
||||||
productRouter.get("/AllProducts/:organization", ProductFlowService.AllProductDatas);
|
productRouter.get(
|
||||||
|
"/AllProducts/:organization",
|
||||||
|
ProductFlowService.AllProductDatas
|
||||||
|
);
|
||||||
productRouter.patch("/productRename", ProductFlowService.productRename);
|
productRouter.patch("/productRename", ProductFlowService.productRename);
|
||||||
export default productRouter;
|
export default productRouter;
|
||||||
|
|||||||
@@ -0,0 +1,180 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
DeleteAisle,
|
||||||
|
GetProjectAisles,
|
||||||
|
SetAisle,
|
||||||
|
} from "../../../../shared/services/builder/AisleService.ts";
|
||||||
|
|
||||||
|
export const UpsertAisleController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { aisleUuid, points, type, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !aisleUuid || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
points,
|
||||||
|
type,
|
||||||
|
aisleUuid,
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await SetAisle(data);
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle Not Updated":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle Not Updated",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle Updated Successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle Updated Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle Not Created":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle Not Created",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle Created Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle validation failed":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle validation failed",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteAisleController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { aisleUuid, projectId } = req.body;
|
||||||
|
if (!organization || !userId || !aisleUuid || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
aisleUuid,
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await DeleteAisle(data);
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle not found":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Aisle Deleted Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const AllAisleController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { organization, userId } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
if (!organization || !userId || !projectId) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId,
|
||||||
|
};
|
||||||
|
const result = await GetProjectAisles(data);
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Aisle not found":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,395 @@
|
|||||||
|
import { Response } from "express";
|
||||||
|
import { AuthenticatedRequest } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AllProductDatas,
|
||||||
|
EventDataDelete,
|
||||||
|
getProductDatas,
|
||||||
|
productAdd,
|
||||||
|
productDataDelete,
|
||||||
|
productRename,
|
||||||
|
} from "../../../../shared/services/simulation/productService.ts";
|
||||||
|
|
||||||
|
export const AddProductController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { productUuid, eventDatas, projectId, productName } = req.body;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!productUuid ||
|
||||||
|
!productName ||
|
||||||
|
!projectId ||
|
||||||
|
!userId ||
|
||||||
|
!organization
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await productAdd({
|
||||||
|
productName,
|
||||||
|
productUuid,
|
||||||
|
eventDatas,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "EventData updated successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "EventData updated successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "EventData add successfully":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "EventData add successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(201).json({
|
||||||
|
message: "Product created Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetProductEventDatas = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { productUuid, projectId } = req.query as {
|
||||||
|
productUuid: string;
|
||||||
|
projectId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!productUuid || !projectId || !userId || !organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await getProductDatas({
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Product not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Product not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Events not found":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteProductController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { productUuid, projectId } = req.body;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!productUuid || !projectId || !userId || !organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await productDataDelete({
|
||||||
|
productUuid,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Product not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Product not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Product Deleted Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteEventsController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { productUuid, projectId, modelUuid } = req.body;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!productUuid || !projectId || !userId || !organization || !modelUuid) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await EventDataDelete({
|
||||||
|
productUuid,
|
||||||
|
modelUuid,
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Product not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Product not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Event Delete Unsuccessful":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Event Delete Unsuccessful",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({
|
||||||
|
message: "Events Deleted Successfully",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const ProjectBasedProductsController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { projectId } = req.params;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!projectId || !userId || !organization) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await AllProductDatas({
|
||||||
|
projectId,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "No products found":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json(result.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const RenameProductController = async (
|
||||||
|
req: AuthenticatedRequest,
|
||||||
|
res: Response
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const { userId, organization } = req.user || {};
|
||||||
|
const { productName, productUuid, projectId } = req.body;
|
||||||
|
|
||||||
|
if (!req.user?.userId || !req.user?.organization) {
|
||||||
|
res.status(401).json({ message: "Unauthorized" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!projectId ||
|
||||||
|
!userId ||
|
||||||
|
!organization ||
|
||||||
|
!productName ||
|
||||||
|
!productUuid
|
||||||
|
) {
|
||||||
|
res.status(400).json({
|
||||||
|
message: "All fields are required",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await productRename({
|
||||||
|
projectId,
|
||||||
|
productName,
|
||||||
|
productUuid,
|
||||||
|
userId,
|
||||||
|
organization,
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (result.status) {
|
||||||
|
case "User not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "User not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Project not found":
|
||||||
|
res.status(404).json({
|
||||||
|
message: "Project not found",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "Product not found":
|
||||||
|
res.status(404).json({ message: "Product not found" });
|
||||||
|
break;
|
||||||
|
case "Rename Unsuccessful":
|
||||||
|
res.status(200).json({ message: "Product Rename Not Updated" });
|
||||||
|
break;
|
||||||
|
case "Success":
|
||||||
|
res.status(200).json({ message: "Product Rename Successfull" });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Internal server error",
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: "Unknown error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
15
src/api-server/V1/v1Routes/BuilderRoutes/V1-AisleRoutes.ts
Normal file
15
src/api-server/V1/v1Routes/BuilderRoutes/V1-AisleRoutes.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AllAisleController,
|
||||||
|
DeleteAisleController,
|
||||||
|
UpsertAisleController,
|
||||||
|
} from "../../v1Controllers/builderController/v1AisleController.ts";
|
||||||
|
|
||||||
|
const V1Aisle = express.Router();
|
||||||
|
|
||||||
|
V1Aisle.post("/UpsertAisle", tokenValidator, UpsertAisleController);
|
||||||
|
V1Aisle.patch("/DeleteAisle", tokenValidator, DeleteAisleController);
|
||||||
|
V1Aisle.get("/Aisles/:projectId", tokenValidator, AllAisleController);
|
||||||
|
|
||||||
|
export default V1Aisle;
|
||||||
@@ -9,26 +9,26 @@ import {
|
|||||||
ZoneDataController,
|
ZoneDataController,
|
||||||
} from "../../v1Controllers/builderController/v1zoneController.ts";
|
} from "../../v1Controllers/builderController/v1zoneController.ts";
|
||||||
|
|
||||||
const v1Zone = express.Router();
|
const V1Zone = express.Router();
|
||||||
|
|
||||||
v1Zone.post("/zones", tokenValidator, CreateZoneController);
|
V1Zone.post("/zones", tokenValidator, CreateZoneController);
|
||||||
v1Zone.patch("/zones/delete", tokenValidator, DeleteZoneController);
|
V1Zone.patch("/zones/delete", tokenValidator, DeleteZoneController);
|
||||||
|
|
||||||
v1Zone.get(
|
V1Zone.get(
|
||||||
"/zones/visualization/:projectId",
|
"/zones/visualization/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
VizZoneController
|
VizZoneController
|
||||||
);
|
);
|
||||||
|
|
||||||
v1Zone.get(
|
V1Zone.get(
|
||||||
"/zones/:projectId/:zoneUuid",
|
"/zones/:projectId/:zoneUuid",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
ZoneDataController
|
ZoneDataController
|
||||||
);
|
);
|
||||||
v1Zone.get(
|
V1Zone.get(
|
||||||
"/zones/panel/:projectId/:zoneUuid",
|
"/zones/panel/:projectId/:zoneUuid",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
SingleZonePanelController
|
SingleZonePanelController
|
||||||
);
|
);
|
||||||
v1Zone.get("/zones/:projectId", tokenValidator, GetZoneController);
|
V1Zone.get("/zones/:projectId", tokenValidator, GetZoneController);
|
||||||
export default v1Zone;
|
export default V1Zone;
|
||||||
|
|||||||
@@ -7,26 +7,26 @@ import {
|
|||||||
ReplaceEventDataController,
|
ReplaceEventDataController,
|
||||||
} from "../../v1Controllers/builderController/v1assetController.ts";
|
} from "../../v1Controllers/builderController/v1assetController.ts";
|
||||||
|
|
||||||
const v1Asset = express.Router();
|
const V1Asset = express.Router();
|
||||||
|
|
||||||
v1Asset.post(
|
V1Asset.post(
|
||||||
"/setAsset",
|
"/setAsset",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
CreateAssetController
|
CreateAssetController
|
||||||
);
|
);
|
||||||
v1Asset.patch(
|
V1Asset.patch(
|
||||||
"/updateFloorAssetPositions",
|
"/updateFloorAssetPositions",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
AssetUpdatePosRotController
|
AssetUpdatePosRotController
|
||||||
);
|
);
|
||||||
v1Asset.get(
|
V1Asset.get(
|
||||||
"/floorAssets/:projectId",
|
"/floorAssets/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetAssetController
|
GetAssetController
|
||||||
);
|
);
|
||||||
v1Asset.patch(
|
V1Asset.patch(
|
||||||
"/updateEventData",
|
"/updateEventData",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
ReplaceEventDataController
|
ReplaceEventDataController
|
||||||
);
|
);
|
||||||
export default v1Asset;
|
export default V1Asset;
|
||||||
|
|||||||
@@ -6,22 +6,22 @@ import {
|
|||||||
SetNewCamera,
|
SetNewCamera,
|
||||||
} from "../../v1Controllers/builderController/v1cameraController.ts";
|
} from "../../v1Controllers/builderController/v1cameraController.ts";
|
||||||
|
|
||||||
const v1Camera = express.Router();
|
const V1Camera = express.Router();
|
||||||
|
|
||||||
v1Camera.post(
|
V1Camera.post(
|
||||||
"/setCamera",
|
"/setCamera",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
SetNewCamera
|
SetNewCamera
|
||||||
);
|
);
|
||||||
v1Camera.get(
|
V1Camera.get(
|
||||||
"/activeCameras",
|
"/activeCameras",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
ActiveOnlineController
|
ActiveOnlineController
|
||||||
);
|
);
|
||||||
v1Camera.get(
|
V1Camera.get(
|
||||||
"/cameras/:projectId",
|
"/cameras/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
CameraList
|
CameraList
|
||||||
);
|
);
|
||||||
|
|
||||||
export default v1Camera;
|
export default V1Camera;
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import {
|
|||||||
SetEnvironmentController,
|
SetEnvironmentController,
|
||||||
} from "../../v1Controllers/builderController/v1EnvironmentController.ts";
|
} from "../../v1Controllers/builderController/v1EnvironmentController.ts";
|
||||||
|
|
||||||
const v1Environment = express.Router();
|
const V1Environment = express.Router();
|
||||||
|
|
||||||
v1Environment.post("/SetEnvironments", tokenValidator, SetEnvironmentController);
|
V1Environment.post("/SetEnvironments", tokenValidator, SetEnvironmentController);
|
||||||
|
|
||||||
v1Environment.get(
|
V1Environment.get(
|
||||||
"/Environments/:projectId",
|
"/Environments/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetEnvironmentController
|
GetEnvironmentController
|
||||||
);
|
);
|
||||||
|
|
||||||
export default v1Environment;
|
export default V1Environment;
|
||||||
|
|||||||
@@ -9,36 +9,36 @@ import {
|
|||||||
UpdateLineController,
|
UpdateLineController,
|
||||||
} from "../../v1Controllers/builderController/v1LineController.ts";
|
} from "../../v1Controllers/builderController/v1LineController.ts";
|
||||||
|
|
||||||
const v1Line = express.Router();
|
const V1Line = express.Router();
|
||||||
|
|
||||||
v1Line.post(
|
V1Line.post(
|
||||||
"/lines",
|
"/lines",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
NewLineController
|
NewLineController
|
||||||
);
|
);
|
||||||
v1Line.post(
|
V1Line.post(
|
||||||
"/points",
|
"/points",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
UpdateLineController
|
UpdateLineController
|
||||||
);
|
);
|
||||||
v1Line.patch(
|
V1Line.patch(
|
||||||
"/layers/delete",
|
"/layers/delete",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
DeleteLayerController
|
DeleteLayerController
|
||||||
);
|
);
|
||||||
v1Line.patch(
|
V1Line.patch(
|
||||||
"/lines/delete",
|
"/lines/delete",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
DeleteLineController
|
DeleteLineController
|
||||||
);
|
);
|
||||||
v1Line.patch(
|
V1Line.patch(
|
||||||
"/points/delete",
|
"/points/delete",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
DeleteLinePointsController
|
DeleteLinePointsController
|
||||||
);
|
);
|
||||||
v1Line.get(
|
V1Line.get(
|
||||||
"/lines/:projectId",
|
"/lines/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetLinesController
|
GetLinesController
|
||||||
);
|
);
|
||||||
export default v1Line;
|
export default V1Line;
|
||||||
|
|||||||
@@ -6,21 +6,21 @@ import {
|
|||||||
WallSetup,
|
WallSetup,
|
||||||
} from "../../v1Controllers/builderController/v1wallController.ts";
|
} from "../../v1Controllers/builderController/v1wallController.ts";
|
||||||
|
|
||||||
const v1Wall = express.Router();
|
const V1Wall = express.Router();
|
||||||
|
|
||||||
v1Wall.post(
|
V1Wall.post(
|
||||||
"/walls",
|
"/walls",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
WallSetup
|
WallSetup
|
||||||
);
|
);
|
||||||
v1Wall.patch(
|
V1Wall.patch(
|
||||||
"/walls/delete",
|
"/walls/delete",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
WallDelete
|
WallDelete
|
||||||
);
|
);
|
||||||
v1Wall.get(
|
V1Wall.get(
|
||||||
"/walls/:projectId",
|
"/walls/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
WallGet
|
WallGet
|
||||||
);
|
);
|
||||||
export default v1Wall;
|
export default V1Wall;
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import express from "express";
|
||||||
|
import { tokenValidator } from "../../../../shared/utils/token.ts";
|
||||||
|
import {
|
||||||
|
AddProductController,
|
||||||
|
DeleteEventsController,
|
||||||
|
DeleteProductController,
|
||||||
|
GetProductEventDatas,
|
||||||
|
ProjectBasedProductsController,
|
||||||
|
RenameProductController,
|
||||||
|
} from "../../v1Controllers/simulationController/v1productController.ts";
|
||||||
|
|
||||||
|
const V1Product = express.Router();
|
||||||
|
|
||||||
|
V1Product.post("/ProductUpsert", tokenValidator, AddProductController);
|
||||||
|
V1Product.get("/EventsByProduct", tokenValidator, GetProductEventDatas);
|
||||||
|
V1Product.patch("/DeleteEvent", tokenValidator, DeleteEventsController);
|
||||||
|
V1Product.patch("/DeleteProduct", tokenValidator, DeleteProductController);
|
||||||
|
V1Product.get(
|
||||||
|
"/ProjectProducts/:projectId",
|
||||||
|
tokenValidator,
|
||||||
|
ProjectBasedProductsController
|
||||||
|
);
|
||||||
|
V1Product.patch("/RenameProduct", tokenValidator, RenameProductController);
|
||||||
|
export default V1Product;
|
||||||
@@ -6,22 +6,22 @@ import {
|
|||||||
searchTrashProjectController,
|
searchTrashProjectController,
|
||||||
} from "../../V1/v1Controllers/homeController/v1homeController.ts";
|
} from "../../V1/v1Controllers/homeController/v1homeController.ts";
|
||||||
|
|
||||||
const v1homeRoutes = express.Router();
|
const V1homeRoutes = express.Router();
|
||||||
|
|
||||||
v1homeRoutes.get(
|
V1homeRoutes.get(
|
||||||
"/RecentlyViewed",
|
"/RecentlyViewed",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
recentDataController
|
recentDataController
|
||||||
);
|
);
|
||||||
v1homeRoutes.get(
|
V1homeRoutes.get(
|
||||||
"/search/searchProjects",
|
"/search/searchProjects",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
searchProjectController
|
searchProjectController
|
||||||
);
|
);
|
||||||
v1homeRoutes.get(
|
V1homeRoutes.get(
|
||||||
"/search/searchTrashProjects",
|
"/search/searchTrashProjects",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
searchTrashProjectController
|
searchTrashProjectController
|
||||||
);
|
);
|
||||||
|
|
||||||
export default v1homeRoutes;
|
export default V1homeRoutes;
|
||||||
|
|||||||
@@ -9,34 +9,34 @@ import {
|
|||||||
} from "../../V1/v1Controllers/projectController/v1projectController.ts";
|
} from "../../V1/v1Controllers/projectController/v1projectController.ts";
|
||||||
import { tokenValidator } from "../../../shared/utils/token.ts";
|
import { tokenValidator } from "../../../shared/utils/token.ts";
|
||||||
|
|
||||||
const v1projectRouter = express.Router();
|
const V1projectRouter = express.Router();
|
||||||
|
|
||||||
v1projectRouter.post("/NewProject", tokenValidator, createProjectController);
|
V1projectRouter.post("/NewProject", tokenValidator, createProjectController);
|
||||||
v1projectRouter.post(
|
V1projectRouter.post(
|
||||||
"/project/Duplicate",
|
"/project/Duplicate",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
ProjectDuplicateController
|
ProjectDuplicateController
|
||||||
);
|
);
|
||||||
v1projectRouter.get(
|
V1projectRouter.get(
|
||||||
"/Projects",
|
"/Projects",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetProjects
|
GetProjects
|
||||||
);
|
);
|
||||||
v1projectRouter.patch(
|
V1projectRouter.patch(
|
||||||
"/Projects/Archive/:projectId",
|
"/Projects/Archive/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
RemoveProject
|
RemoveProject
|
||||||
);
|
);
|
||||||
|
|
||||||
v1projectRouter.patch(
|
V1projectRouter.patch(
|
||||||
"/Projects/:projectId",
|
"/Projects/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
updateProjectController
|
updateProjectController
|
||||||
);
|
);
|
||||||
v1projectRouter.get(
|
V1projectRouter.get(
|
||||||
"/Project/:projectId",
|
"/Project/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
ViewData
|
ViewData
|
||||||
);
|
);
|
||||||
|
|
||||||
export default v1projectRouter;
|
export default V1projectRouter;
|
||||||
|
|||||||
@@ -6,21 +6,21 @@ import {
|
|||||||
RestoreTrash,
|
RestoreTrash,
|
||||||
} from "../../V1/v1Controllers/trashController/v1trashController.ts";
|
} from "../../V1/v1Controllers/trashController/v1trashController.ts";
|
||||||
|
|
||||||
const v1TrashRoutes = express.Router();
|
const V1TrashRoutes = express.Router();
|
||||||
v1TrashRoutes.get(
|
V1TrashRoutes.get(
|
||||||
"/TrashItems",
|
"/TrashItems",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetTrashList
|
GetTrashList
|
||||||
);
|
);
|
||||||
|
|
||||||
v1TrashRoutes.patch(
|
V1TrashRoutes.patch(
|
||||||
"/Trash/restore",
|
"/Trash/restore",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
RestoreTrash
|
RestoreTrash
|
||||||
);
|
);
|
||||||
v1TrashRoutes.patch(
|
V1TrashRoutes.patch(
|
||||||
"/Trash/Delete",
|
"/Trash/Delete",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
DeleteTrashData
|
DeleteTrashData
|
||||||
);
|
);
|
||||||
export default v1TrashRoutes;
|
export default V1TrashRoutes;
|
||||||
|
|||||||
@@ -8,31 +8,31 @@ import {
|
|||||||
SingleFloatController,
|
SingleFloatController,
|
||||||
} from "../../v1Controllers/vizualizationController/v1floatWidgetController.ts";
|
} from "../../v1Controllers/vizualizationController/v1floatWidgetController.ts";
|
||||||
|
|
||||||
const v1FloatWidget = express.Router();
|
const V1FloatWidget = express.Router();
|
||||||
|
|
||||||
v1FloatWidget.post(
|
V1FloatWidget.post(
|
||||||
"/floatWidget/save",
|
"/floatWidget/save",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
FloatAddController
|
FloatAddController
|
||||||
);
|
);
|
||||||
v1FloatWidget.patch(
|
V1FloatWidget.patch(
|
||||||
"/floatWidget/delete",
|
"/floatWidget/delete",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
DeleteFloatController
|
DeleteFloatController
|
||||||
);
|
);
|
||||||
v1FloatWidget.get(
|
V1FloatWidget.get(
|
||||||
"/floatWidgets/:zoneUuid/:projectId",
|
"/floatWidgets/:zoneUuid/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetFloatController
|
GetFloatController
|
||||||
);
|
);
|
||||||
v1FloatWidget.get(
|
V1FloatWidget.get(
|
||||||
"/floatWidget/:floatWidgetId",
|
"/floatWidget/:floatWidgetId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
SingleFloatController
|
SingleFloatController
|
||||||
);
|
);
|
||||||
v1FloatWidget.post(
|
V1FloatWidget.post(
|
||||||
"/floatWidget/duplicate",
|
"/floatWidget/duplicate",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
DuplicateFloatController
|
DuplicateFloatController
|
||||||
);
|
);
|
||||||
export default v1FloatWidget;
|
export default V1FloatWidget;
|
||||||
|
|||||||
@@ -7,26 +7,26 @@ import {
|
|||||||
TemplateDeleteController,
|
TemplateDeleteController,
|
||||||
} from "../../v1Controllers/vizualizationController/v1templateController.ts";
|
} from "../../v1Controllers/vizualizationController/v1templateController.ts";
|
||||||
|
|
||||||
const v1Template = express.Router();
|
const V1Template = express.Router();
|
||||||
|
|
||||||
v1Template.post(
|
V1Template.post(
|
||||||
"/template/save",
|
"/template/save",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
AddTemplateController
|
AddTemplateController
|
||||||
);
|
);
|
||||||
v1Template.post(
|
V1Template.post(
|
||||||
"/template/toZone",
|
"/template/toZone",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
AddTemToZoneController
|
AddTemToZoneController
|
||||||
);
|
);
|
||||||
v1Template.get(
|
V1Template.get(
|
||||||
"/template/data/:projectId",
|
"/template/data/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetTemplateController
|
GetTemplateController
|
||||||
);
|
);
|
||||||
v1Template.patch(
|
V1Template.patch(
|
||||||
"/template/delete",
|
"/template/delete",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
TemplateDeleteController
|
TemplateDeleteController
|
||||||
);
|
);
|
||||||
export default v1Template;
|
export default V1Template;
|
||||||
|
|||||||
@@ -6,22 +6,22 @@ import {
|
|||||||
DeletePanelController,
|
DeletePanelController,
|
||||||
} from "../../v1Controllers/vizualizationController/v1panelController.ts";
|
} from "../../v1Controllers/vizualizationController/v1panelController.ts";
|
||||||
|
|
||||||
const v1PanelRoutes = express.Router();
|
const V1PanelRoutes = express.Router();
|
||||||
|
|
||||||
v1PanelRoutes.post(
|
V1PanelRoutes.post(
|
||||||
"/panel/save",
|
"/panel/save",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
AddPanelController
|
AddPanelController
|
||||||
);
|
);
|
||||||
v1PanelRoutes.patch(
|
V1PanelRoutes.patch(
|
||||||
"/panel/delete",
|
"/panel/delete",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
DeletePanelController
|
DeletePanelController
|
||||||
);
|
);
|
||||||
v1PanelRoutes.patch(
|
V1PanelRoutes.patch(
|
||||||
"/panel/clear",
|
"/panel/clear",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
ClearPanelController
|
ClearPanelController
|
||||||
);
|
);
|
||||||
|
|
||||||
export default v1PanelRoutes;
|
export default V1PanelRoutes;
|
||||||
|
|||||||
@@ -8,28 +8,28 @@ import {
|
|||||||
Update3DwidgetController,
|
Update3DwidgetController,
|
||||||
} from "../../v1Controllers/vizualizationController/widget3Dcontroller.ts";
|
} from "../../v1Controllers/vizualizationController/widget3Dcontroller.ts";
|
||||||
|
|
||||||
const v1Widget3d = express.Router();
|
const V1Widget3d = express.Router();
|
||||||
|
|
||||||
|
|
||||||
v1Widget3d.post(
|
V1Widget3d.post(
|
||||||
"/widget3d/save",
|
"/widget3d/save",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
|
|
||||||
Add3dWidgetController
|
Add3dWidgetController
|
||||||
);
|
);
|
||||||
v1Widget3d.patch(
|
V1Widget3d.patch(
|
||||||
"/widget3d/update",
|
"/widget3d/update",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
Update3DwidgetController
|
Update3DwidgetController
|
||||||
);
|
);
|
||||||
v1Widget3d.get(
|
V1Widget3d.get(
|
||||||
"/widget3d/data/:zoneUuid/:projectId",
|
"/widget3d/data/:zoneUuid/:projectId",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
Get3DWidgetController
|
Get3DWidgetController
|
||||||
);
|
);
|
||||||
v1Widget3d.patch(
|
V1Widget3d.patch(
|
||||||
"/widget3d/delete",
|
"/widget3d/delete",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
Delete3DwidgetController
|
Delete3DwidgetController
|
||||||
);
|
);
|
||||||
export default v1Widget3d;
|
export default V1Widget3d;
|
||||||
|
|||||||
@@ -7,26 +7,26 @@ import {
|
|||||||
WidgetUpdateController,
|
WidgetUpdateController,
|
||||||
} from "../../v1Controllers/vizualizationController/v1widgetController.ts";
|
} from "../../v1Controllers/vizualizationController/v1widgetController.ts";
|
||||||
|
|
||||||
const v1Widget = express.Router();
|
const V1Widget = express.Router();
|
||||||
|
|
||||||
v1Widget.post(
|
V1Widget.post(
|
||||||
"/widget/save",
|
"/widget/save",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
AddWidgetController
|
AddWidgetController
|
||||||
);
|
);
|
||||||
v1Widget.patch(
|
V1Widget.patch(
|
||||||
"/widget/:widgetID",
|
"/widget/:widgetID",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
WidgetUpdateController
|
WidgetUpdateController
|
||||||
);
|
);
|
||||||
v1Widget.get(
|
V1Widget.get(
|
||||||
"/widget/data",
|
"/widget/data",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
GetWidgetController
|
GetWidgetController
|
||||||
);
|
);
|
||||||
v1Widget.patch(
|
V1Widget.patch(
|
||||||
"/widget/delete",
|
"/widget/delete",
|
||||||
tokenValidator,
|
tokenValidator,
|
||||||
WidgetDeleteController
|
WidgetDeleteController
|
||||||
);
|
);
|
||||||
export default v1Widget;
|
export default V1Widget;
|
||||||
|
|||||||
@@ -22,20 +22,22 @@ import trashRouter from "./Routes/trashRoutes.ts";
|
|||||||
import homePageRouter from "./Routes/homepageRoutes.ts";
|
import homePageRouter from "./Routes/homepageRoutes.ts";
|
||||||
import redis from "../shared/redis/redis.ts";
|
import redis from "../shared/redis/redis.ts";
|
||||||
import Authrouter from "./V1/v1Routes/authRoutes.ts";
|
import Authrouter from "./V1/v1Routes/authRoutes.ts";
|
||||||
import v1TrashRoutes from "./V1/v1Routes/v1-trashRoutes.ts";
|
import V1projectRouter from "./V1/v1Routes/v1-projectRoutes.ts";
|
||||||
import v1homeRoutes from "./V1/v1Routes/v1-homeRoutes.ts";
|
import V1TrashRoutes from "./V1/v1Routes/v1-trashRoutes.ts";
|
||||||
import v1projectRouter from "./V1/v1Routes/v1-projectRoutes.ts";
|
import V1homeRoutes from "./V1/v1Routes/v1-homeRoutes.ts";
|
||||||
import v1Asset from "./V1/v1Routes/BuilderRoutes/v1-assetRoutes.ts";
|
import V1Asset from "./V1/v1Routes/BuilderRoutes/v1-assetRoutes.ts";
|
||||||
import v1Camera from "./V1/v1Routes/BuilderRoutes/v1-cameraRoutes.ts";
|
import V1Camera from "./V1/v1Routes/BuilderRoutes/v1-cameraRoutes.ts";
|
||||||
import v1Line from "./V1/v1Routes/BuilderRoutes/v1-linesRoutes.ts";
|
import V1Environment from "./V1/v1Routes/BuilderRoutes/v1-environmentRoutes.ts";
|
||||||
import v1Wall from "./V1/v1Routes/BuilderRoutes/v1-wallRoutes.ts";
|
import V1Line from "./V1/v1Routes/BuilderRoutes/v1-linesRoutes.ts";
|
||||||
import v1Zone from "./V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts";
|
import V1Wall from "./V1/v1Routes/BuilderRoutes/v1-wallRoutes.ts";
|
||||||
import v1FloatWidget from "./V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts";
|
import V1Zone from "./V1/v1Routes/BuilderRoutes/v1-ZoneRoutes.ts";
|
||||||
import v1PanelRoutes from "./V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts";
|
import V1FloatWidget from "./V1/v1Routes/vizRoutes.ts/v1-FloatWidgetRoutes.ts";
|
||||||
import v1Template from "./V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts";
|
import V1PanelRoutes from "./V1/v1Routes/vizRoutes.ts/v1-panelRoutes.ts";
|
||||||
import v1Widget from "./V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts";
|
import V1Template from "./V1/v1Routes/vizRoutes.ts/v1-TemplateRoutes.ts";
|
||||||
import v1Widget3d from "./V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts";
|
import V1Widget from "./V1/v1Routes/vizRoutes.ts/v1-widgetRoutes.ts";
|
||||||
import v1Environment from "./V1/v1Routes/BuilderRoutes/v1-environmentRoutes.ts";
|
import V1Widget3d from "./V1/v1Routes/vizRoutes.ts/v1-widget3dRoutes.ts";
|
||||||
|
import V1Product from "./V1/v1Routes/SimulationRoutes/v1-ProductRoutes.ts";
|
||||||
|
import V1Aisle from "./V1/v1Routes/BuilderRoutes/V1-AisleRoutes.ts";
|
||||||
redis;
|
redis;
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
@@ -72,19 +74,21 @@ app.use("/api/v1", trashRouter);
|
|||||||
app.use("/api/v1", homePageRouter);
|
app.use("/api/v1", homePageRouter);
|
||||||
|
|
||||||
app.use("/api/V1", Authrouter);
|
app.use("/api/V1", Authrouter);
|
||||||
app.use("/api/V1", v1projectRouter);
|
app.use("/api/V1", V1projectRouter);
|
||||||
app.use("/api/V1", v1TrashRoutes);
|
app.use("/api/V1", V1TrashRoutes);
|
||||||
app.use("/api/V1", v1homeRoutes);
|
app.use("/api/V1", V1homeRoutes);
|
||||||
app.use("/api/V1", v1Asset);
|
app.use("/api/V1", V1Asset);
|
||||||
app.use("/api/V1", v1Camera);
|
app.use("/api/V1", V1Camera);
|
||||||
app.use("/api/V1", v1Environment);
|
app.use("/api/V1", V1Line);
|
||||||
app.use("/api/V1", v1Line);
|
app.use("/api/V1", V1Environment);
|
||||||
app.use("/api/V1", v1Wall);
|
app.use("/api/V1", V1Wall);
|
||||||
app.use("/api/V1", v1Zone);
|
app.use("/api/V1", V1Zone);
|
||||||
app.use("/api/V1", v1FloatWidget);
|
app.use("/api/V1", V1FloatWidget);
|
||||||
app.use("/api/V1", v1PanelRoutes);
|
app.use("/api/V1", V1PanelRoutes);
|
||||||
app.use("/api/V1", v1Template);
|
app.use("/api/V1", V1Template);
|
||||||
app.use("/api/V1", v1Widget);
|
app.use("/api/V1", V1Widget);
|
||||||
app.use("/api/V1", v1Widget3d);
|
app.use("/api/V1", V1Widget3d);
|
||||||
|
app.use("/api/V1", V1Product);
|
||||||
|
app.use("/api/V1", V1Aisle);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
161
src/shared/V1Models/Builder/AisleModel.ts
Normal file
161
src/shared/V1Models/Builder/AisleModel.ts
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
import { Schema, Document } from "mongoose";
|
||||||
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
|
|
||||||
|
type PointTypes = "Aisle";
|
||||||
|
|
||||||
|
export interface Point {
|
||||||
|
pointUuid: string;
|
||||||
|
pointType: PointTypes;
|
||||||
|
position: [number, number, number];
|
||||||
|
layer: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ValidAisleTypes = [
|
||||||
|
"solid-aisle",
|
||||||
|
"dashed-aisle",
|
||||||
|
"stripped-aisle",
|
||||||
|
"dotted-aisle",
|
||||||
|
"arrow-aisle",
|
||||||
|
"arrows-aisle",
|
||||||
|
"arc-aisle",
|
||||||
|
"circle-aisle",
|
||||||
|
"junction-aisle",
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
const ValidAisleColors = [
|
||||||
|
"gray",
|
||||||
|
"yellow",
|
||||||
|
"green",
|
||||||
|
"orange",
|
||||||
|
"blue",
|
||||||
|
"purple",
|
||||||
|
"red",
|
||||||
|
"#66FF00",
|
||||||
|
"yellow-black",
|
||||||
|
"white-black",
|
||||||
|
] as const;
|
||||||
|
type AisleTypes =
|
||||||
|
| "solid-aisle"
|
||||||
|
| "dashed-aisle"
|
||||||
|
| "stripped-aisle"
|
||||||
|
| "dotted-aisle"
|
||||||
|
| "arrow-aisle"
|
||||||
|
| "arrows-aisle"
|
||||||
|
| "arc-aisle"
|
||||||
|
| "circle-aisle"
|
||||||
|
| "junction-aisle";
|
||||||
|
|
||||||
|
type AisleColors =
|
||||||
|
| "gray"
|
||||||
|
| "yellow"
|
||||||
|
| "green"
|
||||||
|
| "orange"
|
||||||
|
| "blue"
|
||||||
|
| "purple"
|
||||||
|
| "red"
|
||||||
|
| "#66FF00"
|
||||||
|
| "yellow-black"
|
||||||
|
| "white-black";
|
||||||
|
|
||||||
|
interface ForAisle {
|
||||||
|
aisleType: AisleTypes;
|
||||||
|
aisleColor: AisleColors;
|
||||||
|
}
|
||||||
|
interface SolidAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DashedAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
dashLength: number;
|
||||||
|
gapLength: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DottedAisle extends ForAisle {
|
||||||
|
dotRadius: number;
|
||||||
|
gapLength: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ArrowAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ArrowsAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
aisleLength: number;
|
||||||
|
gapLength: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ArcAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
isFlipped: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CircleAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JunctionAisle extends ForAisle {
|
||||||
|
aisleWidth: number;
|
||||||
|
isFlipped: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AisleType =
|
||||||
|
| SolidAisle
|
||||||
|
| DashedAisle
|
||||||
|
| DottedAisle
|
||||||
|
| ArrowAisle
|
||||||
|
| ArrowsAisle
|
||||||
|
| ArcAisle
|
||||||
|
| CircleAisle
|
||||||
|
| JunctionAisle;
|
||||||
|
|
||||||
|
export interface Aisle extends Document {
|
||||||
|
aisleUuid: string;
|
||||||
|
points: [Point, Point];
|
||||||
|
projectId: Project["_id"];
|
||||||
|
createdBy: User["_id"];
|
||||||
|
type: AisleType;
|
||||||
|
isArchive: boolean;
|
||||||
|
}
|
||||||
|
type Aisles = Aisle[];
|
||||||
|
const AisleSchema: Schema = new Schema(
|
||||||
|
{
|
||||||
|
aisleUuid: { type: String, required: true },
|
||||||
|
createdBy: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
points: {
|
||||||
|
type: [
|
||||||
|
{
|
||||||
|
pointUuid: String,
|
||||||
|
pointType: { type: String, enum: ["Aisle"] },
|
||||||
|
position: [Number],
|
||||||
|
layer: Number,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: Object,
|
||||||
|
validate: {
|
||||||
|
validator: function (value: any) {
|
||||||
|
return (
|
||||||
|
value &&
|
||||||
|
ValidAisleTypes.includes(value.aisleType) &&
|
||||||
|
ValidAisleColors.includes(value.aisleColor)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
message: (props: any) =>
|
||||||
|
`Invalid aisleType or aisleColor: ${JSON.stringify(props.value)}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
const AisleModel = (db: any) => {
|
||||||
|
return MainModel(db, "Aisle", AisleSchema, "Aisle");
|
||||||
|
};
|
||||||
|
export default AisleModel;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Schema, Document } from "mongoose";
|
import { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
import { Project } from "../Project/project-model.ts";
|
||||||
interface AssetEventSchema {
|
interface AssetEventSchema {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
modelName: string;
|
modelName: string;
|
||||||
@@ -130,7 +130,8 @@ interface IPointModel extends Document {
|
|||||||
position: [number];
|
position: [number];
|
||||||
rotation: [number];
|
rotation: [number];
|
||||||
state: string;
|
state: string;
|
||||||
productId: string;
|
productUuid: string;
|
||||||
|
projectId: Project["_id"];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
type: "transfer" | "vehicle" | "roboticArm" | "machine" | "storageUnit";
|
type: "transfer" | "vehicle" | "roboticArm" | "machine" | "storageUnit";
|
||||||
speed: number;
|
speed: number;
|
||||||
@@ -165,7 +166,8 @@ const BaseEventSchema = new Schema<IPointModel>(
|
|||||||
points: {
|
points: {
|
||||||
type: Schema.Types.Mixed,
|
type: Schema.Types.Mixed,
|
||||||
},
|
},
|
||||||
productId: { type: String, required: true },
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
productUuid: { type: String, required: true },
|
||||||
isArchive: { type: Boolean, default: false },
|
isArchive: { type: Boolean, default: false },
|
||||||
},
|
},
|
||||||
{ discriminatorKey: "type", timestamps: true }
|
{ discriminatorKey: "type", timestamps: true }
|
||||||
|
|||||||
@@ -2,25 +2,27 @@ import { Schema, Document } from "mongoose";
|
|||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
import { Project } from "../Project/project-model.ts";
|
import { Project } from "../Project/project-model.ts";
|
||||||
import { Version } from "../Version/versionModel.ts";
|
import { Version } from "../Version/versionModel.ts";
|
||||||
|
import { User } from "../Auth/userAuthModel.ts";
|
||||||
export interface Product extends Document {
|
export interface Product extends Document {
|
||||||
productName: string;
|
productName: string;
|
||||||
productId: string;
|
userId: User["_id"];
|
||||||
|
productUuid: string;
|
||||||
projectId: Project["_id"];
|
projectId: Project["_id"];
|
||||||
versionId: Version["_id"];
|
versionId: Version["_id"];
|
||||||
eventsData: [];
|
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductSchema = new Schema({
|
const ProductSchema = new Schema({
|
||||||
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
projectId: { type: Schema.Types.ObjectId, ref: "Project" },
|
||||||
|
userId: { type: Schema.Types.ObjectId, ref: "User" },
|
||||||
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
versionId: { type: Schema.Types.ObjectId, ref: "Version" },
|
||||||
productName: { type: String, required: true },
|
productName: { type: String, required: true },
|
||||||
productId: { type: String, required: true },
|
productUuid: { type: String, required: true },
|
||||||
isArchive: { type: Boolean, default: false },
|
isArchive: { type: Boolean, default: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
const ProductModel = (db: string) => {
|
const ProductModel = (db: string) => {
|
||||||
return MainModel(db, "Product", ProductSchema, "Product");
|
return MainModel(db, "Products", ProductSchema, "Products");
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ProductModel;
|
export default ProductModel;
|
||||||
|
|||||||
154
src/shared/services/builder/AisleService.ts
Normal file
154
src/shared/services/builder/AisleService.ts
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
import AisleModel, {
|
||||||
|
AisleType,
|
||||||
|
Point,
|
||||||
|
} from "../../V1Models/Builder/AisleModel.ts";
|
||||||
|
import {
|
||||||
|
existingProjectById,
|
||||||
|
existingUser,
|
||||||
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
interface IAisleDatas {
|
||||||
|
userId: string;
|
||||||
|
aisleUuid: string;
|
||||||
|
points?: [Point, Point];
|
||||||
|
type?: AisleType;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IAisleDelete {
|
||||||
|
userId: string;
|
||||||
|
aisleUuid: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IProjectAisles {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
export const SetAisle = async (
|
||||||
|
data: IAisleDatas
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { aisleUuid, points, type, organization, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingAisle = await AisleModel(organization).findOne({
|
||||||
|
aisleUuid: aisleUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (ExistingAisle) {
|
||||||
|
const UpdateAisle = await AisleModel(organization).findOneAndUpdate(
|
||||||
|
{ aisleUuid: aisleUuid, projectId: projectId, isArchive: false },
|
||||||
|
{ type: type, points: points },
|
||||||
|
{ new: true, runValidators: true }
|
||||||
|
);
|
||||||
|
if (!UpdateAisle) return { status: "Aisle Not Updated" };
|
||||||
|
return { status: "Aisle Updated Successfully", data: UpdateAisle };
|
||||||
|
} else {
|
||||||
|
const NewAisle = await AisleModel(organization).create({
|
||||||
|
aisleUuid,
|
||||||
|
projectId,
|
||||||
|
type: type,
|
||||||
|
points: points,
|
||||||
|
createdBy: userId,
|
||||||
|
});
|
||||||
|
if (!NewAisle) return { status: "Aisle Not Created" };
|
||||||
|
return { status: "Success", data: NewAisle };
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
if (error.name === "ValidationError") {
|
||||||
|
return {
|
||||||
|
status: "Aisle validation failed",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const DeleteAisle = async (
|
||||||
|
data: IAisleDelete
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { aisleUuid, organization, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingAisle = await AisleModel(organization).findOne({
|
||||||
|
aisleUuid: aisleUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (ExistingAisle) {
|
||||||
|
await AisleModel(organization).updateOne(
|
||||||
|
{ aisleUuid: aisleUuid, projectId: projectId, isArchive: false },
|
||||||
|
{ isArchive: true }
|
||||||
|
);
|
||||||
|
return { status: "Success" };
|
||||||
|
}
|
||||||
|
return { status: "Aisle not found" };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const GetProjectAisles = async (
|
||||||
|
data: IProjectAisles
|
||||||
|
): Promise<{ status: string; data?: Object }> => {
|
||||||
|
try {
|
||||||
|
const { organization, projectId, userId } = data;
|
||||||
|
const UserExists = await existingUser(userId, organization);
|
||||||
|
if (!UserExists) return { status: "User not found" };
|
||||||
|
const LivingProject = await existingProjectById(
|
||||||
|
projectId,
|
||||||
|
organization,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
|
const ExistingAisle = await AisleModel(organization)
|
||||||
|
.find({
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("aisleUuid points type");
|
||||||
|
if (ExistingAisle) {
|
||||||
|
return { status: "Success", data: ExistingAisle };
|
||||||
|
}
|
||||||
|
return { status: "Aisle not found", data: [] };
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return {
|
||||||
|
status: error.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "An unexpected error occurred",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -288,7 +288,7 @@ export const deleteAssetModel = async (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
await EventsDataModel(organization).updateMany(
|
await EventsDataModel(organization).updateMany(
|
||||||
{ modelUuid, productId: projectId },
|
{ modelUuid, projectId: projectId },
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,6 @@ export const DeleteLayer = async (
|
|||||||
): Promise<{ status: string; data?: object }> => {
|
): Promise<{ status: string; data?: object }> => {
|
||||||
try {
|
try {
|
||||||
const { organization, projectId, layer, userId } = data;
|
const { organization, projectId, layer, userId } = data;
|
||||||
console.log("data: ", data);
|
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
|
|||||||
@@ -5,10 +5,19 @@ import {
|
|||||||
existingProjectById,
|
existingProjectById,
|
||||||
existingUser,
|
existingUser,
|
||||||
} from "../helpers/v1projecthelperFns.ts";
|
} from "../helpers/v1projecthelperFns.ts";
|
||||||
|
interface IEventDatainterface {
|
||||||
|
modelUuid: string;
|
||||||
|
modelName: string;
|
||||||
|
position: [number];
|
||||||
|
rotation: [number];
|
||||||
|
type: string;
|
||||||
|
speed: string;
|
||||||
|
point: Mixed;
|
||||||
|
points: Mixed;
|
||||||
|
}
|
||||||
interface Iproduct {
|
interface Iproduct {
|
||||||
productName: string;
|
productName: string;
|
||||||
productId: string;
|
productUuid: string;
|
||||||
eventDatas: {
|
eventDatas: {
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
modelName: string;
|
modelName: string;
|
||||||
@@ -23,22 +32,41 @@ interface Iproduct {
|
|||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
}
|
}
|
||||||
interface IResult {
|
interface IProductEvent {
|
||||||
status: string;
|
productUuid: string;
|
||||||
data?: object;
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
}
|
}
|
||||||
interface IEventDataDelete {
|
interface IDelEvent {
|
||||||
productId: string;
|
productUuid: string;
|
||||||
modelUuid: string;
|
modelUuid: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
}
|
}
|
||||||
|
interface IProjectProducts {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
}
|
||||||
|
interface IProductRename {
|
||||||
|
userId: string;
|
||||||
|
organization: string;
|
||||||
|
projectId: string;
|
||||||
|
productUuid: string;
|
||||||
|
productName: string;
|
||||||
|
}
|
||||||
|
interface IResult {
|
||||||
|
status: string;
|
||||||
|
data?: object;
|
||||||
|
}
|
||||||
|
|
||||||
export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
productName,
|
productName,
|
||||||
productId,
|
productUuid,
|
||||||
eventDatas,
|
eventDatas,
|
||||||
projectId,
|
projectId,
|
||||||
userId,
|
userId,
|
||||||
@@ -52,73 +80,53 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
const existingProduct = await ProductModel(organization).findOne({
|
const existingProduct = await ProductAFind(
|
||||||
productId: productId,
|
productUuid,
|
||||||
projectId: projectId,
|
projectId,
|
||||||
isArchive: false,
|
organization
|
||||||
});
|
);
|
||||||
if (existingProduct) {
|
if (existingProduct) {
|
||||||
const existingEventData = await EventsDataModel(organization).findOne({
|
const existingEventData = await EventsDataModel(organization).findOne({
|
||||||
productId: productId,
|
productUuid: productUuid,
|
||||||
projectId: projectId,
|
projectId: projectId,
|
||||||
modelUuid: eventDatas.modelUuid,
|
modelUuid: eventDatas.modelUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (existingEventData) {
|
if (existingEventData) {
|
||||||
await EventsDataModel(organization).findOneAndUpdate(
|
await EventUpdateFunction(
|
||||||
{
|
organization,
|
||||||
modelUuid: eventDatas.modelUuid,
|
eventDatas,
|
||||||
productId: productId,
|
productUuid,
|
||||||
isArchive: false,
|
projectId
|
||||||
},
|
|
||||||
{
|
|
||||||
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 {
|
return {
|
||||||
status: "EventData updated successfully",
|
status: "EventData updated successfully",
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
await EventsDataModel(organization).create({
|
await EventCreateFunction(
|
||||||
productId: productId,
|
organization,
|
||||||
modelUuid: eventDatas?.modelUuid,
|
eventDatas,
|
||||||
modelName: eventDatas?.modelName,
|
productUuid,
|
||||||
position: eventDatas?.position,
|
projectId
|
||||||
rotation: eventDatas?.rotation,
|
);
|
||||||
type: eventDatas?.type,
|
|
||||||
speed: eventDatas?.speed,
|
|
||||||
point: eventDatas?.point,
|
|
||||||
points: eventDatas?.points,
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
status: "EventData add successfully",
|
status: "EventData add successfully",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const newProduct = await ProductModel(organization).create({
|
const newProduct = await ProductModel(organization).create({
|
||||||
productId: productId,
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
productName: productName,
|
productName: productName,
|
||||||
});
|
});
|
||||||
if (newProduct) {
|
if (newProduct) {
|
||||||
if (eventDatas) {
|
if (eventDatas) {
|
||||||
await EventsDataModel(organization).create({
|
await EventCreateFunction(
|
||||||
productId: productId,
|
organization,
|
||||||
modelUuid: eventDatas?.modelUuid,
|
eventDatas,
|
||||||
modelName: eventDatas?.modelName,
|
productUuid,
|
||||||
position: eventDatas?.position,
|
projectId
|
||||||
rotation: eventDatas?.rotation,
|
);
|
||||||
type: eventDatas?.type,
|
|
||||||
speed: eventDatas?.speed,
|
|
||||||
point: eventDatas?.point,
|
|
||||||
points: eventDatas?.points,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -137,9 +145,69 @@ export const productAdd = async (data: Iproduct): Promise<IResult> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const getProductDatas = async (data: Iproduct): Promise<IResult> => {
|
|
||||||
|
async function EventCreateFunction(
|
||||||
|
organization: string,
|
||||||
|
eventDatas: IEventDatainterface,
|
||||||
|
productUuid: string,
|
||||||
|
projectId: string
|
||||||
|
) {
|
||||||
|
await EventsDataModel(organization).create({
|
||||||
|
projectId: projectId,
|
||||||
|
productUuid: productUuid,
|
||||||
|
modelUuid: eventDatas?.modelUuid as string,
|
||||||
|
modelName: eventDatas?.modelName,
|
||||||
|
position: eventDatas?.position,
|
||||||
|
rotation: eventDatas?.rotation,
|
||||||
|
type: eventDatas?.type,
|
||||||
|
speed: eventDatas?.speed,
|
||||||
|
point: eventDatas?.point,
|
||||||
|
points: eventDatas?.points,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function EventUpdateFunction(
|
||||||
|
organization: string,
|
||||||
|
eventDatas: IEventDatainterface,
|
||||||
|
productUuid: string,
|
||||||
|
projectId: string
|
||||||
|
) {
|
||||||
|
await EventsDataModel(organization).findOneAndUpdate(
|
||||||
|
{
|
||||||
|
projectId: projectId,
|
||||||
|
modelUuid: eventDatas.modelUuid,
|
||||||
|
productUuid: productUuid,
|
||||||
|
isArchive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
modelUuid: eventDatas?.modelUuid,
|
||||||
|
modelName: eventDatas?.modelName,
|
||||||
|
position: eventDatas?.position,
|
||||||
|
rotation: eventDatas?.rotation,
|
||||||
|
type: eventDatas?.type,
|
||||||
|
speed: eventDatas?.speed,
|
||||||
|
point: eventDatas?.point,
|
||||||
|
points: eventDatas?.points,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
async function ProductAFind(
|
||||||
|
productUuid: string,
|
||||||
|
projectId: string,
|
||||||
|
organization: string
|
||||||
|
) {
|
||||||
|
const existingProduct = await ProductModel(organization).findOne({
|
||||||
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
return existingProduct;
|
||||||
|
}
|
||||||
|
export const getProductDatas = async (
|
||||||
|
data: IProductEvent
|
||||||
|
): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { productId, projectId, userId, organization } = data;
|
const { productUuid, projectId, userId, organization } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -148,17 +216,23 @@ export const getProductDatas = async (data: Iproduct): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
const existingProduct = await ProductModel(organization).findOne({
|
const ExistingProduct = await ProductAFind(
|
||||||
productId: productId,
|
productUuid,
|
||||||
projectId: projectId,
|
projectId,
|
||||||
isArchive: false,
|
organization
|
||||||
});
|
);
|
||||||
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
if (!existingProduct) return { status: "Product not found" };
|
|
||||||
|
|
||||||
const existingEventDatas = await EventsDataModel(organization)
|
const existingEventDatas = await EventsDataModel(organization)
|
||||||
.find({ productId: productId, projectId: projectId })
|
.find({
|
||||||
.select("-productId");
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
})
|
||||||
|
.select("-productUuid");
|
||||||
|
if (!existingEventDatas) {
|
||||||
|
return { status: "Events not found", data: [] };
|
||||||
|
}
|
||||||
return { status: "Success", data: existingEventDatas };
|
return { status: "Success", data: existingEventDatas };
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
@@ -172,9 +246,11 @@ export const getProductDatas = async (data: Iproduct): Promise<IResult> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const productDataDelete = async (data: Iproduct): Promise<IResult> => {
|
export const productDataDelete = async (
|
||||||
|
data: IProductEvent
|
||||||
|
): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { productId, projectId, userId, organization } = data;
|
const { productUuid, projectId, userId, organization } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -183,26 +259,28 @@ export const productDataDelete = async (data: Iproduct): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
const existingProduct = await ProductModel(organization).findOne({
|
const ExistingProduct = await ProductAFind(
|
||||||
productId: productId,
|
productUuid,
|
||||||
isArchive: false,
|
projectId,
|
||||||
});
|
organization
|
||||||
|
);
|
||||||
if (!existingProduct) return { status: "Product not found" };
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
|
|
||||||
await ProductModel(organization).findOneAndUpdate(
|
await ProductModel(organization).findOneAndUpdate(
|
||||||
{ productId: productId, projectId: projectId },
|
{ productUuid: productUuid, projectId: projectId, isArchive: false },
|
||||||
{
|
{
|
||||||
isArchive: true,
|
isArchive: true,
|
||||||
},
|
},
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
const existingEventDatas = await EventsDataModel(organization).find({
|
const existingEventDatas = await EventsDataModel(organization).find({
|
||||||
productId: productId,
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (existingEventDatas) {
|
if (existingEventDatas) {
|
||||||
await EventsDataModel(organization).updateMany(
|
await EventsDataModel(organization).updateMany(
|
||||||
{ productId, projectId },
|
{ productUuid, projectId, isArchive: false },
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -221,11 +299,9 @@ export const productDataDelete = async (data: Iproduct): Promise<IResult> => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const EventDataDelete = async (
|
export const EventDataDelete = async (data: IDelEvent): Promise<IResult> => {
|
||||||
data: IEventDataDelete
|
|
||||||
): Promise<IResult> => {
|
|
||||||
try {
|
try {
|
||||||
const { modelUuid, productId, projectId, userId, organization } = data;
|
const { modelUuid, productUuid, projectId, userId, organization } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -234,21 +310,28 @@ export const EventDataDelete = async (
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
const existingProduct = await ProductModel(organization).findOne({
|
const ExistingProduct = await ProductAFind(
|
||||||
productId: productId,
|
productUuid,
|
||||||
projectId: projectId,
|
projectId,
|
||||||
isArchive: false,
|
organization
|
||||||
});
|
);
|
||||||
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
if (!existingProduct) return { status: "Product not found" };
|
const EventDel = await EventsDataModel(organization).findOneAndUpdate(
|
||||||
await EventsDataModel(organization).findOneAndUpdate(
|
{
|
||||||
{ productId: productId, projectId: projectId, modelUuid: modelUuid },
|
productUuid: productUuid,
|
||||||
|
projectId: projectId,
|
||||||
|
isArchive: false,
|
||||||
|
modelUuid: modelUuid,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
isArchive: true,
|
isArchive: true,
|
||||||
},
|
},
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
if (!EventDel)
|
||||||
|
return {
|
||||||
|
status: "Event Delete Unsuccessful",
|
||||||
|
};
|
||||||
return {
|
return {
|
||||||
status: "Success",
|
status: "Success",
|
||||||
};
|
};
|
||||||
@@ -265,7 +348,7 @@ export const EventDataDelete = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const AllProductDatas = async (
|
export const AllProductDatas = async (
|
||||||
data: IEventDataDelete
|
data: IProjectProducts
|
||||||
): Promise<IResult> => {
|
): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { projectId, userId, organization } = data;
|
const { projectId, userId, organization } = data;
|
||||||
@@ -279,10 +362,12 @@ export const AllProductDatas = async (
|
|||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
const existingProduct = await ProductModel(organization).find({
|
const existingProduct = await ProductModel(organization).find({
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
|
projectId: projectId,
|
||||||
});
|
});
|
||||||
if (!existingProduct) {
|
if (!existingProduct) {
|
||||||
return {
|
return {
|
||||||
status: "No products found",
|
status: "No products found",
|
||||||
|
data: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const result = [];
|
const result = [];
|
||||||
@@ -291,15 +376,15 @@ export const AllProductDatas = async (
|
|||||||
const eventDatas = await EventsDataModel(organization)
|
const eventDatas = await EventsDataModel(organization)
|
||||||
.find({
|
.find({
|
||||||
projectId: product.projectId,
|
projectId: product.projectId,
|
||||||
productId: product.productId,
|
productUuid: product.productUuid,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
})
|
})
|
||||||
.select("-productId -isArchive -createdAt -updatedAt -__v -_id");
|
.select("-productUuid -isArchive -createdAt -updatedAt -__v -_id");
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
projectId: product.projectId,
|
projectId: product.projectId,
|
||||||
productName: product.productName,
|
productName: product.productName,
|
||||||
productId: product.productId,
|
productUuid: product.productUuid,
|
||||||
eventDatas,
|
eventDatas,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -320,9 +405,9 @@ export const AllProductDatas = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export const productRename = async (data: Iproduct): Promise<IResult> => {
|
export const productRename = async (data: IProductRename): Promise<IResult> => {
|
||||||
try {
|
try {
|
||||||
const { productName, productId, projectId, userId, organization } = data;
|
const { productName, productUuid, projectId, userId, organization } = data;
|
||||||
const UserExists = await existingUser(userId, organization);
|
const UserExists = await existingUser(userId, organization);
|
||||||
if (!UserExists) return { status: "User not found" };
|
if (!UserExists) return { status: "User not found" };
|
||||||
const LivingProject = await existingProjectById(
|
const LivingProject = await existingProjectById(
|
||||||
@@ -331,22 +416,25 @@ export const productRename = async (data: Iproduct): Promise<IResult> => {
|
|||||||
userId
|
userId
|
||||||
);
|
);
|
||||||
if (!LivingProject) return { status: "Project not found" };
|
if (!LivingProject) return { status: "Project not found" };
|
||||||
const existingProduct = await ProductModel(organization).findOne({
|
const ExistingProduct = await ProductAFind(
|
||||||
productId: productId,
|
productUuid,
|
||||||
projectId: projectId,
|
projectId,
|
||||||
isArchive: false,
|
organization
|
||||||
});
|
);
|
||||||
|
if (!ExistingProduct) return { status: "Product not found" };
|
||||||
|
|
||||||
if (!existingProduct) return { status: "Product not found" };
|
const UpdateName = await ProductModel(organization).findOneAndUpdate(
|
||||||
|
{ productUuid: productUuid, projectId: projectId, isArchive: false },
|
||||||
await ProductModel(organization).findOneAndUpdate(
|
|
||||||
{ productId: productId },
|
|
||||||
{
|
{
|
||||||
productName: productName,
|
productName: productName,
|
||||||
},
|
},
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
if (!UpdateName) {
|
||||||
|
return {
|
||||||
|
status: "Rename Unsuccessful",
|
||||||
|
};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
status: "Success",
|
status: "Success",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
import { Socket, Server } from "socket.io";
|
||||||
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
|
import {
|
||||||
|
ErrorResponse,
|
||||||
|
FinalResponse,
|
||||||
|
validateFields,
|
||||||
|
} from "../../utils/socketfunctionHelpers.ts";
|
||||||
|
import {
|
||||||
|
DeleteAisle,
|
||||||
|
SetAisle,
|
||||||
|
} from "../../../shared/services/builder/AisleService.ts";
|
||||||
|
export const SetAisleHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.setAisleModel_v1 || !data?.organization) return;
|
||||||
|
const requiredFields = ["aisleUuid", "projectId", "userId", "organization"];
|
||||||
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.Aisle_v1UpdateResponse,
|
||||||
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await SetAisle(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Aisle Created Successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Aisle Not Updated": { message: "Aisle Not Updated" },
|
||||||
|
"Aisle Not Created": { message: "Aisle Not Created" },
|
||||||
|
"Aisle Updated Successfully": { message: "Aisle Updated Successfully" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Camera_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
|
const response = FinalResponse(
|
||||||
|
status,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
messages,
|
||||||
|
Camera_Datas
|
||||||
|
);
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.Aisle_v1UpdateResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const DeleteAisleHandleEvent = async (
|
||||||
|
event: string,
|
||||||
|
socket: Socket,
|
||||||
|
io: Server,
|
||||||
|
data: any,
|
||||||
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
if (event !== EVENTS.delete_v1AisleModel || !data?.organization) return;
|
||||||
|
const requiredFields = ["aisleUuid", "projectId", "userId", "organization"];
|
||||||
|
const missingFields = validateFields(data, requiredFields);
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.Aisle_v1DeleteResponse,
|
||||||
|
ErrorResponse(missingFields, socket, data.organization),
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await DeleteAisle(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
|
const messages: Record<string, { message: string }> = {
|
||||||
|
Success: { message: "Aisle Deleted Successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Aisle not found": { message: "Aisle not found" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const Camera_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
|
const response = FinalResponse(
|
||||||
|
status,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
messages,
|
||||||
|
Camera_Datas
|
||||||
|
);
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.Aisle_v1DeleteResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -142,7 +142,6 @@ export const DeleteLineHandleEvent = async (
|
|||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.deleteLine_v1 || !data?.organization) return;
|
if (event !== EVENTS.deleteLine_v1 || !data?.organization) return;
|
||||||
console.log("data: ", data);
|
|
||||||
console.log("event: ", event);
|
console.log("event: ", event);
|
||||||
const requiredFields = ["line", "projectId", "userId", "organization"];
|
const requiredFields = ["line", "projectId", "userId", "organization"];
|
||||||
|
|
||||||
|
|||||||
@@ -1,272 +1,318 @@
|
|||||||
import { Socket, Server } from "socket.io";
|
import { Socket, Server } from "socket.io";
|
||||||
import { EVENTS } from "../../socket/events.ts";
|
import { EVENTS } from "../../socket/events.ts";
|
||||||
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
import { emitToSenderAndAdmins } from "../../utils/emitEventResponse.ts";
|
||||||
import { EventDataDelete, productAdd, productDataDelete } from "../../../shared/services/simulation/productService.ts";
|
import {
|
||||||
|
EventDataDelete,
|
||||||
|
productAdd,
|
||||||
|
productDataDelete,
|
||||||
|
productRename,
|
||||||
|
} from "../../../shared/services/simulation/productService.ts";
|
||||||
export const productAddHandleEvent = async (
|
export const productAddHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.setAssetModel_v1 || !data?.organization) return;
|
if (event !== EVENTS.setProductModel_v1 || !data?.organization) return;
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
"productName", "productId", "eventDatas",
|
"productName",
|
||||||
"projectId",
|
"productUuid",
|
||||||
"userId",
|
"projectId",
|
||||||
"organization",
|
"userId",
|
||||||
];
|
"organization",
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
];
|
||||||
|
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||||
if (missingFields.length > 0) {
|
|
||||||
const response = {
|
|
||||||
success: false,
|
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
|
||||||
status: "MissingFields",
|
|
||||||
socketId: socket.id,
|
|
||||||
organization: data?.organization ?? "unknown",
|
|
||||||
};
|
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await productAdd(data);
|
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
|
||||||
Success: { message: "Product created successfully" },
|
|
||||||
"User not found": { message: "User not found" },
|
|
||||||
"Project not found": { message: "Project not found" },
|
|
||||||
"EventData updated successfully": { message: "EventData updated successfully" },
|
|
||||||
"EventData add successfully": { message: "EventData add successfully" },
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
|
||||||
const product_Datas =
|
|
||||||
status === "Success" && result?.data
|
|
||||||
|
|
||||||
? {
|
|
||||||
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
const response = {
|
const response = {
|
||||||
success: status === "Success",
|
success: false,
|
||||||
message: msg.message,
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
status,
|
status: "MissingFields",
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization: data.organization,
|
organization: data?.organization ?? "unknown",
|
||||||
...(product_Datas ? { data: product_Datas } : {}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.Product_v1UpdateResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await productAdd(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
const messages: Record<string, { message: string }> = {
|
||||||
}
|
Success: { message: "Product created successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"EventData updated successfully": {
|
||||||
|
message: "EventData updated successfully",
|
||||||
|
},
|
||||||
|
"EventData add successfully": { message: "EventData add successfully" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const product_Datas = status === "Success" && result?.data ? {} : undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(product_Datas ? { data: product_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.Product_v1UpdateResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
export const productDataDeleteHandleEvent = async (
|
export const productDataDeleteHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.setAssetModel_v1 || !data?.organization) return;
|
if (event !== EVENTS.delete_v1ProductModel || !data?.organization) return;
|
||||||
const requiredFields = [
|
const requiredFields = ["productUuid", "projectId", "userId", "organization"];
|
||||||
"productId",
|
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||||
"projectId",
|
|
||||||
"userId",
|
|
||||||
"organization",
|
|
||||||
];
|
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
|
||||||
const response = {
|
|
||||||
success: false,
|
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
|
||||||
status: "MissingFields",
|
|
||||||
socketId: socket.id,
|
|
||||||
organization: data?.organization ?? "unknown",
|
|
||||||
};
|
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await productDataDelete(data);
|
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
|
||||||
Success: { message: "Product deleted successfully" },
|
|
||||||
"User not found": { message: "User not found" },
|
|
||||||
"Project not found": { message: "Project not found" },
|
|
||||||
"Product not found": { message: "Product not found" },
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
|
||||||
const product_Datas =
|
|
||||||
status === "Success" && result?.data
|
|
||||||
|
|
||||||
? {
|
|
||||||
// widget: {
|
|
||||||
// id: result.data.widgetID,
|
|
||||||
// type: result.data.projectName,
|
|
||||||
// position: result.data.position,
|
|
||||||
// },
|
|
||||||
// Data: result.data.Data,
|
|
||||||
// zoneId: result.data.zoneId,
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
const response = {
|
const response = {
|
||||||
success: status === "Success",
|
success: false,
|
||||||
message: msg.message,
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
status,
|
status: "MissingFields",
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization: data.organization,
|
organization: data?.organization ?? "unknown",
|
||||||
...(product_Datas ? { data: product_Datas } : {}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.Product_v1DeleteResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await productDataDelete(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
const messages: Record<string, { message: string }> = {
|
||||||
}
|
Success: { message: "Product deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Product not found": { message: "Product not found" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const product_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(product_Datas ? { data: product_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.Product_v1DeleteResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
export const EventDataDeleteHandleEvent = async (
|
export const EventDataDeleteHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.setAssetModel_v1 || !data?.organization) return;
|
if (event !== EVENTS.deleteEvent_v1ProductModel || !data?.organization)
|
||||||
const requiredFields = [
|
return;
|
||||||
"modelUuid",
|
const requiredFields = [
|
||||||
"productId",
|
"modelUuid",
|
||||||
"projectId",
|
"productUuid",
|
||||||
"userId",
|
"projectId",
|
||||||
"organization",
|
"userId",
|
||||||
];
|
"organization",
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
];
|
||||||
|
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||||
if (missingFields.length > 0) {
|
|
||||||
const response = {
|
|
||||||
success: false,
|
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
|
||||||
status: "MissingFields",
|
|
||||||
socketId: socket.id,
|
|
||||||
organization: data?.organization ?? "unknown",
|
|
||||||
};
|
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await EventDataDelete(data);
|
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
|
||||||
Success: { message: "EventData deleted successfully" },
|
|
||||||
"User not found": { message: "User not found" },
|
|
||||||
"Project not found": { message: "Project not found" },
|
|
||||||
"Product not found": { message: "Product not found" },
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
|
||||||
const product_Datas =
|
|
||||||
status === "Success" && result?.data
|
|
||||||
|
|
||||||
? {
|
|
||||||
// widget: {
|
|
||||||
// id: result.data.widgetID,
|
|
||||||
// type: result.data.projectName,
|
|
||||||
// position: result.data.position,
|
|
||||||
// },
|
|
||||||
// Data: result.data.Data,
|
|
||||||
// zoneId: result.data.zoneId,
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
const response = {
|
const response = {
|
||||||
success: status === "Success",
|
success: false,
|
||||||
message: msg.message,
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
status,
|
status: "MissingFields",
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization: data.organization,
|
organization: data?.organization ?? "unknown",
|
||||||
...(product_Datas ? { data: product_Datas } : {}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.ProductEvent_v1DeleteResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await EventDataDelete(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
const messages: Record<string, { message: string }> = {
|
||||||
}
|
Success: { message: "EventData deleted successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Product not found": { message: "Product not found" },
|
||||||
|
"Event Delete Unsuccessful": { message: "Event Delete Unsuccessful" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const product_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(product_Datas ? { data: product_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.ProductEvent_v1DeleteResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
export const productRenameHandleEvent = async (
|
export const productRenameHandleEvent = async (
|
||||||
event: string,
|
event: string,
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
io: Server,
|
io: Server,
|
||||||
data: any,
|
data: any,
|
||||||
connectedUsersByOrg: { [org: string]: { socketId: string; userId: string; role: string }[] },
|
connectedUsersByOrg: {
|
||||||
|
[org: string]: { socketId: string; userId: string; role: string }[];
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
if (event !== EVENTS.setAssetModel_v1 || !data?.organization) return;
|
if (event !== EVENTS.ProductRenameModel_v1 || !data?.organization) return;
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
"productName",
|
"productName",
|
||||||
"productId",
|
"productUuid",
|
||||||
"projectId",
|
"projectId",
|
||||||
"userId",
|
"userId",
|
||||||
"organization",
|
"organization",
|
||||||
];
|
];
|
||||||
const missingFields = requiredFields.filter(field => !data?.[field]);
|
const missingFields = requiredFields.filter((field) => !data?.[field]);
|
||||||
|
|
||||||
if (missingFields.length > 0) {
|
|
||||||
const response = {
|
|
||||||
success: false,
|
|
||||||
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
|
||||||
status: "MissingFields",
|
|
||||||
socketId: socket.id,
|
|
||||||
organization: data?.organization ?? "unknown",
|
|
||||||
};
|
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const result = await EventDataDelete(data);
|
|
||||||
const status = typeof result?.status === "string" ? result.status : "unknown";
|
|
||||||
|
|
||||||
const messages: Record<string, { message: string }> = {
|
|
||||||
Success: { message: "product Rename successfully" },
|
|
||||||
"User not found": { message: "User not found" },
|
|
||||||
"Project not found": { message: "Project not found" },
|
|
||||||
"Product not found": { message: "Product not found" },
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const msg = messages[status] || { message: "Internal server error" };
|
|
||||||
const product_Datas =
|
|
||||||
status === "Success" && result?.data
|
|
||||||
|
|
||||||
? {
|
|
||||||
// widget: {
|
|
||||||
// id: result.data.widgetID,
|
|
||||||
// type: result.data.projectName,
|
|
||||||
// position: result.data.position,
|
|
||||||
// },
|
|
||||||
// Data: result.data.Data,
|
|
||||||
// zoneId: result.data.zoneId,
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
|
if (missingFields.length > 0) {
|
||||||
const response = {
|
const response = {
|
||||||
success: status === "Success",
|
success: false,
|
||||||
message: msg.message,
|
message: `Missing required field(s): ${missingFields.join(", ")}`,
|
||||||
status,
|
status: "MissingFields",
|
||||||
socketId: socket.id,
|
socketId: socket.id,
|
||||||
organization: data.organization,
|
organization: data?.organization ?? "unknown",
|
||||||
...(product_Datas ? { data: product_Datas } : {}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.ProductRename_v1UpdateResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await productRename(data);
|
||||||
|
const status = typeof result?.status === "string" ? result.status : "unknown";
|
||||||
|
|
||||||
emitToSenderAndAdmins(io, socket, data.organization, EVENTS.asset_v1UpdateResponse, response, connectedUsersByOrg)
|
const messages: Record<string, { message: string }> = {
|
||||||
}
|
Success: { message: "product Rename successfully" },
|
||||||
|
"User not found": { message: "User not found" },
|
||||||
|
"Project not found": { message: "Project not found" },
|
||||||
|
"Product not found": { message: "Product not found" },
|
||||||
|
"Rename Unsuccessful": { message: "Rename Unsuccessful" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const msg = messages[status] || { message: "Internal server error" };
|
||||||
|
const product_Datas =
|
||||||
|
status === "Success" && result?.data
|
||||||
|
? {
|
||||||
|
// widget: {
|
||||||
|
// id: result.data.widgetID,
|
||||||
|
// type: result.data.projectName,
|
||||||
|
// position: result.data.position,
|
||||||
|
// },
|
||||||
|
// Data: result.data.Data,
|
||||||
|
// zoneId: result.data.zoneId,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const response = {
|
||||||
|
success: status === "Success",
|
||||||
|
message: msg.message,
|
||||||
|
status,
|
||||||
|
socketId: socket.id,
|
||||||
|
organization: data.organization,
|
||||||
|
...(product_Datas ? { data: product_Datas } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
emitToSenderAndAdmins(
|
||||||
|
io,
|
||||||
|
socket,
|
||||||
|
data.organization,
|
||||||
|
EVENTS.ProductRename_v1UpdateResponse,
|
||||||
|
response,
|
||||||
|
connectedUsersByOrg
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,24 +1,79 @@
|
|||||||
import { Server, Socket } from 'socket.io';
|
import { Server, Socket } from "socket.io";
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from "jsonwebtoken";
|
||||||
import dotenv from 'dotenv';
|
import dotenv from "dotenv";
|
||||||
import AuthModel from '../../shared/V1Models/Auth/userAuthModel.ts';
|
import AuthModel from "../../shared/V1Models/Auth/userAuthModel.ts";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
import { addCommentHandleEvent, createThreadHandleEvent, deleteCommentHandleEvent, deleteThreadHandleEvent } from '../controllers/thread/threadController.ts';
|
import {
|
||||||
import { DuplicateProjectHandleEvent, projectDeleteHandleEvent, projectHandleEvent, projecUpdateHandleEvent } from '../controllers/projectController/projectController.ts';
|
addCommentHandleEvent,
|
||||||
import { setAssetHandleEvent, deleteAssetHandleEvent, replaceEventDatasHandleEvent } from '../controllers/builderController/asset-Controller.ts';
|
createThreadHandleEvent,
|
||||||
import { SetCameraHandleEvent } from '../controllers/builderController/camera-Controller.ts';
|
deleteCommentHandleEvent,
|
||||||
import { TrashDeleteHandleEvent } from '../controllers/trashController/trash-Controller.ts';
|
deleteThreadHandleEvent,
|
||||||
import { setEnvironmentHandleEvent } from '../controllers/builderController/environment-Controller.ts';
|
} from "../controllers/thread/threadController.ts";
|
||||||
import { CreateLineHandleEvent, UpdateLineHandleEvent, DeleteLineHandleEvent, DeleteLayerHandleEvent, DeleteLinePointsHandleEvent } from '../controllers/builderController/line-Controller.ts';
|
import {
|
||||||
import { deleteWallItemsHandleEvent, setWallItemsHandleEvent } from '../controllers/builderController/wall-Controller.ts';
|
DuplicateProjectHandleEvent,
|
||||||
import { DeleteZoneHandleEvent, SetZoneHandleEvent } from '../controllers/builderController/zone-Controller.ts';
|
projectDeleteHandleEvent,
|
||||||
import { add3DwidgetHandleEvent, Delete3DwidgetHandleEvent, update3DHandleEvent } from '../controllers/vizualizationController/3dWidget-Controller.ts';
|
projectHandleEvent,
|
||||||
import { AddFloatHandleEvent, DeleteFloatHandleEvent, DuplicateFloatHandleEvent } from '../controllers/vizualizationController/floatWidget-Controller.ts';
|
projecUpdateHandleEvent,
|
||||||
import { AddPanelHandleEvent, ClearPanelHandleEvent, DeletePanelHandleEvent, LockedPanelHandleEvent } from '../controllers/vizualizationController/panel-Controller.ts';
|
} from "../controllers/projectController/projectController.ts";
|
||||||
import { AddTemplateHandleEvent, addTemplateZoneHandleEvent, TemplateDeleteHandleEvent } from '../controllers/vizualizationController/template-Controller.ts';
|
import {
|
||||||
import { AddWidgetHandleEvent, WidgetDeleteHandleEvent } from '../controllers/vizualizationController/widget-Controller.ts';
|
setAssetHandleEvent,
|
||||||
import { getUserRole } from '../utils/getUsers.ts';
|
deleteAssetHandleEvent,
|
||||||
|
replaceEventDatasHandleEvent,
|
||||||
|
} from "../controllers/builderController/asset-Controller.ts";
|
||||||
|
import { SetCameraHandleEvent } from "../controllers/builderController/camera-Controller.ts";
|
||||||
|
import { TrashDeleteHandleEvent } from "../controllers/trashController/trash-Controller.ts";
|
||||||
|
import { setEnvironmentHandleEvent } from "../controllers/builderController/environment-Controller.ts";
|
||||||
|
import {
|
||||||
|
CreateLineHandleEvent,
|
||||||
|
UpdateLineHandleEvent,
|
||||||
|
DeleteLineHandleEvent,
|
||||||
|
DeleteLayerHandleEvent,
|
||||||
|
DeleteLinePointsHandleEvent,
|
||||||
|
} from "../controllers/builderController/line-Controller.ts";
|
||||||
|
import {
|
||||||
|
deleteWallItemsHandleEvent,
|
||||||
|
setWallItemsHandleEvent,
|
||||||
|
} from "../controllers/builderController/wall-Controller.ts";
|
||||||
|
import {
|
||||||
|
DeleteZoneHandleEvent,
|
||||||
|
SetZoneHandleEvent,
|
||||||
|
} from "../controllers/builderController/zone-Controller.ts";
|
||||||
|
import {
|
||||||
|
add3DwidgetHandleEvent,
|
||||||
|
Delete3DwidgetHandleEvent,
|
||||||
|
update3DHandleEvent,
|
||||||
|
} from "../controllers/vizualizationController/3dWidget-Controller.ts";
|
||||||
|
import {
|
||||||
|
AddFloatHandleEvent,
|
||||||
|
DeleteFloatHandleEvent,
|
||||||
|
DuplicateFloatHandleEvent,
|
||||||
|
} from "../controllers/vizualizationController/floatWidget-Controller.ts";
|
||||||
|
import {
|
||||||
|
AddPanelHandleEvent,
|
||||||
|
ClearPanelHandleEvent,
|
||||||
|
DeletePanelHandleEvent,
|
||||||
|
LockedPanelHandleEvent,
|
||||||
|
} from "../controllers/vizualizationController/panel-Controller.ts";
|
||||||
|
import {
|
||||||
|
AddTemplateHandleEvent,
|
||||||
|
addTemplateZoneHandleEvent,
|
||||||
|
TemplateDeleteHandleEvent,
|
||||||
|
} from "../controllers/vizualizationController/template-Controller.ts";
|
||||||
|
import {
|
||||||
|
AddWidgetHandleEvent,
|
||||||
|
WidgetDeleteHandleEvent,
|
||||||
|
} from "../controllers/vizualizationController/widget-Controller.ts";
|
||||||
|
import { getUserRole } from "../utils/getUsers.ts";
|
||||||
|
import {
|
||||||
|
DeleteAisleHandleEvent,
|
||||||
|
SetAisleHandleEvent,
|
||||||
|
} from "../controllers/builderController/aisle-Controller.ts";
|
||||||
|
import {
|
||||||
|
EventDataDeleteHandleEvent,
|
||||||
|
productAddHandleEvent,
|
||||||
|
productDataDeleteHandleEvent,
|
||||||
|
productRenameHandleEvent,
|
||||||
|
} from "../controllers/simulationController/product-Controller.ts";
|
||||||
|
|
||||||
interface UserSocketInfo {
|
interface UserSocketInfo {
|
||||||
socketId: string;
|
socketId: string;
|
||||||
@@ -28,24 +83,19 @@ interface UserSocketInfo {
|
|||||||
|
|
||||||
const connectedUsersByOrg: { [organization: string]: UserSocketInfo[] } = {};
|
const connectedUsersByOrg: { [organization: string]: UserSocketInfo[] } = {};
|
||||||
export const SocketServer = (io: Server) => {
|
export const SocketServer = (io: Server) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const namespaces = {
|
const namespaces = {
|
||||||
dashboard: io.of('/dashboard'),
|
dashboard: io.of("/dashboard"),
|
||||||
project: io.of('/project'),
|
project: io.of("/project"),
|
||||||
thread: io.of('/thread'),
|
thread: io.of("/thread"),
|
||||||
Builder_v1: io.of("/Builder_v1"),
|
Builder_v1: io.of("/Builder_v1"),
|
||||||
visualization_v1: io.of("/Visualization_v1"),
|
visualization_v1: io.of("/Visualization_v1"),
|
||||||
|
simulation_v1: io.of("/Simulation_v1"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const onlineUsers: { [organization: string]: Set<string> } = {};
|
const onlineUsers: { [organization: string]: Set<string> } = {};
|
||||||
|
|
||||||
|
|
||||||
const handleNamespace = (namespace: any, ...eventHandlers: Function[]) => {
|
const handleNamespace = (namespace: any, ...eventHandlers: Function[]) => {
|
||||||
namespace.use(async (socket: Socket, next: any) => {
|
namespace.use(async (socket: Socket, next: any) => {
|
||||||
|
|
||||||
const token = socket.handshake.auth.token;
|
const token = socket.handshake.auth.token;
|
||||||
|
|
||||||
const jwt_secret = process.env.JWT_SECRET as string;
|
const jwt_secret = process.env.JWT_SECRET as string;
|
||||||
@@ -59,23 +109,23 @@ export const SocketServer = (io: Server) => {
|
|||||||
return next(new Error("Server configuration error: Missing secret"));
|
return next(new Error("Server configuration error: Missing secret"));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const decoded = jwt.verify(token, jwt_secret) as {
|
const decoded = jwt.verify(token, jwt_secret) as {
|
||||||
userId: string;
|
userId: string;
|
||||||
Email: string;
|
Email: string;
|
||||||
organization: string
|
organization: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const user = await AuthModel(decoded.organization).findOne({ _id: decoded.userId, Email: decoded.Email, });
|
const user = await AuthModel(decoded.organization).findOne({
|
||||||
|
_id: decoded.userId,
|
||||||
|
Email: decoded.Email,
|
||||||
|
});
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
console.log(" User not found in DB");
|
console.log(" User not found in DB");
|
||||||
return next(new Error("Authentication error: User not found"));
|
return next(new Error("Authentication error: User not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
(socket as any).user = {
|
(socket as any).user = {
|
||||||
|
|
||||||
organization: decoded.organization,
|
organization: decoded.organization,
|
||||||
Email: decoded.Email,
|
Email: decoded.Email,
|
||||||
userId: decoded.userId,
|
userId: decoded.userId,
|
||||||
@@ -85,7 +135,6 @@ export const SocketServer = (io: Server) => {
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("❌ Authentication failed:", error.message);
|
console.error("❌ Authentication failed:", error.message);
|
||||||
return next(new Error("Authentication error"));
|
return next(new Error("Authentication error"));
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
namespace.on("connection", async (socket: Socket) => {
|
namespace.on("connection", async (socket: Socket) => {
|
||||||
@@ -93,8 +142,6 @@ export const SocketServer = (io: Server) => {
|
|||||||
const organization = user.organization;
|
const organization = user.organization;
|
||||||
const userId = user.userId;
|
const userId = user.userId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (organization) {
|
if (organization) {
|
||||||
socket.join(organization);
|
socket.join(organization);
|
||||||
}
|
}
|
||||||
@@ -113,52 +160,49 @@ export const SocketServer = (io: Server) => {
|
|||||||
userId,
|
userId,
|
||||||
role,
|
role,
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.warn(`❌ Cannot store user. Missing data:`,);
|
console.warn(`❌ Cannot store user. Missing data:`);
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.onAny((event: string, data: any, callback: any) => {
|
socket.onAny((event: string, data: any, callback: any) => {
|
||||||
eventHandlers.forEach(handler =>
|
eventHandlers.forEach((handler) =>
|
||||||
handler(event, socket, io, data, connectedUsersByOrg, callback)
|
handler(event, socket, io, data, connectedUsersByOrg, callback)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("disconnect", () => {
|
socket.on("disconnect", () => {
|
||||||
onlineUsers[organization]?.delete(socket.id);
|
onlineUsers[organization]?.delete(socket.id);
|
||||||
if (onlineUsers[organization]?.size === 0) delete onlineUsers[organization];
|
if (onlineUsers[organization]?.size === 0)
|
||||||
|
delete onlineUsers[organization];
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("reconnect", (attempt: number) => {
|
socket.on("reconnect", (attempt: number) => {
|
||||||
|
|
||||||
if (organization) {
|
if (organization) {
|
||||||
socket.join(organization);
|
socket.join(organization);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
handleNamespace(namespaces.dashboard);
|
handleNamespace(namespaces.dashboard);
|
||||||
handleNamespace(namespaces.thread,
|
handleNamespace(
|
||||||
|
namespaces.thread,
|
||||||
createThreadHandleEvent,
|
createThreadHandleEvent,
|
||||||
deleteThreadHandleEvent,
|
deleteThreadHandleEvent,
|
||||||
addCommentHandleEvent,
|
addCommentHandleEvent,
|
||||||
deleteCommentHandleEvent)
|
deleteCommentHandleEvent
|
||||||
|
);
|
||||||
|
|
||||||
|
handleNamespace(
|
||||||
|
namespaces.project,
|
||||||
|
|
||||||
handleNamespace(namespaces.project,
|
|
||||||
projectHandleEvent,
|
projectHandleEvent,
|
||||||
projectDeleteHandleEvent,
|
projectDeleteHandleEvent,
|
||||||
projecUpdateHandleEvent,
|
projecUpdateHandleEvent,
|
||||||
DuplicateProjectHandleEvent,
|
DuplicateProjectHandleEvent,
|
||||||
TrashDeleteHandleEvent)
|
TrashDeleteHandleEvent
|
||||||
handleNamespace(namespaces.Builder_v1,
|
);
|
||||||
|
handleNamespace(
|
||||||
|
namespaces.Builder_v1,
|
||||||
setAssetHandleEvent,
|
setAssetHandleEvent,
|
||||||
deleteAssetHandleEvent,
|
deleteAssetHandleEvent,
|
||||||
replaceEventDatasHandleEvent,
|
replaceEventDatasHandleEvent,
|
||||||
@@ -172,9 +216,12 @@ export const SocketServer = (io: Server) => {
|
|||||||
setWallItemsHandleEvent,
|
setWallItemsHandleEvent,
|
||||||
deleteWallItemsHandleEvent,
|
deleteWallItemsHandleEvent,
|
||||||
SetZoneHandleEvent,
|
SetZoneHandleEvent,
|
||||||
DeleteZoneHandleEvent
|
DeleteZoneHandleEvent,
|
||||||
)
|
SetAisleHandleEvent,
|
||||||
handleNamespace(namespaces.visualization_v1,
|
DeleteAisleHandleEvent
|
||||||
|
);
|
||||||
|
handleNamespace(
|
||||||
|
namespaces.visualization_v1,
|
||||||
add3DwidgetHandleEvent,
|
add3DwidgetHandleEvent,
|
||||||
update3DHandleEvent,
|
update3DHandleEvent,
|
||||||
Delete3DwidgetHandleEvent,
|
Delete3DwidgetHandleEvent,
|
||||||
@@ -190,6 +237,13 @@ export const SocketServer = (io: Server) => {
|
|||||||
TemplateDeleteHandleEvent,
|
TemplateDeleteHandleEvent,
|
||||||
AddWidgetHandleEvent,
|
AddWidgetHandleEvent,
|
||||||
WidgetDeleteHandleEvent
|
WidgetDeleteHandleEvent
|
||||||
)
|
);
|
||||||
|
handleNamespace(
|
||||||
|
namespaces.simulation_v1,
|
||||||
|
productAddHandleEvent,
|
||||||
|
productDataDeleteHandleEvent,
|
||||||
|
EventDataDeleteHandleEvent,
|
||||||
|
productRenameHandleEvent
|
||||||
|
);
|
||||||
return io;
|
return io;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -108,7 +108,8 @@ export const EVENTS = {
|
|||||||
addWidget3D: "v1:viz-3D-widget:add",
|
addWidget3D: "v1:viz-3D-widget:add",
|
||||||
addWidget3DResponse: "v1:viz-widget3D:response:add",
|
addWidget3DResponse: "v1:viz-widget3D:response:add",
|
||||||
updateWidget3DPosition: "v1:viz-3D-widget:modifyPositionRotation",
|
updateWidget3DPosition: "v1:viz-3D-widget:modifyPositionRotation",
|
||||||
updateWidget3DPositionResponse:"v1:viz-widget3D:response:modifyPositionRotation",
|
updateWidget3DPositionResponse:
|
||||||
|
"v1:viz-widget3D:response:modifyPositionRotation",
|
||||||
deleteWidget3D: "v1:viz-3D-widget:delete",
|
deleteWidget3D: "v1:viz-3D-widget:delete",
|
||||||
deletewidget3DResponse: "v1:viz-widget3D:response:delete",
|
deletewidget3DResponse: "v1:viz-widget3D:response:delete",
|
||||||
|
|
||||||
@@ -176,4 +177,18 @@ export const EVENTS = {
|
|||||||
|
|
||||||
deleteTrash_v1: "v1:trash:delete",
|
deleteTrash_v1: "v1:trash:delete",
|
||||||
Trash_v1DeleteResponse: "v1:trash:response:delete",
|
Trash_v1DeleteResponse: "v1:trash:response:delete",
|
||||||
|
|
||||||
|
setAisleModel_v1: "v1:model-aisle:add",
|
||||||
|
Aisle_v1UpdateResponse: "v1:model-aisle:response:add",
|
||||||
|
delete_v1AisleModel: "v1:model-aisle:delete",
|
||||||
|
Aisle_v1DeleteResponse: "v1:model-aisle:response:delete",
|
||||||
|
|
||||||
|
setProductModel_v1: "v1:model-product:add",
|
||||||
|
Product_v1UpdateResponse: "v1:model-product:response:add",
|
||||||
|
ProductRenameModel_v1: "v1:model-product:rename",
|
||||||
|
ProductRename_v1UpdateResponse: "v1:model-product:response:rename",
|
||||||
|
delete_v1ProductModel: "v1:model-product:delete",
|
||||||
|
Product_v1DeleteResponse: "v1:model-product:response:delete",
|
||||||
|
deleteEvent_v1ProductModel: "v1:model-productevent:delete",
|
||||||
|
ProductEvent_v1DeleteResponse: "v1:model-productevent:response:delete",
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user