Asset point updated for the vehicle and conveyor widget 3D update delete routing completed

This commit is contained in:
2025-04-04 16:50:39 +05:30
parent 7b8636c43b
commit 33d6519ece
10 changed files with 484 additions and 298 deletions

View File

@@ -4,4 +4,5 @@ const router = express.Router();
router.post("/3dwidget/save", widget3dService.add3Dwidget);
router.get("/3dwidgetData/:zoneId/:organization", widget3dService.get3Dwiget);
router.get("/widget3D/:id/:organization", widget3dService.getSingle3Dwidget);
router.patch("/widget3D/delete", widget3dService.delete3Dwidget);
export default router;

View File

@@ -1,28 +1,10 @@
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<{
@@ -41,25 +23,27 @@ interface IPointConveyor extends IPointBase {
isUsed: boolean;
bufferTime: number;
}>;
connections: {
source: { pathUUID: string; pointUUID: string };
targets: Array<{ pathUUID: string; pointUUID: string }>;
};
}
interface IPointVehicle extends IPointBase {
actions: Array<{
actions: {
uuid: string;
name: string;
type: string;
isUsed: boolean;
hitCount: number;
start: string;
end: string;
start: { x: number; y: number } | {};
end: { x: number; y: number } | {};
buffer: number;
}>;
triggers: Array<{
uuid: string;
name: string;
type: string;
isUsed: boolean;
}>;
};
connections: {
source: { modelUUID: string; pointUUID: string };
targets: Array<{ pathUUID: string; pointUUID: string }>;
};
speed: number;
}
export class pointService {
static async addPoints(req: Request, res: Response): Promise<any> {
@@ -188,31 +172,31 @@ export class pointService {
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 },
],
actions: {
uuid: "randomUUID",
name: "Action 1",
type: "string",
hitCount: 1,
start: { x: 0, y: 0 },
end: { x: 0, y: 0 },
buffer: 0,
},
connections: {
source: { pathUUID: "modelUUID", pointUUID: "point1UUID" },
source: { modelUUID: "modelUUID", pointUUID: "point1UUID" },
targets: [{ pathUUID: "modelUUID", pointUUID: "point1UUID" }],
},
speed: 2,
};
if ("rotation" in vehiclePoint) {
return res
.status(400)
.json({ error: "Rotation not allowed for Vehicle points" });
}
if ("triggers" in vehiclePoint) {
return res
.status(400)
.json({ error: "Triggers not allowed for Vehicle points" });
}
await pointModel(organization).create({
...baseData,
@@ -248,56 +232,3 @@ export class pointService {
}
}
}
// 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 });
// }
// }

View File

