1
1
const { ERROR_CODES_CONSTANTS } = require ( '../../framework' ) ;
2
2
const ProjectModel = require ( '../models/projects.model' ) ;
3
3
4
- const getProjectElementsFiltered = ( project ) => ( {
4
+ const getProjectDetails = ( project ) => ( {
5
5
_id : project . _id ,
6
6
name : project . name ,
7
- refTasks : project . refTasks
7
+ totalTasks : project . refTasks . length ,
8
+ totalFinishedTasks : project . refTasks . filter ( ( task ) => task . finishDate ) . length
8
9
} ) ;
9
10
10
11
const addProject = async ( userId , dataObject ) => {
11
12
const { name } = dataObject ;
12
13
13
14
const createdProject = await ProjectModel . addProject ( userId , { name } ) ;
14
15
15
- return getProjectElementsFiltered ( createdProject ) ;
16
+ return getProjectDetails ( createdProject ) ;
16
17
} ;
17
18
18
19
const getProjects = async ( userId ) => {
19
20
const projectsList = await ProjectModel . getUserProjects ( userId ) ;
20
21
21
- return projectsList . map ( ( project ) => getProjectElementsFiltered ( project ) ) ;
22
+ return projectsList . map ( ( project ) => getProjectDetails ( project ) ) ;
22
23
} ;
23
24
24
25
const updateProject = async ( userId , projectId , dataObject ) => {
@@ -38,7 +39,7 @@ const deleteProject = async (userId, projectId) => {
38
39
const getProjectTasks = async ( userId , projectId ) => {
39
40
const project = await ProjectModel . getUserProject ( userId , projectId ) ;
40
41
41
- return project ;
42
+ return project ? project . refTasks : null ;
42
43
} ;
43
44
44
45
const addProjectTask = async ( userId , projectId , dataObject ) => {
0 commit comments