⚙️ Update seed script (#1083)

This commit is contained in:
Luke Vella 2024-05-01 12:37:55 +08:00 committed by GitHub
parent a869a6eb01
commit 52188c67ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,7 +13,11 @@ async function createPollsForUser(userId: string) {
const polls = await Promise.all( const polls = await Promise.all(
Array.from({ length: 20 }).map(async (_, i) => { Array.from({ length: 20 }).map(async (_, i) => {
// create some polls with no duration (all day) and some with a random duration. // 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({ const poll = await prisma.poll.create({
include: { include: {
participants: true, participants: true,
@ -32,22 +36,19 @@ async function createPollsForUser(userId: string) {
}, },
timeZone: duration !== 0 ? "America/New_York" : undefined, timeZone: duration !== 0 ? "America/New_York" : undefined,
options: { options: {
create: faker.date create: Array.from({ length: numberOfOptions }).map(() => {
.betweens( const startTime = cursor.toDate();
Date.now(), if (duration !== 0) {
Date.now() + 1000 * 60 * 60 * 24 * 30, cursor = cursor.add(randInt(72, 1), "hour");
randInt(30, 1), } else {
) cursor = cursor.add(randInt(7, 1), "day");
.map((date) => { }
// rounded to nearest 15 minutes return {
date.setMinutes(Math.round(date.getMinutes() / 15) * 15); startTime,
date.setSeconds(0); start: startTime,
return { duration,
start: date, };
startTime: date, }),
duration,
};
}),
}, },
participants: { participants: {
create: Array.from({ length: Math.round(Math.random() * 10) }).map( create: Array.from({ length: Math.round(Math.random() * 10) }).map(