forked from yy0ung/nibobnebob
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- table과 매핑될 user entity 생성 - DB관련 작업을 진행할 user repository 생성 - user module의 providers 배열에 repository 추가 - service에서 의존성 주입 - db관련 config 생성 및 app module에 import Co-authored-by: GeunH <[email protected]>
- Loading branch information
Showing
6 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
/dist | ||
/node_modules | ||
|
||
#config | ||
typeorm.config.ts | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { UserModule } from "./user/user.module"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { typeORMConfig } from "./configs/typeorm.config"; | ||
|
||
@Module({ | ||
imports: [UserModule], | ||
imports: [UserModule, TypeOrmModule.forRoot(typeORMConfig)], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
CreateDateColumn, | ||
UpdateDateColumn, | ||
DeleteDateColumn | ||
} from 'typeorm'; | ||
|
||
@Entity() | ||
export class User { | ||
@PrimaryGeneratedColumn('increment') | ||
id: number; | ||
|
||
@Column({ type: 'varchar', length: 20, unique : true }) | ||
nickName: string; | ||
|
||
@Column({ type: 'varchar', length: 50 }) | ||
email: string; | ||
|
||
@Column({ type: 'int' }) | ||
age: number; | ||
|
||
@Column({ type: 'boolean' }) | ||
gender: boolean; | ||
|
||
@Column({ type: 'varchar', length: 50, nullable: true }) | ||
password: string | null; | ||
|
||
@Column({ type: 'varchar', length: 20, nullable: true }) | ||
social_provider: string | null; | ||
|
||
@CreateDateColumn({ type: 'timestamp' }) | ||
created_at: Date; | ||
|
||
@DeleteDateColumn({ type: 'timestamp', nullable: true}) | ||
deleted_at: Date | null; | ||
|
||
@UpdateDateColumn({ type: 'timestamp'}) | ||
updated_at: Date; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { UserController } from "./user.controller"; | ||
import { UserService } from "./user.service"; | ||
import { UserRepository } from "./user.repository"; | ||
|
||
@Module({ | ||
controllers: [UserController], | ||
providers: [UserService], | ||
providers: [UserService, UserRepository], | ||
}) | ||
export class UserModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { DataSource, Repository } from 'typeorm'; | ||
import { User } from './entities/user.entity'; | ||
import { UserInfoDto } from './dto/userInfo.dto'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class UserRepository extends Repository<User> { | ||
constructor(private dataSource: DataSource){ | ||
super(User, dataSource.createEntityManager()); | ||
} | ||
async createUser(userinfoDto: UserInfoDto): Promise<User> { | ||
const newUser = this.create(userinfoDto); | ||
await this.save(newUser); | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { UserInfoDto } from "./dto/userInfo.dto"; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { User } from './entities/user.entity'; | ||
import { UserRepository } from "./user.repository"; | ||
|
||
@Injectable() | ||
export class UserService { | ||
signup(userInfoDto: UserInfoDto) { | ||
const { email, password, provider, nickName, age, gender } = userInfoDto; | ||
|
||
// DB에 저장 | ||
|
||
return userInfoDto; | ||
} | ||
constructor( | ||
@InjectRepository(UserRepository) | ||
private usersRepository: UserRepository, | ||
) {} | ||
signup(userInfoDto: UserInfoDto) { | ||
this.usersRepository.createUser(userInfoDto); | ||
return; | ||
} | ||
} |