@@ -35,63 +35,50 @@ export class NotificationsService {
3535 { user : transaction . seller , role : 'Seller' } ,
3636 ] ;
3737
38- for ( const party of parties ) {
39- const { user, role } = party ;
40- const preferences = user . preferences ;
41-
42- const title = `Transaction ${ transaction . status } ` ;
43- const message = `Your transaction for property "${ transaction . property . title } " has been updated to ${ transaction . status } .` ;
44-
45- // 1. In-App Notification
46- const canInApp = await this . userPreferencesService . shouldDeliverNotification (
47- user . id ,
48- 'TRANSACTION_UPDATE' ,
49- 'inApp' ,
50- ) ;
51- if ( canInApp ) {
52- await this . sendNotification ( user . id , title , message , 'TRANSACTION_UPDATE' , {
53- transactionId : transaction . id ,
54- status : transaction . status ,
55- } ) ;
56- }
57-
58- // 2. Email Notification with template
59- const canEmail = await this . userPreferencesService . shouldDeliverNotification (
60- user . id ,
61- 'TRANSACTION_UPDATE' ,
62- 'email' ,
63- ) ;
64- if ( canEmail ) {
65- await this . emailService . sendTransactionStatusEmail ( user . email , transaction . status , {
66- transactionId : transaction . id ,
67- propertyTitle : transaction . property . title ,
68- propertyAddress : `${ transaction . property . address } , ${ transaction . property . city } , ${ transaction . property . state } ${ transaction . property . zipCode } ` ,
69- buyerName : transaction . buyer . firstName
70- ? `${ transaction . buyer . firstName } ${ transaction . buyer . lastName || '' } `
71- : transaction . buyer . email ,
72- sellerName : transaction . seller . firstName
73- ? `${ transaction . seller . firstName } ${ transaction . seller . lastName || '' } `
74- : transaction . seller . email ,
75- amount : `$${ Number ( transaction . amount || 0 ) . toLocaleString ( ) } ` ,
76- completionDate :
77- transaction . status === 'COMPLETED' ? new Date ( ) . toLocaleDateString ( ) : undefined ,
78- blockchainTxHash : transaction . blockchainTxHash || undefined ,
79- cancellationReason : transaction . cancellationReason || undefined ,
80- cancelledDate :
81- transaction . status === 'CANCELLED' ? new Date ( ) . toLocaleDateString ( ) : undefined ,
82- } ) ;
83- }
84-
85- // 3. SMS Notification
86- const canSms = await this . userPreferencesService . shouldDeliverNotification (
87- user . id ,
88- 'TRANSACTION_UPDATE' ,
89- 'sms' ,
90- ) ;
91- if ( canSms && user . phone ) {
92- await this . smsService . sendSms ( user . phone , message ) ;
93- }
94- }
38+ await Promise . all (
39+ parties . map ( async ( { user, role } ) => {
40+ const title = `Transaction ${ transaction . status } ` ;
41+ const message = `Your transaction for property "${ transaction . property . title } " has been updated to ${ transaction . status } .` ;
42+
43+ const [ canInApp , canEmail , canSms ] = await Promise . all ( [
44+ this . userPreferencesService . shouldDeliverNotification ( user . id , 'TRANSACTION_UPDATE' , 'inApp' ) ,
45+ this . userPreferencesService . shouldDeliverNotification ( user . id , 'TRANSACTION_UPDATE' , 'email' ) ,
46+ this . userPreferencesService . shouldDeliverNotification ( user . id , 'TRANSACTION_UPDATE' , 'sms' ) ,
47+ ] ) ;
48+
49+ await Promise . all ( [
50+ canInApp
51+ ? this . sendNotification ( user . id , title , message , 'TRANSACTION_UPDATE' , {
52+ transactionId : transaction . id ,
53+ status : transaction . status ,
54+ } )
55+ : Promise . resolve ( ) ,
56+ canEmail
57+ ? this . emailService . sendTransactionStatusEmail ( user . email , transaction . status , {
58+ transactionId : transaction . id ,
59+ propertyTitle : transaction . property . title ,
60+ propertyAddress : `${ transaction . property . address } , ${ transaction . property . city } , ${ transaction . property . state } ${ transaction . property . zipCode } ` ,
61+ buyerName : transaction . buyer . firstName
62+ ? `${ transaction . buyer . firstName } ${ transaction . buyer . lastName || '' } `
63+ : transaction . buyer . email ,
64+ sellerName : transaction . seller . firstName
65+ ? `${ transaction . seller . firstName } ${ transaction . seller . lastName || '' } `
66+ : transaction . seller . email ,
67+ amount : `$${ Number ( transaction . amount || 0 ) . toLocaleString ( ) } ` ,
68+ completionDate :
69+ transaction . status === 'COMPLETED' ? new Date ( ) . toLocaleDateString ( ) : undefined ,
70+ blockchainTxHash : transaction . blockchainTxHash || undefined ,
71+ cancellationReason : transaction . cancellationReason || undefined ,
72+ cancelledDate :
73+ transaction . status === 'CANCELLED' ? new Date ( ) . toLocaleDateString ( ) : undefined ,
74+ } )
75+ : Promise . resolve ( ) ,
76+ canSms && user . phone
77+ ? this . smsService . sendSms ( user . phone , message )
78+ : Promise . resolve ( ) ,
79+ ] ) ;
80+ } ) ,
81+ ) ;
9582 }
9683
9784 async sendNotification (
0 commit comments