Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions _dummyData/sprints.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
{
"title" : "운전 면허증 따기",
"percentage" : 100,
"score" : [0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3]
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}, {
"title" : "자격증 따기",
"percentage" : 53,
"score" : [0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3]
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}, {
"title" : "학점 4.0 넘기",
"percentage" : 42,
"score" : [0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3]
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}
],
"review": [
Expand Down Expand Up @@ -103,15 +103,15 @@
{
"title" : "운전 면허증 따기",
"percentage" : 0,
"score" : [0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3]
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}, {
"title" : "자격증 따기",
"percentage" : 0,
"score" : [0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3]
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}, {
"title" : "학점 4.0 넘기",
"percentage" : 0,
"score" : [0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3]
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}
],
"review": [
Expand Down Expand Up @@ -192,13 +192,16 @@
"goal": [
{
"title" : "운전 면허증 따기",
"score" : [0,0,0,5,3,0,-3]
"percentage" : 0,
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}, {
"title" : "자격증 따기",
"score" : [0,0,0,5,3,0,-3]
"percentage" : 0,
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}, {
"title" : "학점 4.0 넘기",
"score" : [0,0,0,5,3,0,-3]
"percentage" : 0,
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}
],
"review": [
Expand Down Expand Up @@ -277,13 +280,16 @@
"goal": [
{
"title" : "운전 면허증 따기",
"score" : [0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3]
"percentage" : 0,
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}, {
"title" : "자격증 따기",
"score" : [0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3]
"percentage" : 0,
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}, {
"title" : "학점 4.0 넘기",
"score" : [0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3,0,0,0,5,3,0,-3,-5,5,3]
"percentage" : 0,
"score" : {"2020-11-30": 0,"2020-12-01": 0,"2020-12-02": 0,"2020-12-03": 5,"2020-12-04": 3,"2020-12-05": 0,"2020-12-06": -3}
}
],
"review": [
Expand Down
49 changes: 48 additions & 1 deletion src/apis/routes/sprints.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express from 'express';
import SprintService from '../../services/sprint.js';
import asyncHandler from '../../modules/async.js';
import date from '../../modules/date.js';
import sprint from '../../services/sprint.js';

const router = express.Router();

Expand Down Expand Up @@ -44,8 +45,9 @@ router.post('/',
asyncHandler(async (req, res) => {
// The actual responsability of the route layer.
const sprintDTO = req.body;
const score = await date.getScoreDateMap(sprintDTO.startTime, sprintDTO.endTime);
sprintDTO.goal = await sprintDTO.goals.map((g) => {
return {title: g, percentage:0, socre:[]}
return {title: g, percentage:0, score:score}
});
const review = await date.getReviewDate(sprintDTO.nextReviewTime, sprintDTO.endTime, sprintDTO.day);
sprintDTO.review = await review.map((date) => {
Expand All @@ -60,4 +62,49 @@ router.post('/',
})
);

router.post('/',
// validators.getSprint, // this middleware take care of validation
asyncHandler(async (req, res) => {
// The actual responsability of the route layer.
const sprintDTO = req.body;
const score = await date.getScoreDateMap(sprintDTO.startTime, sprintDTO.endTime);
sprintDTO.goal = await sprintDTO.goals.map((g) => {
return {title: g, percentage:0, score:score}
});
const review = await date.getReviewDate(sprintDTO.nextReviewTime, sprintDTO.endTime, sprintDTO.day);
sprintDTO.review = await review.map((date) => {
return {reviewTime: date, averageAchievement:0, comments:[]}
});
// Call to service layer.
// Abstraction on how to access the data layer and the business logic.
const { success, message, data } = await SprintService.CreateService(sprintDTO);

// Return a response to client.
return res.json({ success, message, data });
})
);

router.put('/score/:id',
asyncHandler(async (req, res) => {
const id = req.params.id;
const {day, scores} = req.body;

const { success, message, data } = await SprintService.InsertScore({id, day, scores});

// Return a response to client.
return res.json({ success, message, data });
})
);

router.get('/review/:id',
asyncHandler(async (req, res) => {
const id = req.params.id;

const { success, message, data } = await SprintService.GetReview(id);

// Return a response to client.
return res.json({ success, message, data });
})
);

export default router;
3 changes: 2 additions & 1 deletion src/models/sprintModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const SprintSchema = new mongoose.Schema({
default: 0,
},
score: {
type: [Number],
type: Map,
of: String,
},
}],
review: [{
Expand Down
17 changes: 16 additions & 1 deletion src/modules/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,20 @@ export default {
nextTime = await this.getFormatDate(nextDate);
}
return reviewDateArray;
}
},

async getScoreDateMap(startTime, endTime) {
const initScore = -1;
const scoreDateArray = [[startTime, initScore]];
let nextDate = this.getDateType(startTime);
nextDate.setDate(nextDate.getDate() + 1);
let nextTime = await this.getFormatDate(nextDate);
while(nextTime <= endTime ) {
scoreDateArray.push([nextTime, initScore]);
nextDate = this.getDateType(nextTime);
nextDate.setDate(nextDate.getDate() + 1);
nextTime = await this.getFormatDate(nextDate);
}
return new Map(scoreDateArray);
},
};
5 changes: 4 additions & 1 deletion src/modules/responseMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ export default {
NO_SPRINT: '현재 진행중인 스프린트가 없습니다.',
SPRINT_CREATE_SUCCESS: '스프린트 추가에 성공했습니다.',
SPRINT_CREATE_FAIL: '스프린트 추가에 실패했습니다.',

SPRINT_SCORE_SUCCESS: '스프린트 점수 입력에 성공했습니다.',
SPRINT_SCORE_FAIL: '스프린트 점수 입력에 실패했습니다.',
SPRINT_REVIEW_READ_SUCCESS: '해당 스프린트의 회고 정보 조회에 성공했습니다.',
SPRINT_REVIEW_READ_FAIL: '해당 스프린트의 회고 정보 조회에 실패했습니다.',
};
21 changes: 21 additions & 0 deletions src/services/sprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,25 @@ export default {
}
return { success: true, message: message.SPRINT_CREATE_SUCCESS, data: sprintRecord };
},

async InsertScore({id, day, scores}) {
const sprint = await SprintModel.findById(id).select('-review -question');
if (!sprint) {
return { success: false, message: message.SPRINT_SCORE_FAIL, data: null };
}
scores.map((score, i) => {
sprint.goal[i].score.set(day, score);
})
sprint.save();
return { success: true, message: message.SPRINT_SCORE_SUCCESS, data: sprint };
},

async GetReview(id) {
const sprintReview = await SprintModel.findById(id).select('-goal -question');
// If the user is not an admin, they can only add one bootcamp
if (sprintReview && !sprintReview.progress) {
return { success: false, message: message.SPRINT_REVIEW_READ_FAIL, data: null };
}
return { success: true, message: message.SPRINT_REVIEW_READ_SUCCESS, data: sprintReview };
},
};