Skip to content
Snippets Groups Projects
Commit a69e35e4 authored by Ranindya Paramitha's avatar Ranindya Paramitha Committed by Ihsan M. A.
Browse files

#123 Fix get credits

parent 33b3d06d
1 merge request!96#123 Fix get credits
......@@ -151,7 +151,10 @@
"ip": 3.5,
"ipk": 3.5
},
"creditsTotal": 7
"credits": {
"passed": 3,
"scoreT": 2
}
}
```
......
......@@ -11,7 +11,7 @@ const {
const {
getStudent,
getCreditsTotal,
getCredits,
getHistoricalTranscript,
getStudentIP,
getStudentIPK,
......@@ -40,7 +40,7 @@ exports.getStudentData = async (req, res) => {
}
if (req.includeCredits.toLowerCase() === 'true') {
student.dataValues.creditsTotal = await getCreditsTotal(student);
student.dataValues.credits = await getCredits(student);
}
res.json(student);
......
......@@ -234,7 +234,7 @@ describe('Student Test', () => {
res.body.should.have.property('nim');
res.body.should.have.property('nik');
res.body.should.have.property('phone');
res.body.should.have.property('creditsTotal').to.not.eql(null);
res.body.should.have.property('credits').to.not.eql(null);
res.body.should.have.property('advisorId');
res.body.should.have.property('createdAt');
res.body.should.have.property('updatedAt');
......
......@@ -3,6 +3,7 @@ const {
StudyPlanCourse,
Student,
CourseClass,
Course,
} = require('../../models/index');
const { ScoreEnum, ScoreStatusEnum } = require('../../enums/index');
......@@ -106,8 +107,9 @@ const getStudentNR = async (student) => {
return nr;
};
const getCreditsTotal = async (student) => {
let total = 0;
const getCredits = async (student) => {
let passed = 0;
let scoreT = 0;
let studyPlans = student.studyPlans;
if (!studyPlans) {
......@@ -115,10 +117,17 @@ const getCreditsTotal = async (student) => {
}
for (const studyPlan of studyPlans) {
total += studyPlan.creditsTotal;
for (const studyPlanCourse of studyPlan.studyPlanCourses){
if (ScoreEnum[studyPlanCourse.score].value >= ScoreEnum.C.value && studyPlanCourse.scoreStatus === ScoreStatusEnum.FINAL){
passed += studyPlanCourse.CourseClass.Course.credits;
}
if (ScoreEnum[studyPlanCourse.score].name === ScoreEnum.T.name || studyPlanCourse.scoreStatus !== ScoreStatusEnum.FINAL){
scoreT += studyPlanCourse.CourseClass.Course.credits;
}
}
}
return total;
return {passed, scoreT};
};
const getStudent = async (opts) => {
......@@ -142,6 +151,9 @@ const getHistoricalTranscript = async (studentId) => {
{
model: CourseClass,
attributes: ['courseId'],
include: [{
model: Course
}]
},
],
},
......@@ -157,7 +169,7 @@ module.exports = {
getStudentIPK,
getStudentIP,
getStudentNR,
getCreditsTotal,
getCredits,
getStudent,
getHistoricalTranscript,
};
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment