Skip to content

Commit

Permalink
style : prettier 적용 #35
Browse files Browse the repository at this point in the history
Co-authored-by: LeeTH916 <[email protected]>
  • Loading branch information
GeunH and LeeTH916 committed Nov 22, 2023
1 parent e05f207 commit 196f240
Show file tree
Hide file tree
Showing 26 changed files with 374 additions and 325 deletions.
16 changes: 11 additions & 5 deletions be/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand All @@ -19,4 +25,4 @@ import { LoggingInterceptor } from "./logger.interceptor";
},
],
})
export class AppModule { }
export class AppModule {}
2 changes: 1 addition & 1 deletion be/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ import { JwtStrategy } from "./strategy/jwt.strategy";
providers: [AuthService, JwtStrategy],
exports: [PassportModule],
})
export class AuthModule { }
export class AuthModule {}
15 changes: 8 additions & 7 deletions be/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class AuthService {
constructor(
private userRepository: UserRepository,
private jwtService: JwtService
) { }
) {}
async NaverAuth(authorization: string) {
if (!authorization) {
throw new HttpException(
Expand Down Expand Up @@ -46,27 +46,28 @@ 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(
"사용자가 등록되어 있지 않습니다. 회원가입을 진행해주세요"
);
}
}

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);
}
}
}
13 changes: 7 additions & 6 deletions be/src/auth/dto/refreshToken.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ApiProperty } from "@nestjs/swagger";

export class RefreshTokenDto {
@ApiProperty({
example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
description: "클라이언트가 가지고 있는 refreshToken",
})
refreshToken: string;
}
@ApiProperty({
example:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
description: "클라이언트가 가지고 있는 refreshToken",
})
refreshToken: string;
}
91 changes: 46 additions & 45 deletions be/src/custom.logger.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
66 changes: 34 additions & 32 deletions be/src/logger.interceptor.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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<any> {
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);
})
);
}
}
19 changes: 8 additions & 11 deletions be/src/restaurant/dto/restaurantInfo.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 6 additions & 6 deletions be/src/restaurant/dto/seachInfo.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export class SearchInfoDto {
constructor(
public partitalName: string,
public location: string,
public radius: number,
){}
}
constructor(
public partitalName: string,
public location: string,
public radius: number
) {}
}
63 changes: 35 additions & 28 deletions be/src/restaurant/entities/restaurant.entity.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit 196f240

Please sign in to comment.