Add spaces concept (#1776)

This commit is contained in:
Luke Vella 2025-06-15 11:48:51 +02:00 committed by GitHub
parent 92a72dde60
commit 04fcc0350f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 389 additions and 93 deletions

View file

@ -41,7 +41,13 @@ function generateDescription() {
return faker.helpers.arrayElement(descriptions);
}
async function createPollForUser(userId: string) {
async function createPollForUser({
userId,
spaceId,
}: {
userId: string;
spaceId: string;
}) {
const duration = 60 * randInt(8);
let cursor = dayjs().add(randInt(30), "day").second(0).minute(0);
const numberOfOptions = randInt(5, 2); // Reduced for realism
@ -62,6 +68,11 @@ async function createPollForUser(userId: string) {
id: userId,
},
},
space: {
connect: {
id: spaceId,
},
},
status: faker.helpers.arrayElement(["live", "paused", "finalized"]),
timeZone: duration !== 0 ? "Europe/London" : undefined,
options: {
@ -108,8 +119,18 @@ async function createPollForUser(userId: string) {
export async function seedPolls(userId: string) {
console.info("Seeding polls...");
const space = await prisma.space.findFirst({
where: {
ownerId: userId,
},
});
if (!space) {
throw new Error(`No space found for user ${userId}`);
}
const pollPromises = Array.from({ length: 20 }).map(() =>
createPollForUser(userId),
createPollForUser({ userId, spaceId: space.id }),
);
await Promise.all(pollPromises);