@@ -90,40 +90,71 @@ export const sendAddedToWaitlistEmail = async ({
9090export const sendTicketInvitationEmails = async ( {
9191 DB ,
9292 logger,
93- users,
94- ticketId,
93+ userTicketIds,
9594 RPC_SERVICE_EMAIL ,
9695} : {
9796 DB : ORM_TYPE ;
9897 logger : Logger ;
99- users : USER [ ] ;
100- ticketId : string ;
98+ userTicketIds : string [ ] ;
10199 RPC_SERVICE_EMAIL : Context [ "RPC_SERVICE_EMAIL" ] ;
102100} ) => {
103- const ticketInformation = await DB . query . ticketsSchema . findFirst ( {
104- where : ( t , { eq } ) => eq ( t . id , ticketId ) ,
101+ const userTickets = await DB . query . userTicketsSchema . findMany ( {
102+ where : ( t , { inArray } ) => inArray ( t . id , userTicketIds ) ,
105103 with : {
106- event : true ,
104+ user : true ,
105+ ticketTemplate : {
106+ with : {
107+ event : true ,
108+ } ,
109+ } ,
107110 } ,
108111 } ) ;
109112
110- if ( ! ticketInformation ) {
111- throw applicationError (
112- `Could not find ticket and event information associated to: ${ ticketId } ` ,
113- ServiceErrors . NOT_FOUND ,
114- logger ,
115- ) ;
116- }
113+ const to : {
114+ name ?: string ;
115+ email : string ;
116+ tags : { name : string ; value : string } [ ] ;
117+ userTicketId : string ;
118+ ticketName : string ;
119+ ticketId : string ;
120+ eventId : string ;
121+ } [ ] = [ ] ;
122+
123+ userTickets . forEach ( ( userTicket ) => {
124+ if ( ! userTicket . user ) {
125+ return null ;
126+ }
127+
128+ to . push ( {
129+ name : userTicket . user . name ?? undefined ,
130+ email : userTicket . user . email ,
131+ ticketName : userTicket . ticketTemplate . name ,
132+ ticketId : userTicket . ticketTemplate . id ,
133+ userTicketId : userTicket . id ,
134+ eventId : userTicket . ticketTemplate . event . id ,
135+ tags : [
136+ {
137+ name : "userTicket" ,
138+ value : userTicket . id ,
139+ } ,
140+ {
141+ name : "ticketId" ,
142+ value : userTicket . ticketTemplate . id ,
143+ } ,
144+ {
145+ name : "eventId" ,
146+ value : userTicket . ticketTemplate . event . id ,
147+ } ,
148+ {
149+ name : "userId" ,
150+ value : userTicket . user ?. id ?? "" ,
151+ } ,
152+ ] ,
153+ } ) ;
154+ } ) ;
117155
118156 await RPC_SERVICE_EMAIL . bulkSendEventTicketInvitations ( {
119- eventName : ticketInformation . event . name ,
120- ticketId : ticketInformation . id ,
121- eventId : ticketInformation . event . id ,
122- to : users . map ( ( user ) => ( {
123- name : user . name ?? undefined ,
124- email : user . email ,
125- tags : [ ] ,
126- } ) ) ,
157+ to,
127158 } ) ;
128159} ;
129160
@@ -207,6 +238,6 @@ export const sendActualUserTicketQREmails = async ({
207238
208239 await RPC_SERVICE_EMAIL . bulkSendUserQRTicketEmail ( {
209240 to,
210- eventName : userTickets [ 0 ] . ticketTemplate . event . name ,
241+ ticketName : userTickets [ 0 ] . ticketTemplate . name ,
211242 } ) ;
212243} ;
0 commit comments