Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/domain/match/controller/match.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,4 @@ export class MatchController {
const results = await this.matchService.createMatchingResultsBulk(body.results);
return ResponseDto.ok(results);
}
}


}
12 changes: 8 additions & 4 deletions src/domain/match/match.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) => {
Expand All @@ -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,
Expand All @@ -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,
Expand Down