From 65585052bc20f52cea003ed9af58cd1b644fa018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= Date: Mon, 13 Nov 2023 15:04:50 +0100 Subject: [PATCH] Fix period progression update error 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. --- functions/index.js | 1 - functions/progress/handleKeyResultProgress.js | 2 +- functions/progress/index.js | 30 +------------------ 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/functions/index.js b/functions/index.js index eecf88927..510e1093a 100644 --- a/functions/index.js +++ b/functions/index.js @@ -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 }; diff --git a/functions/progress/handleKeyResultProgress.js b/functions/progress/handleKeyResultProgress.js index a94017d7d..fb8f9412a 100644 --- a/functions/progress/handleKeyResultProgress.js +++ b/functions/progress/handleKeyResultProgress.js @@ -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(); diff --git a/functions/progress/index.js b/functions/progress/index.js index e2a8cee83..3a203b2ad 100644 --- a/functions/progress/index.js +++ b/functions/progress/index.js @@ -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) @@ -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); - }); - });