Automatically reset legacy poll date values

This commit is contained in:
Luke Vella 2022-04-12 19:34:47 +01:00
parent 4898b75f9b
commit c9aaddf4cc

View file

@ -66,14 +66,15 @@ export const resetDates = async (legacyPollId: string) => {
const promises = []; const promises = [];
for (let i = 0; i < existingOptions.length; i++) { for (let i = 0; i < existingOptions.length; i++) {
const existingOption = existingOptions[i];
if (existingOption.value.indexOf("T") === -1) {
const legacyOption = legacyPoll.dates?.find( const legacyOption = legacyPoll.dates?.find(
(date) => (date) => date.toISOString().substring(0, 10) === existingOption.value,
date.toISOString().substring(0, 10) === existingOptions[i].value,
); );
if (legacyOption) { if (legacyOption) {
promises.push( promises.push(
prisma.option.update({ prisma.option.update({
where: { id: existingOptions[i].id }, where: { id: existingOption.id },
data: { data: {
value: legacyOption.toISOString(), value: legacyOption.toISOString(),
}, },
@ -81,6 +82,7 @@ export const resetDates = async (legacyPollId: string) => {
); );
} }
} }
}
await prisma.$transaction(promises); await prisma.$transaction(promises);
const poll = await prisma.poll.findUnique({ const poll = await prisma.poll.findUnique({