diff --git a/backend/package.json b/backend/package.json index ce8bc46..18380ea 100644 --- a/backend/package.json +++ b/backend/package.json @@ -20,7 +20,7 @@ "test:e2e": "jest --config ./test/jest-e2e.json", "gen:types": "ts-node ./graphql/generate.typings", "prisma:gen": "prisma generate --watch", - "dev": "concurrently \"yarn:start:dev\" \"yarn:gen:types\" \"yarn:prisma:gen\"" + "dev": "concurrently \"npm:start:dev\" \"npm:gen:types\" \"npm:prisma:gen\"" }, "dependencies": { "@nestjs/apollo": "^10.1.0", diff --git a/backend/prisma/migrations/20220908181816_user_pass/migration.sql b/backend/prisma/migrations/20220908181816_user_pass/migration.sql new file mode 100644 index 0000000..e074ed2 --- /dev/null +++ b/backend/prisma/migrations/20220908181816_user_pass/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "User" ADD COLUMN "password" TEXT, +ALTER COLUMN "time_joined" DROP NOT NULL; diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index f693828..f341611 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -11,7 +11,8 @@ datasource db { } model User { - id String @id @default(uuid()) - email String @unique - time_joined Int + id String @id @default(uuid()) + email String @unique + password String? + time_joined Int? } diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 98d2bed..89b34a1 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -4,7 +4,7 @@ import { AuthModule } from './auth/auth.module'; import { ConfigModule } from '@nestjs/config'; import { GraphQLISODateTime, GraphQLModule } from '@nestjs/graphql'; import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'; -// import { ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core'; +import { ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core'; import { UsersModule } from './users/users.module'; @Module({ @@ -25,9 +25,9 @@ import { UsersModule } from './users/users.module'; driver: ApolloDriver, typePaths: ['./**/*.graphql'], debug: true, - playground: true, - resolvers: {DateTime: GraphQLISODateTime} - // plugins: [ApolloServerPluginLandingPageLocalDefault()], + playground: false, + resolvers: { DateTime: GraphQLISODateTime }, + plugins: [ApolloServerPluginLandingPageLocalDefault()], }), UsersModule, ], diff --git a/backend/src/graphql/graphql.typings.ts b/backend/src/graphql/graphql.typings.ts index 55a0690..0bb6683 100644 --- a/backend/src/graphql/graphql.typings.ts +++ b/backend/src/graphql/graphql.typings.ts @@ -16,7 +16,8 @@ export class CreateUserInput { export class User { id: string; email: string; - time_joined: number; + password?: Nullable; + time_joined?: Nullable; } export abstract class IQuery { diff --git a/backend/src/users/users.graphql b/backend/src/users/users.graphql index b34f0cc..1af9e7c 100644 --- a/backend/src/users/users.graphql +++ b/backend/src/users/users.graphql @@ -3,7 +3,8 @@ scalar DateTime type User { id: String! email: String! - time_joined: Int! + password: String + time_joined: Int, } input CreateUserInput { diff --git a/backend/src/users/users.resolver.ts b/backend/src/users/users.resolver.ts index 371d503..94046f3 100644 --- a/backend/src/users/users.resolver.ts +++ b/backend/src/users/users.resolver.ts @@ -1,5 +1,5 @@ import { Resolver, Query, Mutation, Args } from '@nestjs/graphql'; -import { CreateUserInput } from 'graphql/graphql.typings'; +import { Prisma } from '@prisma/client'; import { UsersService } from './users.service'; @Resolver('User') @@ -7,12 +7,12 @@ export class UsersResolver { constructor(private readonly usersService: UsersService) {} @Mutation('createUser') - // create(@Args('createUserInput') createUserInput: CreateUserInput) { - // return this.usersService.create(createUserInput); - // } + create(@Args('createUserInput') createUserInput: Prisma.UserCreateInput) { + return this.usersService.create(createUserInput); + } @Query('users') - findAll() { - return this.usersService.users({}); + findAll(@Args('params') params: Prisma.UserFindManyArgs) { + return this.usersService.users(params); } @Query('user') diff --git a/backend/src/users/users.service.ts b/backend/src/users/users.service.ts index b05e1e2..0a443ff 100644 --- a/backend/src/users/users.service.ts +++ b/backend/src/users/users.service.ts @@ -1,5 +1,4 @@ import { Injectable } from '@nestjs/common'; -import { CreateUserInput } from 'graphql/graphql.typings'; import { Prisma, User } from '@prisma/client'; import { PrismaService } from 'prisma/prisma.service'; @@ -11,19 +10,13 @@ export class UsersService { return await this.prismaService.user.findUnique({ where: uniqueInput }); } - async users(params: { - skip?: number; - take?: number; - cursor?: Prisma.UserWhereUniqueInput; - where?: Prisma.UserWhereInput; - orderBy?: Prisma.UserOrderByWithRelationInput; - }) { + async users(params: Prisma.UserFindManyArgs) { return await this.prismaService.user.findMany(params); } - // create(createUserInput: CreateUserInput) { - // return 'This action adds a new user'; - // } + create(createUserInput: Prisma.UserCreateInput) { + return this.prismaService.user.create({ data: createUserInput }); + } // findAll() { // return `This action returns all users`;