New and Improved Screens (#1151)

This commit is contained in:
Luke Vella 2024-06-19 11:14:18 +01:00 committed by GitHub
parent 5461c57228
commit 997a1eec78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
75 changed files with 1517 additions and 743 deletions

View file

@ -1,13 +1,31 @@
import { PrismaClient } from "@rallly/database";
import { PrismaClient } from "@prisma/client";
export * from "@prisma/client";
export type * from "@prisma/client";
declare global {
// allow global `var` declarations
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}
const prismaClientSingleton = () => {
return new PrismaClient().$extends({
query: {
poll: {
findMany: ({ args, query }) => {
if (!args.where?.deleted) {
args.where = { ...args.where, deleted: false };
}
export const prisma = global.prisma || new PrismaClient();
return query(args);
},
},
},
});
};
if (process.env.NODE_ENV !== "production") global.prisma = prisma;
export type ExtendedPrismaClient = ReturnType<typeof prismaClientSingleton>;
declare const globalThis: {
prismaGlobal: ExtendedPrismaClient;
} & typeof global;
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton();
export { prisma };
if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = prisma;

View file

@ -9,13 +9,12 @@
"db:migrate": "prisma migrate dev",
"db:seed": "tsx prisma/seed.ts"
},
"main": "./index.ts",
"types": "./index.ts",
"exports": "./index.ts",
"devDependencies": {
"@faker-js/faker": "^7.6.0",
"@rallly/tsconfig": "*",
"@types/node": "^18.15.10",
"prisma": "^5.3.1",
"prisma": "^5.15.0",
"tsx": "^4.6.2"
}
}

View file

@ -159,7 +159,7 @@ model Event {
duration Int @default(0) @map("duration_minutes")
createdAt DateTime @default(now()) @map("created_at")
Poll Poll?
poll Poll?
@@index([userId], type: Hash)
@@map("events")

View file

@ -11,7 +11,7 @@ const randInt = (max = 1, floor = 0) => {
async function createPollsForUser(userId: string) {
// Create some polls
const polls = await Promise.all(
Array.from({ length: 20 }).map(async (_, i) => {
Array.from({ length: 5 }).map(async (_, i) => {
// create some polls with no duration (all day) and some with a random duration.
const duration = i % 2 === 0 ? 60 * randInt(8, 1) : 0;
let cursor = dayjs().add(randInt(30), "day").second(0).minute(0);
@ -25,7 +25,7 @@ async function createPollsForUser(userId: string) {
},
data: {
id: faker.random.alpha(10),
title: `${faker.animal.cat()} meetup - ${faker.date.month()}`,
title: `${faker.animal.cat()} Meetup ${faker.date.month()}`,
description: faker.lorem.paragraph(),
location: faker.address.streetAddress(),
deadline: faker.date.future(),
@ -34,7 +34,7 @@ async function createPollsForUser(userId: string) {
id: userId,
},
},
timeZone: duration !== 0 ? "America/New_York" : undefined,
timeZone: duration !== 0 ? "Europe/London" : undefined,
options: {
create: Array.from({ length: numberOfOptions }).map(() => {
const startTime = cursor.toDate();