AssetData connections added, 3dWidget update and get added
This commit is contained in:
@@ -3,4 +3,5 @@ import { widget3dService } from "../controller/visualization/3dWidgetService.ts"
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
router.post("/3dwidget/save", widget3dService.add3Dwidget);
|
router.post("/3dwidget/save", widget3dService.add3Dwidget);
|
||||||
router.get("/3dwidgetData/:zoneId/:organization", widget3dService.get3Dwiget);
|
router.get("/3dwidgetData/:zoneId/:organization", widget3dService.get3Dwiget);
|
||||||
|
router.get("/widget3D/:id/:organization", widget3dService.getSingle3Dwidget);
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@@ -87,13 +87,18 @@ export class assetsFloorservice {
|
|||||||
triggerRefs.push(triggerDoc._id);
|
triggerRefs.push(triggerDoc._id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// point.connections{
|
||||||
|
// source:{
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
pointRefs.push({
|
pointRefs.push({
|
||||||
uuid: point.uuid,
|
uuid: point.uuid,
|
||||||
position: point.position || [],
|
position: point.position || [],
|
||||||
rotation: point.rotation || [],
|
rotation: point.rotation || [],
|
||||||
actions: actionRefs,
|
actions: actionRefs,
|
||||||
triggers: triggerRefs,
|
triggers: triggerRefs,
|
||||||
|
connections: point.connections,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,14 @@ export class widget3dService {
|
|||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
{ position: widget.position },
|
{
|
||||||
|
position: widget?.position,
|
||||||
|
Data: {
|
||||||
|
measurements: widget?.Data.measurements,
|
||||||
|
duration: widget?.Data.duration,
|
||||||
|
},
|
||||||
|
widgetName: widget?.widgetName,
|
||||||
|
},
|
||||||
{ upsert: true, new: true }
|
{ upsert: true, new: true }
|
||||||
);
|
);
|
||||||
if (update3dwidget)
|
if (update3dwidget)
|
||||||
@@ -34,7 +41,7 @@ export class widget3dService {
|
|||||||
else return res.send("Widget not updated");
|
else return res.send("Widget not updated");
|
||||||
}
|
}
|
||||||
const newWidget3d = await widget3dModel(organization).create({
|
const newWidget3d = await widget3dModel(organization).create({
|
||||||
widgetName: widget.type,
|
type: widget.type,
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
position: widget.position,
|
position: widget.position,
|
||||||
zoneId,
|
zoneId,
|
||||||
@@ -66,7 +73,7 @@ export class widget3dService {
|
|||||||
measurements: widget.Data?.measurements || {},
|
measurements: widget.Data?.measurements || {},
|
||||||
duration: widget.Data?.duration || "1h",
|
duration: widget.Data?.duration || "1h",
|
||||||
},
|
},
|
||||||
type: widget.widgetName,
|
type: widget.type,
|
||||||
id: widget.widgetID,
|
id: widget.widgetID,
|
||||||
position: widget.position,
|
position: widget.position,
|
||||||
}));
|
}));
|
||||||
@@ -103,4 +110,22 @@ export class widget3dService {
|
|||||||
// return res.status(500).send(error.message);
|
// return res.status(500).send(error.message);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
static async getSingle3Dwidget(req: Request, res: Response): Promise<any> {
|
||||||
|
const { organization, id } = req.params;
|
||||||
|
try {
|
||||||
|
const widgetData = await widget3dModel(organization).findOne({
|
||||||
|
widgetID: id,
|
||||||
|
isArchive: false,
|
||||||
|
});
|
||||||
|
if (!widgetData) return res.send("WidgetID not found");
|
||||||
|
const structureData = {
|
||||||
|
measurements: widgetData?.Data.measurements,
|
||||||
|
duration: widgetData?.Data.duration,
|
||||||
|
};
|
||||||
|
const widgetName = widgetData.widgetName;
|
||||||
|
return res.status(200).json({ Data: structureData, widgetName });
|
||||||
|
} catch (error: any) {
|
||||||
|
return res.status(500).send(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export class widgetService {
|
|||||||
$set: {
|
$set: {
|
||||||
// panelID: existingPanel._id,
|
// panelID: existingPanel._id,
|
||||||
// widgetID: widget.id,
|
// widgetID: widget.id,
|
||||||
widgetName: widget.widgetName,
|
widgetName: widget?.widgetName,
|
||||||
Data: {
|
Data: {
|
||||||
measurements: widget.Data?.measurements || {},
|
measurements: widget.Data?.measurements || {},
|
||||||
duration: widget.Data?.duration || "1h",
|
duration: widget.Data?.duration || "1h",
|
||||||
@@ -69,7 +69,7 @@ export class widgetService {
|
|||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
elementType: widget.type,
|
elementType: widget.type,
|
||||||
// widgetOrder: widgetOrder,
|
// widgetOrder: widgetOrder,
|
||||||
widgetName: widget.widgetName,
|
widgetName: widget.title,
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
widgetside: widget.panel,
|
widgetside: widget.panel,
|
||||||
// Data: {
|
// Data: {
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import mongoose, { Schema, Document, model } from "mongoose";
|
|||||||
import MainModel from "../../connect/mongoose.ts";
|
import MainModel from "../../connect/mongoose.ts";
|
||||||
|
|
||||||
export interface Widget3d extends Document {
|
export interface Widget3d extends Document {
|
||||||
widgetName: string;
|
type: string;
|
||||||
widgetID: string;
|
widgetID: string;
|
||||||
|
widgetName: string;
|
||||||
position: [];
|
position: [];
|
||||||
isArchive: boolean;
|
isArchive: boolean;
|
||||||
zoneId: string;
|
zoneId: string;
|
||||||
@@ -14,8 +15,9 @@ export interface Widget3d extends Document {
|
|||||||
}
|
}
|
||||||
const Widget3dSchema: Schema = new Schema(
|
const Widget3dSchema: Schema = new Schema(
|
||||||
{
|
{
|
||||||
widgetName: { type: String },
|
type: { type: String },
|
||||||
widgetID: { type: String },
|
widgetID: { type: String },
|
||||||
|
widgetName: { type: String, default: "Widget3D" },
|
||||||
position: { type: Array },
|
position: { type: Array },
|
||||||
zoneId: { type: String },
|
zoneId: { type: String },
|
||||||
Data: {
|
Data: {
|
||||||
|
|||||||
@@ -3,125 +3,174 @@ import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
|||||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||||
|
|
||||||
export const setAssetModel = async (data: any) => {
|
export const setAssetModel = async (data: any) => {
|
||||||
const {modeluuid, modelname,position,rotation, eventData,modelfileID,isLocked,isVisible,organization, }= data
|
const {
|
||||||
console.log('data: ', data);
|
modeluuid,
|
||||||
// const position=data.position
|
modelname,
|
||||||
// const rotation=data.rotation
|
position,
|
||||||
try {
|
rotation,
|
||||||
const findvalue = await assetModel(organization).findOne({
|
eventData,
|
||||||
modeluuid: modeluuid,
|
modelfileID,
|
||||||
modelname: modelname,
|
isLocked,
|
||||||
});
|
isVisible,
|
||||||
|
organization,
|
||||||
if (findvalue) {
|
} = data;
|
||||||
console.log('findvalue: ', findvalue);
|
console.log("data: ", data);
|
||||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
// const position=data.position
|
||||||
{ modeluuid: modeluuid, modelname: modelname },
|
// const rotation=data.rotation
|
||||||
{
|
try {
|
||||||
position: position,
|
const findvalue = await assetModel(organization).findOne({
|
||||||
rotation: rotation,
|
modeluuid: modeluuid,
|
||||||
isVisible: isVisible,
|
modelname: modelname,
|
||||||
isLocked: isLocked,
|
});
|
||||||
},
|
|
||||||
{ new: true }
|
if (findvalue) {
|
||||||
);
|
console.log("findvalue: ", findvalue);
|
||||||
console.log('updatevalue: ', updatevalue);
|
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||||
return { success: true, message: 'Model updated successfully', data: updatevalue, organization: organization }
|
{ modeluuid: modeluuid, modelname: modelname },
|
||||||
} else {
|
{
|
||||||
let assetData: any = {
|
position: position,
|
||||||
modeluuid,
|
rotation: rotation,
|
||||||
modelname,
|
isVisible: isVisible,
|
||||||
position,
|
isLocked: isLocked,
|
||||||
modelfileID,
|
},
|
||||||
rotation,
|
{ new: true }
|
||||||
isLocked,
|
);
|
||||||
isVisible,
|
console.log("updatevalue: ", updatevalue);
|
||||||
};
|
return {
|
||||||
if (eventData) {
|
success: true,
|
||||||
let pointRefs: any[] = [];
|
message: "Model updated successfully",
|
||||||
|
data: updatevalue,
|
||||||
if (Array.isArray(eventData.points)) {
|
organization: organization,
|
||||||
for (const point of eventData.points) {
|
};
|
||||||
let actionRefs: any[] = [];
|
} else {
|
||||||
let triggerRefs: any[] = [];
|
let assetData: any = {
|
||||||
|
modeluuid,
|
||||||
if (Array.isArray(point.actions)) {
|
modelname,
|
||||||
for (const action of point.actions) {
|
position,
|
||||||
const actionDoc = await actionModel(organization).create({
|
modelfileID,
|
||||||
pointsUUID: point.uuid,
|
rotation,
|
||||||
isArchive: false,
|
isLocked,
|
||||||
uuid: action.uuid,
|
isVisible,
|
||||||
name: action.name,
|
};
|
||||||
type: action.type,
|
if (eventData) {
|
||||||
material: action.material,
|
let pointRefs: any[] = [];
|
||||||
delay: action.delay,
|
|
||||||
spawn_Interval: action.spawn_Interval,
|
if (Array.isArray(eventData.points)) {
|
||||||
});
|
for (const point of eventData.points) {
|
||||||
await actionDoc.save();
|
let actionRefs: any[] = [];
|
||||||
actionRefs.push(actionDoc._id);
|
let triggerRefs: any[] = [];
|
||||||
}
|
|
||||||
}
|
if (Array.isArray(point.actions)) {
|
||||||
|
for (const action of point.actions) {
|
||||||
if (Array.isArray(point.triggers)) {
|
const actionDoc = await actionModel(organization).create({
|
||||||
for (const trigger of point.triggers) {
|
pointsUUID: point.uuid,
|
||||||
const triggerDoc = await triggerModel(organization).create({
|
isArchive: false,
|
||||||
pointsUUID: point.uuid,
|
uuid: action.uuid,
|
||||||
isArchive: false,
|
name: action.name,
|
||||||
uuid: trigger.uuid,
|
type: action.type,
|
||||||
name: trigger.name,
|
material: action.material,
|
||||||
type: trigger.type,
|
delay: action.delay,
|
||||||
bufferTime: trigger.bufferTime,
|
spawn_Interval: action.spawn_Interval,
|
||||||
});
|
});
|
||||||
await triggerDoc.save();
|
await actionDoc.save();
|
||||||
triggerRefs.push(triggerDoc._id);
|
actionRefs.push(actionDoc._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();
|
|
||||||
// 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}
|
|
||||||
}
|
|
||||||
return { success: true, message:"Model created successfully", data: assetDatas, organization: organization }
|
|
||||||
}
|
|
||||||
} catch (error:any) {
|
|
||||||
// console.error("Error creating flooritems:", error);
|
|
||||||
return { success: false, message: error?.message || "Error occurred while ModelAsset", error, organization: organization }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export const deleteAssetModel = async (data: any)=>{
|
|
||||||
const { modeluuid,modelname,organization } = data;
|
|
||||||
try {
|
|
||||||
|
|
||||||
const findValue = await assetModel(organization).findOneAndDelete({modeluuid:modeluuid,modelname:modelname})
|
|
||||||
if (!findValue) {
|
|
||||||
return { success: false, message: 'model not found',organization:organization }
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return { success: true, message: 'Model deleted successfully', data: findValue,organization:organization }
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
// console.error('Error get flooritems:', error);
|
|
||||||
return { success: false, message: 'Failed to delete asset', error,organization:organization }
|
|
||||||
|
|
||||||
|
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,
|
||||||
|
connections: point.connections,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
assetData.speed = eventData.speed;
|
||||||
|
assetData.type = eventData.type;
|
||||||
|
assetData.points = pointRefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Model created successfully",
|
||||||
|
data: assetDatas,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
// console.error("Error creating flooritems:", error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: error?.message || "Error occurred while ModelAsset",
|
||||||
|
error,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const deleteAssetModel = async (data: any) => {
|
||||||
|
const { modeluuid, modelname, organization } = data;
|
||||||
|
try {
|
||||||
|
const findValue = await assetModel(organization).findOneAndDelete({
|
||||||
|
modeluuid: modeluuid,
|
||||||
|
modelname: modelname,
|
||||||
|
});
|
||||||
|
if (!findValue) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "model not found",
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Model deleted successfully",
|
||||||
|
data: findValue,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// console.error('Error get flooritems:', error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Failed to delete asset",
|
||||||
|
error,
|
||||||
|
organization: organization,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user