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,