Skip to content

Commit 3166e9e

Browse files
authored
Merge pull request #106 from topcoder-platform/PM-5065_handle-approval-filter
PM-5065 - handle approval status filter
2 parents cc25ea3 + d5b14ef commit 3166e9e

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/services/ChallengeService.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,13 @@ async function searchChallenges(currentUser, criteria) {
14101410
});
14111411
}
14121412

1413+
// handle approvalStatus
1414+
if (!_.isNil(criteria.approvalStatus)) {
1415+
prismaFilter.where.AND.push({
1416+
approvalStatus: criteria.approvalStatus.toUpperCase(),
1417+
});
1418+
}
1419+
14131420
_.forEach(_.keys(criteria), (key) => {
14141421
if (_.toString(key).indexOf("meta.") > -1) {
14151422
// Parse and use metadata key
@@ -2129,6 +2136,9 @@ searchChallenges.schema = {
21292136
status: Joi.string()
21302137
.valid(..._.values(ChallengeStatusEnum))
21312138
.insensitive(),
2139+
approvalStatus: Joi.string()
2140+
.valid(..._.values(CHALLENGE_APPROVAL_STATUS))
2141+
.insensitive(),
21322142
group: Joi.string(),
21332143
startDateStart: Joi.date(),
21342144
startDateEnd: Joi.date(),

test/unit/ChallengeService.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,16 @@ describe("challenge service unit tests", () => {
11901190
should.equal(result.result[0].name, data.challenge.name);
11911191
});
11921192

1193+
it("search challenges by approvalStatus case-insensitively", async () => {
1194+
const result = await service.searchChallenges(
1195+
{ isMachine: true },
1196+
{ approvalStatus: "approved" },
1197+
);
1198+
1199+
should.equal(result.total > 0, true);
1200+
should.equal(result.result.every((challenge) => challenge.approvalStatus === "APPROVED"), true);
1201+
});
1202+
11931203
it("search challenges successfully 3", async () => {
11941204
const res = await service.searchChallenges(
11951205
{ isMachine: true },
@@ -1403,6 +1413,16 @@ describe("challenge service unit tests", () => {
14031413
}
14041414
throw new Error("should not reach here");
14051415
});
1416+
1417+
it("search challenges - invalid approvalStatus", async () => {
1418+
try {
1419+
await service.searchChallenges({ isMachine: true }, { approvalStatus: "INVALID" });
1420+
} catch (e) {
1421+
should.equal(e.message.includes("approvalStatus") && e.message.includes("must be one of"), true);
1422+
return;
1423+
}
1424+
throw new Error("should not reach here");
1425+
});
14061426
});
14071427

14081428
describe("update challenge tests", () => {

0 commit comments

Comments
 (0)