2
2
* Controller for challenge endpoints
3
3
*/
4
4
const HttpStatus = require ( "http-status-codes" ) ;
5
- const service = require ( "../services/ChallengeService " ) ;
5
+ const { challengeService : service } = require ( "../common/transformer " ) ;
6
6
const helper = require ( "../common/helper" ) ;
7
7
const logger = require ( "../common/logger" ) ;
8
8
@@ -12,7 +12,7 @@ const logger = require("../common/logger");
12
12
* @param {Object } res the response
13
13
*/
14
14
async function searchChallenges ( req , res ) {
15
- let result = await service . searchChallenges ( req . authUser , {
15
+ let result = await service . searchChallenges ( req , req . authUser , {
16
16
...req . query ,
17
17
...req . body ,
18
18
} ) ;
@@ -23,7 +23,7 @@ async function searchChallenges(req, res) {
23
23
logger . debug ( `Staring to get mm challengeId` ) ;
24
24
const legacyId = await helper . getProjectIdByRoundId ( req . query . legacyId ) ;
25
25
logger . debug ( `Get mm challengeId successfully ${ legacyId } ` ) ;
26
- result = await service . searchChallenges ( req . authUser , {
26
+ result = await service . searchChallenges ( req , req . authUser , {
27
27
...req . query ,
28
28
...req . body ,
29
29
legacyId,
@@ -50,7 +50,7 @@ async function createChallenge(req, res) {
50
50
logger . debug (
51
51
`createChallenge User: ${ JSON . stringify ( req . authUser ) } - Body: ${ JSON . stringify ( req . body ) } `
52
52
) ;
53
- const result = await service . createChallenge ( req . authUser , req . body , req . userToken ) ;
53
+ const result = await service . createChallenge ( req , req . authUser , req . body , req . userToken ) ;
54
54
res . status ( HttpStatus . CREATED ) . send ( result ) ;
55
55
}
56
56
@@ -60,7 +60,7 @@ async function createChallenge(req, res) {
60
60
* @param {Object } res the response
61
61
*/
62
62
async function sendNotifications ( req , res ) {
63
- const result = await service . sendNotifications ( req . authUser , req . params . challengeId ) ;
63
+ const result = await service . sendNotifications ( req , req . authUser , req . params . challengeId ) ;
64
64
res . status ( HttpStatus . CREATED ) . send ( result ) ;
65
65
}
66
66
@@ -71,6 +71,7 @@ async function sendNotifications(req, res) {
71
71
*/
72
72
async function getChallenge ( req , res ) {
73
73
const result = await service . getChallenge (
74
+ req ,
74
75
req . authUser ,
75
76
req . params . challengeId ,
76
77
req . query . checkIfExists
@@ -84,7 +85,7 @@ async function getChallenge(req, res) {
84
85
* @param {Object } res the response
85
86
*/
86
87
async function getChallengeStatistics ( req , res ) {
87
- const result = await service . getChallengeStatistics ( req . authUser , req . params . challengeId ) ;
88
+ const result = await service . getChallengeStatistics ( req , req . authUser , req . params . challengeId ) ;
88
89
res . send ( result ) ;
89
90
}
90
91
@@ -99,7 +100,7 @@ async function updateChallenge(req, res) {
99
100
req . params . challengeId
100
101
} - Body: ${ JSON . stringify ( req . body ) } `
101
102
) ;
102
- const result = await service . updateChallenge ( req . authUser , req . params . challengeId , req . body ) ;
103
+ const result = await service . updateChallenge ( req , req . authUser , req . params . challengeId , req . body ) ;
103
104
res . send ( result ) ;
104
105
}
105
106
@@ -112,7 +113,7 @@ async function deleteChallenge(req, res) {
112
113
logger . debug (
113
114
`deleteChallenge User: ${ JSON . stringify ( req . authUser ) } - ChallengeID: ${ req . params . challengeId } `
114
115
) ;
115
- const result = await service . deleteChallenge ( req . authUser , req . params . challengeId ) ;
116
+ const result = await service . deleteChallenge ( req , req . authUser , req . params . challengeId ) ;
116
117
res . send ( result ) ;
117
118
}
118
119
@@ -122,7 +123,7 @@ async function deleteChallenge(req, res) {
122
123
* @param {Object } res the response
123
124
*/
124
125
async function advancePhase ( req , res ) {
125
- res . send ( await service . advancePhase ( req . authUser , req . params . challengeId , req . body ) ) ;
126
+ res . send ( await service . advancePhase ( req , req . authUser , req . params . challengeId , req . body ) ) ;
126
127
}
127
128
128
129
module . exports = {
0 commit comments