forked from StayLitCodes/Vaultix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitdiff_lastparts.txt
More file actions
221 lines (203 loc) · 7.27 KB
/
Copy pathgitdiff_lastparts.txt
File metadata and controls
221 lines (203 loc) · 7.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
commit 9a3434cb656bd0c304e2cd8e6c891917aa82a2a4
Author: Brite <brightheartgfx@gmail.com>
Date: Mon Jun 29 14:13:43 2026 +0100
I have made some changes to file
diff --git a/apps/backend/src/modules/escrow/services/escrow.service.ts b/apps/backend/src/modules/escrow/services/escrow.service.ts
index 880d5da..5cb93da 100644
--- a/apps/backend/src/modules/escrow/services/escrow.service.ts
+++ b/apps/backend/src/modules/escrow/services/escrow.service.ts
@@ -5,6 +5,7 @@ import {
ForbiddenException,
ConflictException,
UnprocessableEntityException,
+ Optional,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Brackets, Repository, SelectQueryBuilder } from 'typeorm';
@@ -44,6 +45,7 @@ import { IpfsService } from '../../ipfs/ipfs.service';
import { AllowedAsset } from '../../assets/entities/allowed-asset.entity';
import { NotificationService } from '../../../notifications/notifications.service';
import { NotificationEventType } from '../../../notifications/enums/notification-event.enum';
+import { EventsGateway } from '../../../gateways/escrow.gateway';
@Injectable()
export class EscrowService {
@@ -67,6 +69,7 @@ export class EscrowService {
private readonly webhookService: WebhookService,
private readonly ipfsService: IpfsService,
private readonly notificationService: NotificationService,
+ @Optional() private readonly eventsGateway?: EventsGateway,
) {}
async create(
@@ -446,6 +449,11 @@ export class EscrowService {
await this.webhookService.dispatchEvent('escrow.cancelled', {
escrowId: id,
});
+ this.eventsGateway?.broadcastEscrowStatusChanged(id, {
+ previousStatus: escrow.status,
+ newStatus: EscrowStatus.CANCELLED,
+ actorId: userId,
+ });
return this.findOne(id);
}
@@ -531,6 +539,7 @@ export class EscrowService {
);
const fundedAt = new Date();
+ const previousStatus = escrow.status;
await this.escrowRepository.update(id, {
stellarTxHash,
fundedAt,
@@ -548,6 +557,11 @@ export class EscrowService {
escrowId: id,
stellarTxHash,
});
+ this.eventsGateway?.broadcastEscrowStatusChanged(id, {
+ previousStatus,
+ newStatus: EscrowStatus.ACTIVE,
+ actorId: userId,
+ });
return this.findOne(id);
}
@@ -626,6 +640,7 @@ export class EscrowService {
escrow.creatorId,
);
+ const previousStatus = escrow.status;
escrow.status = EscrowStatus.COMPLETED;
escrow.isReleased = true;
escrow.releaseTransactionHash = txHash;
@@ -639,6 +654,11 @@ export class EscrowService {
escrowId: escrow.id,
txHash,
});
+ this.eventsGateway?.broadcastEscrowStatusChanged(escrow.id, {
+ previousStatus,
+ newStatus: EscrowStatus.COMPLETED,
+ actorId: currentUserId,
+ });
return escrow;
}
@@ -721,6 +741,10 @@ export class EscrowService {
conditionId,
fulfilledBy: userId,
});
+ this.eventsGateway?.broadcastConditionFulfilled(escrowId, {
+ conditionId,
+ fulfilledBy: userId,
+ });
return condition;
}
@@ -819,6 +843,11 @@ export class EscrowService {
confirmedBy: userId,
allConditionsMet,
});
+ this.eventsGateway?.broadcastConditionConfirmed(escrowId, {
+ conditionId,
+ confirmedBy: userId,
+ allConditionsMet,
+ });
return condition;
}
@@ -970,6 +999,15 @@ export class EscrowService {
escrowId,
disputeId: savedDispute.id,
});
+ this.eventsGateway?.broadcastDisputeFiled(escrowId, {
+ disputeId: savedDispute.id,
+ filedBy: userId,
+ });
+ this.eventsGateway?.broadcastEscrowStatusChanged(escrowId, {
+ previousStatus: escrow.status,
+ newStatus: EscrowStatus.DISPUTED,
+ actorId: userId,
+ });
return this.disputeRepository.findOne({
where: { id: savedDispute.id },
@@ -1071,6 +1109,16 @@ export class EscrowService {
disputeId: resolved.id,
outcome: dto.outcome,
});
+ this.eventsGateway?.broadcastDisputeResolved(escrowId, {
+ disputeId: resolved.id,
+ outcome: dto.outcome,
+ resolvedBy: arbitratorUserId,
+ });
+ this.eventsGateway?.broadcastEscrowStatusChanged(escrowId, {
+ previousStatus: escrow.status,
+ newStatus: nextEscrowStatus,
+ actorId: arbitratorUserId,
+ });
return this.disputeRepository.findOne({
where: { id: resolved.id },
@@ -1411,6 +1459,12 @@ export class EscrowService {
escrowId: escrow.id,
reason: options.webhookReason,
});
+ this.eventsGateway?.broadcastEscrowStatusChanged(escrow.id, {
+ previousStatus: escrow.status,
+ newStatus: EscrowStatus.EXPIRED,
+ actorId: options.actorId,
+ reason: options.reason,
+ });
return this.findOne(escrow.id);
}
diff --git a/apps/backend/src/notifications/notifications.module.ts b/apps/backend/src/notifications/notifications.module.ts
index 5885226..d6bafda 100644
--- a/apps/backend/src/notifications/notifications.module.ts
+++ b/apps/backend/src/notifications/notifications.module.ts
@@ -9,11 +9,13 @@ import { NotificationService } from './notifications.service';
import { PreferenceService } from './preference.service';
import { EmailSender } from './senders/email.sender';
import { WebhookSender } from './senders/webhook.sender';
+import { EventsModule } from '../gateways/events.module';
@Module({
imports: [
ConfigModule,
AuthModule,
+ EventsModule,
TypeOrmModule.forFeature([Notification, NotificationPreference]),
],
controllers: [NotificationController],
diff --git a/apps/backend/src/notifications/notifications.service.ts b/apps/backend/src/notifications/notifications.service.ts
index 1477729..0cbc888 100644
--- a/apps/backend/src/notifications/notifications.service.ts
+++ b/apps/backend/src/notifications/notifications.service.ts
@@ -1,4 +1,4 @@
-import { Injectable, Logger } from '@nestjs/common';
+import { Injectable, Logger, Optional } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
import {
NotificationChannel,
@@ -12,6 +12,7 @@ import { WebhookSender } from './senders/webhook.sender';
import { Repository, IsNull } from 'typeorm';
import { EmailSender } from './senders/email.sender';
import { PreferenceService } from './preference.service';
+import { EventsGateway } from '../gateways/escrow.gateway';
@Injectable()
export class NotificationService {
@@ -24,6 +25,7 @@ export class NotificationService {
private preferenceService: PreferenceService,
emailSender: EmailSender,
webhookSender: WebhookSender,
+ @Optional() private readonly eventsGateway?: EventsGateway,
) {
this.senders = new Map([
[NotificationChannel.EMAIL, emailSender],
@@ -42,7 +44,7 @@ export class NotificationService {
if (!pref.enabled) continue;
if (!pref.eventTypes.includes(eventType)) continue;
- await this.repo.save(
+ const notification = await this.repo.save(
this.repo.create({
userId,
eventType,
@@ -51,6 +53,12 @@ export class NotificationService {
status: NotificationStatus.PENDING,
}),
);
+
+ this.eventsGateway?.broadcastNotification(userId, {
+ notificationId: notification.id,
+ eventType,
+ payload,
+ });
}
}