Я работаю над приложением, которое должно отправить отчет на users email
, содержащий числа inbox messages
, outbox messages
и average
, которые будут outbox/inbox
за выбранный период времени.Прямо сейчас моя логика заключается в том, что когда пользователь выбирает start
и end date
, то есть до текущего дня, отчет отправляется автоматически.Если они выберут тот же день, он автоматически отправит.Как я могу проверить будущие даты?Поскольку у нас еще нет электронных писем на будущие даты, как я могу проверить, будет ли эта функция действительно работать?Я вставлю свой код ниже.
Edit1: я не уверен, в каком направлении следует следовать логике.Я знаю, что Повестка дня намечает рабочие места, но я не уверен, как это поможет с будущими датами.Я хочу быть в состоянии доказать, что я могу получить отчет для будущих дат.Как я могу сделать это, не имея необходимых данных электронной почты на данный момент?
Input
:
startDate: 05/01/2019
endDate: 05/08/2019
Expected Result
:
Toast message displays stating the report was generated. When the user reaches the day of 05/08/2019, the report is sent to them.
Actual Result
:
Toast message displays stating the report was generated. The report is sent to the inbox immediately showing both 0 messages for inbox and outbox. The average returned is NaN
autoreport.js
// gives us the date in the format 2019-03-01
let new_StartDate = parseStartdate.toISOString().slice(0, 10);
let new_EndtDate = parseEnddate.toISOString().slice(0, 10);
// gives us the current date
var rightnow = new Date().toLocaleDateString();
console.log("The current date and time is ", rightnow);
/* trying to check if user selects dates that are before today then we go ahead and
immediately send them the report containing the number of inbox,outbox,and average
emails sent
*/
if (
(parseStartdate && parseEnddate < rightnow) ||
parseStartdate == parseEnddate
) {
//if a user selects a date (select todays date) 2019-04-23:11:00
//on the backend add extra time ( to todays date) 2019-04-23:11:05
/// Add a minute or 30 seconds and see if it sends the report
// using SendGrid's v3 Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: `example@yahoo.com`,
from: `example@gmail.com`,
subject: "Report",
text: "and easy to do anywhere, even with Node.js",
html: `<div><h3>For the week of ${parseStartdate} to ${parseEnddate}</h3></div>
<div><h3> You have an Inbox count of : ${
filterDateSelections.length
}.</h3> </div>
<div><h3> An Outbox Count of : ${
filterDateSelections.length
}.</h3> </div>
<div> <h3> An Average of: ${(
checkIfOutbox.length / filterDateSelections.length
).toFixed(2)} for the week </h3> </div>`
// outbox: "response.outboxCount.Outbox"
};
sgMail.send(msg);
console.log("Wait 5 seconds...");
}
//run();
// here we check if the dates are greater
else if (parseStartdate && parseEnddate > rightnow || parseStartdate > rightnow) {
} else {
// end of check for past dates
console.log("The new date is ", new_StartDate - new_EndtDate);
// Schedule Job
// Agenda Job Scheduler
var connectionString =
`mongodb+srv://moe:${process.env.DB_PASS}@sera-outlook-edxbb.mongodb.net/test?retryWrites=true`;
var agenda = new Agenda({
db: {
address: connectionString,
collection: "agenda"
}
});
async function run() {
await agenda.start();
/*
define(jobName, [options], fn)
Defines a job with the name of jobName. When a job of jobName gets run,
it will be passed to fn(job, done). To maintain asynchronous behavior,
you must call done() when you are processing the job. If your function is
synchronous, you may omit done from the signature.
*/
// agenda.define("In five seconds", function(job, done) {
// console.log("hello world!");
// done();
// });
/*
Schedules a job to run name once at a given time.
when can be a Date or a String such as tomorrow at 5pm.
data is an optional argument that will be passed to the processing function under job.attrs.data.
cb is an optional callback function which will be called when the job has been persisted in the database.
Returns the job.
*/
agenda.schedule(`${rightnow}`, "First Test Run", {
time: new Date(),
startDate: `${rightnow}`,
endDate: "",
totalInboxCount: filterDateSelections.length,
totalOutboxCount: checkIfOutbox.length,
messageAverage: (
checkIfOutbox.length / filterDateSelections.length
).toFixed(2)
});
// using SendGrid's v3 Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: `example@yahoo.com`,
from: `example@gmail.com`,
subject: "Report",
text: "and easy to do anywhere, even with Node.js",
html: `For the week of ${parseStartdate} to ${parseEnddate}, You have an Inbox count of : ${
filterDateSelections.length
}.
An Outbox Count of : ${checkIfOutbox.length}.
and an verage of: ${(
checkIfOutbox.length / filterDateSelections.length
).toFixed(2)}`
// outbox: "response.outboxCount.Outbox"
};
sgMail.send(msg);
console.log("Wait 5 seconds...");
}
run();
}