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.
Co-authored-by: LeeTH916 <[email protected]>
- Loading branch information
Showing
26 changed files
with
374 additions
and
325 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
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
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
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 { 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; | ||
} |
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,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); | ||
} | ||
} |
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,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); | ||
}) | ||
); | ||
} | ||
} |
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,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; | ||
} |
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,7 @@ | ||
export class SearchInfoDto { | ||
constructor( | ||
public partitalName: string, | ||
public location: string, | ||
public radius: number, | ||
){} | ||
} | ||
constructor( | ||
public partitalName: string, | ||
public location: string, | ||
public radius: number | ||
) {} | ||
} |
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,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; | ||
} |
Oops, something went wrong.