Skip to content

Commit

Permalink
added checks and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
NIDHI2023 committed Dec 7, 2024
1 parent c6ae35d commit 098d54c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
25 changes: 23 additions & 2 deletions src/scripts/wrapped-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,31 @@ firebase_admin_1["default"].initializeApp({
databaseURL: 'https://qmi-test.firebaseio.com'
});
dotenv.config();
// eslint-disable-next-line no-console
console.log(process.env.RESEND_API_KEY);
var resend = new resend_1.Resend(process.env.RESEND_API_KEY);
/* Returns an array of email objects to send - should be at most 100 per day.
totalEmails is
batchSize should be 49 or less to maintain free emailing */
var createBatches = function (totalEmails, batchSize) {
var i = 0;
var emailObjs = [];
if (batchSize > 49) {
console.log("Batch size is too large. Must be no more than 49");
}
while (i < totalEmails.length && emailObjs.length <= 100) {
emailObjs.push({
from: '[email protected]',
to: ['[email protected]'],
bcc: totalEmails.slice(i, Math.min(i + batchSize, totalEmails.length)),
subject: 'QMI testing batch ' + i + '!',
html: '<strong>It works!</strong>'
});
i += batchSize;
}
if (emailObjs.length == 100) {
// eslint-disable-next-line no-console
console.log("Reached email limit of 100 emails per day.");
}
return emailObjs;
};
(function () { return __awaiter(void 0, void 0, void 0, function () {
var usersRef, usersSnapshot, userEmails, data, error_1;
Expand Down
14 changes: 11 additions & 3 deletions src/scripts/wrapped-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ admin.initializeApp({
dotenv.config();
const resend = new Resend(process.env.RESEND_API_KEY);

/* Returns an array of email objects to send - should be at most 100 per day.
totalEmails is
batchSize should be 49 or less to maintain free emailing */
const createBatches = (totalEmails: string[], batchSize: number) => {

Check failure on line 17 in src/scripts/wrapped-email.ts

View workflow job for this annotation

GitHub Actions / build

'createBatches' is assigned a value but never used
let i = 0;
const emailObjs = [];
while (i < totalEmails.length) {
if (batchSize > 49) {
console.log("Batch size is too large. Must be no more than 49");

Check failure on line 21 in src/scripts/wrapped-email.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
}
while (i < totalEmails.length && emailObjs.length <= 100) {

emailObjs.push(
{
Expand All @@ -27,6 +33,10 @@ const createBatches = (totalEmails: string[], batchSize: number) => {
)
i+= batchSize;
}
if (emailObjs.length == 100) {
// eslint-disable-next-line no-console
console.log("Reached email limit of 100 emails per day.")
}
return emailObjs;

}
Expand All @@ -49,8 +59,6 @@ const createBatches = (totalEmails: string[], batchSize: number) => {
// eslint-disable-next-line no-console
console.log(userEmails);

// TODO: Creating batch chunks - max limit of 49 for each batch
// TODO: Ensure we never exceed the 100 emails per day limit
//alternate structure, could use resend.batch.send with arrray of data
try {
//ALT:
Expand Down

0 comments on commit 098d54c

Please sign in to comment.