Skip to content

Commit

Permalink
demo seed use local timezone instead of UTC
Browse files Browse the repository at this point in the history
because it runs on server
  • Loading branch information
ettorepuccetti committed Nov 15, 2023
1 parent 326b088 commit 9cac0da
Showing 1 changed file with 42 additions and 30 deletions.
72 changes: 42 additions & 30 deletions prisma/seed-demo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { PrismaClient } from "@prisma/client";
import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import {
allEnglandClubName,
centerCourtName,
Expand All @@ -10,6 +12,11 @@ import {
pietrangeliCourtName,
} from "../src/utils/constants";

dayjs.extend(utc);
dayjs.extend(timezone);

dayjs.tz.setDefault("Europe/Rome");

const prisma = new PrismaClient();
async function main() {
//clean up
Expand Down Expand Up @@ -170,28 +177,34 @@ async function main() {
//recurrent reservations (by admin only)
await prisma.recurrentReservation.create({
data: {
startDate: dayjs().startOf("day").toDate(),
endDate: dayjs().add(2, "weeks").startOf("day").toDate(),
startDate: dayjs.tz().startOf("day").toDate(),
endDate: dayjs.tz().add(2, "weeks").startOf("day").toDate(),
reservations: {
createMany: {
data: [
{
overwriteName: "Mini Tennis U10",
courtId: pietrangeli.id,
userId: adminUser.id,
startTime: dayjs().hour(14).startOf("hour").toDate(),
endTime: dayjs().hour(16).startOf("hour").toDate(),
startTime: dayjs.tz().hour(14).startOf("hour").toDate(),
endTime: dayjs.tz().hour(16).startOf("hour").toDate(),
},
{
overwriteName: "Mario Rossi",
overwriteName: "Mini Tennis U10",
courtId: pietrangeli.id,
userId: adminUser.id,
startTime: dayjs()
startTime: dayjs
.tz()
.add(1, "week")
.hour(14)
.startOf("hour")
.toDate(),
endTime: dayjs().add(1, "week").hour(16).startOf("hour").toDate(),
endTime: dayjs
.tz()
.add(1, "week")
.hour(16)
.startOf("hour")
.toDate(),
},
],
},
Expand All @@ -201,28 +214,34 @@ async function main() {

await prisma.recurrentReservation.create({
data: {
startDate: dayjs().startOf("day").toDate(),
endDate: dayjs().add(2, "weeks").startOf("day").toDate(),
startDate: dayjs.tz().startOf("day").toDate(),
endDate: dayjs.tz().add(2, "weeks").startOf("day").toDate(),
reservations: {
createMany: {
data: [
{
overwriteName: "Ago U16",
courtId: court1foro.id,
userId: adminUser.id,
startTime: dayjs().hour(14).startOf("hour").toDate(),
endTime: dayjs().hour(16).startOf("hour").toDate(),
startTime: dayjs.tz().hour(14).startOf("hour").toDate(),
endTime: dayjs.tz().hour(16).startOf("hour").toDate(),
},
{
overwriteName: "Ago U16",
courtId: court1foro.id,
userId: adminUser.id,
startTime: dayjs()
startTime: dayjs
.tz()
.add(1, "week")
.hour(14)
.startOf("hour")
.toDate(),
endTime: dayjs().add(1, "week").hour(16).startOf("hour").toDate(),
endTime: dayjs
.tz()
.add(1, "week")
.hour(16)
.startOf("hour")
.toDate(),
},
],
},
Expand All @@ -236,45 +255,38 @@ async function main() {
{
courtId: pietrangeli.id,
userId: marioRossi.id,
startTime: dayjs().hour(17).startOf("hour").toDate(),
endTime: dayjs().hour(19).startOf("hour").toDate(),
startTime: dayjs.tz().hour(17).startOf("hour").toDate(),
endTime: dayjs.tz().hour(19).startOf("hour").toDate(),
},
{
courtId: centraleForo.id,
userId: demoUser.id,
startTime: dayjs().hour(10).startOf("hour").toDate(),
endTime: dayjs().hour(11).startOf("hour").toDate(),
startTime: dayjs.tz().hour(10).startOf("hour").toDate(),
endTime: dayjs.tz().hour(11).startOf("hour").toDate(),
},
{
courtId: centraleForo.id,
userId: federerUser.id,
startTime: dayjs().hour(12).startOf("hour").toDate(),
endTime: dayjs().hour(13).startOf("hour").toDate(),
startTime: dayjs.tz().hour(12).startOf("hour").toDate(),
endTime: dayjs.tz().hour(13).startOf("hour").toDate(),
},
{
courtId: court1foro.id,
userId: giovanni.id,
startTime: dayjs().hour(19).minute(30).startOf("minute").toDate(),
endTime: dayjs().hour(20).minute(30).startOf("minute").toDate(),
startTime: dayjs.tz().hour(19).minute(30).startOf("minute").toDate(),
endTime: dayjs.tz().hour(20).minute(30).startOf("minute").toDate(),
},
],
});

//admin reservations
await prisma.reservation.createMany({
data: [
{
courtId: court1foro.id,
userId: adminUser.id,
startTime: dayjs().hour(14).startOf("hour").toDate(),
endTime: dayjs().hour(17).startOf("hour").toDate(),
overwriteName: "S.A.T.",
},
{
courtId: centraleForo.id,
userId: adminUser.id,
startTime: dayjs().hour(15).startOf("hour").toDate(),
endTime: dayjs().hour(16).startOf("hour").toDate(),
startTime: dayjs.tz().hour(15).startOf("hour").toDate(),
endTime: dayjs.tz().hour(16).startOf("hour").toDate(),
overwriteName: "Prenotazione esterno",
},
],
Expand Down

0 comments on commit 9cac0da

Please sign in to comment.