Add prisma:generate script to package.json
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"prisma:generate": "npx prisma generate --schema=./epess-database/prisma/schema.prisma",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
|
||||
@@ -1,20 +1,33 @@
|
||||
import { Resolver, Query, Mutation, Args } from '@nestjs/graphql';
|
||||
import { PrismaService } from 'src/prisma/prisma.service';
|
||||
import { User } from '@prisma/client';
|
||||
import { User } from 'src/types/user.type';
|
||||
import { Role } from '@prisma/client';
|
||||
|
||||
@Resolver('User')
|
||||
export class GraphqlResolver {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
@Query(() => [User])
|
||||
async users(): Promise<User[]> {
|
||||
async users(): Promise<
|
||||
{
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
password: string;
|
||||
phoneNumber: string;
|
||||
oauthToken: string | null;
|
||||
role: Role;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}[]
|
||||
> {
|
||||
return this.prismaService.user.findMany();
|
||||
}
|
||||
|
||||
@Mutation(() => User)
|
||||
async createUser(
|
||||
@Args('email') email: string,
|
||||
@Args('name', { nullable: true }) name?: string,
|
||||
@Args('name') name: string,
|
||||
): Promise<User> {
|
||||
return this.prismaService.user.create({
|
||||
data: {
|
||||
|
||||
51
src/types/user.type.ts
Normal file
51
src/types/user.type.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { ObjectType, Field, Int } from '@nestjs/graphql';
|
||||
import {
|
||||
User as PrismaUser,
|
||||
Role,
|
||||
Order,
|
||||
UploadedDocument,
|
||||
Chat,
|
||||
Feedback,
|
||||
} from '@prisma/client';
|
||||
|
||||
@ObjectType()
|
||||
export class User implements PrismaUser {
|
||||
@Field(() => Int)
|
||||
id: string;
|
||||
|
||||
@Field()
|
||||
name: string;
|
||||
|
||||
@Field()
|
||||
email: string;
|
||||
|
||||
@Field()
|
||||
password: string;
|
||||
|
||||
@Field()
|
||||
phoneNumber: string;
|
||||
|
||||
@Field()
|
||||
oauthToken: string | null;
|
||||
|
||||
@Field()
|
||||
role: Role;
|
||||
|
||||
@Field()
|
||||
createdAt: Date;
|
||||
|
||||
@Field()
|
||||
updatedAt: Date;
|
||||
|
||||
@Field()
|
||||
orders: Order[];
|
||||
|
||||
@Field()
|
||||
feedbacks: Feedback[];
|
||||
|
||||
@Field()
|
||||
chats: Chat[];
|
||||
|
||||
@Field()
|
||||
documents: UploadedDocument[];
|
||||
}
|
||||
Reference in New Issue
Block a user