Skip to content

Commit

Permalink
fix: event names of order were not unique
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanHjelsethStorstad committed Sep 26, 2024
1 parent 2a7727a commit 89867ae
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/prisma/prismaservice/src/dobbelOmega/migrateEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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',
Expand 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
Expand All @@ -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',
Expand Down

0 comments on commit 89867ae

Please sign in to comment.