Zone rename, model rename, clear panel and locked panel API and socket completed
This commit is contained in:
@@ -1,68 +1,91 @@
|
||||
import { Request, Response } from "express";
|
||||
import floorItemsModel from "../../../shared/model/assets/flooritems-Model.ts";
|
||||
|
||||
|
||||
export class floorItems {
|
||||
static async setFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modeluuid, modelname, position, modelfileID,rotation,isLocked,isVisible,organization } = req.body
|
||||
|
||||
static async setFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const {
|
||||
modeluuid,
|
||||
modelname,
|
||||
position,
|
||||
modelfileID,
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
organization,
|
||||
} = req.body;
|
||||
|
||||
const findvalue = await floorItemsModel(organization).findOne({ modeluuid: modeluuid,modelname:modelname })
|
||||
|
||||
if (findvalue) {
|
||||
|
||||
const updatevalue = await floorItemsModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid,modelname:modelname }, { position: position, rotation: rotation,isVisible:isVisible,isLocked:isLocked }, { new: true });
|
||||
res.status(201).json(updatevalue);
|
||||
|
||||
const findvalue = await floorItemsModel(organization).findOne({
|
||||
modeluuid: modeluuid,
|
||||
modelname: modelname,
|
||||
});
|
||||
|
||||
} else {
|
||||
if (findvalue) {
|
||||
const updatevalue = await floorItemsModel(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid, modelname: modelname },
|
||||
{
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
isVisible: isVisible,
|
||||
isLocked: isLocked,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
res.status(201).json(updatevalue);
|
||||
} else {
|
||||
const newValue = await floorItemsModel(organization).create({
|
||||
modeluuid,
|
||||
modelfileID,
|
||||
modelname,
|
||||
position,
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
});
|
||||
|
||||
const newValue = await floorItemsModel(organization).create({ modeluuid, modelfileID,modelname, position, rotation,isLocked,isVisible, });
|
||||
res.status(201).json(newValue);
|
||||
}
|
||||
|
||||
|
||||
res.status(201).json(newValue);
|
||||
|
||||
}
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating flooritems:', error);
|
||||
res.status(500).json({ message: "Failed to create flooritems" });
|
||||
}
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error("Error creating flooritems:", error);
|
||||
res.status(500).json({ message: "Failed to create flooritems" });
|
||||
}
|
||||
static async getFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
// console.log('req.params: ', req.params);
|
||||
}
|
||||
static async getFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
// console.log('req.params: ', req.params);
|
||||
|
||||
const findValue = await floorItemsModel(organization).find()
|
||||
if (!findValue) {
|
||||
res.status(200).json("floorItems 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" });
|
||||
}
|
||||
const findValue = await floorItemsModel(organization).find();
|
||||
if (!findValue) {
|
||||
res.status(200).json("floorItems 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 deleteFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modeluuid,modelname,organization } = req.body;
|
||||
|
||||
const findValue = await floorItemsModel(organization).findOneAndDelete({modeluuid:modeluuid,modelname:modelname})
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
}
|
||||
static async deleteFloorItems(req: Request, res: Response) {
|
||||
try {
|
||||
const { modeluuid, modelname, organization } = req.body;
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get flooritems:', error);
|
||||
res.status(500).json({ error: "Failed to get flooritems" });
|
||||
}
|
||||
const findValue = await floorItemsModel(organization).findOneAndDelete({
|
||||
modeluuid: modeluuid,
|
||||
modelname: modelname,
|
||||
});
|
||||
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" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ interface IPointConveyor extends IPointBase {
|
||||
}
|
||||
|
||||
interface IPointVehicle extends IPointBase {
|
||||
rotation: number[];
|
||||
actions: {
|
||||
uuid: string;
|
||||
name: string;
|
||||
@@ -51,33 +52,34 @@ interface IPointArmbot extends IPointBase {
|
||||
uuid: string;
|
||||
name: string;
|
||||
speed: number;
|
||||
processes: { triggerId: string; startPoint: string; endPoint: string }[]
|
||||
processes: { triggerId: string; startPoint: string; endPoint: string }[];
|
||||
};
|
||||
triggers: { uuid: string; name: string; type: string };
|
||||
connections: {
|
||||
source: { modelUUID: string; pointUUID: string };
|
||||
targets: { modelUUID: string; pointUUID: string }[]
|
||||
targets: { modelUUID: string; pointUUID: string }[];
|
||||
};
|
||||
}
|
||||
interface IPointStaticMachine extends IPointBase{
|
||||
interface IPointStaticMachine extends IPointBase {
|
||||
rotation: number[];
|
||||
actions: {
|
||||
uuid: string;
|
||||
name: string;
|
||||
buffer: number | string;
|
||||
material: string;
|
||||
},
|
||||
};
|
||||
triggers: { uuid: string; name: string; type: string };
|
||||
connections: {
|
||||
source: { modelUUID: string; pointUUID: string };
|
||||
targets: { modelUUID: string; pointUUID: string }[] };
|
||||
connections: {
|
||||
source: { modelUUID: string; pointUUID: string };
|
||||
targets: { modelUUID: string; pointUUID: string }[];
|
||||
};
|
||||
}
|
||||
export class pointService {
|
||||
static async addPoints(req: Request, res: Response): Promise<any> {
|
||||
const { type, modelfileID, organization } = req.body;
|
||||
|
||||
// Validate type
|
||||
if (!["Conveyor", "Vehicle","ArmBot","StaticMachine"].includes(type)) {
|
||||
if (!["Conveyor", "Vehicle", "ArmBot", "StaticMachine"].includes(type)) {
|
||||
return res.status(400).json({ message: "Invalid type requested" });
|
||||
}
|
||||
|
||||
@@ -189,8 +191,7 @@ export class pointService {
|
||||
...baseData,
|
||||
points: conveyorPoints,
|
||||
});
|
||||
}
|
||||
if (type === "Vehicle") {
|
||||
} else if (type === "Vehicle") {
|
||||
console.log("vehcile data");
|
||||
const baseData = {
|
||||
modelfileID: "67e3da19c2e8f37134526e6a",
|
||||
@@ -198,6 +199,7 @@ export class pointService {
|
||||
};
|
||||
const vehiclePoint: IPointVehicle = {
|
||||
uuid: "point1UUID",
|
||||
rotation: [0, 0, 0],
|
||||
position: [0, 1.3, 0],
|
||||
actions: {
|
||||
uuid: "randomUUID",
|
||||
@@ -214,11 +216,6 @@ export class pointService {
|
||||
},
|
||||
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)
|
||||
@@ -229,8 +226,7 @@ export class pointService {
|
||||
...baseData,
|
||||
points: vehiclePoint,
|
||||
});
|
||||
}
|
||||
if (type === "ArmBot") {
|
||||
} else if (type === "ArmBot") {
|
||||
console.log("ArmBot data");
|
||||
const baseData = {
|
||||
modelfileID: "67eb7904c2e8f37134527eae",
|
||||
@@ -239,27 +235,35 @@ export class pointService {
|
||||
const ArmBotPoint: IPointArmbot = {
|
||||
uuid: "point1UUID",
|
||||
position: [0, 2.75, -0.5],
|
||||
rotation:[0,0,0],
|
||||
rotation: [0, 0, 0],
|
||||
actions: {
|
||||
uuid: "randomUUID",
|
||||
name: "Action 1",
|
||||
speed:1,
|
||||
processes:[{triggerId:"triggerId",startPoint:"startPoint",endPoint:"endPoint"}]
|
||||
speed: 1,
|
||||
processes: [
|
||||
{
|
||||
triggerId: "triggerId",
|
||||
startPoint: "startPoint",
|
||||
endPoint: "endPoint",
|
||||
},
|
||||
],
|
||||
},
|
||||
triggers: {
|
||||
uuid: "randomUUID",
|
||||
name: "trigger 1",
|
||||
type: "OnComplete",
|
||||
},
|
||||
triggers: { uuid: "randomUUID", name: "trigger 1", type: "OnComplete" },
|
||||
connections: {
|
||||
source: { modelUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
targets: [{ modelUUID: "modelUUID", pointUUID: "point1UUID" }],
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
await pointModel(organization).create({
|
||||
...baseData,
|
||||
points: ArmBotPoint,
|
||||
});
|
||||
}
|
||||
if (type === "StaticMachine") {
|
||||
} else if (type === "StaticMachine") {
|
||||
console.log("StaticMachine data");
|
||||
const baseData = {
|
||||
modelfileID: "67e3db5ac2e8f37134526f40",
|
||||
@@ -268,26 +272,31 @@ export class pointService {
|
||||
const StaticMachinePoint: IPointStaticMachine = {
|
||||
uuid: "point1UUID",
|
||||
position: [0, 1.5, -0.5],
|
||||
rotation:[0,0,0],
|
||||
rotation: [0, 0, 0],
|
||||
actions: {
|
||||
uuid: "randomUUID",
|
||||
name: "Action 1",
|
||||
buffer: 0, material: "Inherit",
|
||||
buffer: 0,
|
||||
material: "Inherit",
|
||||
},
|
||||
triggers: {
|
||||
uuid: "randomUUID",
|
||||
name: "trigger 1",
|
||||
type: "OnComplete",
|
||||
},
|
||||
triggers: { uuid: "randomUUID", name: "trigger 1", type: "OnComplete" },
|
||||
connections: {
|
||||
source: { modelUUID: "modelUUID", pointUUID: "point1UUID" },
|
||||
targets: [{ modelUUID: "modelUUID", pointUUID: "point1UUID" }],
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
await pointModel(organization).create({
|
||||
...baseData,
|
||||
points: StaticMachinePoint,
|
||||
});
|
||||
} else {
|
||||
return res.json({ message: "Requested type mismatch" });
|
||||
}
|
||||
|
||||
return res.status(201).json({ message: "Points created successfully" });
|
||||
} catch (error) {
|
||||
return res.status(500).json({
|
||||
|
||||
@@ -4,7 +4,6 @@ import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export class Zoneservice {
|
||||
static async addandUpdateZone(req: Request, res: Response): Promise<any> {
|
||||
// console.log("req.body: ", req.body);
|
||||
try {
|
||||
const organization = req.body.organization;
|
||||
const zoneDatas = req.body.zonesdata;
|
||||
@@ -14,7 +13,7 @@ export class Zoneservice {
|
||||
});
|
||||
if (!existingZone) {
|
||||
const newZone = await zoneSchema(organization).create({
|
||||
zoneName: zoneDatas.zonename,
|
||||
zoneName: zoneDatas.zoneName,
|
||||
zoneId: zoneDatas.zoneId,
|
||||
zonePoints: zoneDatas.points,
|
||||
viewPortposition: zoneDatas.viewportPosition,
|
||||
@@ -34,16 +33,23 @@ export class Zoneservice {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// const existingZoneName = await zoneSchema(organization).find({
|
||||
// zoneName: zoneDatas.zoneName,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (existingZoneName.length > 0) {
|
||||
// return res.json({ message: "Zone name already exists" });
|
||||
// }
|
||||
const replaceZone = await zoneSchema(organization).findOneAndUpdate(
|
||||
{ zoneId: zoneDatas.zoneId, isArchive: false },
|
||||
{
|
||||
zoneName: zoneDatas.zoneName,
|
||||
zonePoints: zoneDatas.points,
|
||||
viewPortposition: zoneDatas.viewPortposition,
|
||||
viewPortCenter: zoneDatas.viewPortCenter,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
console.log("replaceZone: ", replaceZone);
|
||||
if (!replaceZone)
|
||||
return res.status(404).json({ message: "Zone not updated" });
|
||||
else
|
||||
@@ -245,6 +251,40 @@ export class Zoneservice {
|
||||
}
|
||||
}
|
||||
|
||||
static async lockedPanel(req: Request, res: Response): Promise<any> {
|
||||
console.log(req.body);
|
||||
const organization = req.body.organization;
|
||||
const zoneId = req.body.zoneId;
|
||||
const lockedPanel = req.body.lockedPanel;
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone) {
|
||||
return res.status(404).json({ message: "Zone not found for the UUID" });
|
||||
} else {
|
||||
const updateLockedPanel = await zoneSchema(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{ zoneId: zoneId, isArchive: false },
|
||||
{
|
||||
lockedPanel: lockedPanel,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
if (updateLockedPanel) {
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "locked panel updated successfully" });
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// static async zoneIdgenerate(req: Request, res: Response): Promise<any> {
|
||||
// const organization = req.query.organization;
|
||||
// const sceneID = req.params.sceneID;
|
||||
|
||||
@@ -18,10 +18,11 @@ export class assetsFloorservice {
|
||||
organization,
|
||||
eventData,
|
||||
} = req.body;
|
||||
console.log("req.body: ", req.body);
|
||||
|
||||
const findvalue = await assetModel(organization).findOne({
|
||||
modeluuid,
|
||||
modelname,
|
||||
// modelname,
|
||||
isArchive: false,
|
||||
});
|
||||
const checkpointType = await pointModel(organization).findOne({
|
||||
@@ -31,8 +32,9 @@ export class assetsFloorservice {
|
||||
|
||||
if (findvalue) {
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid, modelname, isArchive: false },
|
||||
{ modeluuid, isArchive: false },
|
||||
{
|
||||
modelname: modelname,
|
||||
position,
|
||||
rotation,
|
||||
isVisible,
|
||||
@@ -63,18 +65,18 @@ export class assetsFloorservice {
|
||||
.status(400)
|
||||
.json({ message: "Vehicle points must be a single object" });
|
||||
}
|
||||
if (eventData.points.rotation) {
|
||||
return res.status(400).json({
|
||||
message: "Rotation is not allowed for Vehicle points",
|
||||
});
|
||||
}
|
||||
// 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",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if(eventData.type === "ArmBot"){
|
||||
// assetData.speed = eventData.position;
|
||||
// }else if(eventData.type === "StaticMachine"){
|
||||
|
||||
@@ -109,4 +109,47 @@ export class panelService {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async clearPanel(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.body;: ", req.body);
|
||||
const { organization, panelName, zoneId } = req.body;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
panelOrder: { $in: [panelName] },
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone) return res.json({ message: "Zone not found" });
|
||||
const existingPanel = await panelSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
panelName: panelName,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingPanel)
|
||||
return res.json({ message: "Requested Panel not found" });
|
||||
const existingWidgets = await widgetSchema(organization).find({
|
||||
panelID: existingPanel._id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingWidgets.length === 0)
|
||||
return res.json({ message: "No widgets to clear" });
|
||||
const clearWidgetsofPanel = await widgetSchema(organization).updateMany(
|
||||
{ panelID: existingPanel._id, isArchive: false },
|
||||
{ isArchive: true }
|
||||
);
|
||||
const removeWidgetsInPanel = await panelSchema(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{ _id: existingPanel._id, isArchive: false },
|
||||
{ $set: { widgets: [] } },
|
||||
{ new: true }
|
||||
);
|
||||
if (!clearWidgetsofPanel && !removeWidgetsInPanel)
|
||||
return res.json({ message: "Failed to clear widgets in panel" });
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "PanelWidgets cleared successfully" });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user