template,widget delete bug updates

This commit is contained in:
2025-04-02 18:49:01 +05:30
parent 61d0a8c4ed
commit bc97dfa1ed
4 changed files with 14 additions and 4 deletions

View File

@@ -145,6 +145,7 @@ export class templateService {
const newWidget = await widgetSchema(organization).create({ const newWidget = await widgetSchema(organization).create({
widgetID: widgetData.id, widgetID: widgetData.id,
zoneId: zoneId,
elementType: widgetData.type, elementType: widgetData.type,
widgetName: widgetData.widgetName || "Widget", widgetName: widgetData.widgetName || "Widget",
panelID: addedExistingPanel._id, panelID: addedExistingPanel._id,

View File

@@ -95,15 +95,17 @@ export class widgetService {
static async deleteWidget(req: Request, res: Response): Promise<any> { static async deleteWidget(req: Request, res: Response): Promise<any> {
try { try {
const { widgetID, organization } = req.body; const { widgetID, organization,zoneId} = req.body;
console.log(' req.body: ', req.body);
const findWidget = await widgetSchema(organization).findOne({ const findWidget = await widgetSchema(organization).findOne({
zoneId: zoneId,
widgetID: widgetID, widgetID: widgetID,
isArchive: false, isArchive: false,
}); });
if (!findWidget) if (!findWidget)
return res.status(409).json({ message: "Widget not found" }); return res.status(409).json({ message: "Widget not found" });
const widgetData = await widgetSchema(organization).updateOne( const widgetData = await widgetSchema(organization).updateOne(
{ _id: findWidget._id, isArchive: false }, { _id: findWidget._id, isArchive: false,zoneId: zoneId },
{ $set: { isArchive: true } } { $set: { isArchive: true } }
); );
@@ -111,6 +113,7 @@ export class widgetService {
// Find all widgets in the same panel and sort them by widgetOrder // Find all widgets in the same panel and sort them by widgetOrder
const widgets = await widgetSchema(organization).find({ const widgets = await widgetSchema(organization).find({
panelID: findWidget.panelID, panelID: findWidget.panelID,
zoneId: zoneId,
isArchive: false, isArchive: false,
}); });
// .sort({ widgetOrder: 1 }); // .sort({ widgetOrder: 1 });
@@ -122,6 +125,7 @@ export class widgetService {
// } // }
const panelData = await panelSchema(organization).findOne({ const panelData = await panelSchema(organization).findOne({
_id: findWidget.panelID, _id: findWidget.panelID,
zoneId: zoneId,
isArchive: false, isArchive: false,
}); });
if (panelData.widgets.includes(findWidget._id)) { if (panelData.widgets.includes(findWidget._id)) {

View File

@@ -137,6 +137,7 @@ export const addTemplateZone = async (data: any) => {
const newWidget = await widgetSchema(organization).create({ const newWidget = await widgetSchema(organization).create({
widgetID: widgetData.id, widgetID: widgetData.id,
elementType: widgetData.type, elementType: widgetData.type,
zoneId: zoneId,
widgetName: widgetData.widgetName || "Widget", widgetName: widgetData.widgetName || "Widget",
panelID: addedExistingPanel._id, panelID: addedExistingPanel._id,
widgetside: widgetData.panel, widgetside: widgetData.panel,

View File

@@ -96,12 +96,13 @@ export const Widgetdelete = async (data: any) => {
return { success: false, message: "Zone not found", organization: organization } return { success: false, message: "Zone not found", organization: organization }
const findWidget = await widgetSchema(organization).findOne({ const findWidget = await widgetSchema(organization).findOne({
widgetID: widgetID, widgetID: widgetID,
zoneId: zoneId,
isArchive: false, isArchive: false,
}); });
if (!findWidget) if (!findWidget)
return { success: false, message: "Widget not found", organization: organization } return { success: false, message: "Widget not found", organization: organization }
const widgetData = await widgetSchema(organization).updateOne( const widgetData = await widgetSchema(organization).updateOne(
{ _id: findWidget._id, isArchive: false }, { _id: findWidget._id, isArchive: false,zoneId: zoneId },
{ $set: { isArchive: true } } { $set: { isArchive: true } }
); );
@@ -109,7 +110,9 @@ export const Widgetdelete = async (data: any) => {
// Find all widgets in the same panel and sort them by widgetOrder // Find all widgets in the same panel and sort them by widgetOrder
const widgets = await widgetSchema(organization).find({ const widgets = await widgetSchema(organization).find({
panelID: findWidget.panelID, panelID: findWidget.panelID,
zoneId: zoneId,
isArchive: false, isArchive: false,
}); });
// console.log('widgets: ', widgets); // console.log('widgets: ', widgets);
// .sort({ widgetOrder: 1 }); // .sort({ widgetOrder: 1 });
@@ -122,6 +125,7 @@ export const Widgetdelete = async (data: any) => {
const panelData = await panelSchema(organization).findOne({ const panelData = await panelSchema(organization).findOne({
_id: findWidget.panelID, _id: findWidget.panelID,
isArchive: false, isArchive: false,
zoneId: zoneId
}); });
if (panelData.widgets.includes(findWidget._id)) { if (panelData.widgets.includes(findWidget._id)) {
const index1 = panelData.widgets.indexOf(findWidget._id); const index1 = panelData.widgets.indexOf(findWidget._id);
@@ -160,7 +164,7 @@ export const Widgetdelete = async (data: any) => {
widgetDeleteDatas: formattedWidgets, zoneId: zoneId, zoneName: existingZone.zoneName widgetDeleteDatas: formattedWidgets, zoneId: zoneId, zoneName: existingZone.zoneName
} }
// console.log("formattedWidgets",widgetData1); console.log("formattedWidgets",widgetData1);
return { success: true, message: "Widget deleted successfully", data: widgetData1, organization: organization } return { success: true, message: "Widget deleted successfully", data: widgetData1, organization: organization }
} }