From 89867aebb6288fb600d1af886ac349d4e212cc79 Mon Sep 17 00:00:00 2001 From: JohanHjelsethStorstad <82723971+JohanHjelsethStorstad@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:38:15 +0200 Subject: [PATCH] fix: event names of order were not unique --- .../src/dobbelOmega/migrateEvents.ts | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/prisma/prismaservice/src/dobbelOmega/migrateEvents.ts b/src/prisma/prismaservice/src/dobbelOmega/migrateEvents.ts index df0f8cc85..ab9e0db55 100644 --- a/src/prisma/prismaservice/src/dobbelOmega/migrateEvents.ts +++ b/src/prisma/prismaservice/src/dobbelOmega/migrateEvents.ts @@ -18,7 +18,17 @@ export default async function migrateEvents( EventRegistrations: true, } }) - Promise.all(events.map(async event => { + //Make sure no events have same title and order + events.forEach((event) => { + const sameTitle = events.filter(e => e.title === event.title) + if (sameTitle.length > 1) { + sameTitle.forEach((e, i) => { + e.title = `${e.title} (${i + 1})` + }) + } + }) + + await Promise.all(events.map(async event => { const coverId = vevenIdToPnId(imageIdMap, event.ImageId) const coverIage = await pnPrisma.cmsImage.create({ data: { @@ -37,10 +47,12 @@ export default async function migrateEvents( } }) + const order = await upsertOrderBasedOnDate(pnPrisma, event.createdAt) + await pnPrisma.event.create({ data: { name: event.title, - order: await upsertOrderBasedOnDate(pnPrisma, event.createdAt), + order, createdAt: event.createdAt, updatedAt: event.updatedAt, canBeViewdBy: 'ALL', @@ -62,8 +74,17 @@ export default async function migrateEvents( Committees: true, } }) + //Make sure no events have same title and order + simpleEvents.forEach((event) => { + const sameTitle = simpleEvents.filter(e => e.title === event.title) + if (sameTitle.length > 1) { + sameTitle.forEach((e, i) => { + e.title = `${e.title} (${i + 1})` + }) + } + }) - Promise.all(simpleEvents.map(async simpleEvent => { + await Promise.all(simpleEvents.map(async simpleEvent => { const coverIage = await pnPrisma.cmsImage.create({ data: { image: undefined @@ -76,10 +97,13 @@ export default async function migrateEvents( updatedAt: simpleEvent.updatedAt, } }) + + const order = await upsertOrderBasedOnDate(pnPrisma, simpleEvent.createdAt) + await pnPrisma.event.create({ data: { name: simpleEvent.title, - order: await upsertOrderBasedOnDate(pnPrisma, simpleEvent.createdAt), + order, createdAt: simpleEvent.createdAt, updatedAt: simpleEvent.updatedAt, canBeViewdBy: 'ALL',