Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAS-4896: change query to only update BIS docs on latest agendaitem based on agenda-activity #2272

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions app/services/agendaitem-and-subcase-properties-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
62 changes: 36 additions & 26 deletions app/services/piece-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,45 @@ 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,
});
}
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();
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,
});
}
}
}
Expand Down