Skip to content

Commit

Permalink
Fix period progression update error
Browse files Browse the repository at this point in the history
Don't attempt to update legacy period progression on objective updates
anymore, as objectives are decoupled from their legacy periods
automatically when they're updated now, making the update fail.
  • Loading branch information
simenheg committed Nov 15, 2023
1 parent e07b53c commit fc4fef1
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 31 deletions.
1 change: 0 additions & 1 deletion functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export { KPIDelete as auditKPIDelete } from './audit/index.js';
*/
export { handleKeyResultProgress } from './progress/index.js';
export { handleKeyResultProgressOnKeyResultUpdate } from './progress/index.js';
export { handleKeyResultProgressOnObjectiveUpdate } from './progress/index.js';

// // Express servers run via Cloud Functions
export { api, internal };
Expand Down
2 changes: 1 addition & 1 deletion functions/progress/handleKeyResultProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const updateObjectiveProgression = async (objectiveRef, db) => {
}
};

export const updatePeriodProgression = async (periodRef) => {
const updatePeriodProgression = async (periodRef) => {
// Finds all progressions for related objectives and updates the period's progression

const db = getFirestore();
Expand Down
30 changes: 1 addition & 29 deletions functions/progress/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import functions from 'firebase-functions';
import config from '../config.js';
import {
updateKeyResultProgress,
updatePeriodProgression,
} from './handleKeyResultProgress.js';
import { updateKeyResultProgress } from './handleKeyResultProgress.js';

export const handleKeyResultProgress = functions
.runWith(config.runtimeOpts)
Expand All @@ -28,28 +25,3 @@ export const handleKeyResultProgressOnKeyResultUpdate = functions

return true;
});

export const handleKeyResultProgressOnObjectiveUpdate = functions
.runWith(config.runtimeOpts)
.region(config.region)
.firestore.document(`objectives/{objectiveId}`)
.onUpdate(({ before, after }) => {
const beforeData = before.data();
const afterData = after.data();

const weightChanged = beforeData.weight !== afterData.weight;
const periodChanged = beforeData.period !== afterData.period;

if (!weightChanged && !periodChanged) {
return false;
}

return updatePeriodProgression(afterData.period).then(() => {
// Update progression for both periods when an objective's period is altered.
if (!periodChanged) {
return false;
}

return updatePeriodProgression(beforeData.period);
});
});

0 comments on commit fc4fef1

Please sign in to comment.