在这里,我使用的是节点crone箭头函数,我无法在cron箭头函数内部获取返回值,如果在返回值ined之后的条件下,我需要在for循环2nd内部使用这个cron箭头,如果我在2nd上方传递这个箭头函数,如果条件promiser显示错误。
我在这里附上了我的代码,我在这里做的事情,如果我注册了,我会收到第一封邮件,在这封邮件中,我有一个确认链接,如果我没有点击,我需要在第二天和第三天发送一封提醒邮件,请确认它应该等待一天,然后自动发送剩余邮件。
const loginemail = async (req: Request) => {
const connection = await createConnection()
try {
const [dashboardJobCount]: any = await connection.query(`select account_id,datediff(now(),created_date) as days,username,verified,email from account where verified=false;`)
const client = Sib.ApiClient.instance
const apiKey = client.authentications['api-key']
apiKey.apiKey = process.env.SIB_API_KEY
const tranEmailApi = new Sib.TransactionalEmailsApi()
const sender = {
email: 'jagadeeshwaran907@gmail.com',
name: 'Anjan',
}
cron.schedule('* * * * *', async() => {
for (let i = 0; i < dashboardJobCount.length; i++) {
const firstMail = {
sender,
to: [{email: dashboardJobCount[i].email}],
subject: 'Testing mail 1st day',
textContent: `
Cules Coding will teach you how to become {{params.role}} a developer.
`,
templateId: 1,
params: {
role: 'Frontend',
},
}
const secondMail = {
sender,
to:[{email: dashboardJobCount[i].email}],
subject: 'Testing mail 2nd day',
textContent: `
Cules Coding will teach you how to become {{params.role}} a developer.
`,
templateId: 2,
params: {
role: 'Frontend',
},
}
const thirdMail = {
sender,
to: [{email: dashboardJobCount[i].email}],
subject: 'Testing mail 4th day',
textContent: `
Cules Coding will teach you how to become {{params.role}} a developer.
`,
templateId: 2,
params: {
role: 'Frontend',
},
}
if([0,1,2].includes(dashboardJobCount[i].days)){
const msg = await tranEmailApi.sendTransacEmail(firstMail)
console.log("1st",msg)
return msg
}
else if([3].includes(dashboardJobCount[i].days)){
const msg = await tranEmailApi.sendTransacEmail(secondMail)
// console.log("kkkk", dashboardJobCount[i].days)
console.log("2nd",msg)
return msg
}
else if([4,5,6].includes(dashboardJobCount[i].days)){
const msg = await tranEmailApi.sendTransacEmail(thirdMail)
console.log("kkkk", dashboardJobCount[i].days)
return msg
}
else{
console.log("your account has deleted")
}
}
})
} catch (error) {
await connection.end()
throw error
}
}