assetmodel creation and adding for namespace socket
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import * as express from "express";
|
||||
import { widget3dService } from "../controller/visualization/3dWidgetService.ts";
|
||||
const router = express.Router();
|
||||
router.post("/3dwidget/save", widget3dService.add3Dwidget);
|
||||
router.get("/3dwidgetData/:zoneId/:organization", widget3dService.get3Dwiget);
|
||||
export default router;
|
||||
import * as express from "express";
|
||||
import { widget3dService } from "../controller/visualization/3dWidgetService.ts";
|
||||
const router = express.Router();
|
||||
router.post("/3dwidget/save", widget3dService.add3Dwidget);
|
||||
router.get("/3dwidgetData/:zoneId/:organization", widget3dService.get3Dwiget);
|
||||
export default router;
|
||||
|
||||
@@ -1,106 +1,106 @@
|
||||
import { Request, Response } from "express";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||
export class widget3dService {
|
||||
static async add3Dwidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization, widget, zoneId } = req.body;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return res.status(404).json({ message: "Zone not found" });
|
||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||
widgetID: widget.id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existing3Dwidget) {
|
||||
const update3dwidget = await widget3dModel(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{
|
||||
widgetID: widget.id,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
},
|
||||
{ position: widget.position },
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
if (update3dwidget)
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "widget update successfully" });
|
||||
else return res.send("Widget not updated");
|
||||
}
|
||||
const newWidget3d = await widget3dModel(organization).create({
|
||||
widgetName: widget.type,
|
||||
widgetID: widget.id,
|
||||
position: widget.position,
|
||||
zoneId,
|
||||
});
|
||||
if (newWidget3d)
|
||||
return res.status(201).json({ message: "Widget created successfully" });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async get3Dwiget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization, zoneId } = req.params;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone) return res.send("Zone not found");
|
||||
const widgetData = await widget3dModel(organization).find({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!widgetData || widgetData.length === 0) {
|
||||
return res.json([]);
|
||||
}
|
||||
|
||||
const zonebasedWidget = widgetData.map((widget) => ({
|
||||
Data: {
|
||||
measurements: widget.Data?.measurements || {},
|
||||
duration: widget.Data?.duration || "1h",
|
||||
},
|
||||
type: widget.widgetName,
|
||||
id: widget.widgetID,
|
||||
position: widget.position,
|
||||
}));
|
||||
return res.status(200).json(zonebasedWidget);
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
// static async update3Dposition(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const { organization, id, position, zoneId } = req.body;
|
||||
// const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||
// widgetID: id,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (existing3Dwidget) {
|
||||
// const update3dwidget = await widget3dModel(
|
||||
// organization
|
||||
// ).findOneAndUpdate(
|
||||
// {
|
||||
// widgetID: id,
|
||||
// zoneId: zoneId,
|
||||
// isArchive: false,
|
||||
// },
|
||||
// { position: position },
|
||||
// { upsert: true, new: true }
|
||||
// );
|
||||
// if (update3dwidget)
|
||||
// return res.status(200).send("widget update successfully");
|
||||
// } else {
|
||||
// return res.status(404).send("widget not found");
|
||||
// }
|
||||
// } catch (error: any) {
|
||||
// return res.status(500).send(error.message);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
import { Request, Response } from "express";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||
export class widget3dService {
|
||||
static async add3Dwidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization, widget, zoneId } = req.body;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return res.status(404).json({ message: "Zone not found" });
|
||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||
widgetID: widget.id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existing3Dwidget) {
|
||||
const update3dwidget = await widget3dModel(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{
|
||||
widgetID: widget.id,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
},
|
||||
{ position: widget.position },
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
if (update3dwidget)
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "widget update successfully" });
|
||||
else return res.send("Widget not updated");
|
||||
}
|
||||
const newWidget3d = await widget3dModel(organization).create({
|
||||
widgetName: widget.type,
|
||||
widgetID: widget.id,
|
||||
position: widget.position,
|
||||
zoneId,
|
||||
});
|
||||
if (newWidget3d)
|
||||
return res.status(201).json({ message: "Widget created successfully" });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async get3Dwiget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization, zoneId } = req.params;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone) return res.send("Zone not found");
|
||||
const widgetData = await widget3dModel(organization).find({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!widgetData || widgetData.length === 0) {
|
||||
return res.json([]);
|
||||
}
|
||||
|
||||
const zonebasedWidget = widgetData.map((widget) => ({
|
||||
Data: {
|
||||
measurements: widget.Data?.measurements || {},
|
||||
duration: widget.Data?.duration || "1h",
|
||||
},
|
||||
type: widget.widgetName,
|
||||
id: widget.widgetID,
|
||||
position: widget.position,
|
||||
}));
|
||||
return res.status(200).json(zonebasedWidget);
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
// static async update3Dposition(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const { organization, id, position, zoneId } = req.body;
|
||||
// const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||
// widgetID: id,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (existing3Dwidget) {
|
||||
// const update3dwidget = await widget3dModel(
|
||||
// organization
|
||||
// ).findOneAndUpdate(
|
||||
// {
|
||||
// widgetID: id,
|
||||
// zoneId: zoneId,
|
||||
// isArchive: false,
|
||||
// },
|
||||
// { position: position },
|
||||
// { upsert: true, new: true }
|
||||
// );
|
||||
// if (update3dwidget)
|
||||
// return res.status(200).send("widget update successfully");
|
||||
// } else {
|
||||
// return res.status(404).send("widget not found");
|
||||
// }
|
||||
// } catch (error: any) {
|
||||
// return res.status(500).send(error.message);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -33,8 +33,13 @@ export interface assetData extends Document {
|
||||
];
|
||||
}[];
|
||||
}[];
|
||||
assetPosition: number[];
|
||||
assetRotation: number[];
|
||||
position: [];
|
||||
// rotation: [];
|
||||
rotation: {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
};
|
||||
speed: number | string;
|
||||
}
|
||||
|
||||
@@ -66,16 +71,16 @@ const assetDataSchema: Schema = new Schema({
|
||||
},
|
||||
},
|
||||
],
|
||||
assetPosition: { type: [Number] },
|
||||
assetRotation: { type: [Number] },
|
||||
position: { type: Array},
|
||||
// rotation: { type: Array},
|
||||
rotation: {
|
||||
x: { type: Number },
|
||||
y: { type: Number },
|
||||
z: { type: Number },
|
||||
},
|
||||
speed: { type: Schema.Types.Mixed },
|
||||
isLocked: { type: Boolean },
|
||||
isVisible: { type: Boolean },
|
||||
// rotation: {
|
||||
// x: { type: Number },
|
||||
// y: { type: Number },
|
||||
// z: { type: Number },
|
||||
// },
|
||||
});
|
||||
|
||||
// export default floorItemsModel;
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
import mongoose, { Schema, Document, model } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose.ts";
|
||||
|
||||
export interface floatingWidget extends Document {
|
||||
className: string;
|
||||
header: string;
|
||||
floatWidgetID: string;
|
||||
position: {};
|
||||
per: string;
|
||||
value: string;
|
||||
isArchive: boolean;
|
||||
zoneId: string;
|
||||
Data: {
|
||||
measurements: {};
|
||||
duration: string;
|
||||
};
|
||||
}
|
||||
const floatingWidgetSchema: Schema = new Schema(
|
||||
{
|
||||
className: { type: String },
|
||||
header: { type: String },
|
||||
floatWidgetID: { type: String },
|
||||
position: { type: Object },
|
||||
per: { type: String },
|
||||
value: { type: String },
|
||||
zoneId: { type: String },
|
||||
Data: {
|
||||
measurements: { type: Object, default: {} },
|
||||
duration: { type: String, default: "1h" },
|
||||
},
|
||||
isArchive: { type: Boolean, default: false },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
const floatWidgetModel = (db: any) => {
|
||||
return MainModel(
|
||||
db,
|
||||
"FloatingWidget",
|
||||
floatingWidgetSchema,
|
||||
"FloatingWidget"
|
||||
);
|
||||
};
|
||||
export default floatWidgetModel;
|
||||
import mongoose, { Schema, Document, model } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose.ts";
|
||||
|
||||
export interface floatingWidget extends Document {
|
||||
className: string;
|
||||
header: string;
|
||||
floatWidgetID: string;
|
||||
position: {};
|
||||
per: string;
|
||||
value: string;
|
||||
isArchive: boolean;
|
||||
zoneId: string;
|
||||
Data: {
|
||||
measurements: {};
|
||||
duration: string;
|
||||
};
|
||||
}
|
||||
const floatingWidgetSchema: Schema = new Schema(
|
||||
{
|
||||
className: { type: String },
|
||||
header: { type: String },
|
||||
floatWidgetID: { type: String },
|
||||
position: { type: Object },
|
||||
per: { type: String },
|
||||
value: { type: String },
|
||||
zoneId: { type: String },
|
||||
Data: {
|
||||
measurements: { type: Object, default: {} },
|
||||
duration: { type: String, default: "1h" },
|
||||
},
|
||||
isArchive: { type: Boolean, default: false },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
const floatWidgetModel = (db: any) => {
|
||||
return MainModel(
|
||||
db,
|
||||
"FloatingWidget",
|
||||
floatingWidgetSchema,
|
||||
"FloatingWidget"
|
||||
);
|
||||
};
|
||||
export default floatWidgetModel;
|
||||
|
||||
@@ -1,102 +1,127 @@
|
||||
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 const setAssetModel = async (data: any) => {
|
||||
const {modeluuid, modelname,assetPosition, eventData,modelfileID,assetRotation,isLocked,isVisible,organization, }= data
|
||||
console.log('data: ', data);
|
||||
// const points=eventData.points
|
||||
// const speed=eventData.speed
|
||||
try {
|
||||
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 }
|
||||
);
|
||||
return { success: true, message: 'Model updated', data: updatevalue, organization: organization }
|
||||
} else {
|
||||
let assetData: any = {
|
||||
modeluuid,
|
||||
modelname,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
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 assetDoc = await assetModel(organization).create(assetData);
|
||||
await assetDoc.save();
|
||||
// await assetDoc.save();
|
||||
return { success: true, message:"Model stored successfully", data: assetDoc, organization: organization }
|
||||
}
|
||||
} catch (error:any) {
|
||||
console.error("Error creating flooritems:", error);
|
||||
return { success: false, message: error?.message || "Error occurred while ModelAsset", error, organization: organization }
|
||||
}
|
||||
}
|
||||
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 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 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 }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import cameraModel from "../../../shared/model/camera/camera-Model.ts";
|
||||
|
||||
export const createCamera = async (data: any,) => {
|
||||
const { userId, position, target, organization,rotation } = data
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import zoneModel from "../../../shared/model/lines/zone-Model.ts";
|
||||
|
||||
import zoneModel from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
export const setZone = async (data: any) => {
|
||||
const { organization, userId, zoneData } = data
|
||||
try {
|
||||
const { organization, userId, zoneData } = data
|
||||
console.log('data: ', data);
|
||||
const zoneId = zoneData.zoneId
|
||||
const points = zoneData.points
|
||||
const zoneName = zoneData.zoneName
|
||||
@@ -18,7 +16,7 @@ export const setZone = async (data: any) => {
|
||||
return { success: true, message: 'zone updated', data: updateZone, organization: organization }
|
||||
} else {
|
||||
const zoneCreate = await zoneModel(organization).create({
|
||||
zoneId, createBy: userId, zoneName: zoneName, points, layer, viewPortCenter, viewPortposition
|
||||
zoneId, createdBy: userId, zoneName: zoneName, points, layer, viewPortCenter, viewPortposition
|
||||
})
|
||||
const createdZone = await zoneModel(organization)
|
||||
.findById(zoneCreate._id)
|
||||
@@ -28,18 +26,18 @@ export const setZone = async (data: any) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('error: ', error);
|
||||
return { success: false, message: 'Zone not found', error }
|
||||
return { success: false, message: 'Zone not found', error , organization: organization}
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteZone = async (data: any) => {
|
||||
const { organization, userId, zoneId } = data
|
||||
try {
|
||||
const { organization, userId, zoneId } = data
|
||||
|
||||
const findZoneId = await zoneModel(organization).findOne({ zoneId: zoneId })
|
||||
if (findZoneId) {
|
||||
const deleteZone = await zoneModel(organization).findOneAndDelete(
|
||||
{ zoneId: zoneId, createBy: userId }
|
||||
{ zoneId: zoneId, createdBy: userId }
|
||||
).select("-_id -__v")
|
||||
return { success: true, message: 'zone deleted', data: deleteZone, organization: organization }
|
||||
} else {
|
||||
@@ -48,6 +46,6 @@ export const deleteZone = async (data: any) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('error: ', error);
|
||||
return { success: false, message: 'Zone not found', error }
|
||||
return { success: false, message: 'Zone not found', error, organization: organization }
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import userModel from "../../../shared/model/user-Model.ts"
|
||||
|
||||
export const activeUsers = async (data: any) => {
|
||||
const {organization}=data
|
||||
// console.log('data: ', data);
|
||||
try {
|
||||
if (data && data.email) {
|
||||
|
||||
@@ -43,7 +44,7 @@ export const activeUsers = async (data: any) => {
|
||||
// Handle the error or return a default value
|
||||
// Example: Return an error response if the email is invalid
|
||||
|
||||
return { success: false, message: 'Email is missing or invalid', }
|
||||
return { success: false, message: 'Email is missing or invalid', organization:organization }
|
||||
// return res.status(400).send({ message: 'Email is missing or invalid' });
|
||||
}
|
||||
|
||||
@@ -99,3 +100,38 @@ export const activeUserOffline = async (data: any) => {
|
||||
// return { success: false, message: error}
|
||||
}
|
||||
}
|
||||
type OnlineUsersMap = Map<string, Set<string>>;
|
||||
|
||||
// export const addUserToOnlineList = async (
|
||||
// organization: string,
|
||||
// email: string,
|
||||
// onlineUsers: OnlineUsersMap,
|
||||
// socket: any,
|
||||
// namespace: string
|
||||
// ) => {
|
||||
// if (!organization || !email) return;
|
||||
// console.log('organization: ', organization);
|
||||
|
||||
// // Ensure the organization entry exists
|
||||
// if (!onlineUsers.has(organization)) {
|
||||
// onlineUsers.set(organization, new Set());
|
||||
// }
|
||||
// const findUser = await userModel(organization).findOne({email})
|
||||
// if (!findUser) {
|
||||
// return { success: false, message: "User not found", organization };
|
||||
// }
|
||||
// const userId = findUser._id;
|
||||
// console.log(`🔍 Found user with ID: ${userId}`);
|
||||
// // Add user to the online set
|
||||
// onlineUsers.get(organization)!.add(userId);
|
||||
|
||||
// console.log(`✅ User ${userId} is online (Org: ${organization})`);
|
||||
|
||||
// // Emit updated online users list
|
||||
// socket.emit("users:online", {
|
||||
// organization,
|
||||
// users: [...onlineUsers.get(organization)!],
|
||||
// });
|
||||
// };
|
||||
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
import floatWidgetModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
|
||||
export const addfloat = async (data: any) => {
|
||||
const { organization, widget, zoneId } = data;
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return { success: false, message: "Zone not found for the zoneId", organization: organization }
|
||||
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
const updateFloatWidget = await floatWidgetModel(organization).findOneAndUpdate(
|
||||
{
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
// Data: {
|
||||
// // measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1h",
|
||||
// },
|
||||
position: widget.position,
|
||||
},
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
new: true,
|
||||
}
|
||||
);
|
||||
return { success: true, message: "Widget updated successfully", data: updateFloatWidget, organization: organization }
|
||||
}
|
||||
|
||||
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||
className: widget.className,
|
||||
header: widget.header,
|
||||
floatWidgetID: widget.id,
|
||||
position: widget.position,
|
||||
per: widget.per,
|
||||
value: widget.value,
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (newFloadWidget) {
|
||||
return { success: true, message: "FloatWidget created successfully", data: newFloadWidget, organization: organization }
|
||||
}
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "Error occurred while float", error, organization: organization }
|
||||
}
|
||||
|
||||
}
|
||||
import floatWidgetModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
|
||||
export const addfloat = async (data: any) => {
|
||||
const { organization, widget, zoneId } = data;
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return { success: false, message: "Zone not found for the zoneId", organization: organization }
|
||||
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
const updateFloatWidget = await floatWidgetModel(organization).findOneAndUpdate(
|
||||
{
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
// Data: {
|
||||
// // measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1h",
|
||||
// },
|
||||
position: widget.position,
|
||||
},
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
new: true,
|
||||
}
|
||||
);
|
||||
return { success: true, message: "Widget updated successfully", data: updateFloatWidget, organization: organization }
|
||||
}
|
||||
|
||||
const newFloadWidget = await floatWidgetModel(organization).create({
|
||||
className: widget.className,
|
||||
header: widget.header,
|
||||
floatWidgetID: widget.id,
|
||||
position: widget.position,
|
||||
per: widget.per,
|
||||
value: widget.value,
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (newFloadWidget) {
|
||||
return { success: true, message: "FloatWidget created successfully", data: newFloadWidget, organization: organization }
|
||||
}
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "Error occurred while float", error, organization: organization }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
import templateModel from "../../../shared/model/vizualization/templatemodel.ts";
|
||||
export const addTemplate = async (data: any) => {
|
||||
const { organization, templateID, name, panelOrder, widgets, snapshot } =data;
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
|
||||
const existingTemplate = await templateModel(organization).findOne({
|
||||
templateID: templateID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingTemplate)
|
||||
return { success: false, message: "TemplateID alreay exists", organization: organization }
|
||||
const newTemplate = await templateModel(organization).create({
|
||||
templateID,
|
||||
name,
|
||||
panelOrder,
|
||||
widgets,
|
||||
snapshot,
|
||||
});
|
||||
if (newTemplate)
|
||||
return { success: false, message: "Template saved successfully", data: newTemplate, organization: organization }
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "Error occurred while template", error, organization: organization }
|
||||
}
|
||||
|
||||
import templateModel from "../../../shared/model/vizualization/templatemodel.ts";
|
||||
export const addTemplate = async (data: any) => {
|
||||
const { organization, templateID, name, panelOrder, widgets, snapshot } =data;
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
|
||||
const existingTemplate = await templateModel(organization).findOne({
|
||||
templateID: templateID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingTemplate)
|
||||
return { success: false, message: "TemplateID alreay exists", organization: organization }
|
||||
const newTemplate = await templateModel(organization).create({
|
||||
templateID,
|
||||
name,
|
||||
panelOrder,
|
||||
widgets,
|
||||
snapshot,
|
||||
});
|
||||
if (newTemplate)
|
||||
return { success: false, message: "Template saved successfully", data: newTemplate, organization: organization }
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "Error occurred while template", error, organization: organization }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,119 +1,119 @@
|
||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export const addWidget = async (data: any) => {
|
||||
const { organization,panel,zoneId,widget,} = data
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const existingPanel = await panelSchema(organization).findOne({
|
||||
panelName: widget.panel,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingPanel)
|
||||
|
||||
return { success: false, message: "panelName not found",organization: organization}
|
||||
|
||||
|
||||
if (existingPanel.panelName === widget.panel) {
|
||||
const existingWidget = await widgetSchema(organization).findOne({
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
isArchive: false,
|
||||
// widgetOrder: widget.widgetOrder,
|
||||
});
|
||||
if (existingWidget) {
|
||||
const updateWidget = await widgetSchema(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
Data: {
|
||||
measurements: widget.Data.measurements,
|
||||
duration: widget.Data.duration,
|
||||
},
|
||||
isArchive: false,
|
||||
},
|
||||
},
|
||||
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
||||
);
|
||||
|
||||
return { success: false, message: "Widget updated successfully",data:updateWidget,organization: organization}
|
||||
|
||||
}
|
||||
const newWidget = await widgetSchema(organization).create({
|
||||
widgetID: widget.id,
|
||||
elementType: widget.type,
|
||||
// widgetOrder: widgetOrder,
|
||||
widgetName: widget.widgetName,
|
||||
panelID: existingPanel._id,
|
||||
widgetside: widget.panel,
|
||||
// Data: {
|
||||
// measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1hr",
|
||||
// },
|
||||
});
|
||||
if (newWidget) {
|
||||
existingPanel.widgets.push(newWidget._id);
|
||||
await existingPanel.save();
|
||||
return { success: true, message: "Widget already exist for the widgetID",data:existingPanel,organization: organization}
|
||||
}
|
||||
}
|
||||
return { success: false, message: "Type mismatch",organization: organization}
|
||||
|
||||
} catch (error: any) {
|
||||
return { success: false, message: 'widge not found', error,organization: organization }
|
||||
}
|
||||
}
|
||||
export const Widgetdelete = async (data: any) => {
|
||||
const { widgetID, organization } = data
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const findWidget = await widgetSchema(organization).findOne({
|
||||
widgetID: widgetID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findWidget)
|
||||
return { success: false, message: "Widget not found",organization: organization}
|
||||
const widgetData = await widgetSchema(organization).updateOne(
|
||||
{ _id: findWidget._id, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
|
||||
if (widgetData) {
|
||||
// Find all widgets in the same panel and sort them by widgetOrder
|
||||
const widgets = await widgetSchema(organization).find({
|
||||
panelID: findWidget.panelID,
|
||||
isArchive: false,
|
||||
});
|
||||
// .sort({ widgetOrder: 1 });
|
||||
|
||||
// Reassign widgetOrder values
|
||||
// for (let i = 0; i < widgets.length; i++) {
|
||||
// widgets[i].widgetOrder = (i + 1).toString(); // Convert to string
|
||||
// await widgets[i].save();
|
||||
// }
|
||||
const panelData = await panelSchema(organization).findOne({
|
||||
_id: findWidget.panelID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (panelData.widgets.includes(findWidget._id)) {
|
||||
const index1 = panelData.widgets.indexOf(findWidget._id);
|
||||
panelData.widgets.splice(index1, 1);
|
||||
}
|
||||
const panelDeletedata = await panelData.save();
|
||||
console.log('Widget deleted successfully: ');
|
||||
return { success: false, message: "Widget deleted successfully",data:panelDeletedata,organization: organization}
|
||||
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "An unknown error occurred.", error ,organization: organization}
|
||||
}
|
||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
||||
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
|
||||
export const addWidget = async (data: any) => {
|
||||
const { organization,panel,zoneId,widget,} = data
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const existingPanel = await panelSchema(organization).findOne({
|
||||
panelName: widget.panel,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingPanel)
|
||||
|
||||
return { success: false, message: "panelName not found",organization: organization}
|
||||
|
||||
|
||||
if (existingPanel.panelName === widget.panel) {
|
||||
const existingWidget = await widgetSchema(organization).findOne({
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
isArchive: false,
|
||||
// widgetOrder: widget.widgetOrder,
|
||||
});
|
||||
if (existingWidget) {
|
||||
const updateWidget = await widgetSchema(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
isArchive: false,
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
panelID: existingPanel._id,
|
||||
widgetID: widget.id,
|
||||
Data: {
|
||||
measurements: widget.Data.measurements,
|
||||
duration: widget.Data.duration,
|
||||
},
|
||||
isArchive: false,
|
||||
},
|
||||
},
|
||||
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
||||
);
|
||||
|
||||
return { success: false, message: "Widget updated successfully",data:updateWidget,organization: organization}
|
||||
|
||||
}
|
||||
const newWidget = await widgetSchema(organization).create({
|
||||
widgetID: widget.id,
|
||||
elementType: widget.type,
|
||||
// widgetOrder: widgetOrder,
|
||||
widgetName: widget.widgetName,
|
||||
panelID: existingPanel._id,
|
||||
widgetside: widget.panel,
|
||||
// Data: {
|
||||
// measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1hr",
|
||||
// },
|
||||
});
|
||||
if (newWidget) {
|
||||
existingPanel.widgets.push(newWidget._id);
|
||||
await existingPanel.save();
|
||||
return { success: true, message: "Widget already exist for the widgetID",data:existingPanel,organization: organization}
|
||||
}
|
||||
}
|
||||
return { success: false, message: "Type mismatch",organization: organization}
|
||||
|
||||
} catch (error: any) {
|
||||
return { success: false, message: 'widge not found', error,organization: organization }
|
||||
}
|
||||
}
|
||||
export const Widgetdelete = async (data: any) => {
|
||||
const { widgetID, organization } = data
|
||||
console.log('data: ', data);
|
||||
try {
|
||||
const findWidget = await widgetSchema(organization).findOne({
|
||||
widgetID: widgetID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findWidget)
|
||||
return { success: false, message: "Widget not found",organization: organization}
|
||||
const widgetData = await widgetSchema(organization).updateOne(
|
||||
{ _id: findWidget._id, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
|
||||
if (widgetData) {
|
||||
// Find all widgets in the same panel and sort them by widgetOrder
|
||||
const widgets = await widgetSchema(organization).find({
|
||||
panelID: findWidget.panelID,
|
||||
isArchive: false,
|
||||
});
|
||||
// .sort({ widgetOrder: 1 });
|
||||
|
||||
// Reassign widgetOrder values
|
||||
// for (let i = 0; i < widgets.length; i++) {
|
||||
// widgets[i].widgetOrder = (i + 1).toString(); // Convert to string
|
||||
// await widgets[i].save();
|
||||
// }
|
||||
const panelData = await panelSchema(organization).findOne({
|
||||
_id: findWidget.panelID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (panelData.widgets.includes(findWidget._id)) {
|
||||
const index1 = panelData.widgets.indexOf(findWidget._id);
|
||||
panelData.widgets.splice(index1, 1);
|
||||
}
|
||||
const panelDeletedata = await panelData.save();
|
||||
console.log('Widget deleted successfully: ');
|
||||
return { success: false, message: "Widget deleted successfully",data:panelDeletedata,organization: organization}
|
||||
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error?.message || "An unknown error occurred.", error ,organization: organization}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@ export const EVENTS = {
|
||||
connection: "connection",
|
||||
disconnect:"disconnect",
|
||||
//userActiveStatus
|
||||
userConnect:"userConnectRespones",
|
||||
userDisConnect:"userDisConnectRespones",
|
||||
userConnect:"userConnectResponse",
|
||||
userDisConnect:"userDisConnectResponse",
|
||||
// Room management events
|
||||
joinRoom: 'joinRoom',
|
||||
createroom: "createRoom", // When a client joins a room
|
||||
@@ -73,4 +73,8 @@ export const EVENTS = {
|
||||
//model-asset
|
||||
setAssetModel: "v2:model-asset:add",
|
||||
assetUpdateRespones: "model-asset:response:updates",
|
||||
deleteAssetModel:"v2:model-asset:delete",
|
||||
assetDeleteRespones: "model-asset:response:updates",
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user