Merge branch 'dev' into staging
This commit is contained in:
commit
902eb23556
@ -13,6 +13,7 @@ import CronService from "@Services/common/CronService/CronService";
|
||||
Container.get(CronService).archiveFiles();
|
||||
await Container.get(CronService).updateUsers();
|
||||
if(variables.ENV !== "dev"){
|
||||
console.log("STG Good");
|
||||
Container.get(CronService).sendMails();
|
||||
Container.get(CronService).sendRecapMails();
|
||||
}
|
||||
|
@ -52,7 +52,9 @@ export default class MailchimpService extends BaseService {
|
||||
* @throws {Error} If email cannot be sent
|
||||
*/
|
||||
public async sendEmails() {
|
||||
console.log("sendEmails");
|
||||
const emailsToSend = await this.get({ where: { sentAt: null } });
|
||||
console.log(emailsToSend);
|
||||
const currentDate = new Date();
|
||||
let nextTrySendDate = null;
|
||||
|
||||
@ -72,12 +74,14 @@ export default class MailchimpService extends BaseService {
|
||||
|
||||
//If the next try send date is passed, we send the email
|
||||
if (currentDate >= nextTrySendDate) {
|
||||
console.log("if currentDate > nextTrySendDate");
|
||||
try {
|
||||
await this.sendEmail(email);
|
||||
email.sentAt = currentDate;
|
||||
} catch (error) {
|
||||
email.lastTrySendDate = currentDate;
|
||||
email.nbTrySend = email.nbTrySend! + 1;
|
||||
console.log(error);
|
||||
}
|
||||
await this.update(email.uid, email);
|
||||
}
|
||||
@ -85,7 +89,11 @@ export default class MailchimpService extends BaseService {
|
||||
}
|
||||
|
||||
private async sendEmail(email: Emails) {
|
||||
console.log("sendEmail");
|
||||
|
||||
const apiKey = this.variables.MAILCHIMP_API_KEY;
|
||||
console.log(apiKey);
|
||||
|
||||
const mailchimpApiClient = MailchimpClient(apiKey!);
|
||||
|
||||
await mailchimpApiClient.messages.sendTemplate({
|
||||
|
Loading…
x
Reference in New Issue
Block a user