issue # nestjs 로 초기화

This commit is contained in:
geonhee-min
2025-11-21 15:18:37 +09:00
parent ce50a53256
commit 0170421d16
57 changed files with 2483 additions and 143 deletions

View 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);
}
}

View 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 {}

View 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;
}
}

View 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 };
}
}

View File

@@ -0,0 +1,9 @@
import { IsString, IsIn } from '@nestjs/class-validator'
export class CheckDuplicationRequestDto {
@IsIn(['email', 'accountId'])
type: 'email' | 'accountId';
@IsString()
value: string;
}

View File

@@ -0,0 +1,3 @@
export class CheckDuplicationResponseDto {
isDuplicated: boolean;
}