From 568b6743229a0aaa77aebcfce3eaea71133aca58 Mon Sep 17 00:00:00 2001 From: Jeff Sieu Date: Mon, 31 Oct 2022 10:47:15 +0800 Subject: [PATCH] [questions][fix] fix seed questions script (#467) --- apps/portal/prisma/seed-questions.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/portal/prisma/seed-questions.ts b/apps/portal/prisma/seed-questions.ts index 6f8ebbf4..900b63e4 100644 --- a/apps/portal/prisma/seed-questions.ts +++ b/apps/portal/prisma/seed-questions.ts @@ -83,7 +83,6 @@ const CODING_QUESTIONS: Array = CODING_QUESTION_CONTENT.map( userId: null, encounters: { create: { - location: 'Singapore', role: selectRandomRole(), seenAt: generateRandomDate(), }, @@ -98,7 +97,6 @@ const BEHAVIORAL_QUESTIONS: Array = userId: null, encounters: { create: { - location: 'Singapore', role: selectRandomRole(), seenAt: generateRandomDate(), }, @@ -120,6 +118,15 @@ async function main() { ); } + const firstCity = await prisma.city.findFirst({ + include: { + state: true, + }, + }); + if (!firstCity) { + throw new Error('No city found. Please seed db with some cities first.'); + } + // Generate random answers to the questions const users = await prisma.user.findMany(); if (users.length === 0) { @@ -138,6 +145,9 @@ async function main() { create: { ...question.encounters!.create, companyId: firstCompany.id, + stateId: firstCity.stateId, + cityId: firstCity.id, + countryId: firstCity.state.countryId, } as any, }, },