2025-03-29 17:47:16 +05:30
|
|
|
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";
|
|
|
|
|
|
|
|
|
|
export class assetsFloorservice {
|
2025-03-31 18:30:14 +05:30
|
|
|
static async setFloorassets(req: Request, res: Response): Promise<any> {
|
2025-03-29 17:47:16 +05:30
|
|
|
try {
|
2025-03-31 18:30:14 +05:30
|
|
|
console.log("req.body: ", req.body);
|
2025-03-29 17:47:16 +05:30
|
|
|
const {
|
|
|
|
|
modeluuid,
|
|
|
|
|
modelname,
|
|
|
|
|
assetPosition,
|
|
|
|
|
modelfileID,
|
|
|
|
|
assetRotation,
|
|
|
|
|
isLocked,
|
|
|
|
|
isVisible,
|
|
|
|
|
organization,
|
2025-03-31 18:30:14 +05:30
|
|
|
eventData, // Optional
|
2025-03-29 17:47:16 +05:30
|
|
|
} = req.body;
|
|
|
|
|
|
|
|
|
|
const findvalue = await assetModel(organization).findOne({
|
2025-03-31 18:30:14 +05:30
|
|
|
modeluuid,
|
|
|
|
|
modelname,
|
2025-03-29 17:47:16 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (findvalue) {
|
|
|
|
|
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
2025-03-31 18:30:14 +05:30
|
|
|
{ modeluuid, modelname },
|
2025-03-29 17:47:16 +05:30
|
|
|
{
|
2025-03-31 18:30:14 +05:30
|
|
|
assetPosition,
|
|
|
|
|
assetRotation,
|
|
|
|
|
isVisible,
|
|
|
|
|
isLocked,
|
2025-03-29 17:47:16 +05:30
|
|
|
},
|
|
|
|
|
{ new: true }
|
|
|
|
|
);
|
2025-03-31 18:30:14 +05:30
|
|
|
return res.status(201).json(updatevalue);
|
2025-03-29 17:47:16 +05:30
|
|
|
} else {
|
2025-03-31 18:30:14 +05:30
|
|
|
let assetData: any = {
|
|
|
|
|
modeluuid,
|
|
|
|
|
modelname,
|
|
|
|
|
assetPosition,
|
|
|
|
|
modelfileID,
|
|
|
|
|
assetRotation,
|
|
|
|
|
isLocked,
|
|
|
|
|
isVisible,
|
|
|
|
|
};
|
2025-03-29 17:47:16 +05:30
|
|
|
|
2025-03-31 18:30:14 +05:30
|
|
|
if (eventData) {
|
|
|
|
|
let pointRefs: any[] = [];
|
2025-03-29 17:47:16 +05:30
|
|
|
|
2025-03-31 18:30:14 +05:30
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-29 17:47:16 +05:30
|
|
|
|
2025-03-31 18:30:14 +05:30
|
|
|
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,
|
2025-03-29 17:47:16 +05:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-31 18:30:14 +05:30
|
|
|
assetData.speed = eventData.speed;
|
|
|
|
|
assetData.type = eventData.type;
|
|
|
|
|
assetData.points = pointRefs;
|
2025-03-29 17:47:16 +05:30
|
|
|
}
|
|
|
|
|
|
2025-03-31 18:30:14 +05:30
|
|
|
const assetDoc = await assetModel(organization).create(assetData);
|
2025-03-29 17:47:16 +05:30
|
|
|
await assetDoc.save();
|
2025-03-31 18:30:14 +05:30
|
|
|
|
|
|
|
|
return res.status(201).json({
|
2025-03-29 17:47:16 +05:30
|
|
|
message: "Model stored successfully",
|
|
|
|
|
modelId: assetDoc._id,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error creating flooritems:", error);
|
|
|
|
|
res.status(500).json({ message: "Failed to create flooritems" });
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-31 18:30:14 +05:30
|
|
|
static async getFloorItems(req: Request, res: Response): Promise<any> {
|
2025-03-29 17:47:16 +05:30
|
|
|
try {
|
|
|
|
|
const { organization } = req.params;
|
2025-03-31 18:30:14 +05:30
|
|
|
const findValues = await assetModel(organization)
|
2025-03-29 17:47:16 +05:30
|
|
|
.find()
|
|
|
|
|
.select("-_id")
|
|
|
|
|
.populate({
|
|
|
|
|
path: "points",
|
|
|
|
|
select: "-_id",
|
|
|
|
|
})
|
|
|
|
|
.populate({
|
|
|
|
|
path: "points.actions",
|
|
|
|
|
model: actionModel(organization),
|
|
|
|
|
select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt",
|
|
|
|
|
})
|
|
|
|
|
.populate({
|
|
|
|
|
path: "points.triggers",
|
|
|
|
|
model: triggerModel(organization),
|
|
|
|
|
select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt",
|
|
|
|
|
});
|
2025-03-31 18:30:14 +05:30
|
|
|
if (!findValues) {
|
2025-03-29 17:47:16 +05:30
|
|
|
res.status(200).json("floorItems not found");
|
|
|
|
|
} else {
|
2025-03-31 18:30:14 +05:30
|
|
|
return res.status(200).json(
|
|
|
|
|
findValues.map((item) => {
|
|
|
|
|
let responseItem: any = {
|
|
|
|
|
modeluuid: item.modeluuid,
|
|
|
|
|
modelname: item.modelname,
|
|
|
|
|
assetPosition: item.assetPosition,
|
|
|
|
|
modelfileID: item.modelfileID,
|
|
|
|
|
assetRotation: item.assetRotation,
|
|
|
|
|
isLocked: item.isLocked,
|
|
|
|
|
isVisible: item.isVisible,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (item.points.length > 1) {
|
|
|
|
|
responseItem.eventData = {
|
|
|
|
|
speed: item.speed,
|
|
|
|
|
points: item.points,
|
|
|
|
|
type: item.type,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return responseItem;
|
|
|
|
|
})
|
|
|
|
|
);
|
2025-03-29 17:47:16 +05:30
|
|
|
}
|
|
|
|
|
} 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 assetModel(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" });
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-31 18:30:14 +05:30
|
|
|
|
|
|
|
|
static async updateActionsDatas(req: Request, res: Response) {}
|
2025-03-29 17:47:16 +05:30
|
|
|
}
|