Skip to content

Commit f41b159

Browse files
committed
update
1 parent 88151da commit f41b159

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

src/config/constants.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,22 @@ export const ObserverResourceInfoToAdd: ResourceInfoTypeIds[] = [
6161
"PaymentStatus",
6262
"AppealsCompletedEarly",
6363
];
64+
65+
export const ChallengeStatusOrders = {
66+
Draft: 1,
67+
Active: 2,
68+
Completed: 3,
69+
Deleted: 3,
70+
Cancelled: 3,
71+
};
72+
73+
export type ChallengeStatus = keyof typeof ChallengeStatusOrders;
74+
75+
export const ChallengeStatusMap = {
76+
1: "Active",
77+
2: "Draft",
78+
3: "Deleted",
79+
7: "Completed",
80+
};
81+
82+
export type ChallengeStatusIds = keyof typeof ChallengeStatusMap;

src/domain/Sync.ts

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,29 @@ import { queryRunner } from "../helper/QueryRunner";
99

1010
import { Challenge } from "@topcoder-framework/domain-challenge/dist-es/models/domain-layer/challenge/challenge";
1111
import { Operator } from "@topcoder-framework/lib-common";
12+
import {
13+
ChallengeStatus,
14+
ChallengeStatusIds,
15+
ChallengeStatusMap,
16+
ChallengeStatusOrders,
17+
} from "../config/constants";
1218
import LegacyChallengeDomain from "../domain/LegacyChallenge";
1319
import { LegacyChallenge, LegacyChallengeId } from "../models/domain-layer/legacy/challenge";
1420
import { SyncInput, Table } from "../models/domain-layer/legacy/sync";
1521

1622
const challengeDomain = new ChallengeDomain(
17-
process.env.GRPC_CHALLENGE_DOMAIN_SERVER_HOST!,
18-
process.env.GRPC_CHALLENGE_DOMAIN_SERVER_PORT!
23+
process.env.GRPC_CHALLENGE_DOMAIN_SERVER_HOST,
24+
process.env.GRPC_CHALLENGE_DOMAIN_SERVER_PORT
1925
);
2026

2127
class LegacySyncDomain {
2228
public async syncLegacy(input: SyncInput): Promise<void> {
23-
const legacyId = input.projectId;
29+
const legacyId = input2.projectId;
2430
const payload = {};
2531
const legacyChallenge = await LegacyChallengeDomain.getLegacyChallenge(
2632
LegacyChallengeId.create({ legacyChallengeId: legacyId })
2733
);
34+
await challengeDomain.lookup({ key: "legacyId", value: legacyId });
2835
const { items } = await challengeDomain.scan({
2936
criteria: [{ key: "legacyId", operator: Operator.OPERATOR_EQUAL, value: legacyId }],
3037
});
@@ -75,47 +82,16 @@ class LegacySyncDomain {
7582
}
7683

7784
private handleStatusChange(legacyChallenge: LegacyChallenge, v5Challenge: Challenge) {
78-
interface IchallengeStatusOrders {
79-
Draft: number;
80-
Active: number;
81-
Completed: number;
82-
Deleted: number;
83-
Cancelled: number;
84-
}
85-
const challengeStatusOrders: IchallengeStatusOrders = {
86-
Draft: 1,
87-
Active: 2,
88-
Completed: 3,
89-
Deleted: 3,
90-
Cancelled: 3,
91-
};
92-
interface IchallengeStatusMap {
93-
1: string;
94-
2: string;
95-
3: string;
96-
7: string;
97-
}
98-
const challengeStatusMap: IchallengeStatusMap = {
99-
1: "Active",
100-
2: "Draft",
101-
3: "Deleted",
102-
7: "Completed",
103-
};
104-
10585
const v4StatusNumber =
106-
challengeStatusOrders[
107-
challengeStatusMap[
108-
legacyChallenge.projectStatusId as keyof IchallengeStatusMap
109-
] as keyof IchallengeStatusOrders
110-
] || challengeStatusOrders.Cancelled;
86+
ChallengeStatusOrders[
87+
ChallengeStatusMap[legacyChallenge.projectStatusId as ChallengeStatusIds] as ChallengeStatus
88+
] || ChallengeStatusOrders.Cancelled;
11189
const v5StatusNumber =
112-
challengeStatusOrders[v5Challenge.status as keyof IchallengeStatusOrders] ||
113-
challengeStatusOrders.Cancelled;
90+
ChallengeStatusOrders[v5Challenge.status as ChallengeStatus] ||
91+
ChallengeStatusOrders.Cancelled;
11492

11593
if (v4StatusNumber >= v5StatusNumber) {
116-
return {
117-
status: challengeStatusMap[legacyChallenge.projectStatusId as keyof IchallengeStatusMap],
118-
};
94+
return { status: ChallengeStatusMap[legacyChallenge.projectStatusId as ChallengeStatusIds] };
11995
} else {
12096
return {};
12197
}

0 commit comments

Comments
 (0)