diff --git a/docs b/docs index 3cc94e532..97b8ef607 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 3cc94e532274ee194ac05edb33b76980e415b3dd +Subproject commit 97b8ef607aa78cc38d04c030fabd8d55806cd1df diff --git a/src/prisma/prismaservice/src/dobbelOmega/dobbelOmega.ts b/src/prisma/prismaservice/src/dobbelOmega/dobbelOmega.ts index c3f74db12..7fd64db1d 100644 --- a/src/prisma/prismaservice/src/dobbelOmega/dobbelOmega.ts +++ b/src/prisma/prismaservice/src/dobbelOmega/dobbelOmega.ts @@ -5,6 +5,7 @@ import { getLimits } from './migrationLimits' import migrateOmegaquotes from './migrateOmegaquotes' import migrateArticles from './migateArticles' import migrateMailAliases from './migrateMailAlias' +import migrateEvents from './migrateEvents' import { PrismaClient as PrismaClientVeven } from '@/generated/veven' import type { PrismaClient as PrismaClientPn } from '@/generated/pn' @@ -26,6 +27,7 @@ export default async function dobbelOmega(pnPrisma: PrismaClientPn) { await migrateOmegaquotes(pnPrisma, vevenPrisma, limits) await migrateArticles(pnPrisma, vevenPrisma, imageIdMap, limits) await migrateMailAliases(pnPrisma, vevenPrisma, limits) + await migrateEvents(pnPrisma, vevenPrisma, imageIdMap, limits) vevenPrisma.$disconnect() console.log('=======Dobbel Omega ferdig, dagen derpÄ=======') diff --git a/src/prisma/prismaservice/src/dobbelOmega/migateArticles.ts b/src/prisma/prismaservice/src/dobbelOmega/migateArticles.ts index 2581b2d23..761beff65 100644 --- a/src/prisma/prismaservice/src/dobbelOmega/migateArticles.ts +++ b/src/prisma/prismaservice/src/dobbelOmega/migateArticles.ts @@ -1,4 +1,5 @@ import { vevenIdToPnId } from './IdMapper' +import upsertOrderBasedOnDate from './upsertOrderBasedOnDate' import type { PrismaClient as PrismaClientPn } from '@/generated/pn' import type { PrismaClient as PrismaClientVeven } from '@/generated/veven' import type { IdMapper } from './IdMapper' @@ -84,23 +85,7 @@ export default async function migrateArticles( } }) - // The order is assumed to change 1. september, calculate by createdAt - // 1. september 1914 = order 1, 1. september 1915 = order 2, ... - let orderPublished = new Date(article.createdAt).getFullYear() - 1914 - if (new Date(article.createdAt).getMonth() < 8) { - orderPublished-- - } - await pnPrisma.omegaOrder.upsert({ - where: { - order: orderPublished, - }, - update: { - order: orderPublished, - }, - create: { - order: orderPublished, - } - }) + const orderPublished = await upsertOrderBasedOnDate(pnPrisma, article.createdAt) return { ...articlePn, diff --git a/src/prisma/prismaservice/src/dobbelOmega/migrateEvents.ts b/src/prisma/prismaservice/src/dobbelOmega/migrateEvents.ts new file mode 100644 index 000000000..ab9e0db55 --- /dev/null +++ b/src/prisma/prismaservice/src/dobbelOmega/migrateEvents.ts @@ -0,0 +1,121 @@ +import { vevenIdToPnId, type IdMapper } from './IdMapper' +import upsertOrderBasedOnDate from './upsertOrderBasedOnDate' +import type { PrismaClient as PrismaClientPn } from '@/generated/pn' +import type { PrismaClient as PrismaClientVeven } from '@/generated/veven' +import type { Limits } from './migrationLimits' + +export default async function migrateEvents( + pnPrisma: PrismaClientPn, + vevenPrisma: PrismaClientVeven, + imageIdMap: IdMapper, + limits: Limits +) { + const events = await vevenPrisma.events.findMany({ + take: limits.events ? limits.events : undefined, + include: { + Images: true, + Committees: true, + EventRegistrations: true, + } + }) + //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: { + image: coverId ? { + connect: { + id: coverId, + } + } : undefined + } + }) + const paragraph = await pnPrisma.cmsParagraph.create({ + data: { + contentHtml: event.text || '', + createdAt: event.createdAt, + updatedAt: event.updatedAt, + } + }) + + const order = await upsertOrderBasedOnDate(pnPrisma, event.createdAt) + + await pnPrisma.event.create({ + data: { + name: event.title, + order, + createdAt: event.createdAt, + updatedAt: event.updatedAt, + canBeViewdBy: 'ALL', + takesRegistration: !!event.places && (event.places > 0), + places: event.places || 0, + eventStart: event.eventDate ?? event.createdAt, + eventEnd: event.eventDate ?? event.createdAt, + registrationStart: event.registrationStart ?? event.createdAt, + registrationEnd: event.registrationDeadline ?? event.createdAt, + coverImageId: coverIage.id, + cmsParagraphId: paragraph.id, + } + }) + })) + + const simpleEvents = await vevenPrisma.simpleEvents.findMany({ + take: limits.events ? limits.events : undefined, + include: { + 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})` + }) + } + }) + + await Promise.all(simpleEvents.map(async simpleEvent => { + const coverIage = await pnPrisma.cmsImage.create({ + data: { + image: undefined + } + }) + const paragraph = await pnPrisma.cmsParagraph.create({ + data: { + contentHtml: simpleEvent.text || '', + createdAt: simpleEvent.createdAt, + updatedAt: simpleEvent.updatedAt, + } + }) + + const order = await upsertOrderBasedOnDate(pnPrisma, simpleEvent.createdAt) + + await pnPrisma.event.create({ + data: { + name: simpleEvent.title, + order, + createdAt: simpleEvent.createdAt, + updatedAt: simpleEvent.updatedAt, + canBeViewdBy: 'ALL', + takesRegistration: false, + places: 0, + eventStart: simpleEvent.eventDate ?? simpleEvent.createdAt, + eventEnd: simpleEvent.eventDate ?? simpleEvent.createdAt, + registrationStart: simpleEvent.createdAt, + registrationEnd: simpleEvent.createdAt, + coverImageId: coverIage.id, + cmsParagraphId: paragraph.id, + } + }) + })) +} diff --git a/src/prisma/prismaservice/src/dobbelOmega/migrateImages.ts b/src/prisma/prismaservice/src/dobbelOmega/migrateImages.ts index 7c978bd40..24cff972f 100644 --- a/src/prisma/prismaservice/src/dobbelOmega/migrateImages.ts +++ b/src/prisma/prismaservice/src/dobbelOmega/migrateImages.ts @@ -37,8 +37,12 @@ export default async function migrateImages( create: { purpose: 'IMAGE', published: true, - regularLevel: {}, - adminLevel: {}, + regularLevel: { + create: {} + }, + adminLevel: { + create: {} + }, } } }, @@ -55,6 +59,7 @@ export default async function migrateImages( include: { Ombul: true, Articles: true, + Events: true, } }) @@ -74,6 +79,7 @@ export default async function migrateImages( if (!limits.numberOffFullImageCollections) return true if (image.Ombul.length) return true if (image.Articles.length) return true + if (image.Events.length) return true if (image.collectionId === ombulCollection.id) return true if (image.ImageGroupId && image.ImageGroupId < limits.numberOffFullImageCollections) return true return false diff --git a/src/prisma/prismaservice/src/dobbelOmega/migrateMailAlias.ts b/src/prisma/prismaservice/src/dobbelOmega/migrateMailAlias.ts index 8b50f7b47..0b9318bc6 100644 --- a/src/prisma/prismaservice/src/dobbelOmega/migrateMailAlias.ts +++ b/src/prisma/prismaservice/src/dobbelOmega/migrateMailAlias.ts @@ -8,6 +8,7 @@ export default async function migrateMailAliases( vevenPrisma: PrismaClientVeven, limits: Limits, ) { + if (limits.mailaliases === 0) return const aliases = await vevenPrisma.mailAliases.findMany({ take: limits.mailaliases ?? undefined, include: { diff --git a/src/prisma/prismaservice/src/dobbelOmega/migrationLimits.ts b/src/prisma/prismaservice/src/dobbelOmega/migrationLimits.ts index b5b007ff4..ad97b751b 100644 --- a/src/prisma/prismaservice/src/dobbelOmega/migrationLimits.ts +++ b/src/prisma/prismaservice/src/dobbelOmega/migrationLimits.ts @@ -8,7 +8,8 @@ export function getLimits() { numberOffFullImageCollections: 3, omegaquotes: null, articles: 300, - mailaliases: null, + mailaliases: 0, + events: null, } const nullObj: { [key in keyof typeof limits]: null } = { ombul: null, @@ -16,6 +17,7 @@ export function getLimits() { omegaquotes: null, articles: null, mailaliases: null, + events: null, } const limitsOn = process.env.MIGRATION_WITH_LIMITS !== 'false' diff --git a/src/prisma/prismaservice/src/dobbelOmega/upsertOrderBasedOnDate.ts b/src/prisma/prismaservice/src/dobbelOmega/upsertOrderBasedOnDate.ts new file mode 100644 index 000000000..eab14d33f --- /dev/null +++ b/src/prisma/prismaservice/src/dobbelOmega/upsertOrderBasedOnDate.ts @@ -0,0 +1,30 @@ +import type { PrismaClient as PrismaClientPn } from '@/generated/pn' + +/** + * Veven did not have the consept of omegaOrder. This function infers the order based on a date and + * also upserts the order into the database. + * @param date - Date of thing + */ +export default async function upsertOrderBasedOnDate( + pnPrisma: PrismaClientPn, + date: Date +): Promise { + // The order is assumed to change 1. september, calculate by createdAt + // 1. september 1914 = order 1, 1. september 1915 = order 2, ... + let orderPublished = new Date(date).getFullYear() - 1914 + if (new Date(date).getMonth() < 8) { + orderPublished-- + } + await pnPrisma.omegaOrder.upsert({ + where: { + order: orderPublished, + }, + update: { + order: orderPublished, + }, + create: { + order: orderPublished, + } + }) + return orderPublished +} diff --git a/src/prisma/schema/cms.prisma b/src/prisma/schema/cms.prisma index d383e1074..81985ecbf 100644 --- a/src/prisma/schema/cms.prisma +++ b/src/prisma/schema/cms.prisma @@ -43,7 +43,7 @@ enum SpecialCmsParagraph { FRONTPAGE_2 FRONTPAGE_3 FRONTPAGE_4 - + INTEREST_GROUP_GENERAL_INFO CAREER_INFO } diff --git a/src/prisma/schema/event.prisma b/src/prisma/schema/event.prisma index 759f0c32c..503e2d123 100644 --- a/src/prisma/schema/event.prisma +++ b/src/prisma/schema/event.prisma @@ -14,9 +14,11 @@ model Event { coverImageId Int eventTagEvents EventTagEvent[] - eventStart DateTime - eventEnd DateTime - canBeViewdBy EventCanView + eventStart DateTime + eventEnd DateTime + canBeViewdBy EventCanView + hostedByCommitee Committee? @relation(fields: [hostedByCommiteeId], references: [id]) + hostedByCommiteeId Int? takesRegistration Boolean places Int @default(0) diff --git a/src/prisma/schema/group.prisma b/src/prisma/schema/group.prisma index 8b25be0b2..04902fc5c 100644 --- a/src/prisma/schema/group.prisma +++ b/src/prisma/schema/group.prisma @@ -74,6 +74,7 @@ model Committee { logoImageId Int @unique paragraph CmsParagraph @relation(fields: [paragraphId], references: [id]) paragraphId Int @unique + events Event[] } model InterestGroup {