From c9aaddf4cc597088aa2d153dcef4fc3ef2a58d14 Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Tue, 12 Apr 2022 19:34:47 +0100 Subject: [PATCH] Automatically reset legacy poll date values --- utils/legacy-utils.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/utils/legacy-utils.ts b/utils/legacy-utils.ts index 147f06c19..bdd278704 100644 --- a/utils/legacy-utils.ts +++ b/utils/legacy-utils.ts @@ -66,19 +66,21 @@ export const resetDates = async (legacyPollId: string) => { const promises = []; for (let i = 0; i < existingOptions.length; i++) { - const legacyOption = legacyPoll.dates?.find( - (date) => - date.toISOString().substring(0, 10) === existingOptions[i].value, - ); - if (legacyOption) { - promises.push( - prisma.option.update({ - where: { id: existingOptions[i].id }, - data: { - value: legacyOption.toISOString(), - }, - }), + const existingOption = existingOptions[i]; + if (existingOption.value.indexOf("T") === -1) { + const legacyOption = legacyPoll.dates?.find( + (date) => date.toISOString().substring(0, 10) === existingOption.value, ); + if (legacyOption) { + promises.push( + prisma.option.update({ + where: { id: existingOption.id }, + data: { + value: legacyOption.toISOString(), + }, + }), + ); + } } } await prisma.$transaction(promises);