Skip to content

Commit bdeed9e

Browse files
committed
fix(api): skip email if recipients are empty
1 parent 4c33375 commit bdeed9e

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

functions/database/submissions/onCancelSubmission.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ export const cancelSubmission = async (before) => {
1010
// only email ugrc with empty county
1111
const to = await getContactsToNotify(db, null);
1212

13+
if (!to || to.length === 0) {
14+
logger.error('no contacts to notify', { structuredData: true });
15+
16+
return;
17+
}
18+
1319
const template = {
1420
method: 'post',
1521
url: '/v3/mail/send',

functions/emailHelper.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const docMock = vi.fn(() => {
1111
beaver: [{ name: 'beaver', email: 'beaver-email' }],
1212
};
1313
}),
14+
exists: true,
1415
};
1516
}),
1617
};

functions/emailHelpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const notify = (key, template) => {
3131
export const getContactsToNotify = async (db, county) => {
3232
const documentReference = db.collection('contacts').doc('admin');
3333
const documentSnapshot = await documentReference.get();
34+
3435
if (!documentSnapshot.exists) {
3536
logger.error('contacts document does not exist', {
3637
structuredData: true,

functions/storage/onCreateNotify.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export const createNotify = async (
5050
// TODO add document.county to add the county contacts #199
5151
const to = await getContactsToNotify(db, null);
5252

53+
if (!to || to.length === 0) {
54+
logger.error('no contacts to notify', { structuredData: true });
55+
56+
return;
57+
}
58+
5359
const template = {
5460
method: 'post',
5561
url: '/v3/mail/send',

0 commit comments

Comments
 (0)