@@ -9,9 +9,9 @@ const firestore = require('../utils/firestore')
9
9
const challengesModel = firestore . collection ( 'challenges' )
10
10
const userModel = firestore . collection ( 'users' )
11
11
12
- const cannotSubscribe = 'User cannot be subscribed to challenge'
13
- const userDoesNotExistError = 'User does not exist. Please register to participate'
14
- const errorMessage = 'Error getting challenges'
12
+ const CANNOTSUBSCRIBE = 'User cannot be subscribed to challenge'
13
+ const USERDOESNOTEXISTERROR = 'User does not exist. Please register to participate'
14
+ const ERRORMESSAGE = 'Error getting challenges'
15
15
16
16
/**
17
17
* Fetch the challenges
@@ -21,18 +21,16 @@ const errorMessage = 'Error getting challenges'
21
21
const fetchChallenges = async ( ) => {
22
22
try {
23
23
const challengesSnapshot = await challengesModel . get ( )
24
- return ( function ( ) {
25
- const challenges = [ ]
26
- challengesSnapshot . forEach ( ( challengeDoc ) => {
27
- challenges . push ( {
28
- id : challengeDoc . id ,
29
- ...challengeDoc . data ( )
30
- } )
24
+ const challenges = [ ]
25
+ challengesSnapshot . forEach ( ( challengeDoc ) => {
26
+ challenges . push ( {
27
+ id : challengeDoc . id ,
28
+ ...challengeDoc . data ( )
31
29
} )
32
- return challenges
33
- } ) ( )
30
+ } )
31
+ return challenges
34
32
} catch ( err ) {
35
- logger . error ( errorMessage , err )
33
+ logger . error ( ERRORMESSAGE , err )
36
34
throw err
37
35
}
38
36
}
@@ -54,7 +52,7 @@ const postChallenge = async (challengeData) => {
54
52
return allChallenges
55
53
} else return ''
56
54
} catch ( err ) {
57
- logger . error ( errorMessage , err )
55
+ logger . error ( ERRORMESSAGE , err )
58
56
throw err
59
57
}
60
58
}
@@ -74,10 +72,10 @@ const subscribeUserToChallenge = async (userId, challengeId) => {
74
72
await challengeRef . update ( { participants : Firestore . FieldValue . arrayUnion ( { name : user } ) } )
75
73
return challengeRef . get ( )
76
74
} else {
77
- throw new Error ( userDoesNotExistError )
75
+ throw new Error ( USERDOESNOTEXISTERROR )
78
76
}
79
77
} catch ( err ) {
80
- logger . error ( cannotSubscribe , err )
78
+ logger . error ( CANNOTSUBSCRIBE , err )
81
79
throw err
82
80
}
83
81
}
0 commit comments