Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TECH - changement de la structure de la query getConventions pour amélioration des stats pg #2223

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,12 @@ describe("Pg implementation of ConventionQueries", () => {
describe("PG implementation of method getConventionsByFilters", () => {
const agencyId = "bbbbbc15-9c0a-1aaa-aa6d-6aa9ad38aaff";
const agency = AgencyDtoBuilder.create().withId(agencyId).build();
const siret1 = "11110000111100";
const siret2 = "22220000222200";
const siret3 = "33330000333300";

const conventionCancelledAndDateStart20230327 = new ConventionDtoBuilder()
.withSiret(siret1)
.withId("bbbbbc15-9c0a-1aaa-aa6d-6aa9ad38aa01")
.withDateStart(new Date("2023-03-27").toISOString())
.withDateEnd(new Date("2023-03-28").toISOString())
Expand All @@ -346,6 +351,7 @@ describe("Pg implementation of ConventionQueries", () => {
.build();

const conventionDraftAndDateStart20230330 = new ConventionDtoBuilder()
.withSiret(siret3)
.withId("bbbbbc15-9c0a-1aaa-aa6d-6aa9ad38aa02")
.withDateSubmission(new Date("2023-03-05").toISOString())
.withDateStart(new Date("2023-03-30").toISOString())
Expand All @@ -356,6 +362,7 @@ describe("Pg implementation of ConventionQueries", () => {
.build();

const firstValidatedConvention = new ConventionDtoBuilder()
.withSiret(siret1)
.withId("bbbbbc15-9c0a-1aaa-aa6d-6aa9ad38aa03")
.withDateSubmission(new Date("2024-06-20").toISOString())
.withDateStart(new Date("2024-07-01").toISOString())
Expand All @@ -368,6 +375,7 @@ describe("Pg implementation of ConventionQueries", () => {
.build();

const secondValidatedConvention = new ConventionDtoBuilder()
.withSiret(siret2)
.withId("bbbbbc15-9c0a-1aaa-aa6d-6aa9ad38aa04")
.withDateSubmission(new Date("2024-06-21").toISOString())
.withDateStart(new Date("2024-07-02").toISOString())
Expand Down Expand Up @@ -523,6 +531,21 @@ describe("Pg implementation of ConventionQueries", () => {
firstValidatedConvention,
]);
});

it("getConventionsByFilters with some sirets", async () => {
const resultAll = await conventionQueries.getConventions({
filters: {
withSirets: [siret1, siret2],
},
sortBy: "dateStart",
});

expectToEqual(resultAll, [
secondValidatedConvention,
firstValidatedConvention,
conventionCancelledAndDateStart20230327,
]);
});
});

describe("findSimilarConventions", () => {
Expand Down
3 changes: 2 additions & 1 deletion back/src/domains/convention/adapters/PgConventionQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ConventionStatus,
DateRange,
FindSimilarConventionsParams,
SiretDto,
conventionReadSchema,
conventionSchema,
pipeWithValue,
Expand Down Expand Up @@ -279,7 +280,7 @@ const addFiltersToBuilder =

const addWithSiretsIfNeeded: AddToBuilder = (b) =>
withSirets && withSirets.length > 0
? b.where("conventions.siret", "in", withSirets)
? b.where("conventions.siret", "=", sql<SiretDto>`ANY(${withSirets})`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, le fameux

: b;

return pipeWithValue(
Expand Down
Loading