2025-03-29 17:47:16 +05:30
|
|
|
import { Request, Response } from "express";
|
|
|
|
|
import pointModel from "../../../shared/model/builder/assets/assetPoint-Model.ts";
|
2025-04-03 19:51:51 +05:30
|
|
|
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;
|
|
|
|
|
}>;
|
|
|
|
|
}
|
2025-03-29 17:47:16 +05:30
|
|
|
|
2025-04-03 19:51:51 +05:30
|
|
|
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 pointService {
|
|
|
|
|
static async addPoints(req: Request, res: Response): Promise<any> {
|
|
|
|
|
const { type, modelfileID, organization } = req.body;
|
|
|
|
|
|
2025-04-03 19:51:51 +05:30
|
|
|
// Validate type
|
2025-03-29 17:47:16 +05:30
|
|
|
if (!["Conveyor", "Vehicle"].includes(type)) {
|
|
|
|
|
return res.status(400).json({ message: "Invalid type requested" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2025-04-03 19:51:51 +05:30
|
|
|
const existingdata = await pointModel(organization).findOne({
|
|
|
|
|
modelfileID: modelfileID,
|
|
|
|
|
isArchive: false,
|
|
|
|
|
});
|
|
|
|
|
if (existingdata) return res.send("Data already exists");
|
|
|
|
|
|
2025-03-29 17:47:16 +05:30
|
|
|
if (type === "Conveyor") {
|
2025-04-03 19:51:51 +05:30
|
|
|
const baseData = {
|
2025-03-29 17:47:16 +05:30
|
|
|
modelfileID: "672a090f80d91ac979f4d0bd",
|
2025-04-03 19:51:51 +05:30
|
|
|
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: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
|
|
|
|
targets: [{ pathUUID: "modelUUID", pointUUID: "point1UUID" }],
|
2025-03-29 17:47:16 +05:30
|
|
|
},
|
2025-04-03 19:51:51 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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: { pathUUID: "modelUUID", pointUUID: "point2UUID" },
|
|
|
|
|
targets: [{ pathUUID: "modelUUID", pointUUID: "point2UUID" }],
|
2025-03-29 17:47:16 +05:30
|
|
|
},
|
2025-04-03 19:51:51 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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: { pathUUID: "modelUUID", pointUUID: "point3UUID" },
|
|
|
|
|
targets: [{ pathUUID: "modelUUID", pointUUID: "point3UUID" }],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
await pointModel(organization).create({
|
|
|
|
|
...baseData,
|
|
|
|
|
points: conveyorPoints,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (type === "Vehicle") {
|
|
|
|
|
console.log("vehcile data");
|
|
|
|
|
const baseData = {
|
|
|
|
|
modelfileID: "67e3da19c2e8f37134526e6a",
|
|
|
|
|
type: "Vehicle",
|
|
|
|
|
};
|
|
|
|
|
const vehiclePoint: IPointVehicle = {
|
|
|
|
|
uuid: "point1UUID",
|
|
|
|
|
position: [0, 1.3, 0],
|
|
|
|
|
actions: [
|
2025-03-29 17:47:16 +05:30
|
|
|
{
|
2025-04-03 19:51:51 +05:30
|
|
|
uuid: "randomUUID",
|
|
|
|
|
name: "Action 1",
|
|
|
|
|
type: "string",
|
|
|
|
|
hitCount: 1,
|
|
|
|
|
isUsed: false,
|
|
|
|
|
start: "start",
|
|
|
|
|
end: "end",
|
|
|
|
|
buffer: 0,
|
2025-03-29 17:47:16 +05:30
|
|
|
},
|
|
|
|
|
],
|
2025-04-03 19:51:51 +05:30
|
|
|
triggers: [
|
|
|
|
|
{ uuid: "string", name: "string", type: "string", isUsed: false },
|
|
|
|
|
],
|
|
|
|
|
connections: {
|
|
|
|
|
source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
|
|
|
|
targets: [{ pathUUID: "modelUUID", pointUUID: "point1UUID" }],
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
if ("rotation" in vehiclePoint) {
|
|
|
|
|
return res
|
|
|
|
|
.status(400)
|
|
|
|
|
.json({ error: "Rotation not allowed for Vehicle points" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await pointModel(organization).create({
|
|
|
|
|
...baseData,
|
|
|
|
|
points: vehiclePoint,
|
2025-03-29 17:47:16 +05:30
|
|
|
});
|
|
|
|
|
}
|
2025-04-03 19:51:51 +05:30
|
|
|
|
|
|
|
|
return res.status(201).json({ message: "Points created successfully" });
|
2025-03-29 17:47:16 +05:30
|
|
|
} catch (error) {
|
2025-04-03 19:51:51 +05:30
|
|
|
return res.status(500).json({
|
|
|
|
|
message: "Server error",
|
|
|
|
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
|
|
|
});
|
2025-03-29 17:47:16 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async gettypePoints(req: Request, res: Response): Promise<any> {
|
|
|
|
|
const { modelfileID, organization } = req.params;
|
2025-04-03 19:51:51 +05:30
|
|
|
console.log("req.params: ", req.params);
|
2025-03-29 17:47:16 +05:30
|
|
|
try {
|
2025-04-03 19:51:51 +05:30
|
|
|
const pointData = await pointModel(organization)
|
2025-03-29 17:47:16 +05:30
|
|
|
.findOne({
|
|
|
|
|
modelfileID: modelfileID,
|
2025-04-03 19:51:51 +05:30
|
|
|
isArchive: false,
|
2025-03-29 17:47:16 +05:30
|
|
|
})
|
2025-04-03 19:51:51 +05:30
|
|
|
.select("type points -_id");
|
|
|
|
|
if (!pointData) {
|
2025-03-31 18:30:14 +05:30
|
|
|
return res.json({ message: "Data not found" });
|
|
|
|
|
}
|
2025-04-03 19:51:51 +05:30
|
|
|
res.status(200).json(pointData);
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
res.status(500).json({ message: "Server error", error: error.message });
|
2025-03-29 17:47:16 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-03 19:51:51 +05:30
|
|
|
|
|
|
|
|
// Function to remove `_id` recursively
|
|
|
|
|
// const removeIdRecursively = (obj: any): any => {
|
|
|
|
|
// if (Array.isArray(obj)) {
|
|
|
|
|
// return obj.map(removeIdRecursively);
|
|
|
|
|
// } else if (obj !== null && typeof obj === "object") {
|
|
|
|
|
// const { _id, ...rest } = obj; // Remove `_id`
|
|
|
|
|
// return Object.keys(rest).reduce((acc, key) => {
|
|
|
|
|
// acc[key] = removeIdRecursively(rest[key]); // Recursively clean nested objects
|
|
|
|
|
// return acc;
|
|
|
|
|
// }, {} as any);
|
|
|
|
|
// }
|
|
|
|
|
// return obj;
|
|
|
|
|
// };
|
|
|
|
|
// static async gettypePoints(req: Request, res: Response): Promise<any> {
|
|
|
|
|
// const { modelfileID, organization } = req.params;
|
|
|
|
|
// try {
|
|
|
|
|
// const { ConveyorModel, VehicleModel } = pointModel(organization);
|
|
|
|
|
|
|
|
|
|
// const conveyorData = await ConveyorModel.findOne({ modelfileID })
|
|
|
|
|
// .select("-_id -createdAt -updatedAt")
|
|
|
|
|
// .lean();
|
|
|
|
|
|
|
|
|
|
// const vehicleData = await VehicleModel.findOne({ modelfileID })
|
|
|
|
|
// .select("-_id -createdAt -updatedAt")
|
|
|
|
|
// .lean();
|
|
|
|
|
|
|
|
|
|
// if (!conveyorData && !vehicleData) {
|
|
|
|
|
// return res.status(404).json({ message: "Data not found" });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const combinedData = [conveyorData, vehicleData].filter(Boolean);
|
|
|
|
|
|
|
|
|
|
// const formattedData = combinedData.map((data) => {
|
|
|
|
|
// const typedData = data as any;
|
|
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
// modelfileID: typedData.modelfileID,
|
|
|
|
|
// type: typedData.type,
|
|
|
|
|
// points: Array.isArray(typedData.points)
|
|
|
|
|
// ? typedData.points.map((point: any) => ({
|
|
|
|
|
// position: point.position,
|
|
|
|
|
// rotation: point.rotation,
|
|
|
|
|
// }))
|
|
|
|
|
// : [],
|
|
|
|
|
// };
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// return res.status(200).json(formattedData);
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// res.status(500).json({ message: "Server error", error });
|
|
|
|
|
// }
|
|
|
|
|
// }
|