Skip to content

Commit

Permalink
added some tsdoc, improved mail send error management
Browse files Browse the repository at this point in the history
  • Loading branch information
rfontanarosa committed Dec 16, 2024
1 parent f05b4ff commit 6990f3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
26 changes: 9 additions & 17 deletions functions/src/common/mail-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,15 @@ export class MailService {
},
});

await new Promise<void>((resolve, reject) => {
this.transporter_.sendMail(
{from: this.sender_, ...email, html: safeHtml},
(error: Error | any, _: any) => {
if (error) {
// 501 and 550 are errors from the mail server: email address not found
if (error.responseCode === 501 || error.responseCode === 550) {
reject(new Error(error.response));
} else {
reject(error);
}
} else {
resolve();
}
}
);
});
try {
await this.transporter_.sendMail({
from: this.sender_,
...email,
html: safeHtml,
});
} catch (err) {
console.error(err);
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions functions/src/on-create-loi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ type PropertyGenerator = {
url: string;
};

/**
* Handles the creation of a Location of Interest (LOI) document in Firestore.
* This function is triggered by a Cloud Function on Firestore document creation.
*
* @param snapshot The QueryDocumentSnapshot object containing the created LOI data.
* @param context The EventContext object provided by the Cloud Functions framework.
*/
export async function onCreateLoiHandler(
snapshot: QueryDocumentSnapshot,
context: EventContext
Expand Down
9 changes: 8 additions & 1 deletion functions/src/on-create-passlist-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import {getDatastore, getMailService} from './common/context';
import {MailServiceEmail} from './common/mail-service';
import {stringFormat} from './common/utils';

/**
* Handles the creation of a passlist entry.
* This function is triggered by a Cloud Function on Firestore document creation.
*
* @param _ The QueryDocumentSnapshot object (unused in this function).
* @param context The EventContext object provided by the Cloud Functions framework.
*/
export async function onCreatePasslistEntryHandler(
_: QueryDocumentSnapshot,
context: EventContext
Expand All @@ -31,7 +38,7 @@ export async function onCreatePasslistEntryHandler(
const template = await db.fetchMailTemplate('passlisted');

if (!template) {
console.error('Template not found in /config/mail/templates/passlisted');
console.debug('Template not found in /config/mail/templates/passlisted');
return;
}

Expand Down

0 comments on commit 6990f3e

Please sign in to comment.