본문 바로가기

Uber Eats

Uber Eats # 6 validator

npm i class-validator, npm i class-transformer를 설치한다.

 

import { ArgsType, Field } from '@nestjs/graphql';
import { IsBoolean, IsString, Length } from 'class-validator';

@ArgsType()
export class CreateRestaurantDto {
  @Field(type => String)
  @IsString()
  @Length(5, 10)
  name: string;

  @Field(type => Boolean)
  @IsBoolean()
  isVegan: boolean;

  @Field(type => String)
  @IsString()
  address: string;

  @Field(type => String)
  @IsString()
  ownersName: string;
}
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalPipes(
    new ValidationPipe()
  );
  await app.listen(3000);
}
bootstrap();

'Uber Eats' 카테고리의 다른 글

Uber Eats # 8 dotenv  (0) 2021.03.06
Uber Eats # 7 TYPEORM  (0) 2021.03.06
Uber Eats # 5 Arguments, Mutation  (0) 2021.03.06
Uber Eats # 4 entity ObjectType  (0) 2021.03.06
Uber Eats # 3 Apollo server  (0) 2021.03.06