From 196f240267ea68a636d6a66f6b202cae67960505 Mon Sep 17 00:00:00 2001 From: GeunH Date: Thu, 23 Nov 2023 00:18:31 +0900 Subject: [PATCH] =?UTF-8?q?style=20:=20prettier=20=EC=A0=81=EC=9A=A9=20#35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: LeeTH916 --- be/src/app.module.ts | 16 ++- be/src/auth/auth.module.ts | 2 +- be/src/auth/auth.service.ts | 15 +-- be/src/auth/dto/refreshToken.dto.ts | 13 +-- be/src/custom.logger.ts | 91 ++++++++-------- be/src/logger.interceptor.ts | 66 ++++++------ be/src/restaurant/dto/restaurantInfo.dto.ts | 19 ++-- be/src/restaurant/dto/seachInfo.dto.ts | 12 +-- .../restaurant/entities/restaurant.entity.ts | 63 ++++++----- .../restaurant/restaurant.controller.spec.ts | 8 +- be/src/restaurant/restaurant.controller.ts | 4 +- be/src/restaurant/restaurant.module.ts | 12 +-- be/src/restaurant/restaurant.repository.ts | 12 ++- be/src/restaurant/restaurant.service.spec.ts | 8 +- be/src/restaurant/restaurant.service.ts | 37 ++++--- be/src/review/dto/reviewInfo.dto.ts | 100 ++++++++++-------- be/src/review/entities/review.entity.ts | 65 +++++++----- be/src/review/review.module.ts | 2 +- .../user/entities/user.followList.entity.ts | 39 ++++--- .../entities/user.restaurantlist.entity.ts | 20 ++-- be/src/user/user.controller.ts | 6 +- be/src/user/user.module.ts | 2 +- be/src/user/user.repository.ts | 4 +- be/src/user/user.service.spec.ts | 70 ++++++------ be/src/user/user.service.ts | 2 +- be/src/utils/encryption.utils.ts | 11 +- 26 files changed, 374 insertions(+), 325 deletions(-) diff --git a/be/src/app.module.ts b/be/src/app.module.ts index f51e7dbf..8223b0c6 100644 --- a/be/src/app.module.ts +++ b/be/src/app.module.ts @@ -3,14 +3,20 @@ import { UserModule } from "./user/user.module"; import { TypeOrmModule } from "@nestjs/typeorm"; import { typeORMConfig } from "./configs/typeorm.config"; import { AuthModule } from "./auth/auth.module"; -import { RestaurantModule } from './restaurant/restaurant.module'; -import { ReviewModule } from './review/review.module'; +import { RestaurantModule } from "./restaurant/restaurant.module"; +import { ReviewModule } from "./review/review.module"; import { CustomLoggerService } from "./custom.logger"; -import { APP_INTERCEPTOR } from '@nestjs/core'; +import { APP_INTERCEPTOR } from "@nestjs/core"; import { LoggingInterceptor } from "./logger.interceptor"; @Module({ - imports: [UserModule, TypeOrmModule.forRoot(typeORMConfig), AuthModule, RestaurantModule, ReviewModule], + imports: [ + UserModule, + TypeOrmModule.forRoot(typeORMConfig), + AuthModule, + RestaurantModule, + ReviewModule, + ], providers: [ CustomLoggerService, { @@ -19,4 +25,4 @@ import { LoggingInterceptor } from "./logger.interceptor"; }, ], }) -export class AppModule { } +export class AppModule {} diff --git a/be/src/auth/auth.module.ts b/be/src/auth/auth.module.ts index 4b2ae9a6..7606b236 100644 --- a/be/src/auth/auth.module.ts +++ b/be/src/auth/auth.module.ts @@ -21,4 +21,4 @@ import { JwtStrategy } from "./strategy/jwt.strategy"; providers: [AuthService, JwtStrategy], exports: [PassportModule], }) -export class AuthModule { } +export class AuthModule {} diff --git a/be/src/auth/auth.service.ts b/be/src/auth/auth.service.ts index 80c4505e..3b718b3b 100644 --- a/be/src/auth/auth.service.ts +++ b/be/src/auth/auth.service.ts @@ -13,7 +13,7 @@ export class AuthService { constructor( private userRepository: UserRepository, private jwtService: JwtService - ) { } + ) {} async NaverAuth(authorization: string) { if (!authorization) { throw new HttpException( @@ -46,12 +46,11 @@ export class AuthService { const accessToken = this.jwtService.sign(payload); const refreshToken = this.jwtService.sign(payload, { - secret: "nibobnebob", - expiresIn: '7d', + secret: "nibobnebob", + expiresIn: "7d", }); return { accessToken, refreshToken }; - } else { throw new NotFoundException( "사용자가 등록되어 있지 않습니다. 회원가입을 진행해주세요" @@ -59,14 +58,16 @@ export class AuthService { } } - async checkRefreshToken(refreshToken: string){ + async checkRefreshToken(refreshToken: string) { try { - const decoded = this.jwtService.verify(refreshToken, { secret: 'nibobnebob' }); + const decoded = this.jwtService.verify(refreshToken, { + secret: "nibobnebob", + }); const payload = { id: decoded.id }; const accessToken = this.jwtService.sign(payload); return { accessToken }; } catch (err) { - throw new HttpException('Invalid refresh token', HttpStatus.UNAUTHORIZED); + throw new HttpException("Invalid refresh token", HttpStatus.UNAUTHORIZED); } } } diff --git a/be/src/auth/dto/refreshToken.dto.ts b/be/src/auth/dto/refreshToken.dto.ts index 557ee5c5..16410065 100644 --- a/be/src/auth/dto/refreshToken.dto.ts +++ b/be/src/auth/dto/refreshToken.dto.ts @@ -1,9 +1,10 @@ import { ApiProperty } from "@nestjs/swagger"; export class RefreshTokenDto { - @ApiProperty({ - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", - description: "클라이언트가 가지고 있는 refreshToken", - }) - refreshToken: string; - } \ No newline at end of file + @ApiProperty({ + example: + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", + description: "클라이언트가 가지고 있는 refreshToken", + }) + refreshToken: string; +} diff --git a/be/src/custom.logger.ts b/be/src/custom.logger.ts index 17d9d579..e9a60112 100644 --- a/be/src/custom.logger.ts +++ b/be/src/custom.logger.ts @@ -1,55 +1,56 @@ -import { Injectable, LoggerService } from '@nestjs/common'; -import * as winston from 'winston'; +import { Injectable, LoggerService } from "@nestjs/common"; +import * as winston from "winston"; @Injectable() export class CustomLoggerService implements LoggerService { - private logger: winston.Logger; - - constructor() { - this.logger = winston.createLogger({ - level: 'info', - format: winston.format.combine( - winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), - winston.format.printf(({ level, message, timestamp, stack = '' }) => { - return `${timestamp} ${level}: ${message} ${stack} `; - }), - ), - transports: [ - new winston.transports.File({ filename: 'error.log', level: 'error' }), - new winston.transports.File({ filename: 'combined.log' }), - ], - - }); - - if (process.env.NODE_ENV !== 'production') { - this.logger.add(new winston.transports.Console({ - format: winston.format.combine( - winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), - winston.format.printf(({ level, message, timestamp }) => { - return `${timestamp} ${level}: ${message}`; - }) - ), - })); - } + private logger: winston.Logger; + + constructor() { + this.logger = winston.createLogger({ + level: "info", + format: winston.format.combine( + winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), + winston.format.printf(({ level, message, timestamp, stack = "" }) => { + return `${timestamp} ${level}: ${message} ${stack} `; + }) + ), + transports: [ + new winston.transports.File({ filename: "error.log", level: "error" }), + new winston.transports.File({ filename: "combined.log" }), + ], + }); + + if (process.env.NODE_ENV !== "production") { + this.logger.add( + new winston.transports.Console({ + format: winston.format.combine( + winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), + winston.format.printf(({ level, message, timestamp }) => { + return `${timestamp} ${level}: ${message}`; + }) + ), + }) + ); } + } - log(message: string) { - this.logger.info(message); - } + log(message: string) { + this.logger.info(message); + } - error(message: string, trace: string) { - this.logger.error({ message, stack: trace }); - } + error(message: string, trace: string) { + this.logger.error({ message, stack: trace }); + } - warn(message: string) { - this.logger.warn(message); - } + warn(message: string) { + this.logger.warn(message); + } - debug(message: string) { - this.logger.debug(message); - } + debug(message: string) { + this.logger.debug(message); + } - verbose(message: string) { - this.logger.verbose(message); - } + verbose(message: string) { + this.logger.verbose(message); + } } diff --git a/be/src/logger.interceptor.ts b/be/src/logger.interceptor.ts index 213cc981..17278ac8 100644 --- a/be/src/logger.interceptor.ts +++ b/be/src/logger.interceptor.ts @@ -1,41 +1,43 @@ // logging.interceptor.ts import { - Injectable, - NestInterceptor, - ExecutionContext, - CallHandler, - HttpStatus -} from '@nestjs/common'; -import { Observable, throwError } from 'rxjs'; -import { tap, catchError } from 'rxjs/operators'; -import { CustomLoggerService } from './custom.logger'; + Injectable, + NestInterceptor, + ExecutionContext, + CallHandler, + HttpStatus, +} from "@nestjs/common"; +import { Observable, throwError } from "rxjs"; +import { tap, catchError } from "rxjs/operators"; +import { CustomLoggerService } from "./custom.logger"; @Injectable() export class LoggingInterceptor implements NestInterceptor { - constructor(private logger: CustomLoggerService) { } + constructor(private logger: CustomLoggerService) {} - intercept(context: ExecutionContext, next: CallHandler): Observable { - const now = Date.now(); - const request = context.switchToHttp().getRequest(); - const response = context.switchToHttp().getResponse(); - const { method, url } = request; - const clientIp = request.ip || request.headers['x-forwarded-for']; + intercept(context: ExecutionContext, next: CallHandler): Observable { + const now = Date.now(); + const request = context.switchToHttp().getRequest(); + const response = context.switchToHttp().getResponse(); + const { method, url } = request; + const clientIp = request.ip || request.headers["x-forwarded-for"]; - return next - .handle() - .pipe( - tap(() => { - const { statusCode } = response; - const delay = Date.now() - now; - this.logger.log(`[Success] ${clientIp} ${method} ${url} ${statusCode} ${delay}ms`); - }), - catchError((error) => { - const status = error.status || HttpStatus.INTERNAL_SERVER_ERROR; - this.logger.error(`[Error] ${clientIp} ${method} ${url} ${status} ${error.message}`, error.stack); - - return throwError(error); - }), - ); - } + return next.handle().pipe( + tap(() => { + const { statusCode } = response; + const delay = Date.now() - now; + this.logger.log( + `[Success] ${clientIp} ${method} ${url} ${statusCode} ${delay}ms` + ); + }), + catchError((error) => { + const status = error.status || HttpStatus.INTERNAL_SERVER_ERROR; + this.logger.error( + `[Error] ${clientIp} ${method} ${url} ${status} ${error.message}`, + error.stack + ); + return throwError(error); + }) + ); + } } diff --git a/be/src/restaurant/dto/restaurantInfo.dto.ts b/be/src/restaurant/dto/restaurantInfo.dto.ts index 717c2410..b0c66b77 100644 --- a/be/src/restaurant/dto/restaurantInfo.dto.ts +++ b/be/src/restaurant/dto/restaurantInfo.dto.ts @@ -1,15 +1,12 @@ import { ApiProperty } from "@nestjs/swagger"; -import { - IsNotEmpty, - IsInt, -} from "class-validator"; +import { IsNotEmpty, IsInt } from "class-validator"; export class RestaurantInfoDto { - @ApiProperty({ - example: "음식점 id", - description: "The id of the restaurant", - }) - @IsInt() - @IsNotEmpty() - id: number; + @ApiProperty({ + example: "음식점 id", + description: "The id of the restaurant", + }) + @IsInt() + @IsNotEmpty() + id: number; } diff --git a/be/src/restaurant/dto/seachInfo.dto.ts b/be/src/restaurant/dto/seachInfo.dto.ts index 570c5f19..de3b669f 100644 --- a/be/src/restaurant/dto/seachInfo.dto.ts +++ b/be/src/restaurant/dto/seachInfo.dto.ts @@ -1,7 +1,7 @@ export class SearchInfoDto { - constructor( - public partitalName: string, - public location: string, - public radius: number, - ){} -} \ No newline at end of file + constructor( + public partitalName: string, + public location: string, + public radius: number + ) {} +} diff --git a/be/src/restaurant/entities/restaurant.entity.ts b/be/src/restaurant/entities/restaurant.entity.ts index 0185066f..914a9cca 100644 --- a/be/src/restaurant/entities/restaurant.entity.ts +++ b/be/src/restaurant/entities/restaurant.entity.ts @@ -1,41 +1,48 @@ -import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Unique } from 'typeorm'; -import { Point } from 'geojson' +import { + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + UpdateDateColumn, + Unique, +} from "typeorm"; +import { Point } from "geojson"; @Unique("unique_name_location", ["name", "location"]) -@Entity('restaurant') +@Entity("restaurant") export class RestaurantInfoEntity { - @PrimaryGeneratedColumn('increment') - id: number; + @PrimaryGeneratedColumn("increment") + id: number; - @Column({ type: 'varchar', length: 100 }) - name: string; + @Column({ type: "varchar", length: 100 }) + name: string; - @Column({ - type: 'geometry', - spatialFeatureType: 'Point', - srid: 4326, - nullable: true, - }) - location: Point; + @Column({ + type: "geometry", + spatialFeatureType: "Point", + srid: 4326, + nullable: true, + }) + location: Point; - @Column({ type: 'text', nullable: true }) - address: string | null; + @Column({ type: "text", nullable: true }) + address: string | null; - @Column({ type: 'varchar', length: 50, nullable: true }) - category: string | null; + @Column({ type: "varchar", length: 50, nullable: true }) + category: string | null; - @Column({ type: 'int', default: 0 }) - reviewCnt: number; + @Column({ type: "int", default: 0 }) + reviewCnt: number; - @Column({ type: 'varchar', length: 20, nullable: true }) - phoneNumber: string | null; + @Column({ type: "varchar", length: 20, nullable: true }) + phoneNumber: string | null; - @CreateDateColumn({ name: 'created_at' }) - createdAt: Date; + @CreateDateColumn({ name: "created_at" }) + createdAt: Date; - @Column({ name: 'deleted_at', type: 'timestamp', nullable: true }) - deletedAt: Date | null; + @Column({ name: "deleted_at", type: "timestamp", nullable: true }) + deletedAt: Date | null; - @UpdateDateColumn({ name: 'updated_at' }) - updatedAt: Date; + @UpdateDateColumn({ name: "updated_at" }) + updatedAt: Date; } diff --git a/be/src/restaurant/restaurant.controller.spec.ts b/be/src/restaurant/restaurant.controller.spec.ts index c0b43b57..84d3dccb 100644 --- a/be/src/restaurant/restaurant.controller.spec.ts +++ b/be/src/restaurant/restaurant.controller.spec.ts @@ -1,7 +1,7 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { RestaurantController } from './restaurant.controller'; +import { Test, TestingModule } from "@nestjs/testing"; +import { RestaurantController } from "./restaurant.controller"; -describe('RestaurantController', () => { +describe("RestaurantController", () => { let controller: RestaurantController; beforeEach(async () => { @@ -12,7 +12,7 @@ describe('RestaurantController', () => { controller = module.get(RestaurantController); }); - it('should be defined', () => { + it("should be defined", () => { expect(controller).toBeDefined(); }); }); diff --git a/be/src/restaurant/restaurant.controller.ts b/be/src/restaurant/restaurant.controller.ts index aef7ede9..5ac73309 100644 --- a/be/src/restaurant/restaurant.controller.ts +++ b/be/src/restaurant/restaurant.controller.ts @@ -6,9 +6,7 @@ import { SearchInfoDto } from "./dto/seachInfo.dto"; @Controller("restaurant") export class RestaurantController { - constructor( - private restaurantService: RestaurantService - ) { } + constructor(private restaurantService: RestaurantService) {} @Get("autocomplete/:partialRestaurantName") @UseGuards(AuthGuard("jwt")) @ApiBearerAuth() diff --git a/be/src/restaurant/restaurant.module.ts b/be/src/restaurant/restaurant.module.ts index c476230e..addd130e 100644 --- a/be/src/restaurant/restaurant.module.ts +++ b/be/src/restaurant/restaurant.module.ts @@ -1,12 +1,12 @@ -import { Module } from '@nestjs/common'; -import { RestaurantController } from './restaurant.controller'; -import { AuthModule } from 'src/auth/auth.module'; -import { RestaurantService } from './restaurant.service'; -import { RestaurantRepository } from './restaurant.repository'; +import { Module } from "@nestjs/common"; +import { RestaurantController } from "./restaurant.controller"; +import { AuthModule } from "src/auth/auth.module"; +import { RestaurantService } from "./restaurant.service"; +import { RestaurantRepository } from "./restaurant.repository"; @Module({ imports: [AuthModule], controllers: [RestaurantController], - providers: [RestaurantService, RestaurantRepository] + providers: [RestaurantService, RestaurantRepository], }) export class RestaurantModule {} diff --git a/be/src/restaurant/restaurant.repository.ts b/be/src/restaurant/restaurant.repository.ts index 5e284b20..7e5da5e0 100644 --- a/be/src/restaurant/restaurant.repository.ts +++ b/be/src/restaurant/restaurant.repository.ts @@ -19,10 +19,16 @@ export class RestaurantRepository extends Repository { } async updateRestaurantsFromSeoulData(data: RestaurantInfoEntity[]) { - const uniqueData = Array.from(new Map(data.map(item => [item['name'] + JSON.stringify(item['location']), item])).values()); + const uniqueData = Array.from( + new Map( + data.map((item) => [ + item["name"] + JSON.stringify(item["location"]), + item, + ]) + ).values() + ); - await this.upsert(uniqueData, ['name', 'location']); + await this.upsert(uniqueData, ["name", "location"]); return; } - } diff --git a/be/src/restaurant/restaurant.service.spec.ts b/be/src/restaurant/restaurant.service.spec.ts index c89246c6..dff7c21b 100644 --- a/be/src/restaurant/restaurant.service.spec.ts +++ b/be/src/restaurant/restaurant.service.spec.ts @@ -1,7 +1,7 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { RestaurantService } from './restaurant.service'; +import { Test, TestingModule } from "@nestjs/testing"; +import { RestaurantService } from "./restaurant.service"; -describe('RestaurantService', () => { +describe("RestaurantService", () => { let service: RestaurantService; beforeEach(async () => { @@ -12,7 +12,7 @@ describe('RestaurantService', () => { service = module.get(RestaurantService); }); - it('should be defined', () => { + it("should be defined", () => { expect(service).toBeDefined(); }); }); diff --git a/be/src/restaurant/restaurant.service.ts b/be/src/restaurant/restaurant.service.ts index 1b1a5921..7b973fa4 100644 --- a/be/src/restaurant/restaurant.service.ts +++ b/be/src/restaurant/restaurant.service.ts @@ -1,47 +1,53 @@ import { Injectable, OnModuleInit } from "@nestjs/common"; import { RestaurantRepository } from "./restaurant.repository"; import { SearchInfoDto } from "./dto/seachInfo.dto"; -import * as proj4 from 'proj4'; -import axios from 'axios'; +import * as proj4 from "proj4"; +import axios from "axios"; -const key = 'api키 입력하세요'; +const key = "api키 입력하세요"; @Injectable() export class RestaurantService implements OnModuleInit { onModuleInit() { - this.updateRestaurantsFromSeoulData() - setInterval(() => { - this.updateRestaurantsFromSeoulData(); - }, 1000 * 60 * 60 * 24 * 3); + this.updateRestaurantsFromSeoulData(); + setInterval( + () => { + this.updateRestaurantsFromSeoulData(); + }, + 1000 * 60 * 60 * 24 * 3 + ); } - constructor(private restaurantRepository: RestaurantRepository) { } + constructor(private restaurantRepository: RestaurantRepository) {} async searchRestaurant(searchInfoDto: SearchInfoDto) { return this.restaurantRepository.searchRestarant(searchInfoDto); } async getRestaurantsListFromSeoulData(startPage) { - const tm2097 = "+proj=tmerc +lat_0=38 +lon_0=127.0028902777778 +k=1 +x_0=200000 +y_0=500000 +ellps=bessel +units=m +no_defs +towgs84=-115.80,474.99,674.11,1.16,-2.31,-1.63,6.43"; + const tm2097 = + "+proj=tmerc +lat_0=38 +lon_0=127.0028902777778 +k=1 +x_0=200000 +y_0=500000 +ellps=bessel +units=m +no_defs +towgs84=-115.80,474.99,674.11,1.16,-2.31,-1.63,6.43"; const wgs84 = "EPSG:4326"; - const apiUrl = `http://openapi.seoul.go.kr:8088/${key}/json/LOCALDATA_072404/${startPage}/${startPage + 999}/`; + const apiUrl = `http://openapi.seoul.go.kr:8088/${key}/json/LOCALDATA_072404/${startPage}/${ + startPage + 999 + }/`; const response = axios.get(apiUrl); - return response.then(response => { + return response.then((response) => { const result = { data: [], lastPage: false }; if (response.data.RESULT && response.data.RESULT.CODE === "INFO-200") { result.lastPage = true; } else { - response.data.LOCALDATA_072404.row.forEach(element => { + response.data.LOCALDATA_072404.row.forEach((element) => { const tmX = parseFloat(element.X); const tmY = parseFloat(element.Y); if (!isNaN(tmX) && !isNaN(tmY) && element.DTLSTATENM === "영업") { const [lon, lat] = proj4(tm2097, wgs84, [tmX, tmY]); result.data.push({ name: element.BPLCNM, - location: { type: 'Point', coordinates: [lon, lat] }, + location: { type: "Point", coordinates: [lon, lat] }, address: element.SITEWHLADDR, category: element.UPTAENM, phoneNumber: element.SITETEL, @@ -65,7 +71,7 @@ export class RestaurantService implements OnModuleInit { if (promises.length >= 15) { const data = []; const results = await Promise.all(promises); - results.forEach(result => { + results.forEach((result) => { if (result.lastPage) lastPageReached = true; data.push(...result.data); }); @@ -75,6 +81,3 @@ export class RestaurantService implements OnModuleInit { } } } - - - diff --git a/be/src/review/dto/reviewInfo.dto.ts b/be/src/review/dto/reviewInfo.dto.ts index f4d356d9..a372d32a 100644 --- a/be/src/review/dto/reviewInfo.dto.ts +++ b/be/src/review/dto/reviewInfo.dto.ts @@ -1,56 +1,68 @@ import { ApiProperty } from "@nestjs/swagger"; import { - IsBoolean, - IsString, - IsNotEmpty, - IsInt, - MaxLength, - IsOptional, - MinLength + IsBoolean, + IsString, + IsNotEmpty, + IsInt, + MaxLength, + IsOptional, + MinLength, } from "class-validator"; export class ReviewInfoDto { - @ApiProperty({ - example: "true", - description: "The transportation for visiting", - }) - @IsBoolean() - @IsNotEmpty() - visitMethod: boolean; + @ApiProperty({ + example: "true", + description: "The transportation for visiting", + }) + @IsBoolean() + @IsNotEmpty() + visitMethod: boolean; - @ApiProperty({ example: "0", description: "transportation Accessibility for visiting" }) - @IsInt() - @IsOptional() - @MaxLength(1) - transportationAccessibility: number | null; + @ApiProperty({ + example: "0", + description: "transportation Accessibility for visiting", + }) + @IsInt() + @IsOptional() + @MaxLength(1) + transportationAccessibility: number | null; - @ApiProperty({ example: "0", description: "condition of the restaurant's parking area" }) - @IsInt() - @IsOptional() - @MaxLength(1) - parkingArea: number | null; + @ApiProperty({ + example: "0", + description: "condition of the restaurant's parking area", + }) + @IsInt() + @IsOptional() + @MaxLength(1) + parkingArea: number | null; - @ApiProperty({ example: "0", description: "The taste of the food" }) - @IsInt() - @IsNotEmpty() - @MaxLength(1) - taste: number; + @ApiProperty({ example: "0", description: "The taste of the food" }) + @IsInt() + @IsNotEmpty() + @MaxLength(1) + taste: number; - @ApiProperty({ example: "0", description: "The service of the restaurant" }) - @IsInt() - @IsNotEmpty() - @MaxLength(1) - service: number; + @ApiProperty({ example: "0", description: "The service of the restaurant" }) + @IsInt() + @IsNotEmpty() + @MaxLength(1) + service: number; - @ApiProperty({ example: "0", description: "The condition of the restaurant's restroom" }) - @IsInt() - @IsNotEmpty() - @MaxLength(1) - restroomtCleanliness: number; + @ApiProperty({ + example: "0", + description: "The condition of the restaurant's restroom", + }) + @IsInt() + @IsNotEmpty() + @MaxLength(1) + restroomtCleanliness: number; - @ApiProperty({ example: "좋았음", description: "The overallExperience about the restaurant" }) - @IsString() - @IsNotEmpty() - @MinLength(20) - overallExperience: string; + @ApiProperty({ + example: "좋았음", + description: "The overallExperience about the restaurant", + }) + @IsString() + @IsNotEmpty() + @MinLength(20) + overallExperience: string; } diff --git a/be/src/review/entities/review.entity.ts b/be/src/review/entities/review.entity.ts index 26521d13..f298d531 100644 --- a/be/src/review/entities/review.entity.ts +++ b/be/src/review/entities/review.entity.ts @@ -1,41 +1,48 @@ -import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm'; -import { User } from 'src/user/entities/user.entity'; -import { RestaurantInfoEntity } from 'src/restaurant/entities/restaurant.entity'; - -@Entity('review') +import { + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + ManyToOne, + JoinColumn, +} from "typeorm"; +import { User } from "src/user/entities/user.entity"; +import { RestaurantInfoEntity } from "src/restaurant/entities/restaurant.entity"; + +@Entity("review") export class ReviewInfoEntity { - @PrimaryGeneratedColumn('increment') - id: number; + @PrimaryGeneratedColumn("increment") + id: number; - @ManyToOne(() => User) - @JoinColumn({ name: 'user_id' }) - user: User; + @ManyToOne(() => User) + @JoinColumn({ name: "user_id" }) + user: User; - @ManyToOne(() => RestaurantInfoEntity) - @JoinColumn({ name: 'restaurant_id' }) - restaurant: RestaurantInfoEntity; + @ManyToOne(() => RestaurantInfoEntity) + @JoinColumn({ name: "restaurant_id" }) + restaurant: RestaurantInfoEntity; - @Column({ type: 'boolean' }) - visitMethod: boolean; + @Column({ type: "boolean" }) + visitMethod: boolean; - @Column({ type: 'smallint', nullable: true }) - transportationAccessibility: number | null; + @Column({ type: "smallint", nullable: true }) + transportationAccessibility: number | null; - @Column({ type: 'smallint', nullable: true }) - parkingArea: number | null; + @Column({ type: "smallint", nullable: true }) + parkingArea: number | null; - @Column({ type: 'smallint' }) - taste: number; + @Column({ type: "smallint" }) + taste: number; - @Column({ type: 'smallint' }) - service: number; + @Column({ type: "smallint" }) + service: number; - @Column({ type: 'smallint' }) - restroomCleanliness: number; + @Column({ type: "smallint" }) + restroomCleanliness: number; - @Column({ type: 'text' }) - overallExperience: string; + @Column({ type: "text" }) + overallExperience: string; - @CreateDateColumn({ name: 'created_at' }) - createdAt: Date; + @CreateDateColumn({ name: "created_at" }) + createdAt: Date; } diff --git a/be/src/review/review.module.ts b/be/src/review/review.module.ts index b3f019a1..5ff9c83a 100644 --- a/be/src/review/review.module.ts +++ b/be/src/review/review.module.ts @@ -1,4 +1,4 @@ -import { Module } from '@nestjs/common'; +import { Module } from "@nestjs/common"; @Module({}) export class ReviewModule {} diff --git a/be/src/user/entities/user.followList.entity.ts b/be/src/user/entities/user.followList.entity.ts index bc36a587..b45e5c5c 100644 --- a/be/src/user/entities/user.followList.entity.ts +++ b/be/src/user/entities/user.followList.entity.ts @@ -1,27 +1,26 @@ import { - Entity, - PrimaryColumn, - CreateDateColumn, - DeleteDateColumn, - ManyToOne, - JoinColumn -} from 'typeorm'; -import { User } from './user.entity'; + Entity, + PrimaryColumn, + CreateDateColumn, + DeleteDateColumn, + ManyToOne, + JoinColumn, +} from "typeorm"; +import { User } from "./user.entity"; -@Entity('follow') +@Entity("follow") export class FollowEntity { - @ManyToOne(() => User) - @PrimaryColumn({ name: 'following_user_id' }) - followingUserId: number; + @ManyToOne(() => User) + @PrimaryColumn({ name: "following_user_id" }) + followingUserId: number; - @ManyToOne(() => User) - @PrimaryColumn({ name: 'followed_user_id' }) - followedUserId: number; + @ManyToOne(() => User) + @PrimaryColumn({ name: "followed_user_id" }) + followedUserId: number; - @CreateDateColumn({ name: 'created_at' }) - createdAt: Date; - - @DeleteDateColumn({ name: 'deleted_at', nullable: true, type: 'timestamp' }) - deletedAt: Date | null; + @CreateDateColumn({ name: "created_at" }) + createdAt: Date; + @DeleteDateColumn({ name: "deleted_at", nullable: true, type: "timestamp" }) + deletedAt: Date | null; } diff --git a/be/src/user/entities/user.restaurantlist.entity.ts b/be/src/user/entities/user.restaurantlist.entity.ts index f19b859e..e3c7cbec 100644 --- a/be/src/user/entities/user.restaurantlist.entity.ts +++ b/be/src/user/entities/user.restaurantlist.entity.ts @@ -5,28 +5,28 @@ import { ManyToOne, JoinColumn, PrimaryColumn, -} from 'typeorm'; -import { User } from './user.entity'; -import { RestaurantInfoEntity } from 'src/restaurant/entities/restaurant.entity'; -import { ReviewInfoEntity } from 'src/review/entities/review.entity'; +} from "typeorm"; +import { User } from "./user.entity"; +import { RestaurantInfoEntity } from "src/restaurant/entities/restaurant.entity"; +import { ReviewInfoEntity } from "src/review/entities/review.entity"; -@Entity('user_restaurant_lists') +@Entity("user_restaurant_lists") export class UserRestaurantListEntity { @ManyToOne(() => User) - @PrimaryColumn({ name: 'user_id' }) + @PrimaryColumn({ name: "user_id" }) userId: number; @ManyToOne(() => RestaurantInfoEntity) - @PrimaryColumn({ name: 'restaurant_id' }) + @PrimaryColumn({ name: "restaurant_id" }) restaurantId: number; @ManyToOne(() => ReviewInfoEntity) - @JoinColumn({ name: 'review_id' }) + @JoinColumn({ name: "review_id" }) reviewId: ReviewInfoEntity; - @CreateDateColumn({ name: 'created_at', type: 'timestamp' }) + @CreateDateColumn({ name: "created_at", type: "timestamp" }) createdAt: Date; - @Column({ name: 'deleted_at', type: 'timestamp', nullable: true }) + @Column({ name: "deleted_at", type: "timestamp", nullable: true }) deletedAt: Date | null; } diff --git a/be/src/user/user.controller.ts b/be/src/user/user.controller.ts index debd4b91..117f1e45 100644 --- a/be/src/user/user.controller.ts +++ b/be/src/user/user.controller.ts @@ -23,7 +23,7 @@ import { AuthGuard } from "@nestjs/passport"; @Controller("user") export class UserController { - constructor(private userService: UserService) { } + constructor(private userService: UserService) {} @Get() @UseGuards(AuthGuard("jwt")) @@ -93,9 +93,7 @@ export class UserController { @ApiOperation({ summary: "이메일 중복확인" }) @ApiResponse({ status: 200, description: "이메일 중복확인 요청 성공" }) @ApiResponse({ status: 400, description: "부적절한 요청" }) - async getEmailAvailability( - @Param("email") email: UserInfoDto["email"] - ) { + async getEmailAvailability(@Param("email") email: UserInfoDto["email"]) { return await this.userService.getEmailAvailability(email); } diff --git a/be/src/user/user.module.ts b/be/src/user/user.module.ts index c4f96228..abd5c7eb 100644 --- a/be/src/user/user.module.ts +++ b/be/src/user/user.module.ts @@ -10,4 +10,4 @@ import { forwardRef } from "@nestjs/common"; providers: [UserService, UserRepository], exports: [UserRepository], }) -export class UserModule { } +export class UserModule {} diff --git a/be/src/user/user.repository.ts b/be/src/user/user.repository.ts index 080eb58b..8d925a01 100644 --- a/be/src/user/user.repository.ts +++ b/be/src/user/user.repository.ts @@ -3,7 +3,6 @@ import { User } from "./entities/user.entity"; import { UserInfoDto } from "./dto/userInfo.dto"; import { ConflictException, Injectable } from "@nestjs/common"; - @Injectable() export class UserRepository extends Repository { constructor(private dataSource: DataSource) { @@ -79,7 +78,8 @@ export class UserRepository extends Repository { const [emailUser, nickNameUser] = await Promise.all([ this.findOne({ select: ["id"], where: { email: userInfoDto["email"] } }), this.findOne({ - select: ["id"], where: { nickName: userInfoDto["nickName"] }, + select: ["id"], + where: { nickName: userInfoDto["nickName"] }, }), ]); diff --git a/be/src/user/user.service.spec.ts b/be/src/user/user.service.spec.ts index 1e153db8..09e87e7d 100644 --- a/be/src/user/user.service.spec.ts +++ b/be/src/user/user.service.spec.ts @@ -1,56 +1,62 @@ -import { Test } from '@nestjs/testing'; -import { UserRepository } from './user.repository'; -import { UserService } from './user.service'; -import { AuthModule } from '../auth/auth.module'; -import { UserInfoDto } from './dto/userInfo.dto'; -import { newDb } from 'pg-mem'; -import { DataSource, TypeORMError } from 'typeorm'; -import { User } from './entities/user.entity'; -import { TypeOrmModule } from '@nestjs/typeorm'; - -describe('UserService', () => { +import { Test } from "@nestjs/testing"; +import { UserRepository } from "./user.repository"; +import { UserService } from "./user.service"; +import { AuthModule } from "../auth/auth.module"; +import { UserInfoDto } from "./dto/userInfo.dto"; +import { newDb } from "pg-mem"; +import { DataSource, TypeORMError } from "typeorm"; +import { User } from "./entities/user.entity"; +import { TypeOrmModule } from "@nestjs/typeorm"; +describe("UserService", () => { let userService: UserService; let dataSource: DataSource; beforeAll(async () => { const db = newDb({ autoCreateForeignKeyIndices: true }); db.public.registerFunction({ - name: 'current_database', - implementation: () => 'test_database', + name: "current_database", + implementation: () => "test_database", }); db.public.registerFunction({ - name: 'version', - implementation: () => 'PostgreSQL 12.16, compiled by Visual C++ build 1914, 64-bit', + name: "version", + implementation: () => + "PostgreSQL 12.16, compiled by Visual C++ build 1914, 64-bit", }); - dataSource = (await db.adapters.createTypeormDataSource({ - type: 'postgres', + dataSource = await db.adapters.createTypeormDataSource({ + type: "postgres", entities: [User], - })) + }); await dataSource.initialize(); await dataSource.synchronize(); const testModule = await Test.createTestingModule({ - imports: [AuthModule, TypeOrmModule.forRoot(), TypeOrmModule.forFeature([User])], + imports: [ + AuthModule, + TypeOrmModule.forRoot(), + TypeOrmModule.forFeature([User]), + ], providers: [UserService, UserRepository], - }).overrideProvider(DataSource).useValue(dataSource).compile(); + }) + .overrideProvider(DataSource) + .useValue(dataSource) + .compile(); userService = testModule.get(UserService); }); - - it('should create a new user and return the user data', async () => { + it("should create a new user and return the user data", async () => { const userInfoDto: UserInfoDto = { - email: 'test@email.com', + email: "test@email.com", password: "1234", provider: " ", nickName: "hi", region: "인천", birthdate: "1999/10/13", - isMale: true + isMale: true, }; await userService.signup(userInfoDto); @@ -59,14 +65,16 @@ describe('UserService', () => { const foundUser = await userRepository.findOne({ select: ["nickName", "birthdate", "isMale", "region"], - where: { email: 'test@email.com' }, + where: { email: "test@email.com" }, }); - expect(foundUser).toEqual(expect.objectContaining({ - nickName: "hi", - region: "인천", - birthdate: "1999/10/13", - isMale: true - })); + expect(foundUser).toEqual( + expect.objectContaining({ + nickName: "hi", + region: "인천", + birthdate: "1999/10/13", + isMale: true, + }) + ); }); }); diff --git a/be/src/user/user.service.ts b/be/src/user/user.service.ts index fdf10660..f1c9b23a 100644 --- a/be/src/user/user.service.ts +++ b/be/src/user/user.service.ts @@ -10,7 +10,7 @@ export class UserService { constructor( @InjectRepository(UserRepository) private usersRepository: UserRepository - ) { } + ) {} async signup(userInfoDto: UserInfoDto) { userInfoDto.password = await hashPassword(userInfoDto.password); return await this.usersRepository.createUser(userInfoDto); diff --git a/be/src/utils/encryption.utils.ts b/be/src/utils/encryption.utils.ts index b2e4b61b..c3239882 100644 --- a/be/src/utils/encryption.utils.ts +++ b/be/src/utils/encryption.utils.ts @@ -1,9 +1,12 @@ -import * as bcrypt from 'bcrypt'; +import * as bcrypt from "bcrypt"; export async function hashPassword(password: string): Promise { - return await bcrypt.hash(password, 10); + return await bcrypt.hash(password, 10); } -export async function comparePasswords(inputPassword: string, storedPassword: string): Promise { - return await bcrypt.compare(inputPassword, storedPassword); +export async function comparePasswords( + inputPassword: string, + storedPassword: string +): Promise { + return await bcrypt.compare(inputPassword, storedPassword); }