@@ -14,6 +14,7 @@ import { ChatMessageService } from 'src/chat-message/chat-message.service';
14
14
import { ChatRoom } from 'src/common/entities/chat-room.entity' ;
15
15
import { InjectRepository } from '@nestjs/typeorm' ;
16
16
import { GetMatchingsResponse } from './dto/matching.response' ;
17
+ import { MatchingRequestStatusEnum } from 'src/common/enum/matchingRequestStatus' ;
17
18
18
19
@Injectable ( )
19
20
export class MatchingService {
@@ -24,6 +25,35 @@ export class MatchingService {
24
25
private readonly chatMessageService : ChatMessageService ,
25
26
private readonly dataSource : DataSource ,
26
27
) { }
28
+ async getMatchingByUserId (
29
+ requesterId : number ,
30
+ targetId : number ,
31
+ ) : Promise < Matching > {
32
+ return await this . matchingRepository . findOne ( {
33
+ where : [
34
+ {
35
+ requester : { id : requesterId } ,
36
+ target : { id : targetId } ,
37
+ status : 'activated' ,
38
+ } ,
39
+ {
40
+ requester : { id : targetId } ,
41
+ target : { id : requesterId } ,
42
+ status : 'activated' ,
43
+ } ,
44
+ ] ,
45
+ } ) ;
46
+ }
47
+
48
+ async getMatchingsByCurrentId ( currentUserId : number ) : Promise < Matching [ ] > {
49
+ return await this . matchingRepository . find ( {
50
+ relations : [ 'requester' , 'target' ] ,
51
+ where : [
52
+ { requester : { id : currentUserId } , status : 'activated' } ,
53
+ { target : { id : currentUserId } , status : 'activated' } ,
54
+ ] ,
55
+ } ) ;
56
+ }
27
57
28
58
async createMatching ( body : CreateMatchingReqeust ) : Promise < ChatRoom > {
29
59
let matching , chatRoom ;
@@ -68,10 +98,10 @@ export class MatchingService {
68
98
69
99
try {
70
100
if ( body . requestStatus === 'accept' ) {
71
- matching . requestStatus = 'accepted' ;
101
+ matching . requestStatus = MatchingRequestStatusEnum . ACCEPTED ;
72
102
matching . acceptedAt = new Date ( ) ;
73
103
} else if ( body . requestStatus === 'reject' ) {
74
- matching . requestStatus = 'rejected' ;
104
+ matching . requestStatus = MatchingRequestStatusEnum . REJECTED ;
75
105
matching . rejectedAt = new Date ( ) ;
76
106
}
77
107
@@ -157,13 +187,13 @@ export class MatchingService {
157
187
{
158
188
requester : { id : requesterId } ,
159
189
target : { id : targetId } ,
160
- requestStatus : 'accepted' ,
190
+ requestStatus : MatchingRequestStatusEnum . ACCEPTED ,
161
191
status : 'activated' ,
162
192
} ,
163
193
{
164
194
requester : { id : targetId } ,
165
195
target : { id : requesterId } ,
166
- requestStatus : 'accepted' ,
196
+ requestStatus : MatchingRequestStatusEnum . ACCEPTED ,
167
197
status : 'activated' ,
168
198
} ,
169
199
] ,
0 commit comments