Skip to content

Commit 7b01fdb

Browse files
authored
Merge pull request #79 from oodd-team/OD-190
최근 매칭 조회 소켓
2 parents b3a4e14 + f5cd128 commit 7b01fdb

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

src/matching/dto/matching.response.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiProperty } from '@nestjs/swagger';
1+
import { ApiProperty, OmitType } from '@nestjs/swagger';
22
import { Type } from 'class-transformer';
33

44
export class PatchMatchingResponse {
@@ -94,7 +94,7 @@ export class CreateMatchingResponse {
9494

9595
@ApiProperty({
9696
example: '2024-10-11T09:00:00.000Z',
97-
description: '신청청 시각',
97+
description: '신청 시각',
9898
})
9999
createdAt: string;
100100

@@ -129,3 +129,13 @@ export class GetMatchingsResponse {
129129
@Type(() => MatchingResponse)
130130
matching: MatchingResponse[];
131131
}
132+
133+
export class GetOneMatchingResponse extends OmitType(PatchMatchingResponse, [
134+
'chatRoomId',
135+
] as const) {
136+
@ApiProperty({
137+
example: '2024-10-11T09:00:00.000Z',
138+
description: '신청 시각',
139+
})
140+
createdAt: string;
141+
}

src/matching/matching.controller.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
PatchMatchingResponse,
3535
CreateMatchingResponse,
3636
GetMatchingsResponse,
37+
GetOneMatchingResponse,
3738
} from './dto/matching.response';
3839
import { AuthGuard } from 'src/auth/guards/jwt.auth.guard';
3940
import { PostService } from 'src/post/post.service';

src/matching/matching.service.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { InjectRepository } from '@nestjs/typeorm';
1212
import {
1313
CreateMatchingResponse,
1414
GetMatchingsResponse,
15+
GetOneMatchingResponse,
1516
} from './dto/matching.response';
1617
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus';
1718
import { StatusEnum } from 'src/common/enum/entityStatus';
18-
import { UserBlockService } from 'src/user-block/user-block.service';
1919
import dayjs from 'dayjs';
2020

2121
@Injectable()
@@ -147,6 +147,28 @@ export class MatchingService {
147147
}
148148
}
149149

150+
async getLatestMatching(
151+
userId: number,
152+
): Promise<GetOneMatchingResponse | {}> {
153+
const matching = await this.matchingRepository.findOne({
154+
where: { target: { id: userId } },
155+
relations: ['target', 'requester'],
156+
order: { createdAt: 'DESC' },
157+
});
158+
159+
if (!matching) {
160+
return {};
161+
}
162+
163+
return {
164+
id: matching.id,
165+
requesterId: matching.requester.id,
166+
targetId: matching.target.id,
167+
requestStatus: matching.requestStatus,
168+
createdAt: dayjs(matching.createdAt).format('YYYY-MM-DDTHH:mm:ssZ'),
169+
};
170+
}
171+
150172
async getMatchings(currentUserId: number): Promise<GetMatchingsResponse> {
151173
const matchings = await this.matchingRepository
152174
.createQueryBuilder('matching')

src/matchingEventGateway.ts

+13
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,17 @@ export class MatchingEventsGateway
158158
client.emit('error', '매칭 상태 변경 처리 중 오류가 발생했습니다.');
159159
}
160160
}
161+
162+
@SubscribeMessage('getLatestMatching')
163+
async handleGetLatestMatching(client: Socket, payload: { userId: number }) {
164+
const { userId } = payload;
165+
try {
166+
const latestMatching =
167+
await this.matchingService.getLatestMatching(userId);
168+
169+
client.emit('latestMatching', latestMatching);
170+
} catch (error) {
171+
client.emit('error', '매칭 조회 중 오류가 발생했습니다.');
172+
}
173+
}
161174
}

0 commit comments

Comments
 (0)