Skip to content

Commit b83d3a6

Browse files
ThomasKranitsasrakibansary
authored andcommitted
feat(domain-acl): complete challenge update interfaces
1 parent 302c087 commit b83d3a6

38 files changed

+1678
-38
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"license": "ISC",
1717
"dependencies": {
1818
"@grpc/grpc-js": "^1.7.1",
19-
"@topcoder-framework/client-relational": "^0.4.24-ci.0",
19+
"@topcoder-framework/client-relational": "v0.4.23-ci.0",
2020
"@topcoder-framework/lib-common": "^0.4.24-ci.0",
2121
"dayjs": "^1.11.5",
2222
"dotenv": "^16.0.3",
2323
"grpc-server-reflection": "^0.1.5",
2424
"lodash": "^4.17.21",
2525
"source-map-support": "^0.5.21",
26-
"topcoder-interface": "github:topcoder-platform/plat-interface-definition#v0.0.11",
26+
"topcoder-interface": "github:topcoder-platform/plat-interface-definition#feat/challenge-acl-proto",
2727
"uuidv4": "^6.2.13"
2828
},
2929
"devDependencies": {

src/config/constants.ts

Whitespace-only changes.

src/domain/GroupContestEligibility.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { Operator, QueryBuilder } from "@topcoder-framework/client-relational";
2+
import { CreateResult } from "@topcoder-framework/lib-common";
3+
import _ from "lodash";
4+
import { queryRunner } from "../helper/QueryRunner";
5+
import { GetContestEligibilityInput, ContestEligibilityList, ContestEligibility, GetGroupContestEligibilityInput, GroupContestEligibilityList, GroupContestEligibility, DeleteContestEligibilityInput, DeleteGroupContestEligibilityInput } from "../models/domain-layer/legacy/group_contest_eligibility";
6+
import { ContestEligibilitySchema } from "../schema/ContestEligibility.ts/ContestEligibility";
7+
import { GroupContestEligibilitySchema } from "../schema/ContestEligibility.ts/GroupContestEligibility";
8+
9+
class LegacyGroupContestEligibilityDomain {
10+
public async getContestEligibilities(input:GetContestEligibilityInput): Promise<ContestEligibilityList> {
11+
const { rows } = await queryRunner.run(
12+
new QueryBuilder(ContestEligibilitySchema)
13+
.select(..._.map(ContestEligibilitySchema.columns))
14+
.where(ContestEligibilitySchema.columns.contestId, Operator.OPERATOR_EQUAL, {
15+
value: {
16+
$case: "intValue",
17+
intValue: input.contestId,
18+
},
19+
})
20+
.build()
21+
);
22+
23+
return { contestEligibilities: rows && rows?.length > 0 ? rows!.map(r => ContestEligibility.fromPartial(r as ContestEligibility)) : [] }
24+
}
25+
26+
public async createContestEligibility(input:ContestEligibility): Promise<CreateResult> {
27+
const { lastInsertId } = await queryRunner.run(
28+
new QueryBuilder(ContestEligibilitySchema)
29+
.insert({ ...input })
30+
.build()
31+
)
32+
return {
33+
kind: {
34+
$case: "integerId",
35+
integerId: lastInsertId!,
36+
},
37+
};
38+
}
39+
40+
public async getGroupContestEligibilities(input:GetGroupContestEligibilityInput): Promise<GroupContestEligibilityList> {
41+
const { rows } = await queryRunner.run(
42+
new QueryBuilder(GroupContestEligibilitySchema)
43+
.select(..._.map(GroupContestEligibilitySchema.columns))
44+
.where(GroupContestEligibilitySchema.columns.contestEligibilityId, Operator.OPERATOR_EQUAL, {
45+
value: {
46+
$case: "intValue",
47+
intValue: input.contestEligibilityId,
48+
},
49+
})
50+
.build()
51+
);
52+
53+
return { groupContestEligibilities: rows && rows?.length > 0 ? rows!.map(r => GroupContestEligibility.fromPartial(r as GroupContestEligibility)) : [] }
54+
}
55+
56+
public async createGroupContestEligibility(input:GroupContestEligibility): Promise<CreateResult> {
57+
const { lastInsertId } = await queryRunner.run(
58+
new QueryBuilder(GroupContestEligibilitySchema)
59+
.insert({ ...input })
60+
.build()
61+
)
62+
return {
63+
kind: {
64+
$case: "integerId",
65+
integerId: lastInsertId!,
66+
},
67+
};
68+
}
69+
70+
public async deleteContestEligibility (input: DeleteContestEligibilityInput) {
71+
await queryRunner.run(
72+
new QueryBuilder(ContestEligibilitySchema)
73+
.delete()
74+
.where(ContestEligibilitySchema.columns.contestEligibilityId, Operator.OPERATOR_EQUAL, {
75+
value: {
76+
$case: "intValue",
77+
intValue: input.contestEligibilityId,
78+
},
79+
})
80+
.build()
81+
);
82+
}
83+
84+
public async deleteGroupContestEligibility (input: DeleteGroupContestEligibilityInput) {
85+
await queryRunner.run(
86+
new QueryBuilder(GroupContestEligibilitySchema)
87+
.delete()
88+
.where(GroupContestEligibilitySchema.columns.contestEligibilityId, Operator.OPERATOR_EQUAL, {
89+
value: {
90+
$case: "intValue",
91+
intValue: input.contestEligibilityId,
92+
},
93+
})
94+
.andWhere(GroupContestEligibilitySchema.columns.groupId, Operator.OPERATOR_EQUAL, {
95+
value: {
96+
$case: "intValue",
97+
intValue: input.groupId,
98+
},
99+
})
100+
.build()
101+
);
102+
}
103+
}
104+
105+
export default new LegacyGroupContestEligibilityDomain();

src/domain/LegacyChallenge.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,53 @@
1+
import _ from 'lodash';
12
import { Operator, QueryBuilder } from "@topcoder-framework/client-relational";
23
import { queryRunner } from "../helper/QueryRunner";
34
import {
4-
CheckChallengeExistsResponse,
5-
CreateChallengeInput,
5+
CheckChallengeExistsResponse, CloseChallengeInput, LegacyChallenge, LegacyChallengeId, UpdateChallengeInput,
66
} from "../models/domain-layer/legacy/challenge";
77
import { ProjectSchema } from "../schema/project/Project";
88

99
class LegacyChallengeDomain {
10+
11+
public async activateChallenge(input:LegacyChallengeId) {
12+
// TODO: Activate
13+
}
14+
15+
public async closeChallenge(input:CloseChallengeInput) {
16+
// TODO: close challenge
17+
}
18+
19+
public async update(input:UpdateChallengeInput) {
20+
await queryRunner.run(
21+
new QueryBuilder(ProjectSchema)
22+
.update({ projectStatusId: input.projectStatusId, modifyUser: input.modifyUser })
23+
.where(ProjectSchema.columns.projectId, Operator.OPERATOR_EQUAL, {
24+
value: {
25+
$case: "intValue",
26+
intValue: input.projectId,
27+
},
28+
})
29+
.build()
30+
);
31+
}
32+
33+
public async getLegacyChallenge(
34+
input: LegacyChallengeId
35+
): Promise<LegacyChallenge|undefined> {
36+
const { rows } = await queryRunner.run(
37+
new QueryBuilder(ProjectSchema)
38+
.select(..._.map(ProjectSchema.columns))
39+
.where(ProjectSchema.columns.projectId, Operator.OPERATOR_EQUAL, {
40+
value: {
41+
$case: "intValue",
42+
intValue: input.legacyChallengeId,
43+
},
44+
})
45+
.limit(1)
46+
.build()
47+
);
48+
return rows?.length ? LegacyChallenge.fromPartial(rows[0] as LegacyChallenge) : undefined;
49+
}
50+
1051
public async checkChallengeExists(
1152
legacyChallengeId: number
1253
): Promise<CheckChallengeExistsResponse> {
@@ -30,6 +71,7 @@ class LegacyChallengeDomain {
3071
};
3172
}
3273

74+
<<<<<<< HEAD
3375
public async createLegacyChallenge(input: CreateChallengeInput): Promise<number> {
3476
const transaction = queryRunner.beginTransaction();
3577

@@ -52,6 +94,10 @@ class LegacyChallengeDomain {
5294
const { lastInsertId: legacyChallengeId } = createLegacyChallengeQueryResult;
5395

5496
return Promise.resolve(legacyChallengeId!);
97+
=======
98+
public async createLegacyChallenge(input: any): Promise<number> {
99+
return Promise.resolve(123);
100+
>>>>>>> 44dc00a (feat(domain-acl): complete challenge update interfaces)
55101
}
56102

57103
// public async listAvailableChallengeInfoTypes(key: string): Promise<number> {

src/domain/Notification.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Operator, QueryBuilder } from "@topcoder-framework/client-relational";
2+
import _ from "lodash";
3+
import { queryRunner } from "../helper/QueryRunner";
4+
import { DeleteNotificationsInput, GetNotificationsInput, Notification, NotificationList } from "../models/domain-layer/legacy/notification";
5+
import { NotificationSchema } from "../schema/project/Notification";
6+
7+
class LegacyNotificationDomain {
8+
9+
public async getNotifications(input:GetNotificationsInput): Promise<NotificationList> {
10+
const { rows } = await queryRunner.run(
11+
new QueryBuilder(NotificationSchema)
12+
.select(..._.map(NotificationSchema.columns))
13+
.where(NotificationSchema.columns.externalRefId, Operator.OPERATOR_EQUAL, {
14+
value: {
15+
$case: "intValue",
16+
intValue: input.externalRefId,
17+
},
18+
})
19+
.andWhere(NotificationSchema.columns.projectId, Operator.OPERATOR_EQUAL, {
20+
value: {
21+
$case: "intValue",
22+
intValue: input.projectId,
23+
},
24+
})
25+
.build()
26+
);
27+
28+
return { notifications: rows!.map(r => Notification.fromPartial(r as Notification)) };
29+
}
30+
31+
public async deleteNotifications(input:DeleteNotificationsInput) {
32+
await queryRunner.run(
33+
new QueryBuilder(NotificationSchema)
34+
.delete()
35+
.where(NotificationSchema.columns.projectId, Operator.OPERATOR_EQUAL, {
36+
value: {
37+
$case: "intValue",
38+
intValue: input.projectId,
39+
},
40+
})
41+
.andWhere(NotificationSchema.columns.externalRefId, Operator.OPERATOR_EQUAL, {
42+
value: {
43+
$case: "intValue",
44+
intValue: input.externalRefId,
45+
},
46+
})
47+
.build()
48+
);
49+
}
50+
}
51+
52+
export default new LegacyNotificationDomain();

0 commit comments

Comments
 (0)