From 52188c67adf897d4dc32f24407eda440560cd608 Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Wed, 1 May 2024 12:37:55 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Update=20seed=20script=20(?= =?UTF-8?q?#1083)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/database/prisma/seed.ts | 35 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/database/prisma/seed.ts b/packages/database/prisma/seed.ts index 34c19f4e2..95533f34f 100644 --- a/packages/database/prisma/seed.ts +++ b/packages/database/prisma/seed.ts @@ -13,7 +13,11 @@ async function createPollsForUser(userId: string) { const polls = await Promise.all( Array.from({ length: 20 }).map(async (_, i) => { // create some polls with no duration (all day) and some with a random duration. - const duration = i % 2 === 0 ? 15 * randInt(8) : 0; + const duration = i % 2 === 0 ? 60 * randInt(8, 1) : 0; + let cursor = dayjs().add(randInt(30), "day").second(0).minute(0); + + const numberOfOptions = randInt(30, 2); + const poll = await prisma.poll.create({ include: { participants: true, @@ -32,22 +36,19 @@ async function createPollsForUser(userId: string) { }, timeZone: duration !== 0 ? "America/New_York" : undefined, options: { - create: faker.date - .betweens( - Date.now(), - Date.now() + 1000 * 60 * 60 * 24 * 30, - randInt(30, 1), - ) - .map((date) => { - // rounded to nearest 15 minutes - date.setMinutes(Math.round(date.getMinutes() / 15) * 15); - date.setSeconds(0); - return { - start: date, - startTime: date, - duration, - }; - }), + create: Array.from({ length: numberOfOptions }).map(() => { + const startTime = cursor.toDate(); + if (duration !== 0) { + cursor = cursor.add(randInt(72, 1), "hour"); + } else { + cursor = cursor.add(randInt(7, 1), "day"); + } + return { + startTime, + start: startTime, + duration, + }; + }), }, participants: { create: Array.from({ length: Math.round(Math.random() * 10) }).map(