본문 바로가기

Uber Eats

(29)
Uber Eats # 4 entity ObjectType entity는 데이터베이스 모델이다. restaurants 아래 entities를 만들고 restaurant.entity.ts 아래 코드를 작성한다. import { Field, ObjectType } from "@nestjs/graphql"; @ObjectType() export class Restaurant { @Field(type => String) name: string; @Field(type => Boolean, {nullable: true}) isGood?: boolean; } resolver를 아래와 같이 변경한다. import { Query, Resolver } from "@nestjs/graphql"; import { Restaurant } from "./entities/restauran..
Uber Eats # 3 Apollo server Apollo server에 원하는 세팅을 보낼 수 있다. typeDefs DocumentNode or Array Required. Document or documents that represent your server's GraphQL schema, generated by applying the gql tag to valid Schema Definition Language (SDL) strings. resolvers Object or Array Required. A map of functions that populate data for individual schema fields. Can also be an array of multiple maps that are merged. 세팅을 하는 방법에는 Co..
Uber Eats # 2 graphql graphql document를 참고해서 설치하기 $ npm i @nestjs/graphql graphql-tools graphql apollo-server-express graphql과 apollo-server-express로 동작 app.module.ts를 제외하고 나머지 삭제(app.controller.spec.ts, app.controller.ts, app.service.ts) app.module은 main.ts에서 import되는 유일한 모듈이다. main.ts는 application을 실행해준다. NestFactory가 AppModule로부터 application을 생성한다. 따라서 AppModule이 데이터베이스를 가져오고 GraphQL 등등을 다 가져온다. GraphQL 모듈을 AppMod..
Uber Eats # 1 nest, gitignore, github Nest를 활용해서 프로젝트 생성하기 nest g application project name: nuber-eats-backend 생성 후 visual studio code에서 npm i를 통해 필요한 패키지 설치 npm run start:dev 명령어 실행 후 localhost:3000 접속하면 Hello World!를 볼 수 있다. github.com에서 Repository 생성하기 프로젝트에서 git init git remote add origin {HTTP} 5000개가 넘는 파일을 커밋해야 하는 상황 gitignore를 통해 필요한 파일만 업로드하기 플로그인 gitignore를 설치하고 command palette를 클릭하고 add gitignore 후 node를 찾아서 엔터를 누른다. 자동으로..
# 3-1 NestJS - 구조 파악하기 @Module 등 데코레이터를 사용한다. 데코레이터는 클래스에 함수 기능을 추가할 수 있다. 클래스 위에 있는 함수라고 생각하면 된다.
# 3-0 Nest.js NetsJS는 node.js 위에서 동작하는 프레임워크 백엔드를 쉽게 구성하게 해준다. express 위에서 동작하는 것도 가능 node.js에서는 컨트롤러, 템플릿 등을 원하는대로 작성할 수 있지만 NestJS에서는 정해진 규칙을 따라야 한다. 객체지향 프로그래밍과 함수형 프로그래밍, 함수반응형 프로그래밍 요소를 사용한다. REST API 테스트를 위해서 Insomnia를 설치해야한다. npm i -g @nestjs/cli로 설치하고 nest new를 통해서 프로젝트를 생성한다. github.com/hwan02/hey-nest
# 2-5 TypeScript - BlockChain TypeScript는 import 과정이 다르다. import * as CryptoJS from "crypto-js"; Hash를 사용하기 위해서 crypto-js를 설치한다. class 안에서 method 접근 생성자에 따라서 Class 내 Block 생성 후 method에 접근여부가 달라진다. static을 지정하면 접근가능하다. // 예를 들면 sayHello = () => {return "Hello"}; //Block을 생성하지 않고는 sayHello에 접근할 수 없다. //Block.sayHello //Block을 생성하지 않고 접근하려면 아래와 같이 생성한다. static sayHello2 = ():string => {return "Hello"}; //접근 가능하다. Block.sayHello2
# 2-4 TypeScript - class interface는 js로 컴파일 되지 않는다. interface 대신에 class를 쓴다. class Human { public name: string; public age: number; public gender: string; constructor(name: stiring, age: number, gender: string) { this.name = string; this.age = number; this.gender = string; } } const daniel = new Human("Daniel", 30, "male"); const sayHi = (person): string => { return `Hello ${person.name}, you are ${person.age}, you are ..