Skip to content

Commit 2d0bdb5

Browse files
committed
use send to many instead of send bulk endpoint of kir-mail
1 parent 11a884a commit 2d0bdb5

File tree

3 files changed

+38
-51
lines changed

3 files changed

+38
-51
lines changed

src/mailing/mailing.service.ts

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { MailingModule } from './mailing.module'
2222
type Templates = Record<string, string> & { default: string }
2323

2424
interface SendMail {
25-
to: string
25+
to: string[]
2626
from: {
2727
name: string
2828
}
@@ -107,29 +107,28 @@ export class MailingService {
107107
* Sends a mail through the mailing delivery service provided in the setup process.
108108
* @param {SendMail[]} data - Array of objects containing to, from, subject and html string fields.
109109
*/
110-
async sendMail(data: SendMail[]) {
110+
async sendMail(data: SendMail) {
111111
MailingService.checkSetup()
112112
if (process.env.NODE_ENV !== 'production') {
113113
this.logger.debug(
114-
`The app would be sending ${data.length} email(s) right now, but email sending is only enabled in production.`,
114+
`The app would be sending ${data.to.length} email(s) right now, but email sending is only enabled in production.`,
115115
)
116116
return Promise.resolve(false)
117117
}
118118
try {
119119
await axios.post(
120120
MailingService.mailServerUrl,
121121
{
122-
messages: data.map((email) => ({
123-
...email,
124-
queue: process.env.MAIL_QUEUE,
125-
})),
122+
...data,
126123
queue: process.env.MAIL_QUEUE,
127124
},
128125
{
129126
headers: { Authorization: `Api-Key ${MailingService.apiKey}` },
130127
},
131128
)
132-
this.logger.log(`${data.length} email data sent to Kir-Dev email service`)
129+
this.logger.log(
130+
`${data.to.length} email data sent to Kir-Dev email service`,
131+
)
133132
return true
134133
} catch (e) {
135134
this.logger.log('Error during email sending')
@@ -169,8 +168,9 @@ export class MailingService {
169168
consultationQuery,
170169
])
171170

172-
await this.sendMail(
173-
[...request.supporters, request.initializer]
171+
await this.sendMail({
172+
from: { name: 'Konzisite' },
173+
to: [...request.supporters, request.initializer]
174174
.filter((u) => {
175175
if (!u.email) return false
176176
const ability = this.caslFactory.createForConsultationRead(u)
@@ -179,20 +179,13 @@ export class MailingService {
179179
subject('Consultation', consultation),
180180
)
181181
})
182-
.map((u) => {
183-
const html = this.generateMail({
184-
firstName: u.firstName,
185-
subjectName: request.subject.name,
186-
consultationUrl: `${process.env.FRONTEND_HOST}/consultations/${consultation.id}`,
187-
})
188-
return {
189-
from: { name: 'Konzisite' },
190-
to: u.email,
191-
subject: 'Megvalósul egy konzi kérésed!',
192-
html,
193-
}
194-
}),
195-
)
182+
.map((u) => u.email),
183+
subject: 'Megvalósul egy konzi kérésed!',
184+
html: this.generateMail({
185+
subjectName: request.subject.name,
186+
consultationUrl: `${process.env.FRONTEND_HOST}/consultations/${consultation.id}`,
187+
}),
188+
})
196189
}
197190

198191
@OnEvent(ConsultationDetailsChangedKey)
@@ -208,8 +201,9 @@ export class MailingService {
208201
},
209202
})
210203

211-
await this.sendMail(
212-
consultation.participants
204+
await this.sendMail({
205+
from: { name: 'Konzisite' },
206+
to: consultation.participants
213207
// get the actual user from the Participation
214208
.map((p) => p.user)
215209
.filter((u) => {
@@ -220,29 +214,22 @@ export class MailingService {
220214
subject('Consultation', consultation),
221215
)
222216
})
223-
.map((u) => {
224-
const html = this.generateMail(
225-
{
226-
firstName: u.firstName,
227-
consultationName: consultation.name,
228-
consultationUrl: `${process.env.FRONTEND_HOST}/consultations/${consultation.id}`,
229-
dateChanged: this.formatDateChange(
230-
consultation,
231-
payload.startDateChanged,
232-
payload.endDateChanged,
233-
),
234-
locationChanged: payload.locationChanged,
235-
},
236-
'konziDetailsChanged',
237-
)
238-
return {
239-
from: { name: 'Konzisite' },
240-
to: u.email,
241-
subject: 'Megváltozott egy konzultáció helyszíne/időpontja!',
242-
html,
243-
}
244-
}),
245-
)
217+
.map((u) => u.email),
218+
subject: 'Megváltozott egy konzultáció helyszíne/időpontja!',
219+
html: this.generateMail(
220+
{
221+
consultationName: consultation.name,
222+
consultationUrl: `${process.env.FRONTEND_HOST}/consultations/${consultation.id}`,
223+
dateChanged: this.formatDateChange(
224+
consultation,
225+
payload.startDateChanged,
226+
payload.endDateChanged,
227+
),
228+
locationChanged: payload.locationChanged,
229+
},
230+
'konziDetailsChanged',
231+
),
232+
})
246233
}
247234

248235
private formatDateChange(

src/templates/konziDetailsChanged.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
<tr>
189189
<td style="padding: 20px">
190190
<h1 style="text-align: center">Megváltozott egy konzultáció helyszíne/időpontja!</h1>
191-
<p class="greet">Kedves <%=firstName%>!</p>
191+
<p class="greet">Szia!</p>
192192
<p style="text-align: justify">
193193
Megváltoztak a <b><%=consultationName%></b> konzultáció egyes adatai:
194194
</p>

src/templates/requestFulfilled.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
<tr>
186186
<td style="padding: 20px">
187187
<h1 style="text-align: center">Új konzit regisztráltak!</h1>
188-
<p class="greet">Kedves <%=firstName%>!</p>
188+
<p class="greet">Szia!</p>
189189
<p style="text-align: justify">
190190
Konzit fognak tartani egy általad is támogatott kérésre
191191
<b><%=subjectName%></b> tárgyból. Jelentkezés és további

0 commit comments

Comments
 (0)