본문 바로가기

전체 글

(117)
Uber Eats # 14 User Model 공통으로 사용할 Entity 컬럼을 따로 만들어서 extends를 통해서 사용한다. CreatedDate와 UpdatedDate에는 Special columns를 사용한다. @CreateDateColumn is a 자동으로 엔터티 생성 날짜를 만들어준다. @UpdateDateColumn is a 자동으로 엔터티 업데이트 날짜를 만들어준다. @DeleteDateColumn is a special column that is automatically set to the entity's delete time each time you call soft-delete of entity manager or repository. . @VersionColumn is a special column that is automa..
Uber Eats # 13 User CRUD User Module Relationship + 여러 columns을 통해서 User Model을 만든다. CRUD Account, Log In: password Hash, password 검증, authentication, authorization Middlewares, Metadata like guards Custom decorator 만들기 Test: GraphQL resolver, Unit testing, end-to-end testing
Uber Eats # 12 Create Restaurant entity 파일 하나로 데이터베이스 테이블, graphql type, dto 한 번에 만들기 Mapped types import { InputType, OmitType } from '@nestjs/graphql'; import { Restaurant } from '../entities/restaurant.entity'; @InputType() export class CreateRestaurantDto extends OmitType(Restaurant, ["id"]){} 'Input Object type CreateRestaurantDto must define one or more fields.' base class가 InputType 일 때 동작하는데 반해 restaurant.entity.ts는 아래와..
Uber Eats # 11 Repository Repository를 import 하기 restaurants.module.ts에서 restaurant repository가 필요하다. import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { Restaurant } from './entities/restaurant.entity'; import { RestaurantResolver } from './restaurants.resolver'; @Module({ imports: [TypeOrmModule.forFeature([Restaurant])], providers: [RestaurantResolver], }) export class Res..
Uber Eats # 10 TYPEORM and Nest, Active Record vs Data Mapper @ObjectType은 자동으로 스키마를 빌드하기 위해 사용하는 GraphQL decorator이다. @Entity는 TypeORM이 DB에 entity를 저장한다. Active Record vs Data Mapper NestJS Application에서 Data Mapper를 사용하는 이유는 NestJS + TypeORM 개발환경에서 repository를 사용하는 모듈을 사용할 수 있기 때문이다. 또 어디서든 접근 가능하고 대규모 프로젝트에 적합하다. Repository를 통해서 test하고 simulate까지 해볼 수 있다. //Active Record import {BaseEntity, Entity, PrimaryGeneratedColumn, Column} from "typeorm"; @Entity..
Uber Eats # 9 joi joi는 데이터 유효성 검사 툴이다. npm i joi javascript로 되어있는 패키지를 import 할 때는 아래와 같이 작성한다. import * as Joi from 'joi'; import { Module } from '@nestjs/common'; import * as Joi from 'joi'; import { ConfigModule } from '@nestjs/config'; import { GraphQLModule } from '@nestjs/graphql'; import { TypeOrmModule } from '@nestjs/typeorm'; import { RestaurantsModule } from './restaurants/restaurants.module'; @Module(..
Uber Eats # 8 dotenv dotenv는 .env 파일에 환경변수를 로드한다. nestjs도 이에 대한 configuration이 있다. npm i --save @nestjs/config 설치한다. npm i cross-env 설치한다. 가상 변수를 설정할 수 있다. import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { GraphQLModule } from '@nestjs/graphql'; import { TypeOrmModule } from '@nestjs/typeorm'; import { RestaurantsModule } from './restaurants/restaurants.module'; @Module..
Uber Eats # 7 TYPEORM TYPEORM은 Type을 사용할 수 있고 NestJS와 연계하고 데이터베이스 상호작용 테스트를 할 수 있다. 필수는 아니지만 유용하다. SQL문 대신 코드를 써서 쿼리를 작성할 수 있다. Postgresql 홈페이지에서 다운로드 받기 Pgadmin GUI 다운로드 받기 데이터베이스 만들기 NestJS와 Postgresql 연동하기 npm install --save @nestjs/typeorm typeorm pg 명령어 실행하기 app.module.ts에 TypeOrmModule 추가하기 import { Module } from '@nestjs/common'; import { GraphQLModule } from '@nestjs/graphql'; import { TypeOrmModule } from '@..