From ff54652f541d2abb2b7ae98b7e10d38c6f580923 Mon Sep 17 00:00:00 2001 From: Bryann Yeap Kok Keong Date: Wed, 9 Nov 2022 12:53:36 +0800 Subject: [PATCH] [offers][fix] Add script to fix internship cycle seeded values --- apps/portal/package.json | 3 +- apps/portal/prisma/map-internship-cycle.ts | 52 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 apps/portal/prisma/map-internship-cycle.ts diff --git a/apps/portal/package.json b/apps/portal/package.json index cdec2c9c..bb6d52dc 100644 --- a/apps/portal/package.json +++ b/apps/portal/package.json @@ -12,7 +12,8 @@ "seed": "ts-node prisma/seed.ts", "seed-salaries": "ts-node prisma/seed-salaries.ts", "seed-analysis": "ts-node prisma/seed-analysis.ts", - "seed-questions": "ts-node prisma/seed-questions.ts" + "seed-questions": "ts-node prisma/seed-questions.ts", + "map-internship-cycle": "ts-node prisma/map-internship-cycle.ts" }, "dependencies": { "@headlessui/react": "^1.7.3", diff --git a/apps/portal/prisma/map-internship-cycle.ts b/apps/portal/prisma/map-internship-cycle.ts new file mode 100644 index 00000000..62e381f4 --- /dev/null +++ b/apps/portal/prisma/map-internship-cycle.ts @@ -0,0 +1,52 @@ +import { PrismaClient } from '@prisma/client'; + +const prisma = new PrismaClient(); + +const mapInternshipCycle = async () => { + console.log('Mapping internship cycle values'); + + const offersInterns = await prisma.offersIntern.findMany({ + where: { + internshipCycle: 'Summer', + }, + }); + + console.log( + 'Number of incorrect internship cycle values found:', + offersInterns.length, + ); + + let i = 0; + + offersInterns.forEach(async (offersIntern) => { + await prisma.offersIntern.update({ + where: { + id: offersIntern.id, + }, + data: { + internshipCycle: 'summer', + }, + }); + + console.log( + ++i, + ': Mapped internship cycle for intern with id', + offersIntern.id, + ); + }); + + console.log(i, 'internship cycles mapped'); +}; + +Promise.all([mapInternshipCycle()]) + .then(async () => { + await prisma.$disconnect(); + }) + .catch(async (e) => { + console.error(e); + console.log('Mapping stopped!'); + await prisma.$disconnect(); + process.exit(1); + }); + +export {};