Skip to content

Commit

Permalink
Merge branch 'main' of github.com:oddsteam/training-api
Browse files Browse the repository at this point in the history
  • Loading branch information
qapd01 committed Mar 31, 2024
2 parents a5878bb + 80db0b1 commit 141b822
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 42 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ jobs:
aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin 844772501268.dkr.ecr.ap-southeast-1.amazonaws.com
docker pull $DOCKER_IMAGE_WITH_TAG
docker stop training-api | true
docker rm training-api | true
docker run -p 3001:3001 --name training-api -d $DOCKER_IMAGE_WITH_TAG -e $DB_URI
1 change: 1 addition & 0 deletions .github/workflows/ci.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ jobs:
aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin 844772501268.dkr.ecr.ap-southeast-1.amazonaws.com
docker pull $DOCKER_IMAGE_WITH_TAG
docker stop training-api | true
docker rm training-api | true
docker run -p 3001:3001 --name training-api -d $DOCKER_IMAGE_WITH_TAG -e $DB_URI
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ node v20

npm i

npm run start
npm run start

------
กรณีที่ต้องการใช้ email service ให้ทำการ set up ดังนี้

1. ติดตั้ง [aws cli](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
2. configure aws credentials ด้วย command `aws configure` (credentials อยู่ใน discord)
174 changes: 174 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@babel/core": "^7.24.3",
"@babel/node": "^7.23.9",
"@babel/preset-env": "^7.24.3",
"aws-sdk": "^2.1589.0",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
Expand Down
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);
}
};
Loading

0 comments on commit 141b822

Please sign in to comment.