Немного разобрался, кто подскажет, правильный ли ход мыслей? :
Меняем checkUnsentOrders.js :
module.exports =async () => {
const startDate = startOfDate();
const endDate = endOfDate();
const dateBefore = dateBeforeGameDay();
const finishedGameStatusDayBefore = [
...finishedGameOrdersStatusIds
];
let listGameOrders = await getGameOrdersForEmailing(startDate, endDate);
let finishGameOrdersStatus = listGameOrders.filter((order) => {
const gameDate = DateTime.fromJSDate(order.pickupDate)
.toJSDate();
if (dateBefore.getDay() === gameDate.getDay()) {
return !finishedGameStatusDayBefore.includes(order.GameStatus);
}
return !finishedGameOrdersStatusIds.includes(order.GameStatus);
});
let rows = finishGameOrdersStatus
.map(
(id) =>
`</td><td>${game.id}</td></tr>`
)
let view = ``;
let statusGameOrdersView = `
<style></style>
`;
await sentGameHtmlEmail(statusGameOrdersView);
};
и gameMailUnsentOrders.js
const processGamerReminderEmail = async (gamerOrders: OrderData[]) => {
const firstOrder = _.head(gamerOrders);
const gamerName = firstOrder
? firstOrder.gamerName
? firstOrder.gamerName
: ""
: "";
const gamerId = firstOrder
? firstGameOrder.gamerId
? firstGameOrder.gamerId
: ""
: "";
const gamerData = await (await gamer.doc(gamerId).get()).data();
const gamerReminderEmail = gamerData.reminderEmail;
if (gamerReminderEmail === "" || !gamerReminderEmail) {
console.log(
` ${gamerName} reminder email is not detected`
);
return;
}
let rows = gamerOrders
.map(
(doc: OrderData) =>
`...`
)
let view = `<table></table>
`;
return await sentGameHtmlEmail(
gamerReminderEmail
);
};
module.exports = async () => {
const startDate = startOfDate();
const endDate = endOfDate();
const dateBefore = dateBeforeGameDay();
const finalizedStatusDayBefore = [
...finalisedOrdersStatusIds
];
let listGameOrders = await getGameOrdersMailing(startDate, endDate);
let ordersStatus = listGameOrders.filter((gameOrder) => {
const gameDate = DateTime.fromJSDate(gameOrder.gamePDate)
.toJSDate();
if (dateBefore.getDay() === gameDate.getDay()) {
return !finalizedStatusDayBefore.includes(gameOrder.gameStatus.id);
}
return !finalisedOrdersStatusIds.includes(gameOrder.gameStatus.id);
});
let orderedByGamerId = _.orderBy(
ordersStatus.map((order) => order),
"gamerId"
);
return await Promise.all(
_.map(orderedByGamerId, (gameOrders: OrderData[]) => {
return processGamerReminderEmail(gameOrders);
})
);
};
и потом в новосозданой кроне , например dailyEmails.js:
module.exports = functions.pubsub
.schedule("0 0 12 * *")
.timeZone("")
.onRun(async () => {
await checkUnsentOrders();
await gameMailUnsentOrders();
]);
});