Skip to content

Commit

Permalink
Merge commit 'ed9fb3c2ba35be2d113a7d298d8afb548af5d6da'
Browse files Browse the repository at this point in the history
  • Loading branch information
cannarocks committed Aug 9, 2024
2 parents 15c3cb0 + ed9fb3c commit 0f155b9
Show file tree
Hide file tree
Showing 43 changed files with 1,799 additions and 2,194 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ coverage/
keys/*
!/**/.gitkeep.idea
.idea
.vscode/*.log
.vscode/*.log
.aider*
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@appquality/tryber-database": "^0.41.1",
"@appquality/tryber-database": "^0.41.9",
"@appquality/wp-auth": "^1.0.7",
"@googlemaps/google-maps-services-js": "^3.3.7",
"@sendgrid/mail": "^7.6.0",
Expand Down
4 changes: 4 additions & 0 deletions src/features/db/class/PreselectionFormFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type PreselectionFormFieldsType = {
| "address"
| `cuf_${number}`;
options: string;
invalid_options: string;
question: string;
priority: number;
};
Expand All @@ -26,6 +27,7 @@ class PreselectionFormFieldsObject {
options: PreselectionFormFieldsType["options"];
question: PreselectionFormFieldsType["question"];
priority: PreselectionFormFieldsType["priority"];
invalid_options: PreselectionFormFieldsType["invalid_options"];

constructor(item: PreselectionFormFieldsType) {
this.id = item.id;
Expand All @@ -35,6 +37,7 @@ class PreselectionFormFieldsObject {
this.options = item.options;
this.question = item.question;
this.priority = item.priority;
this.invalid_options = item.invalid_options;
}

public getOptions(): string[] | number[] {
Expand Down Expand Up @@ -63,6 +66,7 @@ class Table extends Database<{
"options",
"question",
"priority",
"invalid_options",
],
});
}
Expand Down
460 changes: 133 additions & 327 deletions src/reference/openapi.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ class CandidateDevices implements CandidateData {
private campaignId: number;
private candidateIds: number[];
private filters?: { os?: string[] };
private show: "onlyAccepted" | "onlyCandidates" | "all" = "all";
private show:
| "onlyAccepted"
| "onlyCandidates"
| "all"
| "candidatesAndExcluded" = "all";

private _devices:
| {
Expand Down Expand Up @@ -36,7 +40,7 @@ class CandidateDevices implements CandidateData {
campaignId: number;
candidateIds: number[];
filters?: { os?: string[] };
show: "onlyAccepted" | "onlyCandidates" | "all";
show: "onlyAccepted" | "onlyCandidates" | "all" | "candidatesAndExcluded";
}) {
this.candidateIds = candidateIds;
this.filters = filters;
Expand Down
23 changes: 19 additions & 4 deletions src/routes/campaigns/campaignId/candidates/_get/Candidates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { tryber } from "@src/features/database";

class Candidates {
private campaign_id: number;
private show: "onlyAccepted" | "onlyCandidates" | "all" = "all";
private show:
| "onlyAccepted"
| "onlyCandidates"
| "all"
| "candidatesAndExcluded" = "all";
constructor({
campaign_id,
show,
}: {
campaign_id: number;
show: "onlyAccepted" | "onlyCandidates" | "all";
show: "onlyAccepted" | "onlyCandidates" | "all" | "candidatesAndExcluded";
}) {
this.campaign_id = campaign_id;
this.show = show;
Expand All @@ -29,7 +33,8 @@ class Candidates {
.select(
tryber.ref("id").withSchema("wp_appq_evd_profile"),
"name",
"surname"
"surname",
"accepted"
)
.where("campaign_id", this.campaign_id)
.where("name", "<>", "Deleted User")
Expand All @@ -40,9 +45,19 @@ class Candidates {
query.where("accepted", 1);
} else if (this.show === "onlyCandidates") {
query.where("accepted", 0);
} else if (this.show === "candidatesAndExcluded") {
query.whereIn("accepted", [0, -1]);
}

return await query;
return (await query).map((candidate) => ({
...candidate,
status:
candidate.accepted === 1
? ("selected" as const)
: candidate.accepted === 0
? ("candidate" as const)
: ("excluded" as const),
}));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/routes/campaigns/campaignId/candidates/_get/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export default class RouteItem extends UserRoute<{
age: candidate.age,
questions: candidate.questions,
levels: candidate.levels,
status: candidate.status,
};
}),
size: candidates.length,
Expand Down
70 changes: 63 additions & 7 deletions src/routes/campaigns/campaignId/candidates/_get/show.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ describe("GET /campaigns/:campaignId/candidates - show ", () => {
surname: "pluto",
education_id: 1,
employment_id: 1,
birth_date: "1999-01-01",
total_exp_pts: 90,
sex: 0,
};
await tryber.tables.WpAppqEvdProfile.do().insert([
{
...profile,
id: 1,
wp_user_id: 1,
birth_date: "2000-01-01",
total_exp_pts: 100,
sex: 1,
},
{
...profile,
id: 2,
wp_user_id: 2,
birth_date: "1999-01-01",
total_exp_pts: 90,
sex: 0,
},
{
...profile,
id: 3,
wp_user_id: 3,
},
]);

Expand All @@ -55,6 +57,11 @@ describe("GET /campaigns/:campaignId/candidates - show ", () => {
user_id: 1,
accepted: 0,
},
{
...candidate,
user_id: 3,
accepted: -1,
},
]);
await tryber.tables.WpCrowdAppqHasCandidate.do().insert([
{
Expand Down Expand Up @@ -90,6 +97,11 @@ describe("GET /campaigns/:campaignId/candidates - show ", () => {
id: 3,
id_profile: 2,
},
{
...device,
id: 4,
id_profile: 3,
},
]);

await tryber.tables.WpAppqEvdPlatform.do().insert({
Expand Down Expand Up @@ -145,7 +157,7 @@ describe("GET /campaigns/:campaignId/candidates - show ", () => {
.get("/campaigns/1/candidates?show=all")
.set("authorization", `Bearer tester olp {"appq_tester_selection":true}`);
expect(response.body).toHaveProperty("results");
expect(response.body.results).toHaveLength(2);
expect(response.body.results).toHaveLength(3);
expect(response.body.results).toEqual(
expect.arrayContaining([
expect.objectContaining({
Expand All @@ -154,6 +166,33 @@ describe("GET /campaigns/:campaignId/candidates - show ", () => {
expect.objectContaining({
id: 2,
}),
expect.objectContaining({
id: 3,
}),
])
);
});

it("Should return acceptance status", async () => {
const response = await request(app)
.get("/campaigns/1/candidates?show=all")
.set("authorization", `Bearer tester olp {"appq_tester_selection":true}`);
expect(response.body).toHaveProperty("results");
expect(response.body.results).toHaveLength(3);
expect(response.body.results).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: 1,
status: "candidate",
}),
expect.objectContaining({
id: 2,
status: "selected",
}),
expect.objectContaining({
id: 3,
status: "excluded",
}),
])
);
});
Expand All @@ -168,4 +207,21 @@ describe("GET /campaigns/:campaignId/candidates - show ", () => {
expect(response.body.results[0].devices).toHaveLength(1);
expect(response.body.results[0].devices[0]).toHaveProperty("id", 3);
});
it("Should show candidates and excluded if candidatesAndExcluded", async () => {
const response = await request(app)
.get("/campaigns/1/candidates?show=candidatesAndExcluded")
.set("authorization", `Bearer tester olp {"appq_tester_selection":true}`);
expect(response.body).toHaveProperty("results");
expect(response.body.results).toHaveLength(2);
expect(response.body.results).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: 1,
}),
expect.objectContaining({
id: 3,
}),
])
);
});
});
Loading

0 comments on commit 0f155b9

Please sign in to comment.