@@ -13,17 +13,140 @@ import LegacyPhaseDomain from "./Phase";
13
13
import LegacyReviewDomain from "./Review" ;
14
14
import LegacyResourceDomain from "./Resource" ;
15
15
import LegacyPrizeDomain from "./Prize" ;
16
+ import LegacyProjectInfoDomain from "./ProjectInfo" ;
16
17
import {
17
18
PhaseStatusIds ,
18
19
PhaseTypeIds ,
19
20
ProjectCategories ,
20
21
ResourceRoleTypeIds ,
21
22
} from "../config/constants" ;
22
23
import moment from "moment" ;
24
+ import { CreateResult } from "@topcoder-framework/lib-common" ;
23
25
24
26
class LegacyChallengeDomain {
25
27
public async activateChallenge ( input : LegacyChallengeId ) {
26
- // TODO: Activate
28
+ // update challenge status
29
+ await this . update ( {
30
+ projectId : input . legacyChallengeId ,
31
+ projectStatusId : 1 ,
32
+ modifyUser : 22838965 ,
33
+ } ) ; // TODO: extract user from interceptors
34
+ await LegacyProjectInfoDomain . create ( {
35
+ projectInfoTypeId : 62 , // Project activate date
36
+ value : moment ( ) . format ( "MM.dd.yyyy hh:mm a" ) ,
37
+ projectId : input . legacyChallengeId ,
38
+ } ) ;
39
+ const { projectPhases } = await LegacyPhaseDomain . getProjectPhases ( {
40
+ projectId : input . legacyChallengeId ,
41
+ } ) ;
42
+ const specificationSubmissionPhase = _ . find (
43
+ projectPhases ,
44
+ ( p ) => p . phaseTypeId === PhaseTypeIds . SpecificationSubmission
45
+ ) ;
46
+ if ( specificationSubmissionPhase ) {
47
+ // Start spec review
48
+ await LegacyPhaseDomain . updateProjectPhase ( {
49
+ projectPhaseId : specificationSubmissionPhase . projectPhaseId ,
50
+ fixedStartTime : "CURRENT" ,
51
+ scheduledStartTime : "CURRENT" ,
52
+ scheduledEndTime : moment ( )
53
+ . add ( specificationSubmissionPhase . duration , "milliseconds" )
54
+ . format ( "MM-dd-yyyy hh:mm:ss" ) ,
55
+ } ) ;
56
+ // Check if specification submitter doesn't exist
57
+ const { resources } = await LegacyResourceDomain . getResources ( {
58
+ projectId : input . legacyChallengeId ,
59
+ resourceRoleId : ResourceRoleTypeIds . SpecificationSubmitter ,
60
+ } ) ;
61
+ if ( resources . length === 0 ) {
62
+ // Create spec submitter
63
+ const createResourceRes = await LegacyResourceDomain . createResource ( {
64
+ projectId : input . legacyChallengeId ,
65
+ resourceRoleId : ResourceRoleTypeIds . SpecificationSubmitter ,
66
+ userId : 22838965 , // TODO: extract user from interceptors
67
+ } ) ;
68
+ const specSubmitterId = createResourceRes . kind
69
+ ? _ . get ( createResourceRes . kind , createResourceRes . kind ?. $case , undefined )
70
+ : undefined ;
71
+ if ( ! specSubmitterId ) throw new Error ( "Failed to create specification submitter" ) ;
72
+
73
+ // create resource_info
74
+ await LegacyResourceDomain . createResourceInfos ( {
75
+ resourceId : specSubmitterId ,
76
+ resourceInfoTypeId : 2 ,
77
+ value : "tcwebservice" , // TODO: Extract from RPC interceptor
78
+ } ) ;
79
+ await LegacyResourceDomain . createResourceInfos ( {
80
+ resourceId : specSubmitterId ,
81
+ resourceInfoTypeId : 7 ,
82
+ value : "null" ,
83
+ } ) ;
84
+ await LegacyResourceDomain . createResourceInfos ( {
85
+ resourceId : specSubmitterId ,
86
+ resourceInfoTypeId : 8 ,
87
+ value : "N/A" ,
88
+ } ) ;
89
+ await LegacyResourceDomain . createResourceInfos ( {
90
+ resourceId : specSubmitterId ,
91
+ resourceInfoTypeId : 1 ,
92
+ value : "22838965" , // TODO: Extract from RPC interceptor
93
+ } ) ;
94
+ await LegacyResourceDomain . createResourceInfos ( {
95
+ resourceId : specSubmitterId ,
96
+ resourceInfoTypeId : 6 ,
97
+ value : moment ( ) . add ( ) . format ( "MM-dd-yyyy hh:mm:ss" ) ,
98
+ } ) ;
99
+
100
+ // create upload
101
+ const upload = await LegacyReviewDomain . createUpload ( {
102
+ projectId : input . legacyChallengeId ,
103
+ uploadStatusId : 1 ,
104
+ uploadTypeId : 1 ,
105
+ parameter : "parameter" , // dummy upload so there is no actual file uploaded
106
+ resourceId : specSubmitterId ,
107
+ projectPhaseId : specificationSubmissionPhase . projectPhaseId ,
108
+ } ) ;
109
+ // create submission
110
+ const uploadId = upload . kind
111
+ ? _ . get ( upload . kind , upload . kind ?. $case , undefined )
112
+ : undefined ;
113
+ if ( ! uploadId ) throw new Error ( "Failed to create upload" ) ;
114
+ const createSubmissionRes = await LegacyReviewDomain . createSubmission ( {
115
+ uploadId,
116
+ submissionStatusId : 1 ,
117
+ submissionTypeId : 2 ,
118
+ } ) ;
119
+ // resource_submission
120
+ const submissionId = createSubmissionRes . kind
121
+ ? _ . get ( createSubmissionRes . kind , createSubmissionRes . kind ?. $case , undefined )
122
+ : undefined ;
123
+ if ( ! submissionId ) throw new Error ( "Failed to create submission" ) ;
124
+ await LegacyReviewDomain . createResourceSubmission ( {
125
+ resourceId : specSubmitterId ,
126
+ submissionId,
127
+ } ) ;
128
+ // update project_info to set autopilot to On
129
+ const { projectInfo } = await LegacyProjectInfoDomain . getProjectInfo ( {
130
+ projectId : input . legacyChallengeId ,
131
+ projectInfoTypeId : 9 ,
132
+ } ) ;
133
+ if ( projectInfo . length === 0 ) {
134
+ await LegacyProjectInfoDomain . create ( {
135
+ projectId : input . legacyChallengeId ,
136
+ projectInfoTypeId : 9 ,
137
+ value : "On" ,
138
+ createUser : 22838965 , // TODO: Extract from RPC interceptors
139
+ } ) ;
140
+ } else {
141
+ await LegacyProjectInfoDomain . update ( {
142
+ projectId : input . legacyChallengeId ,
143
+ projectInfoTypeId : 9 ,
144
+ value : "On" ,
145
+ modifyUser : 22838965 , // TODO: Extract from RPC interceptors
146
+ } ) ;
147
+ }
148
+ }
149
+ }
27
150
}
28
151
29
152
public async closeChallenge ( input : CloseChallengeInput ) {
0 commit comments