Full Visualization Page API completed
This commit is contained in:
@@ -5,102 +5,108 @@ import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||
|
||||
export class assetsFloorservice {
|
||||
static async setFloorassets(req: Request, res: Response) {
|
||||
static async setFloorassets(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const {
|
||||
modeluuid,
|
||||
modelname,
|
||||
speed,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
organization,
|
||||
points,
|
||||
eventData, // Optional
|
||||
} = req.body;
|
||||
|
||||
const findvalue = await assetModel(organization).findOne({
|
||||
modeluuid: modeluuid,
|
||||
modelname: modelname,
|
||||
modeluuid,
|
||||
modelname,
|
||||
});
|
||||
|
||||
if (findvalue) {
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid, modelname: modelname },
|
||||
{ modeluuid, modelname },
|
||||
{
|
||||
assetPosition: assetPosition,
|
||||
assetRotation: assetRotation,
|
||||
isVisible: isVisible,
|
||||
isLocked: isLocked,
|
||||
assetPosition,
|
||||
assetRotation,
|
||||
isVisible,
|
||||
isLocked,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
res.status(201).json(updatevalue);
|
||||
return res.status(201).json(updatevalue);
|
||||
} else {
|
||||
let pointRefs = [];
|
||||
|
||||
for (const point of points) {
|
||||
let actionRefs = [];
|
||||
let triggerRefs = [];
|
||||
|
||||
if (point.actions && point.actions.length > 0) {
|
||||
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,
|
||||
// eventData: [action],
|
||||
});
|
||||
await actionDoc.save();
|
||||
actionRefs.push(actionDoc._id);
|
||||
}
|
||||
}
|
||||
|
||||
if (point.triggers && point.triggers.length > 0) {
|
||||
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,
|
||||
// triggerData: [trigger],
|
||||
});
|
||||
await triggerDoc.save();
|
||||
triggerRefs.push(triggerDoc._id);
|
||||
}
|
||||
}
|
||||
|
||||
pointRefs.push({
|
||||
uuid: point.uuid,
|
||||
position: point.position,
|
||||
rotation: point.rotation,
|
||||
actions: actionRefs,
|
||||
triggers: triggerRefs,
|
||||
});
|
||||
}
|
||||
|
||||
const assetDoc = await assetModel(organization).create({
|
||||
let assetData: any = {
|
||||
modeluuid,
|
||||
speed,
|
||||
modelname,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
pointRefs.push({
|
||||
uuid: point.uuid,
|
||||
position: point.position || [],
|
||||
rotation: point.rotation || [],
|
||||
actions: actionRefs,
|
||||
triggers: triggerRefs,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
assetData.speed = eventData.speed;
|
||||
assetData.type = eventData.type;
|
||||
assetData.points = pointRefs;
|
||||
}
|
||||
|
||||
const assetDoc = await assetModel(organization).create(assetData);
|
||||
await assetDoc.save();
|
||||
res.status(201).json({
|
||||
|
||||
return res.status(201).json({
|
||||
message: "Model stored successfully",
|
||||
modelId: assetDoc._id,
|
||||
});
|
||||
@@ -110,39 +116,52 @@ export class assetsFloorservice {
|
||||
res.status(500).json({ message: "Failed to create flooritems" });
|
||||
}
|
||||
}
|
||||
static async getFloorItems(req: Request, res: Response) {
|
||||
static async getFloorItems(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
const findValue = await assetModel(organization)
|
||||
const findValues = await assetModel(organization)
|
||||
.find()
|
||||
.select("-_id")
|
||||
.populate({
|
||||
path: "points",
|
||||
// model: assetModel(organization),
|
||||
select: "-_id",
|
||||
})
|
||||
.populate({
|
||||
path: "points.actions",
|
||||
model: actionModel(organization),
|
||||
// select: "-_id",
|
||||
// populate: {
|
||||
// path: "eventData",
|
||||
select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt",
|
||||
// },
|
||||
})
|
||||
.populate({
|
||||
path: "points.triggers",
|
||||
model: triggerModel(organization),
|
||||
// select: "-_id",
|
||||
// populate: {
|
||||
// path: "triggerData",
|
||||
select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt",
|
||||
// },
|
||||
});
|
||||
if (!findValue) {
|
||||
if (!findValues) {
|
||||
res.status(200).json("floorItems not found");
|
||||
} else {
|
||||
res.status(201).json(findValue);
|
||||
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;
|
||||
})
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get flooritems:", error);
|
||||
@@ -167,4 +186,6 @@ export class assetsFloorservice {
|
||||
res.status(500).json({ error: "Failed to get flooritems" });
|
||||
}
|
||||
}
|
||||
|
||||
static async updateActionsDatas(req: Request, res: Response) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user