Как правильно можно засунуть эти 2 триггера в отдельные 2 метода(exampleWork1 и exampleWork2)?
module.exports = functions.pubsub
.schedule("0 0 12 * *")
.timeZone("")
.onRun(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);
});
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 = functions.pubsub
.schedule("0 0 12 * *")
.timeZone("")
.onRun(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);
})
);
});
Я так понимаю что выглядить методы должны приблизительно так?:
newGameEmails(()==>{
exampleWork1(),
exampleWork2()})