AssetPoints based on type fixed, Asset Get,Create, 3d widget type updated in socket
This commit is contained in:
@@ -1,180 +1,303 @@
|
||||
import { Request, Response } from "express";
|
||||
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;
|
||||
}>;
|
||||
}
|
||||
export class pointService {
|
||||
static async addPoints(req: Request, res: Response): Promise<any> {
|
||||
const { type, modelfileID, organization } = req.body;
|
||||
|
||||
// Validate type
|
||||
if (!["Conveyor", "Vehicle"].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 pointsData = await pointModel(organization).findOne({
|
||||
modelfileID: modelfileID,
|
||||
type: type,
|
||||
});
|
||||
if (pointsData) return res.send("Data already exists");
|
||||
const createData = await pointModel(organization).create({
|
||||
type: "Conveyor",
|
||||
const baseData = {
|
||||
modelfileID: "672a090f80d91ac979f4d0bd",
|
||||
points: [
|
||||
{
|
||||
uuid: "point1UUID",
|
||||
position: [0, 0.85, 2.2],
|
||||
rotation: [0, 0, 0],
|
||||
actions: [
|
||||
{
|
||||
uuid: "randomUUID",
|
||||
name: "Action 1",
|
||||
type: "Inherit",
|
||||
material: "Inherit",
|
||||
delay: "Inherit",
|
||||
spawnInterval: "Inherit",
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
triggers: [
|
||||
{
|
||||
uuid: "randomUUID",
|
||||
name: "trigger 1",
|
||||
type: "Inherit",
|
||||
bufferTime: 0,
|
||||
// delay: "Inherit",
|
||||
// spawnInterval: "Inherit",
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
// connections: {
|
||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
// targets: [],
|
||||
// },
|
||||
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" }],
|
||||
},
|
||||
{
|
||||
uuid: "point2UUID",
|
||||
position: [0, 0.85, 0],
|
||||
rotation: [0, 0, 0],
|
||||
actions: [
|
||||
{
|
||||
uuid: "randomUUID",
|
||||
name: "Action 1",
|
||||
type: "Inherit",
|
||||
material: "Inherit",
|
||||
delay: "Inherit",
|
||||
spawnInterval: "Inherit",
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
triggers: [
|
||||
{
|
||||
uuid: "randomUUID",
|
||||
name: "trigger 1",
|
||||
type: "Inherit",
|
||||
bufferTime: 0,
|
||||
// delay: "Inherit",
|
||||
// spawnInterval: "Inherit",
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
// connections: {
|
||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
// targets: [],
|
||||
// },
|
||||
},
|
||||
{
|
||||
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" }],
|
||||
},
|
||||
{
|
||||
uuid: "point3UUID",
|
||||
position: [0, 0.85, -2.2],
|
||||
rotation: [0, 0, 0],
|
||||
actions: [
|
||||
{
|
||||
uuid: "randomUUID",
|
||||
name: "Action 1",
|
||||
type: "Inherit",
|
||||
material: "Inherit",
|
||||
delay: "Inherit",
|
||||
spawnInterval: "Inherit",
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
triggers: [
|
||||
{
|
||||
uuid: "randomUUID",
|
||||
name: "trigger 1",
|
||||
type: "Inherit",
|
||||
bufferTime: 0,
|
||||
// delay: "Inherit",
|
||||
// spawnInterval: "Inherit",
|
||||
isUsed: false,
|
||||
},
|
||||
],
|
||||
// connections: {
|
||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
// targets: [],
|
||||
// },
|
||||
},
|
||||
{
|
||||
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,
|
||||
});
|
||||
}
|
||||
// else if (type === "Vehicle") {
|
||||
// // responseData = {
|
||||
// // type: "Vehicle",
|
||||
// // points: {
|
||||
// // uuid: "point1UUID",
|
||||
// // position: [10, 20, 30],
|
||||
// // rotation: [0, 0, 0],
|
||||
// // actions: [
|
||||
// // {
|
||||
// // uuid: "randomUUID",
|
||||
// // name: "Action 1",
|
||||
// // type: "Inherit",
|
||||
// // material: "Inherit",
|
||||
// // delay: "Inherit",
|
||||
// // spawnInterval: "Inherit",
|
||||
// // isUsed: false,
|
||||
// // },
|
||||
// // ],
|
||||
// // triggers: [],
|
||||
// // connections: {
|
||||
// // source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
// // targets: [],
|
||||
// // },
|
||||
// // },
|
||||
// // speed: 1,
|
||||
// // };
|
||||
// }
|
||||
if (type === "Vehicle") {
|
||||
console.log("vehcile data");
|
||||
const baseData = {
|
||||
modelfileID: "67e3da19c2e8f37134526e6a",
|
||||
type: "Vehicle",
|
||||
};
|
||||
const vehiclePoint: IPointVehicle = {
|
||||
uuid: "point1UUID",
|
||||
position: [0, 1.3, 0],
|
||||
actions: [
|
||||
{
|
||||
uuid: "randomUUID",
|
||||
name: "Action 1",
|
||||
type: "string",
|
||||
hitCount: 1,
|
||||
isUsed: false,
|
||||
start: "start",
|
||||
end: "end",
|
||||
buffer: 0,
|
||||
},
|
||||
],
|
||||
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" });
|
||||
}
|
||||
|
||||
res.status(200).json({ message: "point created successfully" });
|
||||
await pointModel(organization).create({
|
||||
...baseData,
|
||||
points: vehiclePoint,
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(201).json({ message: "Points created successfully" });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Server error", 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<any> {
|
||||
const { modelfileID, organization } = req.params;
|
||||
console.log("req.params: ", req.params);
|
||||
try {
|
||||
const getData = await pointModel(organization)
|
||||
const pointData = await pointModel(organization)
|
||||
.findOne({
|
||||
modelfileID: modelfileID,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("-_id -__v -createdAt -updatedAt");
|
||||
if (!getData) {
|
||||
.select("type points -_id");
|
||||
if (!pointData) {
|
||||
return res.json({ message: "Data not found" });
|
||||
}
|
||||
|
||||
const formattedData = {
|
||||
modelfileID: getData?.modelfileID,
|
||||
type: getData?.type,
|
||||
points: Array.isArray(getData?.points)
|
||||
? getData.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 });
|
||||
res.status(200).json(pointData);
|
||||
} catch (error: any) {
|
||||
res.status(500).json({ message: "Server error", error: error.message });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 });
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -3,11 +3,72 @@ import { Request, Response } from "express";
|
||||
import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
|
||||
import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||
import pointModel from "../../../shared/model/builder/assets/assetPoint-Model.ts";
|
||||
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;
|
||||
}>;
|
||||
}
|
||||
|
||||
export class assetsFloorservice {
|
||||
static async setFloorassets(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const {
|
||||
modeluuid,
|
||||
modelname,
|
||||
@@ -17,7 +78,7 @@ export class assetsFloorservice {
|
||||
isLocked,
|
||||
isVisible,
|
||||
organization,
|
||||
eventData, // Optional
|
||||
eventData,
|
||||
} = req.body;
|
||||
|
||||
const findvalue = await assetModel(organization).findOne({
|
||||
@@ -25,10 +86,14 @@ export class assetsFloorservice {
|
||||
modelname,
|
||||
isArchive: false,
|
||||
});
|
||||
const checkpointType = await pointModel(organization).findOne({
|
||||
modelfileID: modelfileID,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
if (findvalue) {
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid, modelname,isArchive:false },
|
||||
{ modeluuid, modelname, isArchive: false },
|
||||
{
|
||||
position,
|
||||
rotation,
|
||||
@@ -39,6 +104,46 @@ export class assetsFloorservice {
|
||||
);
|
||||
return res.status(201).json(updatevalue);
|
||||
} else {
|
||||
// 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
|
||||
// // ))
|
||||
// );
|
||||
// };
|
||||
let assetData: any = {
|
||||
modeluuid,
|
||||
modelname,
|
||||
@@ -49,65 +154,103 @@ export class assetsFloorservice {
|
||||
isVisible,
|
||||
};
|
||||
|
||||
console.log("eventData: ", eventData);
|
||||
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,
|
||||
// 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",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
console.log("eventData.points: ", eventData.points);
|
||||
assetData.points = eventData.points;
|
||||
assetData.speed = eventData.speed;
|
||||
assetData.type = eventData.type;
|
||||
assetData.points = pointRefs;
|
||||
}
|
||||
// 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;
|
||||
// }
|
||||
|
||||
const assetDoc = await assetModel(organization).create(assetData);
|
||||
await assetDoc.save();
|
||||
@@ -117,6 +260,9 @@ export class assetsFloorservice {
|
||||
modelId: assetDoc._id,
|
||||
});
|
||||
}
|
||||
// } else {
|
||||
// return res.json({ message: "Type not matched" });
|
||||
// }
|
||||
} catch (error) {
|
||||
console.error("Error creating flooritems:", error);
|
||||
res.status(500).json({ message: "Failed to create flooritems" });
|
||||
@@ -127,48 +273,43 @@ export class assetsFloorservice {
|
||||
const { organization } = req.params;
|
||||
const findValues = await assetModel(organization)
|
||||
.find({ isArchive: false })
|
||||
.select("-_id")
|
||||
.populate({
|
||||
path: "points",
|
||||
select: "-_id",
|
||||
})
|
||||
.populate({
|
||||
path: "points.actions",
|
||||
model: actionModel(organization),
|
||||
select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt",
|
||||
})
|
||||
.populate({
|
||||
path: "points.triggers",
|
||||
model: triggerModel(organization),
|
||||
select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt",
|
||||
});
|
||||
if (!findValues) {
|
||||
res.status(200).json("floorItems not found");
|
||||
} else {
|
||||
return res.status(200).json(
|
||||
findValues.map((item) => {
|
||||
let responseItem: any = {
|
||||
modeluuid: item.modeluuid,
|
||||
modelname: item.modelname,
|
||||
position: item.position,
|
||||
modelfileID: item.modelfileID,
|
||||
rotation: item.rotation,
|
||||
isLocked: item.isLocked,
|
||||
isVisible: item.isVisible,
|
||||
};
|
||||
.select("-_id -isArchive");
|
||||
|
||||
if (item.points.length > 1) {
|
||||
responseItem.eventData = {
|
||||
speed: item.speed,
|
||||
points: item.points,
|
||||
type: item.type,
|
||||
};
|
||||
}
|
||||
|
||||
return responseItem;
|
||||
})
|
||||
);
|
||||
if (!findValues || findValues.length === 0) {
|
||||
return res.status(200).json({ message: "floorItems not found" });
|
||||
}
|
||||
|
||||
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);
|
||||
} catch (error) {
|
||||
console.error("Error get flooritems:", error);
|
||||
res.status(500).json({ error: "Failed to get flooritems" });
|
||||
@@ -230,5 +371,34 @@ export class assetsFloorservice {
|
||||
return res.send(error.message);
|
||||
}
|
||||
}
|
||||
static async updateActionsDatas(req: Request, res: Response) {}
|
||||
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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
249
src/api-server/controller/simulation/productFlowservice.ts
Normal file
249
src/api-server/controller/simulation/productFlowservice.ts
Normal file
@@ -0,0 +1,249 @@
|
||||
// import { Request, Response } from "express";
|
||||
// // import assetModel from "../../../shared/model/assets/flooritems-Model.ts";
|
||||
// import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
|
||||
// import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||
// import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||
// import productFlowModel from "../../../shared/model/simulation/ProductFlowmodel.ts";
|
||||
|
||||
// export class productFlowservice {
|
||||
// static async setproductFlow(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const {
|
||||
// productName,
|
||||
// modeluuid,
|
||||
// modelname,
|
||||
// eventData,
|
||||
// organization,
|
||||
// productID,
|
||||
// } = req.body;
|
||||
|
||||
// // Validate required fields
|
||||
// if (!modeluuid || !modelname || !organization) {
|
||||
// return res.status(400).json({ message: "Missing required fields" });
|
||||
// }
|
||||
|
||||
// // Check if asset exists
|
||||
// const existingAsset = await assetModel(organization).findOne({
|
||||
// modeluuid: modeluuid,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (!existingAsset) {
|
||||
// return res.status(404).json({ message: "Asset not found for the ID" });
|
||||
// }
|
||||
|
||||
// // Prepare point references
|
||||
// let pointRefs: any[] = [];
|
||||
// if (eventData?.points && Array.isArray(eventData.points)) {
|
||||
// for (const point of eventData.points) {
|
||||
// let actionRefs: any[] = [];
|
||||
// let triggerRefs: any[] = [];
|
||||
|
||||
// // Process actions
|
||||
// if (Array.isArray(point.actions)) {
|
||||
// for (const action of point.actions) {
|
||||
// const actionDoc = await actionModel(organization).create({
|
||||
// pointsUUID: point.uuid,
|
||||
// isArchive: false,
|
||||
// uuid: action.uuid,
|
||||
// name: action.name,
|
||||
// type: action.type,
|
||||
// material: action.material || null,
|
||||
// delay: action.delay || null,
|
||||
// spawn_Interval: action.spawn_Interval || null,
|
||||
// });
|
||||
// actionRefs.push({
|
||||
// _id: actionDoc._id,
|
||||
// ...action,
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Process triggers
|
||||
// if (Array.isArray(point.triggers)) {
|
||||
// for (const trigger of point.triggers) {
|
||||
// const triggerDoc = await triggerModel(organization).create({
|
||||
// pointsUUID: point.uuid,
|
||||
// isArchive: false,
|
||||
// uuid: trigger.uuid,
|
||||
// name: trigger.name,
|
||||
// type: trigger.type,
|
||||
// bufferTime: trigger.bufferTime || null,
|
||||
// });
|
||||
// triggerRefs.push({
|
||||
// _id: triggerDoc._id,
|
||||
// ...trigger,
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// pointRefs.push({
|
||||
// pointuuid: point.uuid,
|
||||
// position: point.position || [],
|
||||
// rotation: point.rotation || [],
|
||||
// actions: actionRefs,
|
||||
// triggers: triggerRefs,
|
||||
// connections: point.connections || null,
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Check if product flow exists
|
||||
// const existingproductData = await productFlowModel(organization).findOne({
|
||||
// _id: productID,
|
||||
// });
|
||||
|
||||
// let result;
|
||||
// if (existingproductData) {
|
||||
// // Update existing product flow
|
||||
// result = await productFlowModel(organization).findOneAndUpdate(
|
||||
// { _id: productID },
|
||||
// {
|
||||
// $push: {
|
||||
// ProductData: {
|
||||
// AssetName: modelname,
|
||||
// Assetuuid: modeluuid,
|
||||
// paths: {
|
||||
// Points: pointRefs,
|
||||
// },
|
||||
// isArchive: false,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// { new: true }
|
||||
// );
|
||||
// } else {
|
||||
// // Create new product flow
|
||||
// result = await productFlowModel(organization).create({
|
||||
// _id: productID,
|
||||
// productName: productName,
|
||||
// ProductData: [
|
||||
// {
|
||||
// AssetName: modelname,
|
||||
// Assetuuid: modeluuid,
|
||||
// paths: {
|
||||
// Points: pointRefs,
|
||||
// },
|
||||
// isArchive: false,
|
||||
// },
|
||||
// ],
|
||||
// eventType: eventData?.type || null,
|
||||
// speed: eventData?.speed || null,
|
||||
// });
|
||||
// }
|
||||
|
||||
// res.status(201).json({
|
||||
// message: "Product flow processed successfully",
|
||||
// data: result,
|
||||
// });
|
||||
// } catch (error) {
|
||||
// console.error("Error creating flooritems:", error);
|
||||
// res.status(500).json({ message: "Failed to create flooritems" });
|
||||
// }
|
||||
// }
|
||||
// static async pointActionList(req: Request, res: Response): Promise<any> {}
|
||||
// static async productpathsList(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const { organization } = req.params;
|
||||
// const productFlowList = await productFlowModel(organization)
|
||||
// .find()
|
||||
// .select("ProductData productName -_id")
|
||||
// .exec();
|
||||
|
||||
// const formattedData = await Promise.all(
|
||||
// productFlowList.map(async (item) => ({
|
||||
// productName: item.productName,
|
||||
// paths: await Promise.all(
|
||||
// item.ProductData.map(async (data: any) => ({
|
||||
// Points: await Promise.all(
|
||||
// data.paths.Points.map(async (point: any) => {
|
||||
// const actions = await actionModel(organization)
|
||||
// .find({ _id: { $in: point.actions } })
|
||||
// .select(
|
||||
// "-_id -pointsUUID -isArchive -createdAt -updatedAt -__v"
|
||||
// )
|
||||
// .lean();
|
||||
// const triggers = await triggerModel(organization)
|
||||
// .find({ _id: { $in: point.triggers } })
|
||||
// .select(
|
||||
// "-_id -pointsUUID -isArchive -createdAt -updatedAt -__v"
|
||||
// )
|
||||
// .lean();
|
||||
// return {
|
||||
// connections: point.connections || null,
|
||||
// pointuuid: point.pointuuid,
|
||||
// actions: actions,
|
||||
// triggers: triggers,
|
||||
// position: point.position,
|
||||
// rotation: point.rotation,
|
||||
// };
|
||||
// })
|
||||
// ),
|
||||
// }))
|
||||
// ),
|
||||
// }))
|
||||
// );
|
||||
|
||||
// return res.status(200).json(formattedData);
|
||||
// } catch (error) {
|
||||
// console.error("Error get flooritems:", error);
|
||||
// res.status(500).json({ error: "Failed to get flooritems" });
|
||||
// }
|
||||
// }
|
||||
// // static async deleteFloorItems(req: Request, res: Response): Promise<any> {
|
||||
// // try {
|
||||
// // const { modeluuid, modelname, organization } = req.body;
|
||||
|
||||
// // const findValue = await assetModel(organization).findOneAndDelete({
|
||||
// // modeluuid: modeluuid,
|
||||
// // modelname: modelname,
|
||||
// // isArchive: false,
|
||||
// // });
|
||||
// // if (!findValue) {
|
||||
// // res.status(200).json("user not found");
|
||||
// // } else {
|
||||
// // res.status(201).json(findValue);
|
||||
// // }
|
||||
// // } catch (error) {
|
||||
// // console.error("Error get flooritems:", error);
|
||||
// // res.status(500).json({ error: "Failed to get flooritems" });
|
||||
// // }
|
||||
// // }
|
||||
// // static async updateAssetPositionRotation(
|
||||
// // req: Request,
|
||||
// // res: Response
|
||||
// // ): Promise<any> {
|
||||
// // try {
|
||||
// // const {
|
||||
// // modeluuid,
|
||||
// // modelname,
|
||||
// // position,
|
||||
// // modelfileID,
|
||||
// // rotation,
|
||||
// // isLocked,
|
||||
// // isVisible,
|
||||
// // organization,
|
||||
// // // eventData, // Optional
|
||||
// // } = req.body;
|
||||
|
||||
// // const existingAsset = await assetModel(organization).findOne({
|
||||
// // modeluuid: modeluuid,
|
||||
// // isArchive: false,
|
||||
// // });
|
||||
// // if (!existingAsset) return res.send("Asset not found");
|
||||
// // const updateAsset = await assetModel(organization).updateMany(
|
||||
// // { modeluuid: modeluuid, modelname: modelname, isArchive: false },
|
||||
// // {
|
||||
// // position: position,
|
||||
// // rotation: rotation,
|
||||
// // isVisible: isVisible,
|
||||
// // isLocked: isLocked,
|
||||
// // }
|
||||
// // );
|
||||
// // if (updateAsset)
|
||||
// // return res.status(200).json({ message: "Asset updated successfully" });
|
||||
// // } catch (error: any) {
|
||||
// // return res.send(error.message);
|
||||
// // }
|
||||
// // }
|
||||
// // static async updateActionsDatas(req: Request, res: Response) {}
|
||||
// }
|
||||
Reference in New Issue
Block a user