Skip to content

Commit a979f43

Browse files
committed
feature: Add project conclusion progression; code: some code refactor
1 parent 422c93c commit a979f43

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

api/controllers/projects.controller.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ const getProjectTasks = async (req, res) => {
8989
const projectId = req.params.id;
9090

9191
try {
92-
const project = await projectsService.getProjectTasks(userId, projectId, req.body);
92+
const projectTasks = await projectsService.getProjectTasks(userId, projectId, req.body);
9393

94-
if (!project) {
94+
if (!projectTasks) {
9595
return expressResponsesKit.sendError(res, { code: ERROR_CODES_CONSTANTS.PROJECT_NOT_FOUND });
9696
}
9797

98-
return expressResponsesKit.sendSuccess(res, project.refTasks || []);
98+
return expressResponsesKit.sendSuccess(res, projectTasks || []);
9999
}
100100
catch (error) {
101101
const stackTrace = {};

api/services/projects.service.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
const { ERROR_CODES_CONSTANTS } = require('../../framework');
22
const ProjectModel = require('../models/projects.model');
33

4-
const getProjectElementsFiltered = (project) => ({
4+
const getProjectDetails = (project) => ({
55
_id: project._id,
66
name: project.name,
7-
refTasks: project.refTasks
7+
totalTasks: project.refTasks.length,
8+
totalFinishedTasks: project.refTasks.filter((task) => task.finishDate).length
89
});
910

1011
const addProject = async (userId, dataObject) => {
1112
const { name } = dataObject;
1213

1314
const createdProject = await ProjectModel.addProject(userId, { name });
1415

15-
return getProjectElementsFiltered(createdProject);
16+
return getProjectDetails(createdProject);
1617
};
1718

1819
const getProjects = async (userId) => {
1920
const projectsList = await ProjectModel.getUserProjects(userId);
2021

21-
return projectsList.map((project) => getProjectElementsFiltered(project));
22+
return projectsList.map((project) => getProjectDetails(project));
2223
};
2324

2425
const updateProject = async (userId, projectId, dataObject) => {
@@ -38,7 +39,7 @@ const deleteProject = async (userId, projectId) => {
3839
const getProjectTasks = async (userId, projectId) => {
3940
const project = await ProjectModel.getUserProject(userId, projectId);
4041

41-
return project;
42+
return project ? project.refTasks : null;
4243
};
4344

4445
const addProjectTask = async (userId, projectId, dataObject) => {

frontend/directives/project/project.template.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div flex="100" layout="row" layout-align="space-between center">
22
<div flex="100" layout="row" layout-align="start center">
33
<md-progress-circular class="progress-circular-indicator" flex="none" md-diameter="55" md-mode="determinate" value="100"></md-progress-circular>
4-
<md-progress-circular class="md-avatar" flex="none" md-diameter="55" md-mode="determinate" value="0"></md-progress-circular>
5-
<h5 class="progress-circular-text">0%</h5>
4+
<md-progress-circular class="md-avatar" flex="none" md-diameter="55" md-mode="determinate" value="{{data.getConclusionPercentage()}}"></md-progress-circular>
5+
<h5 class="progress-circular-text">{{data.getConclusionPercentage()}}%</h5>
66
<p>{{data.name}}</p>
77
</div>
88
<div flex="none" layout="row" layout-align="center center">

frontend/models/Project.model.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22
angular.module('TaskifyApp').service('ProjectModel', ProjectModel);
33

44
function ProjectModel() {
5-
return function (data = {}) {
5+
function Model(data = {}) {
66
this.id = data._id;
77
this.name = data.name;
88
this.tasks = data.refTasks;
9+
this.totalFinishedTasks = data.totalFinishedTasks;
10+
this.totalTasks = data.totalTasks;
11+
}
12+
13+
Model.prototype = {
14+
getConclusionPercentage() {
15+
return Math.floor((this.totalFinishedTasks / this.totalTasks) * 100);
16+
}
917
};
18+
19+
return Model;
1020
}
1121
}());

frontend/views/projects/projects.controller.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@
8585
return ProjectsService.createProjectTask((self.selectedProject || {}).id, description)
8686
.then((result) => {
8787
self.tasksList.push(new TaskModel(result.data.data));
88-
UtilsService.sendToast('Task Criada!');
88+
self.selectedProject.totalTasks += 1;
89+
90+
UtilsService.sendToast('Tarefa Criada!');
8991
})
9092
.catch(() => UtilsService.sendToast('Error on task creation'));
9193
});
@@ -103,6 +105,8 @@
103105
ProjectsService.updateProjectTask(self.selectedProject.id, taskData.id, { isFinished: taskData.isFinished })
104106
.then(() => {
105107
taskData.isDisabled = false;
108+
109+
self.selectedProject.totalFinishedTasks += taskData.isFinished ? 1 : -1;
106110
})
107111
.catch(() => {
108112
taskData.isDisabled = false;

0 commit comments

Comments
 (0)