Skip to content

Commit c46188a

Browse files
committed
made requested changes
1 parent b7bbf19 commit c46188a

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

controllers/challengeController.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const challengeQuery = require('../models/challenges')
22

3-
const errorAdminString = 'Something went wrong. Please try again or contact admin'
3+
const ERRORADMINSTRING = 'Something went wrong. Please try again or contact admin'
44

55
/**
66
* Get the challenges or add the challenge
@@ -33,11 +33,11 @@ const sendChallengeResponse = async (req, res) => {
3333
return res.boom.notFound('Unable to add challenge')
3434
}
3535
}
36+
return ''
3637
} catch (err) {
3738
logger.error(`Error while retriving challenges ${err}`)
38-
return res.boom.serverUnavailable(errorAdminString)
39+
return res.boom.serverUnavailable(ERRORADMINSTRING)
3940
}
40-
return ''
4141
}
4242

4343
/**
@@ -59,7 +59,7 @@ const subscribeToChallenge = async (req, res) => {
5959
}
6060
} catch (err) {
6161
logger.error(`Error while retrieving challenges ${err}`)
62-
return res.boom.serverUnavailable(errorAdminString)
62+
return res.boom.serverUnavailable(ERRORADMINSTRING)
6363
}
6464
}
6565

models/challenges.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const firestore = require('../utils/firestore')
99
const challengesModel = firestore.collection('challenges')
1010
const userModel = firestore.collection('users')
1111

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'
1515

1616
/**
1717
* Fetch the challenges
@@ -21,18 +21,16 @@ const errorMessage = 'Error getting challenges'
2121
const fetchChallenges = async () => {
2222
try {
2323
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()
3129
})
32-
return challenges
33-
})()
30+
})
31+
return challenges
3432
} catch (err) {
35-
logger.error(errorMessage, err)
33+
logger.error(ERRORMESSAGE, err)
3634
throw err
3735
}
3836
}
@@ -54,7 +52,7 @@ const postChallenge = async (challengeData) => {
5452
return allChallenges
5553
} else return ''
5654
} catch (err) {
57-
logger.error(errorMessage, err)
55+
logger.error(ERRORMESSAGE, err)
5856
throw err
5957
}
6058
}
@@ -74,10 +72,10 @@ const subscribeUserToChallenge = async (userId, challengeId) => {
7472
await challengeRef.update({ participants: Firestore.FieldValue.arrayUnion({ name: user }) })
7573
return challengeRef.get()
7674
} else {
77-
throw new Error(userDoesNotExistError)
75+
throw new Error(USERDOESNOTEXISTERROR)
7876
}
7977
} catch (err) {
80-
logger.error(cannotSubscribe, err)
78+
logger.error(CANNOTSUBSCRIBE, err)
8179
throw err
8280
}
8381
}

routes/challenges.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const challengesController = require('../controllers/challengeController')
55

66
/**
77
* @swagger
8-
* /challenges/:
8+
* /challenges:
99
* get:
1010
* summary: Used to get all the challenges
1111
* tags:

0 commit comments

Comments
 (0)