diff --git a/be/.gitignore b/be/.gitignore index 22f55adc..c4e6ba84 100644 --- a/be/.gitignore +++ b/be/.gitignore @@ -2,6 +2,9 @@ /dist /node_modules +#config +typeorm.config.ts + # Logs logs *.log diff --git a/be/src/app.module.ts b/be/src/app.module.ts index f953c1a4..63c2d113 100644 --- a/be/src/app.module.ts +++ b/be/src/app.module.ts @@ -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 {} diff --git a/be/src/user/entities/user.entity.ts b/be/src/user/entities/user.entity.ts new file mode 100644 index 00000000..676811c4 --- /dev/null +++ b/be/src/user/entities/user.entity.ts @@ -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; + } + \ No newline at end of file diff --git a/be/src/user/user.module.ts b/be/src/user/user.module.ts index 3e2e48b3..286fb14e 100644 --- a/be/src/user/user.module.ts +++ b/be/src/user/user.module.ts @@ -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 {} diff --git a/be/src/user/user.repository.ts b/be/src/user/user.repository.ts new file mode 100644 index 00000000..6e37868a --- /dev/null +++ b/be/src/user/user.repository.ts @@ -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 { + constructor(private dataSource: DataSource){ + super(User, dataSource.createEntityManager()); + } + async createUser(userinfoDto: UserInfoDto): Promise { + const newUser = this.create(userinfoDto); + await this.save(newUser); + return; + } +} \ No newline at end of file diff --git a/be/src/user/user.service.ts b/be/src/user/user.service.ts index 37dd2fb8..5f63889d 100644 --- a/be/src/user/user.service.ts +++ b/be/src/user/user.service.ts @@ -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; + } }