@@ -47,6 +47,10 @@ exports.counter = functions.database.ref('/v2/results/{projectId}/{groupId}/{use
4747 const endTimeRef = admin . database ( ) . ref ( '/v2/results/' + context . params . projectId + '/' + context . params . groupId + '/' + context . params . userId + '/endTime' )
4848 const timeSpentMappingRef = admin . database ( ) . ref ( '/v2/results/' + context . params . projectId + '/' + context . params . groupId + '/' + context . params . userId + '/timeSpentMappingRef' )
4949
50+ // references for project based counters for tasks and groups
51+ const projectTaskContributionCountRef = admin . database ( ) . ref ( '/v2/users/' + context . params . userId + '/contributions/' + context . params . projectId + '/taskContributionCount' )
52+ const projectGroupContributionCountRef = admin . database ( ) . ref ( '/v2/users/' + context . params . userId + '/contributions/' + context . params . projectId + '/groupContributionCount' )
53+
5054 // Counter for groups
5155 const groupFinishedCount = groupFinishedCountRef . transaction ( ( currentCount ) => {
5256 return currentCount + 1
@@ -118,6 +122,25 @@ exports.counter = functions.database.ref('/v2/results/{projectId}/{groupId}/{use
118122 } )
119123 promises . push ( contributions )
120124
125+ // counters for tasks and groups per user and per project
126+ const projectTaskContributionCount = numberOfTasksRef . once ( 'value' )
127+ . then ( ( dataSnapshot ) => {
128+ const numberOfTasks = dataSnapshot . val ( )
129+ return numberOfTasks
130+ } )
131+ . then ( ( numberOfTasks ) => {
132+ return projectTaskContributionCountRef . transaction ( ( currentCount ) => {
133+ return currentCount + numberOfTasks
134+ } )
135+ } )
136+ promises . push ( projectTaskContributionCount )
137+
138+ // Counter for groups
139+ const projectGroupContributionCount = projectGroupContributionCountRef . transaction ( ( currentCount ) => {
140+ return currentCount + 1
141+ } ) ;
142+ promises . push ( projectGroupContributionCount )
143+
121144 // // TODO: Does not work
122145 // const timeSpentMapping = timeSpentMappingRef.set((timeSpentMapping) => {
123146 // const startTime = startTimeRef.once('value')
@@ -268,4 +291,4 @@ exports.decProjectProgress = functions.database.ref('/v2/projects/{projectId}/re
268291 } )
269292 } )
270293 return projectProgress
271- } )
294+ } )
0 commit comments