From 75a6f8bbe69e71c23530dacaa73dc9bc96bdf47f Mon Sep 17 00:00:00 2001 From: Sven Valenberghs Date: Tue, 10 Dec 2024 15:11:07 +0100 Subject: [PATCH 1/2] KAS-4896 change query to only update BIS docs on latest agendaitem based on agenda-activity --- .../agendaitem-and-subcase-properties-sync.js | 20 ++++--- app/services/piece-upload.js | 55 ++++++++++--------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/app/services/agendaitem-and-subcase-properties-sync.js b/app/services/agendaitem-and-subcase-properties-sync.js index b537c9d231..4427a0a32b 100644 --- a/app/services/agendaitem-and-subcase-properties-sync.js +++ b/app/services/agendaitem-and-subcase-properties-sync.js @@ -71,15 +71,21 @@ export default class AgendaitemAndSubcasePropertiesSyncService extends Service { await setModifiedOnAgendaOfAgendaitem(item); } else { await setNewPropertiesToModel(item, propertiesToSetOnSubcase, false); - const agendaitemsOnDesignAgendaToEdit = await this.store.query('agendaitem', { - 'filter[agenda-activity][subcase][:id:]': item.id, + // in normal cases, only 1 agendaitem should exist on a design agenda. + // only in special cases, 2 agendaitems can exist on different meetings (different agenda-activity) + // fe. agendaitem gets retracted on friday agenda to be rushed on a wednesday agenda. + // Normally we don't want to update the friday agenda anymore then. + // this query will only get the agendaitem on a design agenda of the latest agenda-activity + // should result in max 1 agendaitem or 0 (everything approved but changes happen) + const agendaitemOnDesignAgenda = await this.store.queryOne('agendaitem', { + 'filter[agenda-activity][subcase][:id:]': item.id, 'filter[agenda][status][:uri:]': CONSTANTS.AGENDA_STATUSSES.DESIGN, + 'filter[:has-no:next-version]': 't', + sort: '-agenda-activity.start-date,-created', }); - if (agendaitemsOnDesignAgendaToEdit?.length > 0) { - await Promise.all(agendaitemsOnDesignAgendaToEdit.map(async(agendaitem) => { - await setNewPropertiesToModel(agendaitem, propertiesToSetOnAgendaitem, resetFormallyOk); - await setModifiedOnAgendaOfAgendaitem(agendaitem); - })); + if (agendaitemOnDesignAgenda?.id) { + await setNewPropertiesToModel(agendaitemOnDesignAgenda, propertiesToSetOnAgendaitem, resetFormallyOk); + await setModifiedOnAgendaOfAgendaitem(agendaitemOnDesignAgenda); } } } diff --git a/app/services/piece-upload.js b/app/services/piece-upload.js index 12c0ad7faa..2bfaa62bce 100644 --- a/app/services/piece-upload.js +++ b/app/services/piece-upload.js @@ -55,35 +55,38 @@ export default class PieceUploadService extends Service { updateRelatedAgendaitems = task(async (pieces, subcase) => { // Link piece to all agendaitems that are related to the subcase via an agendaActivity // and related to an agenda in the design status - const agendaitems = await this.store.query('agendaitem', { - 'filter[agenda-activity][subcase][:id:]': subcase.id, + + // agendaitems can only have more than 1 item + // in case the subcase is on multiple (future) open agendas (retracted and resubmitted) + // in that exception case we only want to update the agendaitem with the most recent agenda-activity + // that should always be the one that is not retracted (without having to check the decision-result-code) + const agendaitem = await this.store.queryOne('agendaitem', { + 'filter[agenda-activity][subcase][:id:]': subcase.id, 'filter[agenda][status][:uri:]': CONSTANTS.AGENDA_STATUSSES.DESIGN, + 'filter[:has-no:next-version]': 't', + sort: '-agenda-activity.start-date,-created', }); - // agendaitems can only have more than 1 item - // in case the subcase is on multiple (future) open agendas - for (const agendaitem of agendaitems.slice()) { - setNotYetFormallyOk(agendaitem); - // save prior to adding pieces, micro-service does all the changes with docs - await agendaitem.save(); - for (const piece of pieces) { - await addPieceToAgendaitem(agendaitem, piece); - } - // ensure the cache does not hold stale data + refresh our local store for future saves of agendaitem - for (let index = 0; index < 10; index++) { - const agendaitemPieces = await agendaitem.hasMany('pieces').reload(); - if (agendaitemPieces.includes(pieces[pieces.length - 1])) { - // last added piece was found in the list from cache - break; - } else { - // list from cache is stale, wait with back-off strategy - await timeout(500 + (index * 500)); - if (index >= 9) { - this.toaster.error(this.intl.t('documents-may-not-be-saved-message'), this.intl.t('warning-title'), - { - timeOut: 60000, - }); - } + setNotYetFormallyOk(agendaitem); + // save prior to adding pieces, micro-service does all the changes with docs + await agendaitem.save(); + for (const piece of pieces) { + await addPieceToAgendaitem(agendaitem, piece); + } + // ensure the cache does not hold stale data + refresh our local store for future saves of agendaitem + for (let index = 0; index < 10; index++) { + const agendaitemPieces = await agendaitem.hasMany('pieces').reload(); + if (agendaitemPieces.includes(pieces[pieces.length - 1])) { + // last added piece was found in the list from cache + break; + } else { + // list from cache is stale, wait with back-off strategy + await timeout(500 + (index * 500)); + if (index >= 9) { + this.toaster.error(this.intl.t('documents-may-not-be-saved-message'), this.intl.t('warning-title'), + { + timeOut: 60000, + }); } } } From ef2c96839e66acf057a590ef098b7b0ec72a7d26 Mon Sep 17 00:00:00 2001 From: Sven Valenberghs Date: Tue, 7 Jan 2025 11:21:35 +0100 Subject: [PATCH 2/2] KAS-4896 add comment and failsafe in method --- app/services/piece-upload.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/services/piece-upload.js b/app/services/piece-upload.js index 2bfaa62bce..ee0398e3d3 100644 --- a/app/services/piece-upload.js +++ b/app/services/piece-upload.js @@ -67,6 +67,13 @@ export default class PieceUploadService extends Service { sort: '-agenda-activity.start-date,-created', }); + if (!agendaitem?.id) { + // should be unreachable. only use this method after verifying there is atleast 1 valid agenda-activity with + // local getAgendaActivity method + console.warn('updateRelatedAgendaitems should not be called without valid agenda-activity'); + return; + } + setNotYetFormallyOk(agendaitem); // save prior to adding pieces, micro-service does all the changes with docs await agendaitem.save();