forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulk-activity-example.ts
More file actions
43 lines (41 loc) · 1.15 KB
/
Copy pathbulk-activity-example.ts
File metadata and controls
43 lines (41 loc) · 1.15 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
import { Injectable } from "@nestjs/common";
import { ActivitiesService } from "./activities.service";
/**
* Example 4: Bulk Activity Tracking
* Useful for batch operations or migrations
*/
@Injectable()
export class BulkActivityExample {
constructor(private readonly activitiesService: ActivitiesService) {}
async trackBulkActivities(
activities: Array<{
userId: string;
type: "payment_made" | "payment_received";
splitId: string;
amount: number;
txHash: string;
}>
) {
// Process activities in parallel for better performance
await Promise.all(
activities.map(async (activity) => {
if (activity.type === "payment_made") {
await this.activitiesService.trackPaymentMade(
activity.userId,
activity.splitId,
activity.amount,
activity.txHash
);
} else {
await this.activitiesService.trackPaymentReceived(
activity.userId,
activity.splitId,
activity.amount,
activity.txHash,
"unknown" // sender address if available
);
}
})
);
}
}