From 7b624b59647df475255d70ff09cf72d02dc71125 Mon Sep 17 00:00:00 2001 From: sumin Date: Wed, 21 May 2025 17:48:54 +0900 Subject: [PATCH] =?UTF-8?q?#5=20:recycle:=20[Refactor]=20:=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/match/controller/match.controller.ts | 4 +--- src/domain/match/match.service.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/domain/match/controller/match.controller.ts b/src/domain/match/controller/match.controller.ts index 59748e5..0c99208 100644 --- a/src/domain/match/controller/match.controller.ts +++ b/src/domain/match/controller/match.controller.ts @@ -44,6 +44,4 @@ export class MatchController { const results = await this.matchService.createMatchingResultsBulk(body.results); return ResponseDto.ok(results); } -} - - +} \ No newline at end of file diff --git a/src/domain/match/match.service.ts b/src/domain/match/match.service.ts index 95a2760..821b56f 100644 --- a/src/domain/match/match.service.ts +++ b/src/domain/match/match.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { BadRequestException, Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { MatchingResult } from './entity/matching-result.entity'; import { Feed } from '../feed/entity/feed.entity'; @@ -18,11 +18,17 @@ export class MatchService { private userRepository: UserRepository, ) {} - // matching.service.ts async createMatchingResultsBulk( results: { feed_id: number; authorId: number; similarity_score: number }[] ): Promise<{ feed_id: number; authorId: number; saved: boolean; message?: string }[]> { + + if (!Array.isArray(results)) { + throw new BadRequestException('results 필드는 배열이어야 합니다.'); + } + if (results.length === 0) { + throw new BadRequestException('results 배열이 비어있습니다.'); + } // 여러 결과를 병렬로 저장 return Promise.all( results.map(async (item) => { @@ -38,7 +44,6 @@ export class MatchService { const user = await this.userRepository.findOne({ where: { id: item.authorId } }); if (!user) throw new CommonException(ErrorCode.NOT_FOUND_USER); - // 저장 const result = this.matchingResultRepository.create({ feed, user, @@ -54,7 +59,6 @@ export class MatchService { message: percent >= 80 ? `잃어버린 동물을 제보해주셨어요! 유사도 ${Math.round(percent)}%!` : undefined, }; } catch (e) { - // 에러 발생 시 저장 실패 표시 return { feed_id: item.feed_id, authorId: item.authorId,