Data 처리 및 저장

User Data Users service 이제 유저서비스를 다뤄보자. users.service.ts 파일을 수정하자 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 // users.service.ts import { Injectable } from '@nestjs/common'; import { Repository } from 'typeorm'; import { InjectRepository } from '@nestjs/typeorm'; import { User } from './user.entity'; @Injectable() export class UsersService { // repo : argument name // Repository<User> : User type을 다루는 Repository에 접근하여 instance를 받는다. // @InjtectRepository(User) : DI 시스템에게 우리가 User Repository가 필요하다는것을 말하는 코드 // DI 시스템은 뒤에 Repository<User>부분에서 inject할 인스턴스가 무엇인지 파악하기 위해 // type annotation 한다. generic에는 잘 작동 안하니까 앞에 decorator를 통해 더 분명히 제공한 것. constructor(@InjectRepository(User) private repo: Repository<User>) {} // create는 service 내에서 받은 정보(email과 password)로 User Entity Instance를 만든다. // save는 entity instance를 실제 Database에 저장해준다. create(email: string, password: string) { const user = this.repo.create({ email, password }); return this.repo.save(user); } } 이제 컨트롤러에 넣어보자 ...

2023년 10월 7일 · 9 분 · 배준수

Typescript 언어의 특징 알아보기

Typescript 개념 Typescript = Javascript + A type system 이다. TS Type System의 특징은 다음과 같다. 개발 중 에러 포착 가능 type annotation 개발중에만 active된다 성능 최적화 없음 TS를 작성하지만 실제론 컴파일러에선 JS를 실행하는 것이다! 자세히 말하자면, 사실 JS를 작성하고 Type annotiation 추가하는 것이 TS를 작성하는 것. 이 과정을 풀어서 설명하자면 Typescript code = Javascript with type annotations -> Typescript Compiler -> Plain old Javascript 인 것이다. json 데이터 받아오기 교육용 Json 사이트 를 접속해서 밑의 resource에 todo를 들어가보자 ...

2023년 10월 4일 · 4 분 · 배준수