@@ -1,70 +1,8 @@
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 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> {
@@ -162,6 +100,7 @@ export class assetsFloorservice {
// return res.send("Type mismatch");
// }
if (eventData.type === "Conveyor") {
assetData.speed = eventData.speed;
// console.log("eventData.points: ", typeof eventData.points);
// if (!Array.isArray(eventData.points) || eventData.points) {
// return res
@@ -174,22 +113,27 @@ export class assetsFloorservice {
// .json({ message: "Invalid Conveyor point structure" });
// }
} else if (eventData.type === "Vehicle") {
console.log("eventData.points: ", typeof eventData.points);
assetData.speed = eventData.points.speed;
if (!eventData.points) {
return res
.status(400)
.json({ message: "Vehicle points must be a single object" });
}
// if(eventData.poin)
if (eventData.points.rotation) {
return res.status(400).json({
message: "Rotation is not allowed for Vehicle points",
});
}
if (eventData.points.triggers) {
return res.status(400).json({
message: "triggers is not allowed for Vehicle points",
});
}
}
console.log("eventData.points: ", eventData.points);
assetData.points = eventData.points;
assetData.speed = eventData.speed;
assetData.type = eventData.type;
}
// if (eventData) {
@@ -280,7 +224,10 @@ export class assetsFloorservice {
}
const response = findValues.map((item) => {
console.log("item.points: ", item.points);
console.log("item: ", item);
console.log("item: ", item.type);
// console.log('findValues: ', findValues);
// console.log("item.points: ", item.points);
const responseItem: any = {
modeluuid: item.modeluuid,
modelname: item.modelname,
@@ -300,7 +247,6 @@ export class assetsFloorservice {
if (item.type === "Vehicle" && item.points) {
responseItem.eventData = {
speed: item.speed,
type: item.type,
points: item.points,
};
@@ -311,7 +257,6 @@ export class assetsFloorservice {
return res.status(200).json(response);
} catch (error) {
console.error("Error get flooritems:", error);
res.status(500).json({ error: "Failed to get flooritems" });
}
}
@@ -330,7 +275,6 @@ export class assetsFloorservice {
res.status(201).json(findValue);
}
} catch (error) {
console.error("Error get flooritems:", error);
res.status(500).json({ error: "Failed to get flooritems" });
}
}
@@ -373,7 +317,6 @@ export class assetsFloorservice {
}
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,
@@ -382,14 +325,20 @@ export class assetsFloorservice {
if (!existingModel)
return res.json({ message: "Model not for this UUID" });
else {
let speed;
if (existingModel.type === "Conveyor") {
speed = eventData?.speed;
}
// if (existingModel.type === "Vehicle") {
// speed = eventData?.points?.speed;
// }
const updatedModel = await assetModel(organization).findOneAndUpdate(
{ modeluuid, isArchive: false },
{
$set: {
points: eventData.points,
speed: eventData.speed,
type: eventData.type,
},
points: eventData?.points,
// speed: speed,
type: eventData?.type || existingModel?.type,
},
{ new: true }
);
@@ -398,7 +347,7 @@ export class assetsFloorservice {
return res.status(200).json({ message: "Data updated successfully" });
}
} catch (error: any) {
res.status(500).json({ message: "Server error", error: error.message });
return res.status(500).send(error.message);
}
}
}

View File

@@ -26,6 +26,7 @@ export class widget3dService {
},
{
position: widget?.position,
rotation: widget?.rotation,
Data: {
measurements: widget?.Data.measurements,
duration: widget?.Data.duration,
@@ -44,6 +45,7 @@ export class widget3dService {
type: widget.type,
widgetID: widget.id,
position: widget.position,
rotation: widget.rotation,
zoneId,
});
if (newWidget3d)
@@ -128,4 +130,37 @@ export class widget3dService {
return res.status(500).send(error.message);
}
}
static async delete3Dwidget(req: Request, res: Response): Promise<any> {
const { organization, id, zoneId } = req.body;
try {
const existingZone = await zoneSchema(organization).findOne({
zoneId: zoneId,
isArchive: false,
});
if (!existingZone)
return res.status(404).json({ message: "Zone not found" });
const existing3Dwidget = await widget3dModel(organization).findOne({
widgetID: id,
isArchive: false,
zoneId: zoneId,
});
if (!existing3Dwidget) {
return res.send("3D widget not found for the ID");
}
const updateWidget = await widget3dModel(organization).findOneAndUpdate(
{
widgetID: id,
zoneId: zoneId,
isArchive: false,
},
{ isArchive: true },
{ new: true }
);
if (!updateWidget)
return res.json({ message: "3DWidget delete unsuccessfull" });
return res.status(200).json({ message: "3DWidget deleted successfully" });
} catch (error: any) {
return res.status(500).send(error.message);
}
}
}

View File

@@ -102,9 +102,6 @@ export class panelService {
{ $pull: { panelOrder: existingPanel.panelName } }
);
console.log("zonepanelname: ", zonepanelname);
// existingZone.panelOrder.splice(index1, 1);
// existingZone.markModified("panelOrder"); // Mark modified
// await existingZone.save();
}
return res.status(200).json({ message: "Panel deleted successfully" });