2025-03-29 17:47:16 +05:30
|
|
|
import { Request, Response } from "express";
|
|
|
|
|
// import assetModel from "../../../shared/model/assets/flooritems-Model.ts";
|
|
|
|
|
import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
|
|
|
|
|
import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
|
|
|
|
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
2025-04-03 19:51:51 +05:30
|
|
|
import pointModel from "../../../shared/model/builder/assets/assetPoint-Model.ts";
|
|
|
|
|
interface ITriggerConveyor {
|
|
|
|
|
uuid: string;
|
|
|
|
|
name: string;
|
|
|
|
|
type: string;
|
|
|
|
|
isUsed: boolean;
|
|
|
|
|
bufferTime: number;
|
|
|
|
|
}
|
|
|
|
|
interface ITriggerVehicle {
|
|
|
|
|
uuid: string;
|
|
|
|
|
name: string;
|
|
|
|
|
type: string;
|
|
|
|
|
isUsed: boolean;
|
|
|
|
|
}
|
|
|
|
|
interface IConnection {
|
|
|
|
|
source: { pathUUID: string; pointUUID: string };
|
|
|
|
|
targets: { pathUUID: string; pointUUID: string }[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IPointBase {
|
|
|
|
|
uuid: string;
|
|
|
|
|
position: number[];
|
|
|
|
|
connections: IConnection;
|
|
|
|
|
}
|
|
|
|
|
interface IPointConveyor extends IPointBase {
|
|
|
|
|
rotation: number[];
|
|
|
|
|
actions: Array<{
|
|
|
|
|
uuid: string;
|
|
|
|
|
name: string;
|
|
|
|
|
type: string;
|
|
|
|
|
material: string;
|
|
|
|
|
delay: number | string;
|
|
|
|
|
spawnInterval: number | string;
|
|
|
|
|
isUsed: boolean;
|
|
|
|
|
}>;
|
|
|
|
|
triggers: Array<{
|
|
|
|
|
uuid: string;
|
|
|
|
|
name: string;
|
|
|
|
|
type: string;
|
|
|
|
|
isUsed: boolean;
|
|
|
|
|
bufferTime: number;
|
|
|
|
|
}>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IPointVehicle extends IPointBase {
|
|
|
|
|
actions: Array<{
|
|
|
|
|
uuid: string;
|
|
|
|
|
name: string;
|
|
|
|
|
type: string;
|
|
|
|
|
isUsed: boolean;
|
|
|
|
|
hitCount: number;
|
|
|
|
|
start: string;
|
|
|
|
|
end: string;
|
|
|
|
|
buffer: number;
|
|
|
|
|
}>;
|
|
|
|
|
triggers: Array<{
|
|
|
|
|
uuid: string;
|
|
|
|
|
name: string;
|
|
|
|
|
type: string;
|
|
|
|
|
isUsed: boolean;
|
|
|
|
|
}>;
|
|
|
|
|
}
|
2025-03-29 17:47:16 +05:30
|
|
|
|
|
|
|
|
export class assetsFloorservice {
|
2025-03-31 18:30:14 +05:30
|
|
|
static async setFloorassets(req: Request, res: Response): Promise<any> {
|
2025-03-29 17:47:16 +05:30
|
|
|
try {
|
|
|
|
|
const {
|
|
|
|
|
modeluuid,
|
|
|
|
|
modelname,
|
2025-04-01 13:55:43 +05:30
|
|
|
position,
|
2025-03-29 17:47:16 +05:30
|
|
|
modelfileID,
|
2025-04-01 13:55:43 +05:30
|
|
|
rotation,
|
2025-03-29 17:47:16 +05:30
|
|
|
isLocked,
|
|
|
|
|
isVisible,
|
|
|
|
|
organization,
|
2025-04-03 19:51:51 +05:30
|
|
|
eventData,
|
2025-03-29 17:47:16 +05:30
|
|
|
} = req.body;
|
|
|
|
|
|
|
|
|
|
const findvalue = await assetModel(organization).findOne({
|
2025-03-31 18:30:14 +05:30
|
|
|
modeluuid,
|
|
|
|
|
modelname,
|
2025-04-02 09:55:23 +05:30
|
|
|
isArchive: false,
|
2025-03-29 17:47:16 +05:30
|
|
|
});
|
2025-04-03 19:51:51 +05:30
|
|
|
const checkpointType = await pointModel(organization).findOne({
|
|
|
|
|
modelfileID: modelfileID,
|
|
|
|
|
isArchive: false,
|
|
|
|
|
});
|
2025-03-29 17:47:16 +05:30
|
|
|
|
|
|
|
|
if (findvalue) {
|
|
|
|
|
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
2025-04-03 19:51:51 +05:30
|
|
|
{ modeluuid, modelname, isArchive: false },
|
2025-03-29 17:47:16 +05:30
|
|
|
{
|
2025-04-01 13:55:43 +05:30
|
|
|
position,
|
|
|
|
|
rotation,
|
2025-03-31 18:30:14 +05:30
|
|
|
isVisible,
|
|
|
|
|
isLocked,
|
2025-03-29 17:47:16 +05:30
|
|
|
},
|
|
|
|
|
{ new: true }
|
|
|
|
|
);
|
2025-03-31 18:30:14 +05:30
|
|
|
return res.status(201).json(updatevalue);
|
2025-03-29 17:47:16 +05:30
|
|
|
} else {
|
2025-04-03 19:51:51 +05:30
|
|
|
// const validateConveyorPoint = (point: any): boolean => {
|
|
|
|
|
// return (
|
|
|
|
|
// Array.isArray(point?.rotation) &&
|
|
|
|
|
// Array.isArray(point?.actions) &&
|
|
|
|
|
// Array.isArray(point?.triggers)
|
|
|
|
|
// // point.actions.every(
|
|
|
|
|
// // (action: any) => action.uuid && action.name && action.type
|
|
|
|
|
// // ) &&
|
|
|
|
|
// // (!point.triggers ||
|
|
|
|
|
// // point.triggers.every(
|
|
|
|
|
// // (trigger: any) =>
|
|
|
|
|
// // trigger.uuid &&
|
|
|
|
|
// // trigger.name &&
|
|
|
|
|
// // trigger.type &&
|
|
|
|
|
// // trigger.bufferTime !== undefined
|
|
|
|
|
// // ))
|
|
|
|
|
// );
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// const validateVehiclePoint = (point: any): boolean => {
|
|
|
|
|
// return (
|
|
|
|
|
// !point.rotation &&
|
|
|
|
|
// Array.isArray(point?.actions) &&
|
|
|
|
|
// Array.isArray(point?.triggers)
|
|
|
|
|
// // point.actions.every(
|
|
|
|
|
// // (action: any) =>
|
|
|
|
|
// // action.uuid &&
|
|
|
|
|
// // action.name &&
|
|
|
|
|
// // action.type &&
|
|
|
|
|
// // action.hitCount !== undefined &&
|
|
|
|
|
// // action.start !== undefined &&
|
|
|
|
|
// // action.end !== undefined &&
|
|
|
|
|
// // action.buffer !== undefined
|
|
|
|
|
// // ) &&
|
|
|
|
|
// // (!point.triggers ||
|
|
|
|
|
// // point.triggers.every(
|
|
|
|
|
// // (trigger: any) => trigger.uuid && trigger.name && trigger.type
|
|
|
|
|
// // ))
|
|
|
|
|
// );
|
|
|
|
|
// };
|
2025-03-31 18:30:14 +05:30
|
|
|
let assetData: any = {
|
|
|
|
|
modeluuid,
|
|
|
|
|
modelname,
|
2025-04-01 13:55:43 +05:30
|
|
|
position,
|
2025-03-31 18:30:14 +05:30
|
|
|
modelfileID,
|
2025-04-01 13:55:43 +05:30
|
|
|
rotation,
|
2025-03-31 18:30:14 +05:30
|
|
|
isLocked,
|
|
|
|
|
isVisible,
|
|
|
|
|
};
|
2025-03-29 17:47:16 +05:30
|
|
|
|
2025-04-03 19:51:51 +05:30
|
|
|
console.log("eventData: ", eventData);
|
2025-03-31 18:30:14 +05:30
|
|
|
if (eventData) {
|
2025-04-03 19:51:51 +05:30
|
|
|
// console.log("checkpointType?.type: ", checkpointType?.type);
|
|
|
|
|
// console.log("eventData.typ: ", eventData.type);
|
|
|
|
|
// if (checkpointType?.type !== eventData.type) {
|
|
|
|
|
// return res.send("Type mismatch");
|
|
|
|
|
// }
|
|
|
|
|
if (eventData.type === "Conveyor") {
|
|
|
|
|
// console.log("eventData.points: ", typeof eventData.points);
|
|
|
|
|
// if (!Array.isArray(eventData.points) || eventData.points) {
|
|
|
|
|
// return res
|
|
|
|
|
// .status(400)
|
|
|
|
|
// .json({ message: "Points must be an array" });
|
|
|
|
|
// }
|
|
|
|
|
// if (!eventData.points.every(validateConveyorPoint)) {
|
|
|
|
|
// return res
|
|
|
|
|
// .status(400)
|
|
|
|
|
// .json({ message: "Invalid Conveyor point structure" });
|
|
|
|
|
// }
|
|
|
|
|
} else if (eventData.type === "Vehicle") {
|
|
|
|
|
console.log("eventData.points: ", typeof eventData.points);
|
|
|
|
|
if (!eventData.points) {
|
|
|
|
|
return res
|
|
|
|
|
.status(400)
|
|
|
|
|
.json({ message: "Vehicle points must be a single object" });
|
|
|
|
|
}
|
|
|
|
|
if (eventData.points.rotation) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
message: "Rotation is not allowed for Vehicle points",
|
2025-03-29 17:47:16 +05:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-03 19:51:51 +05:30
|
|
|
console.log("eventData.points: ", eventData.points);
|
|
|
|
|
assetData.points = eventData.points;
|
2025-03-31 18:30:14 +05:30
|
|
|
assetData.speed = eventData.speed;
|
|
|
|
|
assetData.type = eventData.type;
|
2025-03-29 17:47:16 +05:30
|
|
|
}
|
2025-04-03 19:51:51 +05:30
|
|
|
// if (eventData) {
|
|
|
|
|
// let pointRefs: any[] = [];
|
|
|
|
|
|
|
|
|
|
// if (Array.isArray(eventData.points)) {
|
|
|
|
|
// for (const point of eventData.points) {
|
|
|
|
|
// let actionRefs: any[] = [];
|
|
|
|
|
// let triggerRefs: any[] = [];
|
|
|
|
|
|
|
|
|
|
// if (Array.isArray(point.actions)) {
|
|
|
|
|
// for (const action of point.actions) {
|
|
|
|
|
// const actionDoc = await actionModel(organization).create({
|
|
|
|
|
// pointsUUID: point.uuid,
|
|
|
|
|
// isArchive: false,
|
|
|
|
|
// uuid: action.uuid,
|
|
|
|
|
// name: action.name,
|
|
|
|
|
// type: action.type,
|
|
|
|
|
// material: action.material,
|
|
|
|
|
// delay: action.delay,
|
|
|
|
|
// spawn_Interval: action.spawn_Interval,
|
|
|
|
|
// });
|
|
|
|
|
// await actionDoc.save();
|
|
|
|
|
// actionRefs.push(actionDoc._id);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (Array.isArray(point.triggers)) {
|
|
|
|
|
// for (const trigger of point.triggers) {
|
|
|
|
|
// const triggerDoc = await triggerModel(organization).create({
|
|
|
|
|
// pointsUUID: point.uuid,
|
|
|
|
|
// isArchive: false,
|
|
|
|
|
// uuid: trigger.uuid,
|
|
|
|
|
// name: trigger.name,
|
|
|
|
|
// type: trigger.type,
|
|
|
|
|
// bufferTime: trigger.bufferTime,
|
|
|
|
|
// });
|
|
|
|
|
// await triggerDoc.save();
|
|
|
|
|
// triggerRefs.push(triggerDoc._id);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// // point.connections{
|
|
|
|
|
// // source:{
|
|
|
|
|
|
|
|
|
|
// // }
|
|
|
|
|
// // }
|
|
|
|
|
// pointRefs.push({
|
|
|
|
|
// uuid: point.uuid,
|
|
|
|
|
// position: point.position || [],
|
|
|
|
|
// rotation: point.rotation || [],
|
|
|
|
|
// actions: actionRefs,
|
|
|
|
|
// triggers: triggerRefs,
|
|
|
|
|
// connections: point.connections,
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// assetData.speed = eventData.speed;
|
|
|
|
|
// assetData.type = eventData.type;
|
|
|
|
|
// assetData.points = pointRefs;
|
|
|
|
|
// }
|
2025-03-29 17:47:16 +05:30
|
|
|
|
2025-03-31 18:30:14 +05:30
|
|
|
const assetDoc = await assetModel(organization).create(assetData);
|
2025-03-29 17:47:16 +05:30
|
|
|
await assetDoc.save();
|
2025-03-31 18:30:14 +05:30
|
|
|
|
|
|
|
|
return res.status(201).json({
|
2025-03-29 17:47:16 +05:30
|
|
|
message: "Model stored successfully",
|
|
|
|
|
modelId: assetDoc._id,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-04-03 19:51:51 +05:30
|
|
|
// } else {
|
|
|
|
|
// return res.json({ message: "Type not matched" });
|
|
|
|
|
// }
|
2025-03-29 17:47:16 +05:30
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error creating flooritems:", error);
|
|
|
|
|
res.status(500).json({ message: "Failed to create flooritems" });
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-31 18:30:14 +05:30
|
|
|
static async getFloorItems(req: Request, res: Response): Promise<any> {
|
2025-03-29 17:47:16 +05:30
|
|
|
try {
|
|
|
|
|
const { organization } = req.params;
|
2025-03-31 18:30:14 +05:30
|
|
|
const findValues = await assetModel(organization)
|
2025-04-02 09:55:23 +05:30
|
|
|
.find({ isArchive: false })
|
2025-04-03 19:51:51 +05:30
|
|
|
.select("-_id -isArchive");
|
2025-03-31 18:30:14 +05:30
|
|
|
|
2025-04-03 19:51:51 +05:30
|
|
|
if (!findValues || findValues.length === 0) {
|
|
|
|
|
return res.status(200).json({ message: "floorItems not found" });
|
2025-03-29 17:47:16 +05:30
|
|
|
}
|
2025-04-03 19:51:51 +05:30
|
|
|
|
|
|
|
|
const response = findValues.map((item) => {
|
|
|
|
|
console.log("item.points: ", item.points);
|
|
|
|
|
const responseItem: any = {
|
|
|
|
|
modeluuid: item.modeluuid,
|
|
|
|
|
modelname: item.modelname,
|
|
|
|
|
position: item.position,
|
|
|
|
|
rotation: item.rotation,
|
|
|
|
|
modelfileID: item.modelfileID,
|
|
|
|
|
isLocked: item.isLocked,
|
|
|
|
|
isVisible: item.isVisible,
|
|
|
|
|
};
|
|
|
|
|
if (item.type === "Conveyor" && item.points.length > 0) {
|
|
|
|
|
responseItem.eventData = {
|
|
|
|
|
speed: item.speed,
|
|
|
|
|
points: item.points,
|
|
|
|
|
type: item.type,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.type === "Vehicle" && item.points) {
|
|
|
|
|
responseItem.eventData = {
|
|
|
|
|
speed: item.speed,
|
|
|
|
|
type: item.type,
|
|
|
|
|
points: item.points,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return responseItem;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return res.status(200).json(response);
|
2025-03-29 17:47:16 +05:30
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error get flooritems:", error);
|
|
|
|
|
res.status(500).json({ error: "Failed to get flooritems" });
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-02 09:55:23 +05:30
|
|
|
static async deleteFloorItems(req: Request, res: Response): Promise<any> {
|
2025-03-29 17:47:16 +05:30
|
|
|
try {
|
|
|
|
|
const { modeluuid, modelname, organization } = req.body;
|
|
|
|
|
|
|
|
|
|
const findValue = await assetModel(organization).findOneAndDelete({
|
|
|
|
|
modeluuid: modeluuid,
|
|
|
|
|
modelname: modelname,
|
2025-04-02 09:55:23 +05:30
|
|
|
isArchive: false,
|
2025-03-29 17:47:16 +05:30
|
|
|
});
|
|
|
|
|
if (!findValue) {
|
|
|
|
|
res.status(200).json("user not found");
|
|
|
|
|
} else {
|
|
|
|
|
res.status(201).json(findValue);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error get flooritems:", error);
|
|
|
|
|
res.status(500).json({ error: "Failed to get flooritems" });
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-02 09:55:23 +05:30
|
|
|
static async updateAssetPositionRotation(
|
|
|
|
|
req: Request,
|
|
|
|
|
res: Response
|
|
|
|
|
): Promise<any> {
|
|
|
|
|
try {
|
|
|
|
|
const {
|
|
|
|
|
modeluuid,
|
|
|
|
|
modelname,
|
|
|
|
|
position,
|
|
|
|
|
modelfileID,
|
|
|
|
|
rotation,
|
|
|
|
|
isLocked,
|
|
|
|
|
isVisible,
|
|
|
|
|
organization,
|
|
|
|
|
// eventData, // Optional
|
|
|
|
|
} = req.body;
|
2025-03-31 18:30:14 +05:30
|
|
|
|
2025-04-02 09:55:23 +05:30
|
|
|
const existingAsset = await assetModel(organization).findOne({
|
|
|
|
|
modeluuid: modeluuid,
|
|
|
|
|
isArchive: false,
|
|
|
|
|
});
|
|
|
|
|
if (!existingAsset) return res.send("Asset not found");
|
|
|
|
|
const updateAsset = await assetModel(organization).updateMany(
|
|
|
|
|
{ modeluuid: modeluuid, modelname: modelname, isArchive: false },
|
|
|
|
|
{
|
|
|
|
|
position: position,
|
|
|
|
|
rotation: rotation,
|
|
|
|
|
isVisible: isVisible,
|
|
|
|
|
isLocked: isLocked,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
if (updateAsset)
|
|
|
|
|
return res.status(200).json({ message: "Asset updated successfully" });
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
return res.send(error.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-03 19:51:51 +05:30
|
|
|
static async replaceEventDatas(req: Request, res: Response): Promise<any> {
|
|
|
|
|
const { organization, modeluuid, eventData } = req.body;
|
|
|
|
|
console.log("req.body: ", req.body);
|
|
|
|
|
try {
|
|
|
|
|
const existingModel = await assetModel(organization).findOne({
|
|
|
|
|
modeluuid: modeluuid,
|
|
|
|
|
isArchive: false,
|
|
|
|
|
});
|
|
|
|
|
if (!existingModel)
|
|
|
|
|
return res.json({ message: "Model not for this UUID" });
|
|
|
|
|
else {
|
|
|
|
|
const updatedModel = await assetModel(organization).findOneAndUpdate(
|
|
|
|
|
{ modeluuid, isArchive: false },
|
|
|
|
|
{
|
|
|
|
|
$set: {
|
|
|
|
|
points: eventData.points,
|
|
|
|
|
speed: eventData.speed,
|
|
|
|
|
type: eventData.type,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{ new: true }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (updatedModel)
|
|
|
|
|
return res.status(200).json({ message: "Data updated successfully" });
|
|
|
|
|
}
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
res.status(500).json({ message: "Server error", error: error.message });
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-29 17:47:16 +05:30
|
|
|
}
|