diff --git a/package.json b/package.json index bf0f4b1..21e1d2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "qnaplus", - "version": "1.2.0", + "version": "1.2.1", "description": "", "private": true, "author": "battlesqui_d", diff --git a/packages/utils/src/arrays.ts b/packages/utils/src/arrays.ts index d4fb586..5692ecf 100644 --- a/packages/utils/src/arrays.ts +++ b/packages/utils/src/arrays.ts @@ -36,14 +36,14 @@ export const mergeByKey = < B extends Record, >( key: K, - a: A[], - b: B[], + current: A[], + updated: B[], ): (A | B | (A & B))[] => { const map = new Map(); - for (const item of a) { + for (const item of current) { map.set(item[key], item); } - for (const item of b) { + for (const item of updated) { const existing = map.get(item[key]); map.set(item[key], existing ? { ...existing, ...item } : item); } diff --git a/services/updater/src/update_storage.ts b/services/updater/src/update_storage.ts index 5360848..296a08c 100644 --- a/services/updater/src/update_storage.ts +++ b/services/updater/src/update_storage.ts @@ -43,7 +43,7 @@ export const updateStorage = async ( if (seasonQuestions === null) { return; } - const updatedSeasonQuestions = mergeByKey("id", updates, seasonQuestions).toSorted( + const updatedSeasonQuestions = mergeByKey("id", seasonQuestions, updates).toSorted( (a, b) => Number.parseInt(b.id) - Number.parseInt(a.id), ); await update(logger, updatedSeasonQuestions, SEASON_QUESTIONS_KEY); @@ -52,7 +52,7 @@ export const updateStorage = async ( if (questions === null) { return; } - const updatedQuestions = mergeByKey("id", updatedSeasonQuestions, questions).toSorted( + const updatedQuestions = mergeByKey("id", questions, updatedSeasonQuestions).toSorted( (a, b) => Number.parseInt(b.id) - Number.parseInt(a.id), ); await update(logger, updatedQuestions, ALL_QUESTIONS_KEY);