Skip to content

Commit

Permalink
create remind class
Browse files Browse the repository at this point in the history
  • Loading branch information
kktsdk committed Mar 31, 2024
1 parent 3982ab4 commit 80db0b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 41 deletions.
53 changes: 12 additions & 41 deletions src/controllers/reminder.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,17 @@
const createContent = function (class_detail, enrollmentInfo) {
return `Hello ${enrollmentInfo.fullName} <br> Welcome! Also looking forward to joining with you for 3 days of Certified LeSS Practitioner: Principles to Practices by Bas Vodde.<br>`
}
const classService = require('../services/classes');
const enrollmentService = require('../services/classes');

const setEmailClassReminder = function (req, res){

const classes = [{
id: 1,
description: `ตอนผู้สอนทั้ง 2 มาเป็น ScrumMaster ใหม่ ๆ เราพบช่วงเวลายากลำบากหลายครั้ง`,
place:"Geeky Base All Star",
googleMapUrl: "https://maps.app.goo.gl/UQKuNzejJNNwVB2K9",
startDate: "2024-03-22T04:51:16.100Z",
endDate: "31/3/2024",
instructor: [{name: 'Jane'}]
},
{
id: 2,
description: `ตอนผู้สอนทั้ง 2 มาเป็น ScrumMaster ใหม่ ๆ เราพบช่วงเวลายากลำบากหลายครั้ง`,
place:"Geeky Base All Star",
googleMapUrl: "https://maps.app.goo.gl/UQKuNzejJNNwVB2K9",
startDate: "2024-03-22T04:51:16.100Z",
endDate: "31/3/2024",
instructor: [{name: 'Jane'}]
}]

for (let cls in classes) {
const enrollmentInfo = {
classId: 1,
email: 1,
fullName: "Roofimon",
}
const content = createContent(cls, enrollmentInfo);
console.log(content)
const startDate = new Date(cls.startDate)
console.log("ss", startDate)
const dateNow = Date.now()
// if (startDate.getDate() - 5 === dateNow) {
// // sendEmail(enrollmentInfo.email, cls.name, content);
// console.log("Send email")
// }
}

res.send("Success")
const classesData = classService.getClasses();
for (let cls in classesData) {
const enrollmentData = enrollmentService.getEnrollmentByClassId(cls.classId)
const startDate = new Date(cls.startDate)
const dateNow = Date.now()
if (startDate.getDate() - 5 === dateNow) {
sendEmail(enrollmentData.email, cls.name, cls.preClassContent);
}
}
res.send("Success")
}

exports.setEmailClassReminder = setEmailClassReminder;
9 changes: 9 additions & 0 deletions src/services/enrollment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ export const create = async (body) => {
console.log(error);
}
};

export const getEnrollmentByClassId = async (classId) => {
try {
const data = await EnrollmentModel.findOne({ classId });
return data;
} catch (error) {
console.log(error);
}
};

0 comments on commit 80db0b1

Please sign in to comment.