@@ -9,7 +9,7 @@ import LegacyPhaseDomain from "./Phase";
9
9
import LegacyReviewDomain from "./Review" ;
10
10
import LegacyResourceDomain from "./Resource" ;
11
11
import LegacyPrizeDomain from "./Prize" ;
12
- import { PhaseStatusIds , PhaseTypeIds } from '../config/constants' ;
12
+ import { PhaseStatusIds , PhaseTypeIds , ProjectCategories , ResourceRoleTypeIds } from '../config/constants' ;
13
13
import moment from "moment" ;
14
14
15
15
class LegacyChallengeDomain {
@@ -19,6 +19,8 @@ class LegacyChallengeDomain {
19
19
}
20
20
21
21
public async closeChallenge ( input :CloseChallengeInput ) {
22
+ // Get the challenge
23
+ const challenge = await this . getLegacyChallenge ( { legacyChallengeId : input . projectId } )
22
24
// Get the challenge phases:
23
25
const { projectPhases } = await LegacyPhaseDomain . getProjectPhases ( { projectId : input . projectId } )
24
26
@@ -141,7 +143,7 @@ class LegacyChallengeDomain {
141
143
142
144
// Create new reviewer using current user's id (22838965 - tcwebservice)
143
145
const createResourceRes = await LegacyResourceDomain . createResource ( {
144
- resourceRoleId : 4 ,
146
+ resourceRoleId : challenge . projectCategoryId === ProjectCategories . First2Finish ? ResourceRoleTypeIds . IterativeReviewer : ResourceRoleTypeIds . Reviewer ,
145
147
projectId : input . projectId ,
146
148
userId : 22838965 // TODO: get this from interceptors
147
149
} )
@@ -238,7 +240,7 @@ class LegacyChallengeDomain {
238
240
239
241
public async getLegacyChallenge (
240
242
input : LegacyChallengeId
241
- ) : Promise < LegacyChallenge | undefined > {
243
+ ) : Promise < LegacyChallenge > {
242
244
const { rows } = await queryRunner . run (
243
245
new QueryBuilder ( ProjectSchema )
244
246
. select ( ..._ . map ( ProjectSchema . columns ) )
@@ -251,7 +253,8 @@ class LegacyChallengeDomain {
251
253
. limit ( 1 )
252
254
. build ( )
253
255
) ;
254
- return rows ?. length ? LegacyChallenge . fromPartial ( rows [ 0 ] as LegacyChallenge ) : undefined ;
256
+ if ( ! rows || rows . length === 0 ) throw new Error ( `Cannot find challenge with id: ${ input . legacyChallengeId } ` )
257
+ return LegacyChallenge . fromPartial ( rows [ 0 ] as LegacyChallenge ) ;
255
258
}
256
259
257
260
public async checkChallengeExists (
0 commit comments