@@ -22,7 +22,7 @@ import { MailingModule } from './mailing.module'
2222type Templates = Record < string , string > & { default : string }
2323
2424interface 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 (
0 commit comments