Merge branch 'branch-v2' into branch-1
This commit is contained in:
@@ -7,5 +7,8 @@ router.get(
|
||||
"/floadData/:zoneId/:organization",
|
||||
floatWidgetService.getfloatWidget
|
||||
);
|
||||
router.get("/A_floatWidget/:floatWidgetID/:organization",floatWidgetService.getsinglefloatWidget)
|
||||
export default router;
|
||||
router.get(
|
||||
"/A_floatWidget/:floatWidgetID/:organization",
|
||||
floatWidgetService.getsinglefloatWidget
|
||||
);
|
||||
export default router;
|
||||
|
||||
@@ -3,4 +3,5 @@ import { widget3dService } from "../controller/visualization/3dWidgetService.ts"
|
||||
const router = express.Router();
|
||||
router.post("/3dwidget/save", widget3dService.add3Dwidget);
|
||||
router.get("/3dwidgetData/:zoneId/:organization", widget3dService.get3Dwiget);
|
||||
router.get("/widget3D/:id/:organization", widget3dService.getSingle3Dwidget);
|
||||
export default router;
|
||||
|
||||
@@ -4,7 +4,7 @@ export class zone {
|
||||
static async setZone(req: Request, res: Response) {
|
||||
try {
|
||||
const { organization, userId, zoneData } = req.body
|
||||
console.log('req.body: ', req.body);
|
||||
// console.log('req.body: ', req.body);
|
||||
const zoneId = zoneData.zoneId
|
||||
const points = zoneData.points
|
||||
const zoneName = zoneData.zoneName
|
||||
|
||||
@@ -4,7 +4,7 @@ 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);
|
||||
// console.log("req.body: ", req.body);
|
||||
try {
|
||||
const organization = req.body.organization;
|
||||
const zoneDatas = req.body.zonesdata;
|
||||
|
||||
@@ -11,9 +11,9 @@ export class assetsFloorservice {
|
||||
const {
|
||||
modeluuid,
|
||||
modelname,
|
||||
assetPosition,
|
||||
position,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
organization,
|
||||
@@ -29,8 +29,8 @@ export class assetsFloorservice {
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid, modelname },
|
||||
{
|
||||
assetPosition,
|
||||
assetRotation,
|
||||
position,
|
||||
rotation,
|
||||
isVisible,
|
||||
isLocked,
|
||||
},
|
||||
@@ -41,9 +41,9 @@ export class assetsFloorservice {
|
||||
let assetData: any = {
|
||||
modeluuid,
|
||||
modelname,
|
||||
assetPosition,
|
||||
position,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
};
|
||||
@@ -87,13 +87,18 @@ export class assetsFloorservice {
|
||||
triggerRefs.push(triggerDoc._id);
|
||||
}
|
||||
}
|
||||
// point.connections{
|
||||
// source:{
|
||||
|
||||
// }
|
||||
// }
|
||||
pointRefs.push({
|
||||
uuid: point.uuid,
|
||||
position: point.position || [],
|
||||
rotation: point.rotation || [],
|
||||
actions: actionRefs,
|
||||
triggers: triggerRefs,
|
||||
connections: point.connections,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -144,9 +149,9 @@ export class assetsFloorservice {
|
||||
let responseItem: any = {
|
||||
modeluuid: item.modeluuid,
|
||||
modelname: item.modelname,
|
||||
assetPosition: item.assetPosition,
|
||||
position: item.position,
|
||||
modelfileID: item.modelfileID,
|
||||
assetRotation: item.assetRotation,
|
||||
rotation: item.rotation,
|
||||
isLocked: item.isLocked,
|
||||
isVisible: item.isVisible,
|
||||
};
|
||||
|
||||
@@ -24,7 +24,14 @@ export class widget3dService {
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
},
|
||||
{ position: widget.position },
|
||||
{
|
||||
position: widget?.position,
|
||||
Data: {
|
||||
measurements: widget?.Data.measurements,
|
||||
duration: widget?.Data.duration,
|
||||
},
|
||||
widgetName: widget?.widgetName,
|
||||
},
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
if (update3dwidget)
|
||||
@@ -34,7 +41,7 @@ export class widget3dService {
|
||||
else return res.send("Widget not updated");
|
||||
}
|
||||
const newWidget3d = await widget3dModel(organization).create({
|
||||
widgetName: widget.type,
|
||||
type: widget.type,
|
||||
widgetID: widget.id,
|
||||
position: widget.position,
|
||||
zoneId,
|
||||
@@ -66,7 +73,7 @@ export class widget3dService {
|
||||
measurements: widget.Data?.measurements || {},
|
||||
duration: widget.Data?.duration || "1h",
|
||||
},
|
||||
type: widget.widgetName,
|
||||
type: widget.type,
|
||||
id: widget.widgetID,
|
||||
position: widget.position,
|
||||
}));
|
||||
@@ -103,4 +110,22 @@ export class widget3dService {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,17 +98,18 @@ export class floatWidgetService {
|
||||
|
||||
static async deletefloatWidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const { floatWidgetID, organization } = req.body;
|
||||
const findfloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: floatWidgetID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findfloatWidget)
|
||||
return res.status(409).json({ message: "Widget not found" });
|
||||
if (!findfloatWidget) return res.json({ message: "Widget not found" });
|
||||
const widgetData = await floatWidgetModel(organization).updateOne(
|
||||
{ _id: findfloatWidget._id, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
console.log("widgetData: ", widgetData);
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "FloatingWidget deleted successfully" });
|
||||
|
||||
@@ -66,6 +66,7 @@ export class panelService {
|
||||
}
|
||||
static async deletePanel(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,
|
||||
@@ -80,15 +81,15 @@ export class panelService {
|
||||
});
|
||||
if (!existingPanel)
|
||||
return res.status(409).json({ message: "Panel Already Deleted" });
|
||||
const updatePanel = await panelSchema(organization).updateOne(
|
||||
const updatePanel = await panelSchema(organization).findOneAndUpdate(
|
||||
{ _id: existingPanel._id, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
{ isArchive: true },
|
||||
{ new: true }
|
||||
);
|
||||
const existingWidgets = await widgetSchema(organization).find({
|
||||
panelID: existingPanel._id,
|
||||
isArchive: false,
|
||||
});
|
||||
|
||||
for (const widgetData of existingWidgets) {
|
||||
widgetData.isArchive = true;
|
||||
await widgetData.save();
|
||||
@@ -96,9 +97,15 @@ export class panelService {
|
||||
|
||||
if (existingZone.panelOrder.includes(existingPanel.panelName)) {
|
||||
const index1 = existingZone.panelOrder.indexOf(existingPanel.panelName);
|
||||
existingZone.panelOrder.splice(index1, 1);
|
||||
const zonepanelname = await zoneSchema(organization).updateOne(
|
||||
{ _id: existingZone._id },
|
||||
{ $pull: { panelOrder: existingPanel.panelName } }
|
||||
);
|
||||
console.log("zonepanelname: ", zonepanelname);
|
||||
// existingZone.panelOrder.splice(index1, 1);
|
||||
// existingZone.markModified("panelOrder"); // Mark modified
|
||||
// await existingZone.save();
|
||||
}
|
||||
await existingZone.save();
|
||||
|
||||
return res.status(200).json({ message: "Panel deleted successfully" });
|
||||
} catch (error: any) {
|
||||
|
||||
@@ -47,7 +47,7 @@ export class widgetService {
|
||||
$set: {
|
||||
// panelID: existingPanel._id,
|
||||
// widgetID: widget.id,
|
||||
widgetName: widget.widgetName,
|
||||
widgetName: widget?.widgetName,
|
||||
Data: {
|
||||
measurements: widget.Data?.measurements || {},
|
||||
duration: widget.Data?.duration || "1h",
|
||||
@@ -69,7 +69,7 @@ export class widgetService {
|
||||
widgetID: widget.id,
|
||||
elementType: widget.type,
|
||||
// widgetOrder: widgetOrder,
|
||||
widgetName: widget.widgetName,
|
||||
widgetName: widget.title,
|
||||
panelID: existingPanel._id,
|
||||
widgetside: widget.panel,
|
||||
// Data: {
|
||||
|
||||
@@ -2,8 +2,9 @@ import mongoose, { Schema, Document, model } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose.ts";
|
||||
|
||||
export interface Widget3d extends Document {
|
||||
widgetName: string;
|
||||
type: string;
|
||||
widgetID: string;
|
||||
widgetName: string;
|
||||
position: [];
|
||||
isArchive: boolean;
|
||||
zoneId: string;
|
||||
@@ -14,8 +15,9 @@ export interface Widget3d extends Document {
|
||||
}
|
||||
const Widget3dSchema: Schema = new Schema(
|
||||
{
|
||||
widgetName: { type: String },
|
||||
type: { type: String },
|
||||
widgetID: { type: String },
|
||||
widgetName: { type: String, default: "Widget3D" },
|
||||
position: { type: Array },
|
||||
zoneId: { type: String },
|
||||
Data: {
|
||||
|
||||
@@ -3,125 +3,174 @@ import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||
|
||||
export const setAssetModel = async (data: any) => {
|
||||
const {modeluuid, modelname,position,rotation, eventData,modelfileID,isLocked,isVisible,organization, }= data
|
||||
console.log('data: ', data);
|
||||
// const position=data.position
|
||||
// const rotation=data.rotation
|
||||
try {
|
||||
const findvalue = await assetModel(organization).findOne({
|
||||
modeluuid: modeluuid,
|
||||
modelname: modelname,
|
||||
});
|
||||
|
||||
if (findvalue) {
|
||||
console.log('findvalue: ', findvalue);
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid, modelname: modelname },
|
||||
{
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
isVisible: isVisible,
|
||||
isLocked: isLocked,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
console.log('updatevalue: ', updatevalue);
|
||||
return { success: true, message: 'Model updated successfully', data: updatevalue, organization: organization }
|
||||
} else {
|
||||
let assetData: any = {
|
||||
modeluuid,
|
||||
modelname,
|
||||
position,
|
||||
modelfileID,
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
};
|
||||
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 {
|
||||
modeluuid,
|
||||
modelname,
|
||||
position,
|
||||
rotation,
|
||||
eventData,
|
||||
modelfileID,
|
||||
isLocked,
|
||||
isVisible,
|
||||
organization,
|
||||
} = data;
|
||||
console.log("data: ", data);
|
||||
// const position=data.position
|
||||
// const rotation=data.rotation
|
||||
try {
|
||||
const findvalue = await assetModel(organization).findOne({
|
||||
modeluuid: modeluuid,
|
||||
modelname: modelname,
|
||||
});
|
||||
|
||||
if (findvalue) {
|
||||
console.log("findvalue: ", findvalue);
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid, modelname: modelname },
|
||||
{
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
isVisible: isVisible,
|
||||
isLocked: isLocked,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
console.log("updatevalue: ", updatevalue);
|
||||
return {
|
||||
success: true,
|
||||
message: "Model updated successfully",
|
||||
data: updatevalue,
|
||||
organization: organization,
|
||||
};
|
||||
} else {
|
||||
let assetData: any = {
|
||||
modeluuid,
|
||||
modelname,
|
||||
position,
|
||||
modelfileID,
|
||||
rotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
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