-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from boostcampwm2023/BE/task/modify-db
[BE] โป๏ธ : db์์ (mongodb -> mysql)
- Loading branch information
Showing
31 changed files
with
1,240 additions
and
696 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
10 changes: 10 additions & 0 deletions
10
BE/musicspot/src/common/decorator/customRepository.decorator.ts
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,10 @@ | ||
import { SetMetadata } from "@nestjs/common"; | ||
|
||
export const TYPEORM_EX_CUSTOM_REPOSITORY = "TYPEORM_EX_CUSTOM_REPOSITORY"; | ||
|
||
export function CustomRepository(entity : Function): ClassDecorator{ | ||
return SetMetadata(TYPEORM_EX_CUSTOM_REPOSITORY, entity); | ||
} | ||
|
||
// SetMetadata๋ key, value ํํ์ ๊ฐ์ ์ทจํจ | ||
// ์ฆ TYPEORM_EX_CUSTOM_REPOSITORY : entity |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { DynamicModule, Provider } from "@nestjs/common"; | ||
import { TYPEORM_EX_CUSTOM_REPOSITORY } from "./common/decorator/customRepository.decorator"; | ||
import { getDataSourceToken } from "@nestjs/typeorm"; | ||
import { DataSource } from "typeorm"; | ||
|
||
export class TypeOrmExModule{ | ||
public static forFeature<T extends new (...args: any[]) => any>(repositories: T[]): DynamicModule { | ||
const providers: Provider[] = []; | ||
for(const repository of repositories){ | ||
|
||
const entity = Reflect.getMetadata(TYPEORM_EX_CUSTOM_REPOSITORY, repository); | ||
|
||
if(!entity){ | ||
continue; | ||
} | ||
|
||
providers.push({ | ||
inject: [getDataSourceToken()], | ||
provide : repository, | ||
useFactory : (dataSource:DataSource) : typeof repository =>{ | ||
const baseRepository = dataSource.getRepository<any>(entity); | ||
return new repository(baseRepository.target, baseRepository.manager, baseRepository) | ||
} | ||
}) | ||
} | ||
return { | ||
exports : providers, | ||
module : TypeOrmExModule, | ||
providers | ||
} | ||
} | ||
} |
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,5 +1,5 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsString, IsDateString } from 'class-validator'; | ||
import { IsString, IsDateString, IsNumber } from 'class-validator'; | ||
import { UUID } from 'crypto'; | ||
export class DeleteJourneyReqDTO { | ||
@ApiProperty({ | ||
|
@@ -15,8 +15,8 @@ export class DeleteJourneyReqDTO { | |
description: '์ฌ์ id', | ||
required: true, | ||
}) | ||
@IsString() | ||
readonly journeyId: string; | ||
@IsNumber() | ||
readonly journeyId: number; | ||
} | ||
|
||
export class DeleteJourneyResDTO { | ||
|
@@ -42,12 +42,4 @@ export class DeleteJourneyResDTO { | |
}) | ||
@IsString() | ||
readonly journeyId: string; | ||
|
||
// @ApiProperty({ | ||
// example: '[email protected]', | ||
// description: '์ด๋ฉ์ผ', | ||
// required: true, | ||
// }) | ||
// @IsString() | ||
// readonly email: 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
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
Oops, something went wrong.