mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-24 21:37:10 +02:00
🏗️ Update how we store date values
This also fixes a few bugs: - some values had end times that were before the start times - some values has end times a couple of days in the future It’s not entirely clear how users were able to set these values but this update fixes these values and helps avoid similar issues in the future.
This commit is contained in:
parent
8a9159c322
commit
51c5016656
12 changed files with 203 additions and 158 deletions
|
@ -1,5 +1,5 @@
|
|||
import { faker } from "@faker-js/faker";
|
||||
import { PrismaClient, VoteType } from "@prisma/client";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
|
@ -11,14 +11,16 @@ async function main() {
|
|||
// Create some users
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
name: faker.name.fullName(),
|
||||
email: faker.internet.email(),
|
||||
name: "Dev User",
|
||||
email: "dev@rallly.co",
|
||||
},
|
||||
});
|
||||
|
||||
// Create some polls
|
||||
const polls = await Promise.all(
|
||||
Array.from({ length: 20 }).map(async () => {
|
||||
Array.from({ length: 20 }).map(async (_, i) => {
|
||||
// create some polls with no duration (all day) and some with a random duration.
|
||||
const duration = i % 5 === 0 ? 15 * randInt(8) : 0;
|
||||
const poll = await prisma.poll.create({
|
||||
include: {
|
||||
participants: true,
|
||||
|
@ -30,7 +32,6 @@ async function main() {
|
|||
description: faker.lorem.paragraph(),
|
||||
location: faker.address.streetAddress(),
|
||||
deadline: faker.date.future(),
|
||||
type: "date",
|
||||
user: {
|
||||
connect: {
|
||||
id: user.id,
|
||||
|
@ -46,7 +47,8 @@ async function main() {
|
|||
) //
|
||||
.map((date) => {
|
||||
return {
|
||||
value: date.toISOString().substring(0, 10),
|
||||
start: date,
|
||||
duration,
|
||||
};
|
||||
}),
|
||||
},
|
||||
|
@ -73,7 +75,7 @@ async function main() {
|
|||
data: poll.options.map((option) => {
|
||||
const randomNumber = randInt(100);
|
||||
const vote =
|
||||
randomNumber > 90 ? "ifNeedBe" : randomNumber > 50 ? "yes" : "no";
|
||||
randomNumber > 95 ? "ifNeedBe" : randomNumber > 50 ? "yes" : "no";
|
||||
return {
|
||||
participantId: participant.id,
|
||||
pollId: poll.id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue