From fb0ca6a3ba5fde404f0a02c23c09578162760aba Mon Sep 17 00:00:00 2001 From: Julian Cuni Date: Thu, 8 Sep 2022 21:43:50 +0200 Subject: [PATCH] Migrations! --- .../20220908194155_user_created_updated_at/migration.sql | 3 +++ backend/prisma/schema.prisma | 6 ++++-- backend/src/graphql/graphql.typings.ts | 2 ++ backend/src/main.ts | 2 +- backend/src/users/users.graphql | 2 ++ backend/src/users/users.resolver.ts | 2 +- backend/src/users/users.service.ts | 2 +- 7 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 backend/prisma/migrations/20220908194155_user_created_updated_at/migration.sql diff --git a/backend/prisma/migrations/20220908194155_user_created_updated_at/migration.sql b/backend/prisma/migrations/20220908194155_user_created_updated_at/migration.sql new file mode 100644 index 0000000..b453b1b --- /dev/null +++ b/backend/prisma/migrations/20220908194155_user_created_updated_at/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "User" ADD COLUMN "createdAt" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3); diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index f341611..bb6f92e 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -11,8 +11,10 @@ datasource db { } model User { - id String @id @default(uuid()) - email String @unique + id String @id @default(uuid()) + email String @unique password String? time_joined Int? + createdAt DateTime? @default(now()) + updatedAt DateTime? @updatedAt } diff --git a/backend/src/graphql/graphql.typings.ts b/backend/src/graphql/graphql.typings.ts index 0bb6683..2bf683d 100644 --- a/backend/src/graphql/graphql.typings.ts +++ b/backend/src/graphql/graphql.typings.ts @@ -18,6 +18,8 @@ export class User { email: string; password?: Nullable; time_joined?: Nullable; + createdAt?: Nullable; + updatedAt?: Nullable; } export abstract class IQuery { diff --git a/backend/src/main.ts b/backend/src/main.ts index b9d0211..5f6da9a 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -7,7 +7,7 @@ import { PrismaService } from 'prisma/prisma.service'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.enableCors({ - origin: [process.env.WEBAPP_URL], + origin: [process.env.WEBAPP_URL, 'https://studio.apollographql.com'], allowedHeaders: ['content-type', ...supertokens.getAllCORSHeaders()], credentials: true, }); diff --git a/backend/src/users/users.graphql b/backend/src/users/users.graphql index 1af9e7c..452248e 100644 --- a/backend/src/users/users.graphql +++ b/backend/src/users/users.graphql @@ -5,6 +5,8 @@ type User { email: String! password: String time_joined: Int, + createdAt: DateTime + updatedAt: DateTime } input CreateUserInput { diff --git a/backend/src/users/users.resolver.ts b/backend/src/users/users.resolver.ts index 94046f3..5e1e557 100644 --- a/backend/src/users/users.resolver.ts +++ b/backend/src/users/users.resolver.ts @@ -11,7 +11,7 @@ export class UsersResolver { return this.usersService.create(createUserInput); } @Query('users') - findAll(@Args('params') params: Prisma.UserFindManyArgs) { + findAll(@Args('params') params?: Prisma.UserFindManyArgs) { return this.usersService.users(params); } diff --git a/backend/src/users/users.service.ts b/backend/src/users/users.service.ts index 0a443ff..90f278c 100644 --- a/backend/src/users/users.service.ts +++ b/backend/src/users/users.service.ts @@ -10,7 +10,7 @@ export class UsersService { return await this.prismaService.user.findUnique({ where: uniqueInput }); } - async users(params: Prisma.UserFindManyArgs) { + async users(params?: Prisma.UserFindManyArgs) { return await this.prismaService.user.findMany(params); }