51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
|
|
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||
|
|
import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||
|
|
export const add3Dwidget = 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 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 { success: true, message:"widget update successfully", organization: organization }
|
||
|
|
|
||
|
|
|
||
|
|
else return{ success: false, message: "Widget not updated", organization: organization }
|
||
|
|
}
|
||
|
|
const newWidget3d = await widget3dModel(organization).create({
|
||
|
|
widgetName: widget.type,
|
||
|
|
widgetID: widget.id,
|
||
|
|
position: widget.position,
|
||
|
|
zoneId,
|
||
|
|
});
|
||
|
|
if (newWidget3d)
|
||
|
|
return { success: false, message: "Widget created successfully",data:newWidget3d, organization: organization }
|
||
|
|
|
||
|
|
} catch (error: any) {
|
||
|
|
return { success: false, message: error?.message || "Error occurred while 3Dwidget", error, organization: organization }
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|