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" });

View File

@@ -2,30 +2,33 @@ import mongoose, { Schema, Document } from "mongoose";
import MainModel from "../../../connect/mongoose.ts";
// Common Interfaces
interface ITriggerConveyor {
uuid: string;
name: string;
type: string;
isUsed: boolean;
bufferTime: number;
}
interface ITriggerVehicle {
uuid: string;
name: string;
type: string;
isUsed: boolean;
}
// 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 IConnectionConveyor {
// source: { pathUUID: string; pointUUID: string };
// targets: { pathUUID: string; pointUUID: string }[];
// }
// interface IConnectionVehicle {
// source: { modelUUID: string; pointUUID: string };
// targets: { pathUUID: string; pointUUID: string }[];
// }
// Point Types
interface IPointBase {
uuid: string;
position: number[];
connections: IConnection;
}
interface IPointConveyor extends IPointBase {
@@ -46,25 +49,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;
}>;
};
speed: number;
connections: {
source: { modelUUID: string; pointUUID: string };
targets: Array<{ pathUUID: string; pointUUID: string }>;
};
}
// Main Document Interface

View File

@@ -6,6 +6,7 @@ export interface Widget3d extends Document {
widgetID: string;
widgetName: string;
position: [];
rotation: [];
isArchive: boolean;
zoneId: string;
Data: {
@@ -19,6 +20,7 @@ const Widget3dSchema: Schema = new Schema(
widgetID: { type: String },
widgetName: { type: String, default: "Widget3D" },
position: { type: Array },
rotation: { type: Array },
zoneId: { type: String },
Data: {
measurements: { type: Object, default: {} },

View File

@@ -1,45 +1,44 @@
const swaggerAutogen = require('swagger-autogen')
const swaggerAutogen = require("swagger-autogen");
const dotenv = require('dotenv')
const dotenv = require("dotenv");
const path = require("path");
const envPath = path.resolve(__dirname, "../../../.env");
dotenv.config({ path: envPath });
const ip = require('ip')
const ip = require("ip");
const PORT = process.env.API_PORT;
const doc = {
info: {
title: 'dwinzo documentation',
description: 'Description'
title: "dwinzo documentation",
description: "Description",
},
host: '185.100.212.76:5000',
basePath: '/api/v1',
schemes: ['http'],
// host: "185.100.212.76:5000",
host: "192.168.0.102:5000",
// basePath: "/api/v1",
schemes: ["http"],
};
const outputFile = './../../../swagger-output.json';
const outputFile = "./../../../swagger-output.json";
const routes = [
'./../../api-server/Routes/user-Routes.ts',
'./../../api-server/Routes/camera-Routes.ts',
'./../../api-server/Routes/environments-Routes.ts',
'./../../api-server/Routes/flooritem-Routes.ts',
'./../../api-server/Routes/lines-Routes.ts',
'./../../api-server/Routes/share-Routes.ts',
'./../../api-server/Routes/wallItems-Routes.ts',
"./../../api-server/Routes/user-Routes.ts",
"./../../api-server/Routes/camera-Routes.ts",
"./../../api-server/Routes/environments-Routes.ts",
"./../../api-server/Routes/flooritem-Routes.ts",
"./../../api-server/Routes/lines-Routes.ts",
"./../../api-server/Routes/share-Routes.ts",
"./../../api-server/Routes/wallItems-Routes.ts",
"./../../api-server/Routes/floadWidgetRoute.ts",
"./../../api-server/Routes/panelRoutes.ts",
"./../../api-server/Routes/templateRoutes.ts",
"./../../api-server/Routes/widget3dRoutes.ts",
"./../../api-server/Routes/widgetRoute.ts",
"./../../api-server/Routes/assetfloorRoutes.ts",
"./../../api-server/Routes/assetpointRoutes.ts",
"./../../api-server/Routes/zoneRoutes.ts",
];
swaggerAutogen()(outputFile, routes, doc).then(() => {
console.log('Swagger documentation generated!');
})
console.log("Swagger documentation generated!");
});

View File

@@ -158,8 +158,6 @@ export const setAssetModel = async (data: any) => {
organization,
} = data;
console.log("data: ", data);
// const position=data.position
// const rotation=data.rotation
try {
const findvalue = await assetModel(organization).findOne({
modeluuid: modeluuid,
@@ -168,7 +166,6 @@ export const setAssetModel = async (data: any) => {
});
if (findvalue) {
console.log("findvalue: ", findvalue);
const updatevalue = await assetModel(organization).findOneAndUpdate(
{ modeluuid: modeluuid, modelname: modelname, isArchive: false },
{
@@ -198,25 +195,10 @@ export const setAssetModel = async (data: any) => {
};
if (eventData) {
// console.log("checkpointType?.type: ", checkpointType?.type);
// console.log("eventData.typ: ", eventData.type);
// if (checkpointType?.type !== eventData.type) {
// return res.send("Type mismatch");
// }
if (eventData.type === "Conveyor") {
// console.log("eventData.points: ", typeof eventData.points);
// if (!Array.isArray(eventData.points) || eventData.points) {
// return res
// .status(400)
// .json({ message: "Points must be an array" });
// }
// if (!eventData.points.every(validateConveyorPoint)) {
// return res
// .status(400)
// .json({ message: "Invalid Conveyor point structure" });
// }
assetData.speed = eventData.speed;
} else if (eventData.type === "Vehicle") {
console.log("eventData.points: ", typeof eventData.points);
assetData.speed = eventData.points.speed;
if (!eventData.points) {
return {
success: false,
@@ -231,29 +213,51 @@ export const setAssetModel = async (data: any) => {
organization: organization,
};
}
if (eventData.points.triggers) {
return {
success: false,
message: "triggers is not allowed for Vehicle points",
organization: organization,
};
}
}
assetData.points = eventData.points;
assetData.speed = eventData.speed;
assetData.type = eventData.type;
}
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,
},
};
let assetDatas;
if (assetDoc.type === "Conveyor") {
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,
},
};
}
if (assetDoc.type === "Vehicle") {
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,
},
};
}
return {
success: true,
message: "Model created successfully",
@@ -304,3 +308,51 @@ export const deleteAssetModel = async (data: any) => {
};
}
};
export const replaceEventDatas = async (data: any) => {
const { organization, modeluuid, eventData } = data;
try {
const existingModel = await assetModel(organization).findOne({
modeluuid: modeluuid,
isArchive: false,
});
if (!existingModel)
return {
success: false,
message: "Model not for this UUID",
organization: organization,
};
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 },
{
points: eventData?.points,
// speed: speed,
type: eventData?.type || existingModel?.type,
},
{ new: true }
);
if (updatedModel)
return {
success: true,
message: "Data updated successfully",
data: updatedModel,
organization: organization,
};
}
} catch (error: any) {
return {
success: false,
message: error?.message || "Error occurred while ModelAsset",
error,
organization: organization,
};
}
};