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