forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail.service.ts
More file actions
78 lines (70 loc) · 1.79 KB
/
Copy pathemail.service.ts
File metadata and controls
78 lines (70 loc) · 1.79 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
import { Injectable, Logger } from "@nestjs/common";
import { InjectQueue } from "@nestjs/bull";
import { Queue } from "bull";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { User } from "../entities/user.entity";
@Injectable()
export class EmailService {
private readonly logger = new Logger(EmailService.name);
constructor(
@InjectQueue("email_queue") private readonly emailQueue: Queue,
@InjectRepository(User) private readonly userRepository: Repository<User>,
) {}
async sendInvitation(
to: string,
context: {
inviterName: string;
splitDescription: string;
amount: number;
joinLink: string;
},
) {
await this.emailQueue.add("sendEmail", {
to,
type: "invitation",
context,
});
}
async sendPaymentReminder(
to: string,
context: {
participantName: string;
splitDescription: string;
amountDue: number;
paymentLink: string;
},
) {
await this.emailQueue.add("sendEmail", {
to,
type: "reminder",
context,
});
}
async sendPaymentConfirmation(
to: string,
context: { amount: number; splitDescription: string; txHash: string },
) {
await this.emailQueue.add("sendEmail", {
to,
type: "confirmation",
context,
});
}
async sendSplitCompleted(
to: string,
context: { splitDescription: string; totalAmount: number },
) {
await this.emailQueue.add("sendEmail", {
to,
type: "completed",
context,
});
}
async updatePreferences(userId: string, preferences: any) {
await this.userRepository.update(userId, { emailPreferences: preferences });
}
async getUser(userId: string) {
return this.userRepository.findOne({ where: { id: userId } });
}
}