Skip to content

Commit 2a15445

Browse files
rakibansaryThomasKranitsaseisbilir
authored
feature: challenge update (#25)
* ci: deploy to dev * fix: use elasticsearch when opensearch-js is not availalbe - this is a temporary feature till we overhaul how we do indexing Signed-off-by: Rakib Ansary <[email protected]> * fix: project category id Signed-off-by: Rakib Ansary <[email protected]> * fix: project phase during challenge creation Signed-off-by: Rakib Ansary <[email protected]> * fix: scorecards to use Signed-off-by: Rakib Ansary <[email protected]> * fix: dev scorecard ids are different Signed-off-by: Rakib Ansary <[email protected]> * chore: publish image * fix: save creator * fix: save createdBy and updatedBy Signed-off-by: Rakib Ansary <[email protected]> * fix: turn autopilot on * update scorecard mapping (#16) * Feat/phase logic update (#17) * fix: legacy phase mapper * feat: remove timezone conversion * fix: bump versions * fix: fixed start time * fix: use uuid * Fix/sc (#19) * fix: scorecard mapping * fix: scorecard mapper * wip: challenge updatge * fix: non-null assertion Signed-off-by: Rakib Ansary <[email protected]> * fix: improve handling of draft challenges Signed-off-by: Rakib Ansary <[email protected]> * fix: legacy challenge update Signed-off-by: Rakib Ansary <[email protected]> * fix: saving phase on challenge:update Signed-off-by: Rakib Ansary <[email protected]> * chore: remove logs Signed-off-by: Rakib Ansary <[email protected]> * fix: remove undefined from map Signed-off-by: Rakib Ansary <[email protected]> * fix: update to topcoder-interface v0.0.40 Signed-off-by: Rakib Ansary <[email protected]> * feat: add logging interceptor * fix: version bump * fix: do not call acl for v5 tasks * fix: add iterative review phase constraint * fix: prize amount in cents * fix: total prize calculation * map v5 groupId to v4 groupId Signed-off-by: Rakib Ansary <[email protected]> * fix: prize calculation Signed-off-by: Rakib Ansary <[email protected]> * fix: post mortem flag Signed-off-by: Rakib Ansary <[email protected]> * fix: not creating ba in legacy Signed-off-by: Rakib Ansary <[email protected]> * support delete challenge (#22) * correct the f2f scorecard ID for dev (#23) * fix typo in challenge.delete (#24) * ci: publish image to prod ecr Signed-off-by: Rakib Ansary <[email protected]> --------- Signed-off-by: Rakib Ansary <[email protected]> Co-authored-by: Thomas Kranitsas <[email protected]> Co-authored-by: eisbilir <[email protected]> Co-authored-by: eisbilir <[email protected]>
1 parent f4ef49e commit 2a15445

31 files changed

+4882
-2980
lines changed

.circleci/config.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
- image: cimg/aws:2023.01
77
environment:
88
CODEARTIFACT_ENV: PROD
9-
ECR_ENV: QA
9+
ECR_ENV: PROD
1010
SERVICE_NAME: "domain-challenge"
1111
OUT_DIR: "buildscripts"
1212
steps:
@@ -48,5 +48,4 @@ workflows:
4848
filters:
4949
branches:
5050
only:
51-
- fix/update-pre-release
5251
- main

.prettierrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{}
1+
{
2+
"printWidth": 100
3+
}

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ ENV AUTH0_CLIENT_ID=""
3636
ENV AUTH0_CLIENT_SECRET=""
3737
ENV AUTH0_PROXY_SERVER_URL=""
3838
ENV AUTH0_URL=""
39+
ENV TOPCODER_API_URL=""
3940

4041
CMD ["server.js"]

package.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@
2323
"@aws-sdk/util-utf8-node": "^3.259.0",
2424
"@grpc/grpc-js": "^1.7.1",
2525
"@opensearch-project/opensearch": "^2.2.0",
26-
"@topcoder-framework/domain-acl": "^0.7.0",
27-
"@topcoder-framework/lib-common": "^0.7.0",
26+
"@topcoder-framework/domain-acl": "^0.10.13",
27+
"@topcoder-framework/lib-common": "^0.10.13",
28+
"@types/uuid": "^9.0.1",
29+
"aws-sdk": "^2.1339.0",
2830
"axios": "^1.2.2",
2931
"dayjs": "^1.11.7",
3032
"dotenv": "^16.0.3",
33+
"elasticsearch": "^16.7.3",
3134
"grpc-server-reflection": "^0.1.5",
35+
"http-aws-es": "^6.0.0",
3236
"lodash": "^4.17.21",
3337
"moment": "^2.29.4",
3438
"source-map-support": "^0.5.21",
3539
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6.4",
36-
"topcoder-interface": "github:topcoder-platform/plat-interface-definition#v0.0.29",
37-
"uuidv4": "^6.2.13",
40+
"topcoder-interface": "github:topcoder-platform/plat-interface-definition#v0.0.46",
41+
"uuid": "^9.0.0",
3842
"xss": "^1.0.14"
3943
},
4044
"volta": {
@@ -43,6 +47,7 @@
4347
"yarn": "1.22.19"
4448
},
4549
"devDependencies": {
50+
"@types/elasticsearch": "^5.0.40",
4651
"@types/lodash": "^4.14.191",
4752
"@types/node": "^18.11.17",
4853
"ts-node-dev": "^2.0.0",

src/api/v5Api.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
const { V4_TECHNOLOGIES_API_URL, V4_PLATFORMS_API_URL, V4_CHALLENGE_API_URL } =
2-
process.env;
3-
41
import _ from "lodash";
52
import axios from "axios";
63

7-
export const getRequest = async (url:string, token:string): Promise<any> => {
8-
const res = await axios.get(url, { headers: { authorization: `Bearer ${token}` }})
4+
export const getRequest = async (url: string, token: string): Promise<any> => {
5+
const res = await axios.get(url, { headers: { authorization: `Bearer ${token}` } });
96
return res.data;
10-
}
7+
};

src/common/Constants.ts

+22
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,26 @@ export const ResourceInfoIds = {
4343
export const ChallengeStatuses = {
4444
New: "New",
4545
Active: "Active",
46+
Draft: "Draft",
47+
};
48+
49+
export const PhaseTypeIds = {
50+
Registration: 1,
51+
Submission: 2,
52+
Screening: 3,
53+
Review: 4,
54+
Appeals: 5,
55+
AppealsResponse: 6,
56+
Aggregation: 7,
57+
AggregationReview: 8,
58+
FinalFix: 9,
59+
FinalReview: 10,
60+
Approval: 11,
61+
PostMortem: 12,
62+
SpecificationSubmission: 13,
63+
SpecificationReview: 14,
64+
CheckpointSubmission: 15,
65+
CheckpointScreening: 16,
66+
CheckpointReview: 17,
67+
IterativeReview: 18,
4668
};

src/common/ConversionMap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const V4_TRACKS = {
5858
DESIGN: "DESIGN",
5959
};
6060

61-
const V4_SUBTRACKS = {
61+
export const V4_SUBTRACKS = {
6262
MARATHON_MATCH: "MARATHON_MATCH",
6363
DESIGN_FIRST_2_FINISH: "DESIGN_FIRST_2_FINISH",
6464
APPLICATION_FRONT_END_DESIGN: "APPLICATION_FRONT_END_DESIGN",

src/common/CoreOperations.ts

+22-29
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
import { noSqlClient } from "../dal/client/nosql";
33

44
// TODO: Import from @topcoder-framework/lib-common
5-
import {
6-
LookupCriteria,
7-
ScanCriteria,
8-
ScanResult,
9-
} from "../models/common/common";
5+
import { LookupCriteria, ScanCriteria, ScanResult } from "../models/common/common";
106

117
// TODO: Import from @topcoder-framework/lib-common
128
import { Value } from "../models/google/protobuf/struct";
@@ -25,7 +21,7 @@ import {
2521
UpdateType,
2622
Value as PartiQLValue,
2723
} from "../dal/models/nosql/parti_ql";
28-
import { StatusBuilder } from "@grpc/grpc-js";
24+
import { Metadata, StatusBuilder } from "@grpc/grpc-js";
2925
import { Status } from "@grpc/grpc-js/build/src/constants";
3026

3127
export type ValueType =
@@ -44,24 +40,20 @@ export type DynamoTableIndex = {
4440
};
4541
};
4642

47-
abstract class CoreOperations<
48-
T extends { [key: string]: any },
49-
I extends { [key: string]: any }
50-
> {
43+
abstract class CoreOperations<T extends { [key: string]: any }, I extends { [key: string]: any }> {
5144
public constructor(
5245
private entityName: string,
5346
private entityAttributes: Attribute[],
5447
private entityIndexList: DynamoTableIndex
5548
) {}
5649

57-
private attributesKeyTypeMap: { [key: string]: DataType } =
58-
this.entityAttributes.reduce(
59-
(map, attribute) => ({
60-
...map,
61-
[attribute.name]: attribute.type,
62-
}),
63-
{}
64-
);
50+
private attributesKeyTypeMap: { [key: string]: DataType } = this.entityAttributes.reduce(
51+
(map, attribute) => ({
52+
...map,
53+
[attribute.name]: attribute.type,
54+
}),
55+
{}
56+
);
6557

6658
public async lookup(lookupCriteria: LookupCriteria): Promise<T> {
6759
const selectQuery: SelectQuery = {
@@ -150,7 +142,7 @@ abstract class CoreOperations<
150142
};
151143
}
152144

153-
protected async create(entity: I & T): Promise<T> {
145+
protected async create(entity: I & T, metadata?: Metadata): Promise<T> {
154146
const queryRequest: QueryRequest = {
155147
kind: {
156148
$case: "query",
@@ -177,7 +169,8 @@ abstract class CoreOperations<
177169

178170
public async update(
179171
scanCriteria: ScanCriteria[],
180-
entity: unknown
172+
entity: unknown,
173+
metadata?: Metadata
181174
): Promise<{ items: T[] }> {
182175
if (typeof entity != "object" || entity == null) {
183176
throw new Error("Expected key-value pairs to update");
@@ -193,12 +186,14 @@ abstract class CoreOperations<
193186
update: {
194187
table: this.entityName,
195188
// TODO: Write a convenience method in @topcoder-framework/lib-common to support additional update operations like LIST_APPEND, SET_ADD, SET_REMOVE, etc
196-
updates: Object.entries(entity).map(([key, value]) => ({
197-
action: UpdateAction.UPDATE_ACTION_SET,
198-
type: UpdateType.UPDATE_TYPE_VALUE,
199-
attribute: key,
200-
value: this.toValue(key, value),
201-
})),
189+
updates: Object.entries(entity)
190+
.filter(([key, value]) => value !== undefined)
191+
.map(([key, value]) => ({
192+
action: UpdateAction.UPDATE_ACTION_SET,
193+
type: UpdateType.UPDATE_TYPE_VALUE,
194+
attribute: key,
195+
value: this.toValue(key, value),
196+
})),
202197
filters,
203198
returnValue: ReturnValue.RETURN_VALUE_ALL_NEW,
204199
},
@@ -330,9 +325,7 @@ abstract class CoreOperations<
330325
break;
331326

332327
default:
333-
throw new Error(
334-
"Lookups are only supported for string, number & boolean value"
335-
);
328+
throw new Error("Lookups are only supported for string, number & boolean value");
336329
}
337330

338331
return value;

src/dal/models/nosql/google/protobuf/struct.ts

+66-22
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,20 @@ export const Struct = {
115115
const tag = reader.uint32();
116116
switch (tag >>> 3) {
117117
case 1:
118+
if (tag != 10) {
119+
break;
120+
}
121+
118122
const entry1 = Struct_FieldsEntry.decode(reader, reader.uint32());
119123
if (entry1.value !== undefined) {
120124
message.fields[entry1.key] = entry1.value;
121125
}
122-
break;
123-
default:
124-
reader.skipType(tag & 7);
125-
break;
126+
continue;
127+
}
128+
if ((tag & 7) == 4 || tag == 0) {
129+
break;
126130
}
131+
reader.skipType(tag & 7);
127132
}
128133
return message;
129134
},
@@ -209,15 +214,24 @@ export const Struct_FieldsEntry = {
209214
const tag = reader.uint32();
210215
switch (tag >>> 3) {
211216
case 1:
217+
if (tag != 10) {
218+
break;
219+
}
220+
212221
message.key = reader.string();
213-
break;
222+
continue;
214223
case 2:
224+
if (tag != 18) {
225+
break;
226+
}
227+
215228
message.value = Value.unwrap(Value.decode(reader, reader.uint32()));
216-
break;
217-
default:
218-
reader.skipType(tag & 7);
219-
break;
229+
continue;
230+
}
231+
if ((tag & 7) == 4 || tag == 0) {
232+
break;
220233
}
234+
reader.skipType(tag & 7);
221235
}
222236
return message;
223237
},
@@ -282,27 +296,52 @@ export const Value = {
282296
const tag = reader.uint32();
283297
switch (tag >>> 3) {
284298
case 1:
299+
if (tag != 8) {
300+
break;
301+
}
302+
285303
message.kind = { $case: "nullValue", nullValue: nullValueFromJSON(reader.int32()) };
286-
break;
304+
continue;
287305
case 2:
306+
if (tag != 17) {
307+
break;
308+
}
309+
288310
message.kind = { $case: "numberValue", numberValue: reader.double() };
289-
break;
311+
continue;
290312
case 3:
313+
if (tag != 26) {
314+
break;
315+
}
316+
291317
message.kind = { $case: "stringValue", stringValue: reader.string() };
292-
break;
318+
continue;
293319
case 4:
320+
if (tag != 32) {
321+
break;
322+
}
323+
294324
message.kind = { $case: "boolValue", boolValue: reader.bool() };
295-
break;
325+
continue;
296326
case 5:
327+
if (tag != 42) {
328+
break;
329+
}
330+
297331
message.kind = { $case: "structValue", structValue: Struct.unwrap(Struct.decode(reader, reader.uint32())) };
298-
break;
332+
continue;
299333
case 6:
334+
if (tag != 50) {
335+
break;
336+
}
337+
300338
message.kind = { $case: "listValue", listValue: ListValue.unwrap(ListValue.decode(reader, reader.uint32())) };
301-
break;
302-
default:
303-
reader.skipType(tag & 7);
304-
break;
339+
continue;
340+
}
341+
if ((tag & 7) == 4 || tag == 0) {
342+
break;
305343
}
344+
reader.skipType(tag & 7);
306345
}
307346
return message;
308347
},
@@ -435,12 +474,17 @@ export const ListValue = {
435474
const tag = reader.uint32();
436475
switch (tag >>> 3) {
437476
case 1:
477+
if (tag != 10) {
478+
break;
479+
}
480+
438481
message.values.push(Value.unwrap(Value.decode(reader, reader.uint32())));
439-
break;
440-
default:
441-
reader.skipType(tag & 7);
442-
break;
482+
continue;
483+
}
484+
if ((tag & 7) == 4 || tag == 0) {
485+
break;
443486
}
487+
reader.skipType(tag & 7);
444488
}
445489
return message;
446490
},

0 commit comments

Comments
 (0)