RT-Vis 2d and floating widget API collaboration completed, template Save and get API completed. SOCKET 2d panel and widgets events completed
This commit is contained in:
@@ -1,170 +1,170 @@
|
||||
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 {
|
||||
static async setFloorassets(req: Request, res: Response) {
|
||||
try {
|
||||
const {
|
||||
modeluuid,
|
||||
modelname,
|
||||
speed,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
organization,
|
||||
points,
|
||||
} = req.body;
|
||||
|
||||
const findvalue = await assetModel(organization).findOne({
|
||||
modeluuid: modeluuid,
|
||||
modelname: modelname,
|
||||
});
|
||||
|
||||
if (findvalue) {
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid, modelname: modelname },
|
||||
{
|
||||
assetPosition: assetPosition,
|
||||
assetRotation: assetRotation,
|
||||
isVisible: isVisible,
|
||||
isLocked: isLocked,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
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({
|
||||
modeluuid,
|
||||
speed,
|
||||
modelname,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
points: pointRefs,
|
||||
});
|
||||
|
||||
await assetDoc.save();
|
||||
res.status(201).json({
|
||||
message: "Model stored successfully",
|
||||
modelId: assetDoc._id,
|
||||
});
|
||||
}
|
||||
} 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;
|
||||
const findValue = 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) {
|
||||
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 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" });
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
static async setFloorassets(req: Request, res: Response) {
|
||||
try {
|
||||
const {
|
||||
modeluuid,
|
||||
modelname,
|
||||
speed,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
organization,
|
||||
points,
|
||||
} = req.body;
|
||||
|
||||
const findvalue = await assetModel(organization).findOne({
|
||||
modeluuid: modeluuid,
|
||||
modelname: modelname,
|
||||
});
|
||||
|
||||
if (findvalue) {
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid, modelname: modelname },
|
||||
{
|
||||
assetPosition: assetPosition,
|
||||
assetRotation: assetRotation,
|
||||
isVisible: isVisible,
|
||||
isLocked: isLocked,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
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({
|
||||
modeluuid,
|
||||
speed,
|
||||
modelname,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
points: pointRefs,
|
||||
});
|
||||
|
||||
await assetDoc.save();
|
||||
res.status(201).json({
|
||||
message: "Model stored successfully",
|
||||
modelId: assetDoc._id,
|
||||
});
|
||||
}
|
||||
} 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;
|
||||
const findValue = 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) {
|
||||
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 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" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user