import { Request, Response } from "express"; import pointModel from "../../../shared/model/builder/assets/assetPoint-Model.ts"; interface IPointBase { uuid: string; position: number[]; } 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; }>; connections: { source: { modelUUID: string; pointUUID: string }; targets: Array<{ modelUUID: string; pointUUID: string }>; }; } interface IPointVehicle extends IPointBase { rotation: number[]; actions: { uuid: string; name: string; type: string; hitCount: number; start: { x: number; y: number } | {}; end: { x: number; y: number } | {}; buffer: number; }; connections: { source: { modelUUID: string; pointUUID: string }; targets: Array<{ modelUUID: string; pointUUID: string }>; }; speed: number; } interface IPointArmbot extends IPointBase { rotation: number[]; actions: { uuid: string; name: string; speed: number; processes: { triggerId: string; startPoint: string; endPoint: string }[]; }; triggers: { uuid: string; name: string; type: string }; connections: { source: { modelUUID: string; pointUUID: string }; targets: { modelUUID: string; pointUUID: string }[]; }; } interface IPointStaticMachine extends IPointBase { rotation: number[]; actions: { uuid: string; name: string; buffer: number | string; material: string; }; triggers: { uuid: string; name: string; type: string }; connections: { source: { modelUUID: string; pointUUID: string }; targets: { modelUUID: string; pointUUID: string }[]; }; } export class PointService { static async addPoints(req: Request, res: Response): Promise { const { type, modelfileID, organization } = req.body; // Validate type if (!["Conveyor", "Vehicle", "ArmBot", "StaticMachine"].includes(type)) { return res.status(400).json({ message: "Invalid type requested" }); } try { const existingdata = await pointModel(organization).findOne({ modelfileID: modelfileID, isArchive: false, }); if (existingdata) return res.send("Data already exists"); if (type === "Conveyor") { const baseData = { // modelfileID: "672a090f80d91ac979f4d0bd", modelfileID: "7dc04e36882e4debbc1a8e3d", type: "Conveyor", }; const conveyorPoints: IPointConveyor[] = [ { uuid: "point1UUID", position: [0, 0.85, 2.2], rotation: [0, 0, 0], actions: [ { uuid: "randomUUID", name: "Action 1", type: "actionType", material: "actionMaterial", delay: "Inherit", spawnInterval: "Inherit", isUsed: false, }, ], triggers: [ { uuid: "randomUUID", name: "trigger 1", type: "triggerType", bufferTime: 0, // delay: "Inherit", // spawnInterval: "Inherit", isUsed: false, }, ], connections: { source: { modelUUID: "modelUUID", pointUUID: "point1UUID" }, targets: [{ modelUUID: "modelUUID", pointUUID: "point1UUID" }], }, }, { uuid: "point2UUID", position: [0, 0.85, 0], rotation: [0, 0, 0], actions: [ { uuid: "randomUUID", name: "Action 1", type: "actionType", material: "actionMaterial", delay: "Inherit", spawnInterval: "Inherit", isUsed: false, }, ], triggers: [ { uuid: "randomUUID", name: "trigger 1", type: "triggerType", bufferTime: 0, isUsed: false, }, ], connections: { source: { modelUUID: "modelUUID", pointUUID: "point2UUID" }, targets: [{ modelUUID: "modelUUID", pointUUID: "point2UUID" }], }, }, { uuid: "point3UUID", position: [0, 0.85, -2.2], rotation: [0, 0, 0], actions: [ { uuid: "randomUUID", name: "Action 1", type: "actionType", material: "actionMaterial", delay: "Inherit", spawnInterval: "Inherit", isUsed: false, }, ], triggers: [ { uuid: "randomUUID", name: "trigger 1", type: "triggerType", bufferTime: 0, isUsed: false, }, ], connections: { source: { modelUUID: "modelUUID", pointUUID: "point3UUID" }, targets: [{ modelUUID: "modelUUID", pointUUID: "point3UUID" }], }, }, ]; await pointModel(organization).create({ ...baseData, points: conveyorPoints, }); } else if (type === "Vehicle") { console.log("vehcile data"); const baseData = { // modelfileID: "67e3da19c2e8f37134526e6a", modelfileID: "a1ee92554935007b10b3eb05", type: "Vehicle", }; const vehiclePoint: IPointVehicle = { uuid: "point1UUID", rotation: [0, 0, 0], position: [0, 1.3, 0], actions: { uuid: "randomUUID", name: "Action 1", type: "string", hitCount: 1, start: { x: 0, y: 0 }, end: { x: 0, y: 0 }, buffer: 0, }, connections: { source: { modelUUID: "modelUUID", pointUUID: "point1UUID" }, targets: [{ modelUUID: "modelUUID", pointUUID: "point1UUID" }], }, speed: 2, }; if ("triggers" in vehiclePoint) { return res .status(400) .json({ error: "Triggers not allowed for Vehicle points" }); } await pointModel(organization).create({ ...baseData, points: vehiclePoint, }); } else if (type === "ArmBot") { console.log("ArmBot data"); const baseData = { // modelfileID: "67eb7904c2e8f37134527eae", modelfileID: "52e6681fbb743a890d96c914", type: "ArmBot", }; const ArmBotPoint: IPointArmbot = { uuid: "point1UUID", position: [0, 2.75, -0.5], rotation: [0, 0, 0], actions: { uuid: "randomUUID", name: "Action 1", speed: 1, processes: [ { triggerId: "triggerId", startPoint: "startPoint", endPoint: "endPoint", }, ], }, triggers: { uuid: "randomUUID", name: "trigger 1", type: "OnComplete", }, connections: { source: { modelUUID: "modelUUID", pointUUID: "point1UUID" }, targets: [{ modelUUID: "modelUUID", pointUUID: "point1UUID" }], }, }; await pointModel(organization).create({ ...baseData, points: ArmBotPoint, }); } else if (type === "StaticMachine") { console.log("StaticMachine data"); const baseData = { // modelfileID: "67e3db5ac2e8f37134526f40", modelfileID: "ca164ffdfa74f6622536bb0f", type: "StaticMachine", }; const StaticMachinePoint: IPointStaticMachine = { uuid: "point1UUID", position: [-0.25, 1.5, 0.85], rotation: [0, 0, 0], actions: { uuid: "randomUUID", name: "Action 1", buffer: 0, material: "Inherit", }, triggers: { uuid: "randomUUID", name: "trigger 1", type: "OnComplete", }, connections: { source: { modelUUID: "modelUUID", pointUUID: "point1UUID" }, targets: [{ modelUUID: "modelUUID", pointUUID: "point1UUID" }], }, }; await pointModel(organization).create({ ...baseData, points: StaticMachinePoint, }); } else { return res.json({ message: "Requested type mismatch" }); } return res.status(201).json({ message: "Points created successfully" }); } catch (error) { return res.status(500).json({ message: "Server error", error: error instanceof Error ? error.message : "Unknown error", }); } } static async gettypePoints(req: Request, res: Response): Promise { const { modelfileID, organization } = req.params; try { const pointData = await pointModel(organization) .findOne({ modelfileID: modelfileID, isArchive: false, }) .select("type points -_id"); if (!pointData) { return res.json({ message: "Data not found" }); } res.status(200).json(pointData); } catch (error: any) { res.status(500).json({ message: "Server error", error: error.message }); } } }