AssetPoints based on type fixed, Asset Get,Create, 3d widget type updated in socket
This commit is contained in:
@@ -7,5 +7,6 @@ router.patch(
|
|||||||
"/updateFloorAssets",
|
"/updateFloorAssets",
|
||||||
assetsFloorservice.updateAssetPositionRotation
|
assetsFloorservice.updateAssetPositionRotation
|
||||||
);
|
);
|
||||||
|
router.patch("/eventDataUpdate", assetsFloorservice.replaceEventDatas);
|
||||||
// router.get("/pointData/:modelfileID/:organization", assetsFloorservice.gettypePoints);
|
// router.get("/pointData/:modelfileID/:organization", assetsFloorservice.gettypePoints);
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
6
src/api-server/Routes/productFlowRouts.ts
Normal file
6
src/api-server/Routes/productFlowRouts.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// import * as express from "express";
|
||||||
|
// import { productFlowservice } from "../controller/simulation/productFlowservice.ts";
|
||||||
|
// const router = express.Router();
|
||||||
|
// router.post("/createProduct", productFlowservice.setproductFlow);
|
||||||
|
// router.get("/productFlowList/:organization", productFlowservice.productpathsList);
|
||||||
|
// export default router;
|
||||||
@@ -18,6 +18,7 @@ import assetfloorRoutes from "./Routes/assetfloorRoutes.ts";
|
|||||||
import floadWidgetRoutes from "./Routes/floadWidgetRoute.ts";
|
import floadWidgetRoutes from "./Routes/floadWidgetRoute.ts";
|
||||||
import templateRoutes from "./Routes/templateRoutes.ts";
|
import templateRoutes from "./Routes/templateRoutes.ts";
|
||||||
import widget3dRoutes from "./Routes/widget3dRoutes.ts";
|
import widget3dRoutes from "./Routes/widget3dRoutes.ts";
|
||||||
|
// import productFlowRoutes from "./Routes/productFlowRouts.ts";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
@@ -47,4 +48,5 @@ app.use("/api/v2", assetfloorRoutes);
|
|||||||
app.use("/api/v2", floadWidgetRoutes);
|
app.use("/api/v2", floadWidgetRoutes);
|
||||||
app.use("/api/v2", templateRoutes);
|
app.use("/api/v2", templateRoutes);
|
||||||
app.use("/api/v2", widget3dRoutes);
|
app.use("/api/v2", widget3dRoutes);
|
||||||
|
// app.use("/api/v2", productFlowRoutes);
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
@@ -1,180 +1,303 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import pointModel from "../../../shared/model/builder/assets/assetPoint-Model.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 pointService {
|
export class pointService {
|
||||||
static async addPoints(req: Request, res: Response): Promise<any> {
|
static async addPoints(req: Request, res: Response): Promise<any> {
|
||||||
const { type, modelfileID, organization } = req.body;
|
const { type, modelfileID, organization } = req.body;
|
||||||
|
|
||||||
|
// Validate type
|
||||||
if (!["Conveyor", "Vehicle"].includes(type)) {
|
if (!["Conveyor", "Vehicle"].includes(type)) {
|
||||||
return res.status(400).json({ message: "Invalid type requested" });
|
return res.status(400).json({ message: "Invalid type requested" });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const existingdata = await pointModel(organization).findOne({
|
||||||
|
modelfileID: modelfileID,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (existingdata) return res.send("Data already exists");
|
||||||
|
|
||||||
if (type === "Conveyor") {
|
if (type === "Conveyor") {
|
||||||
const pointsData = await pointModel(organization).findOne({
|
const baseData = {
|
||||||
modelfileID: modelfileID,
|
|
||||||
type: type,
|
|
||||||
});
|
|
||||||
if (pointsData) return res.send("Data already exists");
|
|
||||||
const createData = await pointModel(organization).create({
|
|
||||||
type: "Conveyor",
|
|
||||||
modelfileID: "672a090f80d91ac979f4d0bd",
|
modelfileID: "672a090f80d91ac979f4d0bd",
|
||||||
points: [
|
type: "Conveyor",
|
||||||
{
|
};
|
||||||
uuid: "point1UUID",
|
const conveyorPoints: IPointConveyor[] = [
|
||||||
position: [0, 0.85, 2.2],
|
{
|
||||||
rotation: [0, 0, 0],
|
uuid: "point1UUID",
|
||||||
actions: [
|
position: [0, 0.85, 2.2],
|
||||||
{
|
rotation: [0, 0, 0],
|
||||||
uuid: "randomUUID",
|
actions: [
|
||||||
name: "Action 1",
|
{
|
||||||
type: "Inherit",
|
uuid: "randomUUID",
|
||||||
material: "Inherit",
|
name: "Action 1",
|
||||||
delay: "Inherit",
|
type: "actionType",
|
||||||
spawnInterval: "Inherit",
|
material: "actionMaterial",
|
||||||
isUsed: false,
|
delay: "Inherit",
|
||||||
},
|
spawnInterval: "Inherit",
|
||||||
],
|
isUsed: false,
|
||||||
triggers: [
|
},
|
||||||
{
|
],
|
||||||
uuid: "randomUUID",
|
triggers: [
|
||||||
name: "trigger 1",
|
{
|
||||||
type: "Inherit",
|
uuid: "randomUUID",
|
||||||
bufferTime: 0,
|
name: "trigger 1",
|
||||||
// delay: "Inherit",
|
type: "triggerType",
|
||||||
// spawnInterval: "Inherit",
|
bufferTime: 0,
|
||||||
isUsed: false,
|
// delay: "Inherit",
|
||||||
},
|
// spawnInterval: "Inherit",
|
||||||
],
|
isUsed: false,
|
||||||
// connections: {
|
},
|
||||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
],
|
||||||
// targets: [],
|
connections: {
|
||||||
// },
|
source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||||
|
targets: [{ pathUUID: "modelUUID", pointUUID: "point1UUID" }],
|
||||||
},
|
},
|
||||||
{
|
},
|
||||||
uuid: "point2UUID",
|
{
|
||||||
position: [0, 0.85, 0],
|
uuid: "point2UUID",
|
||||||
rotation: [0, 0, 0],
|
position: [0, 0.85, 0],
|
||||||
actions: [
|
rotation: [0, 0, 0],
|
||||||
{
|
actions: [
|
||||||
uuid: "randomUUID",
|
{
|
||||||
name: "Action 1",
|
uuid: "randomUUID",
|
||||||
type: "Inherit",
|
name: "Action 1",
|
||||||
material: "Inherit",
|
type: "actionType",
|
||||||
delay: "Inherit",
|
material: "actionMaterial",
|
||||||
spawnInterval: "Inherit",
|
delay: "Inherit",
|
||||||
isUsed: false,
|
spawnInterval: "Inherit",
|
||||||
},
|
isUsed: false,
|
||||||
],
|
},
|
||||||
triggers: [
|
],
|
||||||
{
|
triggers: [
|
||||||
uuid: "randomUUID",
|
{
|
||||||
name: "trigger 1",
|
uuid: "randomUUID",
|
||||||
type: "Inherit",
|
name: "trigger 1",
|
||||||
bufferTime: 0,
|
type: "triggerType",
|
||||||
// delay: "Inherit",
|
bufferTime: 0,
|
||||||
// spawnInterval: "Inherit",
|
isUsed: false,
|
||||||
isUsed: false,
|
},
|
||||||
},
|
],
|
||||||
],
|
connections: {
|
||||||
// connections: {
|
source: { pathUUID: "modelUUID", pointUUID: "point2UUID" },
|
||||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
targets: [{ pathUUID: "modelUUID", pointUUID: "point2UUID" }],
|
||||||
// targets: [],
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
{
|
},
|
||||||
uuid: "point3UUID",
|
{
|
||||||
position: [0, 0.85, -2.2],
|
uuid: "point3UUID",
|
||||||
rotation: [0, 0, 0],
|
position: [0, 0.85, -2.2],
|
||||||
actions: [
|
rotation: [0, 0, 0],
|
||||||
{
|
actions: [
|
||||||
uuid: "randomUUID",
|
{
|
||||||
name: "Action 1",
|
uuid: "randomUUID",
|
||||||
type: "Inherit",
|
name: "Action 1",
|
||||||
material: "Inherit",
|
type: "actionType",
|
||||||
delay: "Inherit",
|
material: "actionMaterial",
|
||||||
spawnInterval: "Inherit",
|
delay: "Inherit",
|
||||||
isUsed: false,
|
spawnInterval: "Inherit",
|
||||||
},
|
isUsed: false,
|
||||||
],
|
},
|
||||||
triggers: [
|
],
|
||||||
{
|
triggers: [
|
||||||
uuid: "randomUUID",
|
{
|
||||||
name: "trigger 1",
|
uuid: "randomUUID",
|
||||||
type: "Inherit",
|
name: "trigger 1",
|
||||||
bufferTime: 0,
|
type: "triggerType",
|
||||||
// delay: "Inherit",
|
bufferTime: 0,
|
||||||
// spawnInterval: "Inherit",
|
isUsed: false,
|
||||||
isUsed: false,
|
},
|
||||||
},
|
],
|
||||||
],
|
connections: {
|
||||||
// connections: {
|
source: { pathUUID: "modelUUID", pointUUID: "point3UUID" },
|
||||||
// source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
targets: [{ pathUUID: "modelUUID", pointUUID: "point3UUID" }],
|
||||||
// targets: [],
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
await pointModel(organization).create({
|
||||||
|
...baseData,
|
||||||
|
points: conveyorPoints,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// else if (type === "Vehicle") {
|
if (type === "Vehicle") {
|
||||||
// // responseData = {
|
console.log("vehcile data");
|
||||||
// // type: "Vehicle",
|
const baseData = {
|
||||||
// // points: {
|
modelfileID: "67e3da19c2e8f37134526e6a",
|
||||||
// // uuid: "point1UUID",
|
type: "Vehicle",
|
||||||
// // position: [10, 20, 30],
|
};
|
||||||
// // rotation: [0, 0, 0],
|
const vehiclePoint: IPointVehicle = {
|
||||||
// // actions: [
|
uuid: "point1UUID",
|
||||||
// // {
|
position: [0, 1.3, 0],
|
||||||
// // uuid: "randomUUID",
|
actions: [
|
||||||
// // name: "Action 1",
|
{
|
||||||
// // type: "Inherit",
|
uuid: "randomUUID",
|
||||||
// // material: "Inherit",
|
name: "Action 1",
|
||||||
// // delay: "Inherit",
|
type: "string",
|
||||||
// // spawnInterval: "Inherit",
|
hitCount: 1,
|
||||||
// // isUsed: false,
|
isUsed: false,
|
||||||
// // },
|
start: "start",
|
||||||
// // ],
|
end: "end",
|
||||||
// // triggers: [],
|
buffer: 0,
|
||||||
// // connections: {
|
},
|
||||||
// // source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
|
],
|
||||||
// // targets: [],
|
triggers: [
|
||||||
// // },
|
{ uuid: "string", name: "string", type: "string", isUsed: false },
|
||||||
// // },
|
],
|
||||||
// // speed: 1,
|
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) {
|
} 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> {
|
static async gettypePoints(req: Request, res: Response): Promise<any> {
|
||||||
const { modelfileID, organization } = req.params;
|
const { modelfileID, organization } = req.params;
|
||||||
|
console.log("req.params: ", req.params);
|
||||||
try {
|
try {
|
||||||
const getData = await pointModel(organization)
|
const pointData = await pointModel(organization)
|
||||||
.findOne({
|
.findOne({
|
||||||
modelfileID: modelfileID,
|
modelfileID: modelfileID,
|
||||||
|
isArchive: false,
|
||||||
})
|
})
|
||||||
.select("-_id -__v -createdAt -updatedAt");
|
.select("type points -_id");
|
||||||
if (!getData) {
|
if (!pointData) {
|
||||||
return res.json({ message: "Data not found" });
|
return res.json({ message: "Data not found" });
|
||||||
}
|
}
|
||||||
|
res.status(200).json(pointData);
|
||||||
const formattedData = {
|
} catch (error: any) {
|
||||||
modelfileID: getData?.modelfileID,
|
res.status(500).json({ message: "Server error", error: error.message });
|
||||||
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 });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
|
||||||
import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.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 {
|
export class assetsFloorservice {
|
||||||
static async setFloorassets(req: Request, res: Response): Promise<any> {
|
static async setFloorassets(req: Request, res: Response): Promise<any> {
|
||||||
try {
|
try {
|
||||||
console.log("req.body: ", req.body);
|
|
||||||
const {
|
const {
|
||||||
modeluuid,
|
modeluuid,
|
||||||
modelname,
|
modelname,
|
||||||
@@ -17,7 +78,7 @@ export class assetsFloorservice {
|
|||||||
isLocked,
|
isLocked,
|
||||||
isVisible,
|
isVisible,
|
||||||
organization,
|
organization,
|
||||||
eventData, // Optional
|
eventData,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
const findvalue = await assetModel(organization).findOne({
|
const findvalue = await assetModel(organization).findOne({
|
||||||
@@ -25,10 +86,14 @@ export class assetsFloorservice {
|
|||||||
modelname,
|
modelname,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
|
const checkpointType = await pointModel(organization).findOne({
|
||||||
|
modelfileID: modelfileID,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
|
||||||
if (findvalue) {
|
if (findvalue) {
|
||||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||||
{ modeluuid, modelname,isArchive:false },
|
{ modeluuid, modelname, isArchive: false },
|
||||||
{
|
{
|
||||||
position,
|
position,
|
||||||
rotation,
|
rotation,
|
||||||
@@ -39,6 +104,46 @@ export class assetsFloorservice {
|
|||||||
);
|
);
|
||||||
return res.status(201).json(updatevalue);
|
return res.status(201).json(updatevalue);
|
||||||
} else {
|
} 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 = {
|
let assetData: any = {
|
||||||
modeluuid,
|
modeluuid,
|
||||||
modelname,
|
modelname,
|
||||||
@@ -49,65 +154,103 @@ export class assetsFloorservice {
|
|||||||
isVisible,
|
isVisible,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("eventData: ", eventData);
|
||||||
if (eventData) {
|
if (eventData) {
|
||||||
let pointRefs: any[] = [];
|
// console.log("checkpointType?.type: ", checkpointType?.type);
|
||||||
|
// console.log("eventData.typ: ", eventData.type);
|
||||||
if (Array.isArray(eventData.points)) {
|
// if (checkpointType?.type !== eventData.type) {
|
||||||
for (const point of eventData.points) {
|
// return res.send("Type mismatch");
|
||||||
let actionRefs: any[] = [];
|
// }
|
||||||
let triggerRefs: any[] = [];
|
if (eventData.type === "Conveyor") {
|
||||||
|
// console.log("eventData.points: ", typeof eventData.points);
|
||||||
if (Array.isArray(point.actions)) {
|
// if (!Array.isArray(eventData.points) || eventData.points) {
|
||||||
for (const action of point.actions) {
|
// return res
|
||||||
const actionDoc = await actionModel(organization).create({
|
// .status(400)
|
||||||
pointsUUID: point.uuid,
|
// .json({ message: "Points must be an array" });
|
||||||
isArchive: false,
|
// }
|
||||||
uuid: action.uuid,
|
// if (!eventData.points.every(validateConveyorPoint)) {
|
||||||
name: action.name,
|
// return res
|
||||||
type: action.type,
|
// .status(400)
|
||||||
material: action.material,
|
// .json({ message: "Invalid Conveyor point structure" });
|
||||||
delay: action.delay,
|
// }
|
||||||
spawn_Interval: action.spawn_Interval,
|
} else if (eventData.type === "Vehicle") {
|
||||||
});
|
console.log("eventData.points: ", typeof eventData.points);
|
||||||
await actionDoc.save();
|
if (!eventData.points) {
|
||||||
actionRefs.push(actionDoc._id);
|
return res
|
||||||
}
|
.status(400)
|
||||||
}
|
.json({ message: "Vehicle points must be a single object" });
|
||||||
|
}
|
||||||
if (Array.isArray(point.triggers)) {
|
if (eventData.points.rotation) {
|
||||||
for (const trigger of point.triggers) {
|
return res.status(400).json({
|
||||||
const triggerDoc = await triggerModel(organization).create({
|
message: "Rotation is not allowed for Vehicle points",
|
||||||
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("eventData.points: ", eventData.points);
|
||||||
|
assetData.points = eventData.points;
|
||||||
assetData.speed = eventData.speed;
|
assetData.speed = eventData.speed;
|
||||||
assetData.type = eventData.type;
|
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);
|
const assetDoc = await assetModel(organization).create(assetData);
|
||||||
await assetDoc.save();
|
await assetDoc.save();
|
||||||
@@ -117,6 +260,9 @@ export class assetsFloorservice {
|
|||||||
modelId: assetDoc._id,
|
modelId: assetDoc._id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// } else {
|
||||||
|
// return res.json({ message: "Type not matched" });
|
||||||
|
// }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error creating flooritems:", error);
|
console.error("Error creating flooritems:", error);
|
||||||
res.status(500).json({ message: "Failed to create flooritems" });
|
res.status(500).json({ message: "Failed to create flooritems" });
|
||||||
@@ -127,48 +273,43 @@ export class assetsFloorservice {
|
|||||||
const { organization } = req.params;
|
const { organization } = req.params;
|
||||||
const findValues = await assetModel(organization)
|
const findValues = await assetModel(organization)
|
||||||
.find({ isArchive: false })
|
.find({ isArchive: false })
|
||||||
.select("-_id")
|
.select("-_id -isArchive");
|
||||||
.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,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (item.points.length > 1) {
|
if (!findValues || findValues.length === 0) {
|
||||||
responseItem.eventData = {
|
return res.status(200).json({ message: "floorItems not found" });
|
||||||
speed: item.speed,
|
|
||||||
points: item.points,
|
|
||||||
type: item.type,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseItem;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
} catch (error) {
|
||||||
console.error("Error get flooritems:", error);
|
console.error("Error get flooritems:", error);
|
||||||
res.status(500).json({ error: "Failed to get flooritems" });
|
res.status(500).json({ error: "Failed to get flooritems" });
|
||||||
@@ -230,5 +371,34 @@ export class assetsFloorservice {
|
|||||||
return res.send(error.message);
|
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) {}
|
||||||
|
// }
|
||||||
@@ -8,35 +8,10 @@ export interface assetData extends Document {
|
|||||||
isLocked: boolean;
|
isLocked: boolean;
|
||||||
type: string;
|
type: string;
|
||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
isArchive:false
|
isArchive: false;
|
||||||
// position: [];
|
points: [] | {};
|
||||||
// rotation: {
|
|
||||||
// x: number;
|
|
||||||
// y: number;
|
|
||||||
// z: number;
|
|
||||||
// };
|
|
||||||
points: {
|
|
||||||
uuid: string;
|
|
||||||
position: [];
|
|
||||||
rotation: [];
|
|
||||||
actions: [mongoose.Types.ObjectId];
|
|
||||||
triggers: [mongoose.Types.ObjectId];
|
|
||||||
connections: {
|
|
||||||
source: {
|
|
||||||
pathUUID: string;
|
|
||||||
pointUUID: string;
|
|
||||||
};
|
|
||||||
targets: [
|
|
||||||
{
|
|
||||||
pathUUID: string;
|
|
||||||
pointUUID: string;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}[];
|
|
||||||
}[];
|
|
||||||
position: [];
|
position: [];
|
||||||
// rotation: [];
|
rotation: {
|
||||||
rotation: {
|
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
z: number;
|
z: number;
|
||||||
@@ -44,37 +19,14 @@ export interface assetData extends Document {
|
|||||||
speed: number | string;
|
speed: number | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the Mongoose Schema
|
|
||||||
const assetDataSchema: Schema = new Schema({
|
const assetDataSchema: Schema = new Schema({
|
||||||
isArchive:{type:Boolean,default:false},
|
isArchive: { type: Boolean, default: false },
|
||||||
modeluuid: { type: String },
|
modeluuid: { type: String },
|
||||||
modelfileID: { type: String },
|
modelfileID: { type: String },
|
||||||
modelname: { type: String },
|
modelname: { type: String },
|
||||||
type: { type: String },
|
type: { type: String },
|
||||||
// assetPosition: { type: Array },
|
points: { type: Schema.Types.Mixed },
|
||||||
points: [
|
position: { type: Array },
|
||||||
{
|
|
||||||
uuid: { type: String },
|
|
||||||
position: { type: Array },
|
|
||||||
rotation: { type: Array },
|
|
||||||
actions: [{ type: mongoose.Schema.Types.ObjectId, ref: "Actions" }],
|
|
||||||
triggers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Triggers" }],
|
|
||||||
connections: {
|
|
||||||
source: {
|
|
||||||
pathUUID: { type: String },
|
|
||||||
pointUUID: { type: String },
|
|
||||||
},
|
|
||||||
targets: [
|
|
||||||
{
|
|
||||||
pathUUID: { type: String },
|
|
||||||
pointUUID: { type: String },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
position: { type: Array},
|
|
||||||
// rotation: { type: Array},
|
|
||||||
rotation: {
|
rotation: {
|
||||||
x: { type: Number },
|
x: { type: Number },
|
||||||
y: { type: Number },
|
y: { type: Number },
|
||||||
@@ -90,3 +42,96 @@ const assetModel = (db: string) => {
|
|||||||
return MainModel(db, "Assets", assetDataSchema, "Assets");
|
return MainModel(db, "Assets", assetDataSchema, "Assets");
|
||||||
};
|
};
|
||||||
export default assetModel;
|
export default assetModel;
|
||||||
|
|
||||||
|
// import mongoose, { Document, Schema } from "mongoose";
|
||||||
|
// import MainModel from "../../../connect/mongoose.ts";
|
||||||
|
|
||||||
|
// export interface assetData extends Document {
|
||||||
|
// modeluuid: string;
|
||||||
|
// modelfileID: string;
|
||||||
|
// modelname: string;
|
||||||
|
// isLocked: boolean;
|
||||||
|
// type: string;
|
||||||
|
// isVisible: boolean;
|
||||||
|
// isArchive: false;
|
||||||
|
// // position: [];
|
||||||
|
// // rotation: {
|
||||||
|
// // x: number;
|
||||||
|
// // y: number;
|
||||||
|
// // z: number;
|
||||||
|
// // };
|
||||||
|
// points: {
|
||||||
|
// uuid: string;
|
||||||
|
// position: [];
|
||||||
|
// rotation: [];
|
||||||
|
// actions: [mongoose.Types.ObjectId];
|
||||||
|
// triggers: [mongoose.Types.ObjectId];
|
||||||
|
// connections: {
|
||||||
|
// source: {
|
||||||
|
// pathUUID: string;
|
||||||
|
// pointUUID: string;
|
||||||
|
// };
|
||||||
|
// targets: [
|
||||||
|
// {
|
||||||
|
// pathUUID: string;
|
||||||
|
// pointUUID: string;
|
||||||
|
// }
|
||||||
|
// ];
|
||||||
|
// }[];
|
||||||
|
// }[];
|
||||||
|
// position: [];
|
||||||
|
// // rotation: [];
|
||||||
|
// rotation: {
|
||||||
|
// x: number;
|
||||||
|
// y: number;
|
||||||
|
// z: number;
|
||||||
|
// };
|
||||||
|
// speed: number | string;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Define the Mongoose Schema
|
||||||
|
// const assetDataSchema: Schema = new Schema({
|
||||||
|
// isArchive: { type: Boolean, default: false },
|
||||||
|
// modeluuid: { type: String },
|
||||||
|
// modelfileID: { type: String },
|
||||||
|
// modelname: { type: String },
|
||||||
|
// type: { type: String },
|
||||||
|
// // assetPosition: { type: Array },
|
||||||
|
// points: [
|
||||||
|
// {
|
||||||
|
// uuid: { type: String },
|
||||||
|
// position: { type: Array },
|
||||||
|
// rotation: { type: Array },
|
||||||
|
// actions: [{ type: mongoose.Schema.Types.ObjectId, ref: "Actions" }],
|
||||||
|
// triggers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Triggers" }],
|
||||||
|
// connections: {
|
||||||
|
// source: {
|
||||||
|
// pathUUID: { type: String },
|
||||||
|
// pointUUID: { type: String },
|
||||||
|
// },
|
||||||
|
// targets: [
|
||||||
|
// {
|
||||||
|
// pathUUID: { type: String },
|
||||||
|
// pointUUID: { type: String },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// position: { type: Array },
|
||||||
|
// // rotation: { type: Array},
|
||||||
|
// rotation: {
|
||||||
|
// x: { type: Number },
|
||||||
|
// y: { type: Number },
|
||||||
|
// z: { type: Number },
|
||||||
|
// },
|
||||||
|
// speed: { type: Schema.Types.Mixed },
|
||||||
|
// isLocked: { type: Boolean },
|
||||||
|
// isVisible: { type: Boolean },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // export default floorItemsModel;
|
||||||
|
// const assetModel = (db: string) => {
|
||||||
|
// return MainModel(db, "Assets", assetDataSchema, "Assets");
|
||||||
|
// };
|
||||||
|
// export default assetModel;
|
||||||
|
|||||||
@@ -1,107 +1,410 @@
|
|||||||
import mongoose, { Schema, Document } from "mongoose";
|
import mongoose, { Schema, Document } from "mongoose";
|
||||||
import MainModel from "../../../connect/mongoose.ts";
|
import MainModel from "../../../connect/mongoose.ts";
|
||||||
|
|
||||||
interface IAction {
|
// Common Interfaces
|
||||||
uuid: string;
|
interface ITriggerConveyor {
|
||||||
name: string;
|
|
||||||
type: string;
|
|
||||||
material: string;
|
|
||||||
delay: string;
|
|
||||||
spawnInterval: string;
|
|
||||||
isUsed: boolean;
|
|
||||||
hitCount: number;
|
|
||||||
start: string;
|
|
||||||
end: string;
|
|
||||||
buffer: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ITriggers {
|
|
||||||
uuid: string;
|
uuid: string;
|
||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
isUsed: boolean;
|
isUsed: boolean;
|
||||||
bufferTime: number;
|
bufferTime: number;
|
||||||
}
|
}
|
||||||
|
interface ITriggerVehicle {
|
||||||
|
uuid: string;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
isUsed: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
interface IConnection {
|
interface IConnection {
|
||||||
source: { pathUUID: string; pointUUID: string };
|
source: { pathUUID: string; pointUUID: string };
|
||||||
targets: { pathUUID: string; pointUUID: string }[];
|
targets: { pathUUID: string; pointUUID: string }[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IPoint {
|
// Point Types
|
||||||
|
interface IPointBase {
|
||||||
uuid: string;
|
uuid: string;
|
||||||
position: number[];
|
position: number[];
|
||||||
rotation: number[];
|
|
||||||
actions: IAction[];
|
|
||||||
triggers: ITriggers[];
|
|
||||||
connections: IConnection;
|
connections: IConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IBaseModel extends Document {
|
interface IPointConveyor extends IPointBase {
|
||||||
modelfileID: string;
|
rotation: number[];
|
||||||
type: "Conveyor" | "Vehicle";
|
actions: Array<{
|
||||||
points: IPoint[] | IPoint;
|
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;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Base Schema
|
interface IPointVehicle extends IPointBase {
|
||||||
const PointSchema = new Schema<IPoint>({
|
actions: Array<{
|
||||||
uuid: { type: String, required: true },
|
uuid: string;
|
||||||
position: { type: [Number] },
|
name: string;
|
||||||
rotation: { type: [Number] },
|
type: string;
|
||||||
actions: [
|
isUsed: boolean;
|
||||||
{
|
hitCount: number;
|
||||||
uuid: { type: String, default: "" },
|
start: string;
|
||||||
name: { type: String },
|
end: string;
|
||||||
type: { type: String },
|
buffer: number;
|
||||||
material: { type: String },
|
}>;
|
||||||
delay: { type: String },
|
triggers: Array<{
|
||||||
spawnInterval: { type: String },
|
uuid: string;
|
||||||
isUsed: { type: Boolean },
|
name: string;
|
||||||
hitCount: { type: String },
|
type: string;
|
||||||
start: { type: String },
|
isUsed: boolean;
|
||||||
end: { type: String },
|
}>;
|
||||||
buffer: { type: String },
|
}
|
||||||
},
|
|
||||||
],
|
|
||||||
triggers: [
|
|
||||||
{
|
|
||||||
uuid: { type: String, default: "" },
|
|
||||||
name: { type: String },
|
|
||||||
type: { type: String },
|
|
||||||
bufferTime: { type: Number },
|
|
||||||
isUsed: { type: Boolean },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
connections: {
|
|
||||||
source: {
|
|
||||||
pathUUID: { type: String },
|
|
||||||
pointUUID: { type: String },
|
|
||||||
},
|
|
||||||
targets: [
|
|
||||||
{
|
|
||||||
pathUUID: { type: String },
|
|
||||||
pointUUID: { type: String },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const BaseSchema = new Schema<IBaseModel>(
|
// Main Document Interface
|
||||||
|
interface IPointModel extends Document {
|
||||||
|
modelfileID: string;
|
||||||
|
type: "Conveyor" | "Vehicle";
|
||||||
|
points: IPointConveyor[] | IPointVehicle;
|
||||||
|
isArchive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single Schema for both types
|
||||||
|
const PointSchema = new Schema<IPointModel>(
|
||||||
{
|
{
|
||||||
modelfileID: { type: String },
|
modelfileID: { type: String },
|
||||||
type: { type: String, enum: ["Conveyor", "Vehicle"] },
|
type: { type: String, enum: ["Conveyor", "Vehicle"], required: true },
|
||||||
|
isArchive: { type: Boolean, default: false },
|
||||||
points: {
|
points: {
|
||||||
type: Schema.Types.Mixed,
|
type: Schema.Types.Mixed, // Flexible structure based on type
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ discriminatorKey: "type", timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Model Creation
|
||||||
const pointModel = (db: string) => {
|
const pointModel = (db: string) => {
|
||||||
return MainModel(db, "Points", BaseSchema, "Points");
|
return MainModel(db, "Points", PointSchema, "Points"); // Single collection
|
||||||
};
|
};
|
||||||
|
|
||||||
export default pointModel;
|
export default pointModel;
|
||||||
|
|
||||||
// const pointModel = mongoose.model<IBaseModel>("Points", BaseSchema, "Points");
|
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
// import mongoose, { Schema, Document } from "mongoose";
|
||||||
|
// import MainModel from "../../../connect/mongoose.ts";
|
||||||
|
|
||||||
|
// interface IActionConveyor {
|
||||||
|
// uuid: string;
|
||||||
|
// name: string;
|
||||||
|
// type: string;
|
||||||
|
// material: string;
|
||||||
|
// delay: number | string;
|
||||||
|
// spawnInterval: number | string;
|
||||||
|
// spawnMaterial: string;
|
||||||
|
// isUsed: boolean;
|
||||||
|
// hitCount: number;
|
||||||
|
// start: string;
|
||||||
|
// end: string;
|
||||||
|
// buffer: number;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// interface ITriggers {
|
||||||
|
// uuid: string;
|
||||||
|
// name: string;
|
||||||
|
// type: string;
|
||||||
|
// isUsed: boolean;
|
||||||
|
// bufferTime: number;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// interface IConnection {
|
||||||
|
// source: { pathUUID: string; pointUUID: string };
|
||||||
|
// targets: { pathUUID: string; pointUUID: string }[];
|
||||||
|
// }
|
||||||
|
// interface IActionVehicle {
|
||||||
|
// uuid: string;
|
||||||
|
// name: string;
|
||||||
|
// type: string;
|
||||||
|
// isUsed: boolean;
|
||||||
|
// hitCount: number;
|
||||||
|
// start: string;
|
||||||
|
// end: string;
|
||||||
|
// buffer: number;
|
||||||
|
// }
|
||||||
|
// interface IPointConveyor {
|
||||||
|
// uuid: string;
|
||||||
|
// position: number[];
|
||||||
|
// rotation: number[];
|
||||||
|
// actions: IActionConveyor[];
|
||||||
|
// triggers: ITriggers[];
|
||||||
|
// connections: IConnection;
|
||||||
|
// }
|
||||||
|
// interface IPointVehicle {
|
||||||
|
// uuid: string;
|
||||||
|
// position: number[];
|
||||||
|
// actions: IActionVehicle[];
|
||||||
|
// triggers: ITriggers[];
|
||||||
|
// connections: IConnection;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// interface IBaseModel extends Document {
|
||||||
|
// modelfileID: string;
|
||||||
|
// type: "Conveyor" | "Vehicle";
|
||||||
|
// points: IPointConveyor[] | IPointVehicle;
|
||||||
|
// }
|
||||||
|
// const PointconveyorSchema = new Schema<IPointConveyor>({
|
||||||
|
// uuid: { type: String, required: true },
|
||||||
|
// position: { type: [Number] },
|
||||||
|
// rotation: { type: [Number] },
|
||||||
|
// actions: [
|
||||||
|
// {
|
||||||
|
// uuid: { type: String, default: "" },
|
||||||
|
// name: { type: String },
|
||||||
|
// type: { type: String },
|
||||||
|
// material: { type: String },
|
||||||
|
// delay: { type: Schema.Types.Mixed },
|
||||||
|
// spawnInterval: { type: Schema.Types.Mixed },
|
||||||
|
// spawnMaterial: { type: String },
|
||||||
|
// isUsed: { type: Boolean },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// triggers: [
|
||||||
|
// {
|
||||||
|
// uuid: { type: String, default: "" },
|
||||||
|
// name: { type: String },
|
||||||
|
// type: { type: String },
|
||||||
|
// bufferTime: { type: Number },
|
||||||
|
// isUsed: { type: Boolean },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// connections: {
|
||||||
|
// source: {
|
||||||
|
// pathUUID: { type: String },
|
||||||
|
// pointUUID: { type: String },
|
||||||
|
// },
|
||||||
|
// targets: [
|
||||||
|
// {
|
||||||
|
// pathUUID: { type: String },
|
||||||
|
// pointUUID: { type: String },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// const PointvehicleSchema = new Schema<IPointVehicle>({
|
||||||
|
// uuid: { type: String, required: true },
|
||||||
|
// position: { type: [Number] },
|
||||||
|
// actions: [
|
||||||
|
// {
|
||||||
|
// uuid: { type: String, default: "" },
|
||||||
|
// name: { type: String },
|
||||||
|
// type: { type: String },
|
||||||
|
// isUsed: { type: Boolean },
|
||||||
|
// hitCount: { type: String },
|
||||||
|
// start: { type: String },
|
||||||
|
// end: { type: String },
|
||||||
|
// buffer: { type: String },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// triggers: [
|
||||||
|
// {
|
||||||
|
// uuid: { type: String, default: "" },
|
||||||
|
// name: { type: String },
|
||||||
|
// type: { type: String },
|
||||||
|
// bufferTime: { type: Number },
|
||||||
|
// isUsed: { type: Boolean },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// connections: {
|
||||||
|
// source: {
|
||||||
|
// pathUUID: { type: String },
|
||||||
|
// pointUUID: { type: String },
|
||||||
|
// },
|
||||||
|
// targets: [
|
||||||
|
// {
|
||||||
|
// pathUUID: { type: String },
|
||||||
|
// pointUUID: { type: String },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const BaseSchema = new Schema<IBaseModel>(
|
||||||
|
// {
|
||||||
|
// modelfileID: { type: String },
|
||||||
|
// type: { type: String, enum: ["Conveyor", "Vehicle"] },
|
||||||
|
// points: {
|
||||||
|
// type: Schema.Types.Mixed,
|
||||||
|
// required: true,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// { discriminatorKey: "type", timestamps: true }
|
||||||
|
// );
|
||||||
|
|
||||||
|
// const pointModel = (db: string) => {
|
||||||
|
// const BasePointModel = MainModel(db, "Points", BaseSchema, "Points");
|
||||||
|
|
||||||
|
// const ConveyorModel = BasePointModel.discriminator(
|
||||||
|
// "Conveyor",
|
||||||
|
// new Schema({
|
||||||
|
// points: [PointconveyorSchema],
|
||||||
|
// })
|
||||||
|
// );
|
||||||
|
|
||||||
|
// const VehicleModel = BasePointModel.discriminator(
|
||||||
|
// "Vehicle",
|
||||||
|
// new Schema({
|
||||||
|
// points: PointvehicleSchema,
|
||||||
|
// })
|
||||||
|
// );
|
||||||
|
|
||||||
|
// return { ConveyorModel, VehicleModel };
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export default pointModel;
|
||||||
|
|
||||||
|
// ===
|
||||||
|
// const pointModel = (db: string) => {
|
||||||
|
// const BasePointModel =
|
||||||
|
// mongoose.models.Points || MainModel(db, "Points", BaseSchema, "Points");
|
||||||
|
|
||||||
|
// if (!BasePointModel.discriminators?.Conveyor) {
|
||||||
|
// BasePointModel.discriminator(
|
||||||
|
// "Conveyor",
|
||||||
|
// new Schema({
|
||||||
|
// points: [PointconveyorSchema],
|
||||||
|
// })
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (!BasePointModel.discriminators?.Vehicle) {
|
||||||
|
// BasePointModel.discriminator(
|
||||||
|
// "Vehicle",
|
||||||
|
// new Schema({
|
||||||
|
// points: PointvehicleSchema,
|
||||||
|
// })
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const ConveyorModel =
|
||||||
|
// mongoose.models.Conveyor || BasePointModel.discriminators?.Conveyor;
|
||||||
|
// const VehicleModel =
|
||||||
|
// mongoose.models.Vehicle || BasePointModel.discriminators?.Vehicle;
|
||||||
|
|
||||||
|
// return { ConveyorModel, VehicleModel, BasePointModel };
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export default pointModel;
|
||||||
|
// ===========================================
|
||||||
|
// ===
|
||||||
|
// import mongoose, { Schema, Document } from "mongoose";
|
||||||
|
// import MainModel from "../../../connect/mongoose.ts";
|
||||||
|
|
||||||
|
// interface IAction {
|
||||||
|
// uuid: string;
|
||||||
|
// name: string;
|
||||||
|
// type: string;
|
||||||
|
// material: string;
|
||||||
|
// delay: number | string;
|
||||||
|
// spawnInterval: number | string;
|
||||||
|
// spawnMaterial: string;
|
||||||
|
// isUsed: boolean;
|
||||||
|
// hitCount: number;
|
||||||
|
// start: string;
|
||||||
|
// end: string;
|
||||||
|
// buffer: number;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// interface ITriggers {
|
||||||
|
// uuid: string;
|
||||||
|
// name: string;
|
||||||
|
// type: string;
|
||||||
|
// isUsed: boolean;
|
||||||
|
// bufferTime: number;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// interface IConnection {
|
||||||
|
// source: { pathUUID: string; pointUUID: string };
|
||||||
|
// targets: { pathUUID: string; pointUUID: string }[];
|
||||||
|
// }
|
||||||
|
// interface IPoint {
|
||||||
|
// uuid: string;
|
||||||
|
// position: number[];
|
||||||
|
// rotation: number[];
|
||||||
|
// actions: IAction[];
|
||||||
|
// triggers: ITriggers[];
|
||||||
|
// connections: IConnection;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// interface IBaseModel extends Document {
|
||||||
|
// modelfileID: string;
|
||||||
|
// type: "Conveyor" | "Vehicle";
|
||||||
|
// points: IPoint[] | IPoint;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const PointSchema = new Schema<IPoint>({
|
||||||
|
// uuid: { type: String, required: true },
|
||||||
|
// position: { type: [Number] },
|
||||||
|
// rotation: { type: [Number] },
|
||||||
|
// actions: [
|
||||||
|
// {
|
||||||
|
// uuid: { type: String, default: "" },
|
||||||
|
// name: { type: String },
|
||||||
|
// type: { type: String },
|
||||||
|
// material: { type: String },
|
||||||
|
// delay: { type: String },
|
||||||
|
// spawnInterval: { type: String },
|
||||||
|
// spawnMaterial: { type: String },
|
||||||
|
// isUsed: { type: Boolean },
|
||||||
|
// hitCount: { type: String },
|
||||||
|
// start: { type: String },
|
||||||
|
// end: { type: String },
|
||||||
|
// buffer: { type: String },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// triggers: [
|
||||||
|
// {
|
||||||
|
// uuid: { type: String, default: "" },
|
||||||
|
// name: { type: String },
|
||||||
|
// type: { type: String },
|
||||||
|
// bufferTime: { type: Number },
|
||||||
|
// isUsed: { type: Boolean },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// connections: {
|
||||||
|
// source: {
|
||||||
|
// pathUUID: { type: String },
|
||||||
|
// pointUUID: { type: String },
|
||||||
|
// },
|
||||||
|
// targets: [
|
||||||
|
// {
|
||||||
|
// pathUUID: { type: String },
|
||||||
|
// pointUUID: { type: String },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
// // Base Schema
|
||||||
|
|
||||||
|
// const BaseSchema = new Schema<IBaseModel>(
|
||||||
|
// {
|
||||||
|
// modelfileID: { type: String },
|
||||||
|
// type: { type: String, enum: ["Conveyor", "Vehicle"] },
|
||||||
|
// points: {
|
||||||
|
// type: Schema.Types.Mixed,
|
||||||
|
// required: true,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// { discriminatorKey: "type", timestamps: true }
|
||||||
|
// );
|
||||||
|
|
||||||
|
// const pointModel = (db: string) => {
|
||||||
|
// return MainModel(db, "Points", BaseSchema, "Points");
|
||||||
|
// };
|
||||||
// export default pointModel;
|
// export default pointModel;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const environmentSchema: Schema = new Schema({
|
|||||||
roofVisibility: { type: Boolean, default: false },
|
roofVisibility: { type: Boolean, default: false },
|
||||||
wallVisibility: { type: Boolean, default: false },
|
wallVisibility: { type: Boolean, default: false },
|
||||||
shadowVisibility: { type: Boolean, default: false },
|
shadowVisibility: { type: Boolean, default: false },
|
||||||
renderDistance: { type: Number, default: false },
|
renderDistance: { type: Number, default: 40 },
|
||||||
limitDistance: { type: Boolean, default: true },
|
limitDistance: { type: Boolean, default: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export interface Action extends Document {
|
|||||||
material: string;
|
material: string;
|
||||||
delay: string;
|
delay: string;
|
||||||
spawnInterval: string;
|
spawnInterval: string;
|
||||||
|
spawnMaterial: string;
|
||||||
isUsed: boolean;
|
isUsed: boolean;
|
||||||
hitCount: number;
|
hitCount: number;
|
||||||
start: string;
|
start: string;
|
||||||
@@ -31,6 +32,7 @@ const actionSchema: Schema = new Schema(
|
|||||||
material: { type: String },
|
material: { type: String },
|
||||||
delay: { type: String },
|
delay: { type: String },
|
||||||
spawnInterval: { type: String },
|
spawnInterval: { type: String },
|
||||||
|
spawnMaterial: { type: String },
|
||||||
isUsed: { type: Boolean },
|
isUsed: { type: Boolean },
|
||||||
hitCount: { type: String },
|
hitCount: { type: String },
|
||||||
start: { type: String },
|
start: { type: String },
|
||||||
|
|||||||
97
src/shared/model/simulation/productFlowmodel.ts
Normal file
97
src/shared/model/simulation/productFlowmodel.ts
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
// import mongoose, { Schema, Document, model } from "mongoose";
|
||||||
|
// import MainModel from "../../connect/mongoose.ts";
|
||||||
|
|
||||||
|
// export interface ProductFlow extends Document {
|
||||||
|
// productName: string;
|
||||||
|
// ProductData: [
|
||||||
|
// {
|
||||||
|
// AssetName: string;
|
||||||
|
// Assetuuid: string;
|
||||||
|
// paths: {
|
||||||
|
// Points: [
|
||||||
|
// {
|
||||||
|
// pointuuid: string;
|
||||||
|
// actions: [mongoose.Types.ObjectId];
|
||||||
|
// triggers: [mongoose.Types.ObjectId];
|
||||||
|
// position: [];
|
||||||
|
// rotation: [number];
|
||||||
|
// connections: {
|
||||||
|
// source: {
|
||||||
|
// // pathUUID: { type: String };
|
||||||
|
// pointUUID: string;
|
||||||
|
// };
|
||||||
|
// targets: [
|
||||||
|
// {
|
||||||
|
// // pathUUID: { type: String };
|
||||||
|
// pointUUID: string;
|
||||||
|
// }
|
||||||
|
// ];
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// ];
|
||||||
|
// // endPoint: {
|
||||||
|
// // pointuuid: string;
|
||||||
|
// // actions: [mongoose.Types.ObjectId];
|
||||||
|
// // triggers: [mongoose.Types.ObjectId];
|
||||||
|
// // position: [];
|
||||||
|
// // rotation: [];
|
||||||
|
// // };
|
||||||
|
// };
|
||||||
|
// isArchive: false;
|
||||||
|
// }
|
||||||
|
// ];
|
||||||
|
// isArchive: false;
|
||||||
|
// }
|
||||||
|
// const productFlowSchema: Schema = new Schema(
|
||||||
|
// {
|
||||||
|
// productName: { type: String },
|
||||||
|
// ProductData: [
|
||||||
|
// {
|
||||||
|
// AssetName: { type: String },
|
||||||
|
// Assetuuid: { type: String },
|
||||||
|
// paths: {
|
||||||
|
// Points: [
|
||||||
|
// {
|
||||||
|
// pointuuid: { type: String },
|
||||||
|
// actions: [
|
||||||
|
// { type: mongoose.Schema.Types.ObjectId, ref: "Actions" },
|
||||||
|
// ],
|
||||||
|
// triggers: [
|
||||||
|
// { type: mongoose.Schema.Types.ObjectId, ref: "Triggers" },
|
||||||
|
// ],
|
||||||
|
// connections: {
|
||||||
|
// source: {
|
||||||
|
// // pathUUID: { type: String };
|
||||||
|
// pointUUID: { type: String },
|
||||||
|
// },
|
||||||
|
// targets: [
|
||||||
|
// {
|
||||||
|
// // pathUUID: { type: String };
|
||||||
|
// pointUUID: { type: String },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// position: { type: Array },
|
||||||
|
// rotation: {
|
||||||
|
// type: [Number],
|
||||||
|
// validate: {
|
||||||
|
// validator: function (value: number[]) {
|
||||||
|
// return value && value.length > 0; // Ensures it's only stored if it has values
|
||||||
|
// },
|
||||||
|
// message: "Rotation array should not be empty",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// isArchive: { type: Boolean, default: false },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// { timestamps: true }
|
||||||
|
// );
|
||||||
|
|
||||||
|
// const productFlowModel = (db: any) => {
|
||||||
|
// return MainModel(db, "ProductFlow", productFlowSchema, "ProductFlow");
|
||||||
|
// };
|
||||||
|
// export default productFlowModel;
|
||||||
@@ -2,6 +2,149 @@ import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
|
|||||||
import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||||
|
|
||||||
|
// export const setAssetModel = async (data: any) => {
|
||||||
|
// const {
|
||||||
|
// modeluuid,
|
||||||
|
// modelname,
|
||||||
|
// position,
|
||||||
|
// rotation,
|
||||||
|
// eventData,
|
||||||
|
// modelfileID,
|
||||||
|
// isLocked,
|
||||||
|
// isVisible,
|
||||||
|
// organization,
|
||||||
|
// } = data;
|
||||||
|
// console.log("data: ", data);
|
||||||
|
// // const position=data.position
|
||||||
|
// // const rotation=data.rotation
|
||||||
|
// try {
|
||||||
|
// const findvalue = await assetModel(organization).findOne({
|
||||||
|
// modeluuid: modeluuid,
|
||||||
|
// modelname: modelname,
|
||||||
|
// isArchive: false,
|
||||||
|
// });
|
||||||
|
|
||||||
|
// if (findvalue) {
|
||||||
|
// console.log("findvalue: ", findvalue);
|
||||||
|
// const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||||
|
// { modeluuid: modeluuid, modelname: modelname, isArchive: false },
|
||||||
|
// {
|
||||||
|
// position: position,
|
||||||
|
// rotation: rotation,
|
||||||
|
// isVisible: isVisible,
|
||||||
|
// isLocked: isLocked,
|
||||||
|
// },
|
||||||
|
// { new: true }
|
||||||
|
// );
|
||||||
|
// console.log("updatevalue: ", updatevalue);
|
||||||
|
// return {
|
||||||
|
// success: true,
|
||||||
|
// message: "Model updated successfully",
|
||||||
|
// data: updatevalue,
|
||||||
|
// organization: organization,
|
||||||
|
// };
|
||||||
|
// } else {
|
||||||
|
// let assetData: any = {
|
||||||
|
// modeluuid,
|
||||||
|
// modelname,
|
||||||
|
// position,
|
||||||
|
// modelfileID,
|
||||||
|
// rotation,
|
||||||
|
// isLocked,
|
||||||
|
// isVisible,
|
||||||
|
// };
|
||||||
|
// 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);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
// // await assetDoc.save();
|
||||||
|
// // if(assetDoc.)
|
||||||
|
// const assetDatas = {
|
||||||
|
// modeluuid: assetDoc.modeluuid,
|
||||||
|
// modelname: assetDoc.modelname,
|
||||||
|
// modelfileID: assetDoc.modelfileID,
|
||||||
|
// position: assetDoc.position,
|
||||||
|
// rotation: assetDoc.rotation,
|
||||||
|
// isLocked: assetDoc.isLocked,
|
||||||
|
// isVisible: assetDoc.isVisible,
|
||||||
|
// eventData: {
|
||||||
|
// points: assetDoc.points,
|
||||||
|
// type: assetDoc.type,
|
||||||
|
// speed: assetDoc.speed,
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
// return {
|
||||||
|
// success: true,
|
||||||
|
// message: "Model created successfully",
|
||||||
|
// data: assetDatas,
|
||||||
|
// organization: organization,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// } catch (error: any) {
|
||||||
|
// // console.error("Error creating flooritems:", error);
|
||||||
|
// return {
|
||||||
|
// success: false,
|
||||||
|
// message: error?.message || "Error occurred while ModelAsset",
|
||||||
|
// error,
|
||||||
|
// organization: organization,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
export const setAssetModel = async (data: any) => {
|
export const setAssetModel = async (data: any) => {
|
||||||
const {
|
const {
|
||||||
modeluuid,
|
modeluuid,
|
||||||
@@ -53,62 +196,46 @@ export const setAssetModel = async (data: any) => {
|
|||||||
isLocked,
|
isLocked,
|
||||||
isVisible,
|
isVisible,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (eventData) {
|
if (eventData) {
|
||||||
let pointRefs: any[] = [];
|
// console.log("checkpointType?.type: ", checkpointType?.type);
|
||||||
|
// console.log("eventData.typ: ", eventData.type);
|
||||||
if (Array.isArray(eventData.points)) {
|
// if (checkpointType?.type !== eventData.type) {
|
||||||
for (const point of eventData.points) {
|
// return res.send("Type mismatch");
|
||||||
let actionRefs: any[] = [];
|
// }
|
||||||
let triggerRefs: any[] = [];
|
if (eventData.type === "Conveyor") {
|
||||||
|
// console.log("eventData.points: ", typeof eventData.points);
|
||||||
if (Array.isArray(point.actions)) {
|
// if (!Array.isArray(eventData.points) || eventData.points) {
|
||||||
for (const action of point.actions) {
|
// return res
|
||||||
const actionDoc = await actionModel(organization).create({
|
// .status(400)
|
||||||
pointsUUID: point.uuid,
|
// .json({ message: "Points must be an array" });
|
||||||
isArchive: false,
|
// }
|
||||||
uuid: action.uuid,
|
// if (!eventData.points.every(validateConveyorPoint)) {
|
||||||
name: action.name,
|
// return res
|
||||||
type: action.type,
|
// .status(400)
|
||||||
material: action.material,
|
// .json({ message: "Invalid Conveyor point structure" });
|
||||||
delay: action.delay,
|
// }
|
||||||
spawn_Interval: action.spawn_Interval,
|
} else if (eventData.type === "Vehicle") {
|
||||||
});
|
console.log("eventData.points: ", typeof eventData.points);
|
||||||
await actionDoc.save();
|
if (!eventData.points) {
|
||||||
actionRefs.push(actionDoc._id);
|
return {
|
||||||
}
|
success: false,
|
||||||
}
|
message: "Vehicle points must be a single object",
|
||||||
|
organization: organization,
|
||||||
if (Array.isArray(point.triggers)) {
|
};
|
||||||
for (const trigger of point.triggers) {
|
}
|
||||||
const triggerDoc = await triggerModel(organization).create({
|
if (eventData.points.rotation) {
|
||||||
pointsUUID: point.uuid,
|
return {
|
||||||
isArchive: false,
|
success: false,
|
||||||
uuid: trigger.uuid,
|
message: "Rotation is not allowed for Vehicle points",
|
||||||
name: trigger.name,
|
organization: organization,
|
||||||
type: trigger.type,
|
};
|
||||||
bufferTime: trigger.bufferTime,
|
|
||||||
});
|
|
||||||
await triggerDoc.save();
|
|
||||||
triggerRefs.push(triggerDoc._id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pointRefs.push({
|
|
||||||
uuid: point.uuid,
|
|
||||||
position: point.position || [],
|
|
||||||
rotation: point.rotation || [],
|
|
||||||
actions: actionRefs,
|
|
||||||
triggers: triggerRefs,
|
|
||||||
connections: point.connections,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assetData.points = eventData.points;
|
||||||
assetData.speed = eventData.speed;
|
assetData.speed = eventData.speed;
|
||||||
assetData.type = eventData.type;
|
assetData.type = eventData.type;
|
||||||
assetData.points = pointRefs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const assetDoc = await assetModel(organization).create(assetData);
|
const assetDoc = await assetModel(organization).create(assetData);
|
||||||
await assetDoc.save();
|
await assetDoc.save();
|
||||||
// await assetDoc.save();
|
// await assetDoc.save();
|
||||||
@@ -144,6 +271,7 @@ export const setAssetModel = async (data: any) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteAssetModel = async (data: any) => {
|
export const deleteAssetModel = async (data: any) => {
|
||||||
const { modeluuid, modelname, organization } = data;
|
const { modeluuid, modelname, organization } = data;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||||
import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts";
|
import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||||
export const add3Dwidget = async (data: any) => {
|
export const add3Dwidget = async (data: any) => {
|
||||||
const { organization, widget, zoneId } = data
|
const { organization, widget, zoneId } = data;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const existingZone = await zoneSchema(organization).findOne({
|
const existingZone = await zoneSchema(organization).findOne({
|
||||||
@@ -9,15 +9,17 @@ export const add3Dwidget = async (data: any) => {
|
|||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!existingZone)
|
if (!existingZone)
|
||||||
return { success: false, message: "Zone not found for the zoneId", organization: organization }
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Zone not found for the zoneId",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (existing3Dwidget) {
|
if (existing3Dwidget) {
|
||||||
const update3dwidget = await widget3dModel(
|
const update3dwidget = await widget3dModel(organization).findOneAndUpdate(
|
||||||
organization
|
|
||||||
).findOneAndUpdate(
|
|
||||||
{
|
{
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
@@ -27,29 +29,47 @@ export const add3Dwidget = async (data: any) => {
|
|||||||
{ upsert: true, new: true }
|
{ upsert: true, new: true }
|
||||||
);
|
);
|
||||||
if (update3dwidget)
|
if (update3dwidget)
|
||||||
return { success: true, message: "widget update successfully", organization: organization }
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "widget update successfully",
|
||||||
else return { success: false, message: "Widget not updated", organization: organization }
|
organization: organization,
|
||||||
|
};
|
||||||
|
else
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Widget not updated",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const newWidget3d = await widget3dModel(organization).create({
|
const newWidget3d = await widget3dModel(organization).create({
|
||||||
widgetName: widget.type,
|
type: widget.type,
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
position: widget.position,
|
position: widget.position,
|
||||||
zoneId,
|
zoneId,
|
||||||
});
|
});
|
||||||
if (newWidget3d) {
|
if (newWidget3d) {
|
||||||
|
|
||||||
const widgemodel3D_Datas = {
|
const widgemodel3D_Datas = {
|
||||||
widget: { id: newWidget3d.widgetID, type: newWidget3d.widgetName, position: newWidget3d.position, },
|
widget: {
|
||||||
Data: newWidget3d.Data, zoneId: zoneId,
|
id: newWidget3d.widgetID,
|
||||||
}
|
type: newWidget3d.type,
|
||||||
return { success: true, message: "Widget created successfully", data: widgemodel3D_Datas, organization: organization }
|
position: newWidget3d.position,
|
||||||
|
},
|
||||||
|
Data: newWidget3d.Data,
|
||||||
|
zoneId: zoneId,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Widget created successfully",
|
||||||
|
data: widgemodel3D_Datas,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return { success: false, message: error?.message || "Error occurred while 3Dwidget", error, organization: organization }
|
return {
|
||||||
|
success: false,
|
||||||
|
message: error?.message || "Error occurred while 3Dwidget",
|
||||||
|
error,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,18 @@ import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
|||||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||||
|
|
||||||
export const addPanel = async (data: any) => {
|
export const addPanel = async (data: any) => {
|
||||||
const { organization, zoneId, panelName, panelOrder } = data
|
const { organization, zoneId, panelName, panelOrder } = data;
|
||||||
try {
|
try {
|
||||||
const findZone = await zoneSchema(organization).findOne({
|
const findZone = await zoneSchema(organization).findOne({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!findZone) {
|
if (!findZone) {
|
||||||
return { success: false, message: 'Zone not found', organization: organization }
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Zone not found",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const updatezone = await zoneSchema(organization).findOneAndUpdate(
|
const updatezone = await zoneSchema(organization).findOneAndUpdate(
|
||||||
{ zoneId: zoneId, isArchive: false },
|
{ zoneId: zoneId, isArchive: false },
|
||||||
@@ -43,24 +46,36 @@ export const addPanel = async (data: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (createdPanels.length === 0) {
|
if (createdPanels.length === 0) {
|
||||||
return { success: false, message: "No new panels were created. All panels already exist", organization: organization }
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "No new panels were created. All panels already exist",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
// const IDdata = createdPanels.map((ID: any) => {
|
// const IDdata = createdPanels.map((ID: any) => {
|
||||||
// return ID._id;
|
// return ID._id;
|
||||||
// });
|
// });
|
||||||
// console.log("IDdata: ", createdPanels);
|
// console.log("IDdata: ", createdPanels);
|
||||||
createdPanels
|
createdPanels;
|
||||||
const zoneAndPanelData = await getZoneAndPanelData(organization, zoneId);
|
const zoneAndPanelData = await getZoneAndPanelData(organization, zoneId);
|
||||||
if (!zoneAndPanelData) {
|
if (!zoneAndPanelData) {
|
||||||
return zoneAndPanelData; // If the zone and panel data retrieval fails, return the error.
|
return zoneAndPanelData; // If the zone and panel data retrieval fails, return the error.
|
||||||
}
|
}
|
||||||
return { success: true, message: "Panels created successfully", data: zoneAndPanelData, organization: organization }
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Panels created successfully",
|
||||||
|
data: zoneAndPanelData,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, message: 'Panel not found', error, organization: organization }
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Panel not found",
|
||||||
|
error,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
|
||||||
export const panelDelete = async (data: any) => {
|
export const panelDelete = async (data: any) => {
|
||||||
const { organization, panelName, zoneId } = data;
|
const { organization, panelName, zoneId } = data;
|
||||||
try {
|
try {
|
||||||
@@ -69,7 +84,11 @@ export const panelDelete = async (data: any) => {
|
|||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!existingZone)
|
if (!existingZone)
|
||||||
return { success: false, message: 'Zone not found', organization: organization }
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Zone not found",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
|
||||||
const existingPanel = await panelSchema(organization).findOne({
|
const existingPanel = await panelSchema(organization).findOne({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
@@ -77,7 +96,11 @@ export const panelDelete = async (data: any) => {
|
|||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!existingPanel)
|
if (!existingPanel)
|
||||||
return { success: false, message: 'Panel Already Deleted', organization: organization }
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Panel Already Deleted",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
const updatePanel = await panelSchema(organization).updateOne(
|
const updatePanel = await panelSchema(organization).updateOne(
|
||||||
{ _id: existingPanel._id, isArchive: false },
|
{ _id: existingPanel._id, isArchive: false },
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
@@ -94,22 +117,33 @@ export const panelDelete = async (data: any) => {
|
|||||||
|
|
||||||
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
||||||
const index1 = existingZone.panelOrder.indexOf(existingPanel.panelName);
|
const index1 = existingZone.panelOrder.indexOf(existingPanel.panelName);
|
||||||
existingZone.panelOrder.splice(index1, 1);
|
const zonepanelname = await zoneSchema(organization).updateOne(
|
||||||
|
{ _id: existingZone._id },
|
||||||
|
{ $pull: { panelOrder: existingPanel.panelName } }
|
||||||
|
);
|
||||||
|
|
||||||
const panelDeleteDatas = await existingZone.save();
|
// const panelDeleteDatas = await existingZone.save();
|
||||||
// console.log('panelDeleteDatas: ', panelDeleteDatas);
|
// console.log('panelDeleteDatas: ', panelDeleteDatas);
|
||||||
const zoneAndPanelData = await getZoneAndPanelData(organization, zoneId);
|
const zoneAndPanelData = await getZoneAndPanelData(organization, zoneId);
|
||||||
if (!zoneAndPanelData) {
|
if (!zoneAndPanelData) {
|
||||||
return zoneAndPanelData; // If the zone and panel data retrieval fails, return the error.
|
return zoneAndPanelData; // If the zone and panel data retrieval fails, return the error.
|
||||||
}
|
}
|
||||||
return { success: true, message: 'Panel deleted successfully', data: zoneAndPanelData, organization: organization }
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Panel deleted successfully",
|
||||||
|
data: zoneAndPanelData,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, message: 'Panel not found', error, organization: organization }
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Panel not found",
|
||||||
|
error,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const getZoneAndPanelData = async (organization: string, zoneId: string) => {
|
const getZoneAndPanelData = async (organization: string, zoneId: string) => {
|
||||||
// const { organization, zoneId, } = data
|
// const { organization, zoneId, } = data
|
||||||
@@ -125,7 +159,11 @@ const getZoneAndPanelData = async (organization: string, zoneId: string) => {
|
|||||||
"panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition"
|
"panelOrder zoneName zonePoints lockedPanel zoneId viewPortCenter viewPortposition"
|
||||||
);
|
);
|
||||||
if (!existingZone) {
|
if (!existingZone) {
|
||||||
return { success: false, message: 'Zone not found', organization: organization }
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Zone not found",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
const panelData = await panelSchema(organization).find({
|
const panelData = await panelSchema(organization).find({
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
@@ -164,10 +202,14 @@ const getZoneAndPanelData = async (organization: string, zoneId: string) => {
|
|||||||
widgets: flattenedWidgets,
|
widgets: flattenedWidgets,
|
||||||
};
|
};
|
||||||
|
|
||||||
return { data: objectData, }
|
return { data: objectData };
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return { success: false, message: 'Panel not found', error, organization: organization }
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Panel not found",
|
||||||
|
error,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user