widget3d update,delete creation
This commit is contained in:
@@ -2,6 +2,8 @@ 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({
|
||||
@@ -73,3 +75,128 @@ export const add3Dwidget = async (data: any) => {
|
||||
};
|
||||
}
|
||||
};
|
||||
export const update3D = async (data: any) => {
|
||||
const { organization, id, position, rotation, 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",
|
||||
organization: organization,
|
||||
};
|
||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||
widgetID: id,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existing3Dwidget) {
|
||||
const update3dwidget = await widget3dModel(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{
|
||||
widgetID: id,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
},
|
||||
{ position: position, rotation: rotation },
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
if (update3dwidget){
|
||||
|
||||
const updateDatas = {
|
||||
widget: {
|
||||
id: update3dwidget.widgetID,
|
||||
type: update3dwidget.type,
|
||||
position: update3dwidget.position,
|
||||
rotation: update3dwidget.rotation,
|
||||
},
|
||||
zoneId: zoneId,
|
||||
};
|
||||
return {
|
||||
success: true,
|
||||
message: "widget update successfully",
|
||||
data:updateDatas,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
message: "widget not found",
|
||||
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error?.message || "Error occurred while 3Dwidget",
|
||||
error,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
};
|
||||
export const delete3Dwidget = async (data: any) => {
|
||||
const { organization, id, 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",
|
||||
organization: organization,
|
||||
};
|
||||
const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||
widgetID: id,
|
||||
isArchive: false,
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (!existing3Dwidget) {
|
||||
return {
|
||||
success: false,
|
||||
message: "3D widget not found for the ID",
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
const updateWidget = await widget3dModel(organization).findOneAndUpdate(
|
||||
{
|
||||
widgetID: id,
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
},
|
||||
{ isArchive: true },
|
||||
{ new: true }
|
||||
);
|
||||
if (updateWidget){
|
||||
const delete_Datas = {
|
||||
zoneId: zoneId,id:existing3Dwidget.widgetID
|
||||
};
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data:delete_Datas,
|
||||
message: "3DWidget delete successfull",
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error?.message || "Error occurred while 3Dwidget",
|
||||
error,
|
||||
organization: organization,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user