supervisor step3
This commit is contained in:
32
supervisor/html/js/utils/PointsCalculator.js
Normal file
32
supervisor/html/js/utils/PointsCalculator.js
Normal file
@ -0,0 +1,32 @@
|
||||
// js/utils/PointsCalculator.js
|
||||
export class PointsCalculator {
|
||||
calculate({ checkins, latePoints = 0 }) {
|
||||
const totalPoints = this.calculateTotalPoints(checkins);
|
||||
const buyPoints = this.calculateBuyPoints(checkins);
|
||||
|
||||
return {
|
||||
totalPoints,
|
||||
buyPoints,
|
||||
latePoints,
|
||||
finalPoints: totalPoints + buyPoints + latePoints
|
||||
};
|
||||
}
|
||||
|
||||
calculateTotalPoints(checkins) {
|
||||
return checkins.reduce((total, checkin) => {
|
||||
if (checkin.validate_location && !checkin.buy_flag) {
|
||||
return total + (checkin.checkin_point || 0);
|
||||
}
|
||||
return total;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
calculateBuyPoints(checkins) {
|
||||
return checkins.reduce((total, checkin) => {
|
||||
if (checkin.validate_location && checkin.buy_flag) {
|
||||
return total + (checkin.buy_point || 0);
|
||||
}
|
||||
return total;
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user