issue # nestjs 로 초기화
This commit is contained in:
14
src/modules/account/account.controller.ts
Normal file
14
src/modules/account/account.controller.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Controller, Get, Post, Query } from "@nestjs/common";
|
||||
import { CheckDuplicationRequestDto } from "./dto/checkDuplication/check-duplication-request.dto";
|
||||
import { CheckDuplicationResponseDto } from "./dto/checkDuplication/check-duplication-response.dto";
|
||||
import { AccountService } from "./account.service";
|
||||
|
||||
@Controller('account')
|
||||
export class AccountController {
|
||||
constructor(private readonly accountService: AccountService) {}
|
||||
|
||||
@Get('check-duplication')
|
||||
async checkDuplication(@Query() query: CheckDuplicationRequestDto): Promise<CheckDuplicationResponseDto> {
|
||||
return this.accountService.checkDuplication(query);
|
||||
}
|
||||
}
|
||||
10
src/modules/account/account.module.ts
Normal file
10
src/modules/account/account.module.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { AccountController } from "./account.controller";
|
||||
import { AccountRepo } from "./account.repo";
|
||||
import { AccountService } from "./account.service";
|
||||
|
||||
@Module({
|
||||
controllers: [AccountController],
|
||||
providers: [AccountService, AccountRepo]
|
||||
})
|
||||
export class AccountModule {}
|
||||
21
src/modules/account/account.repo.ts
Normal file
21
src/modules/account/account.repo.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import * as schema from "drizzle/schema";
|
||||
import { countDistinct, and, eq } from 'drizzle-orm';
|
||||
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
||||
|
||||
@Injectable()
|
||||
export class AccountRepo {
|
||||
constructor(@Inject('DRIZZLE') private readonly db: NodePgDatabase<typeof schema>) {}
|
||||
|
||||
async checkDuplication(type: 'email' | 'accountId', value: string) {
|
||||
const result = await this
|
||||
.db
|
||||
.select({ count: countDistinct(schema.account[type])})
|
||||
.from(schema.account)
|
||||
.where(
|
||||
eq(schema.account[type], value)
|
||||
);
|
||||
|
||||
return result[0].count;
|
||||
}
|
||||
}
|
||||
15
src/modules/account/account.service.ts
Normal file
15
src/modules/account/account.service.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { AccountRepo } from "./account.repo";
|
||||
import { CheckDuplicationRequestDto } from "./dto/checkDuplication/check-duplication-request.dto";
|
||||
import { CheckDuplicationResponseDto } from "./dto/checkDuplication/check-duplication-response.dto";
|
||||
|
||||
@Injectable()
|
||||
export class AccountService {
|
||||
constructor(private readonly accountRepo: AccountRepo) {}
|
||||
|
||||
async checkDuplication(data: CheckDuplicationRequestDto): Promise<CheckDuplicationResponseDto> {
|
||||
const count = await this.accountRepo.checkDuplication(data.type, data.value);
|
||||
|
||||
return { isDuplicated: count > 0 };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { IsString, IsIn } from '@nestjs/class-validator'
|
||||
|
||||
export class CheckDuplicationRequestDto {
|
||||
@IsIn(['email', 'accountId'])
|
||||
type: 'email' | 'accountId';
|
||||
|
||||
@IsString()
|
||||
value: string;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export class CheckDuplicationResponseDto {
|
||||
isDuplicated: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user