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