@@ -12,6 +12,7 @@ import { InjectRepository } from '@nestjs/typeorm';
12
12
import {
13
13
CreateMatchingResponse ,
14
14
GetMatchingsResponse ,
15
+ GetOneMatchingResponse ,
15
16
} from './dto/matching.response' ;
16
17
import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus' ;
17
18
import { StatusEnum } from 'src/common/enum/entityStatus' ;
@@ -146,12 +147,26 @@ export class MatchingService {
146
147
}
147
148
}
148
149
149
- async getLatestMatching ( currentUserId : number ) : Promise < Matching > {
150
- return await this . matchingRepository . findOne ( {
151
- where : { target : { id : currentUserId } } ,
150
+ async getLatestMatching (
151
+ userId : number ,
152
+ ) : Promise < GetOneMatchingResponse | { } > {
153
+ const matching = await this . matchingRepository . findOne ( {
154
+ where : { target : { id : userId } } ,
152
155
relations : [ 'target' , 'requester' ] ,
153
156
order : { createdAt : 'DESC' } ,
154
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
+ } ;
155
170
}
156
171
157
172
async getMatchings ( currentUserId : number ) : Promise < GetMatchingsResponse > {
0 commit comments