mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-17 08:17:26 +02:00
✨ Add spaces concept (#1776)
This commit is contained in:
parent
92a72dde60
commit
04fcc0350f
21 changed files with 389 additions and 93 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue