Skip to content

Commit e7a3271

Browse files
authored
chore: strip empty in query build request (#1285)
## Ticket(s) lié(s) <!-- If you have a Jira Ticket / Sentry Ticket / GitHub Issue --> ## Description empeche d'envoyer des valeurs null ou vide dans les query string quand on utilise le `buildRequest` ## Screenshot / liens loom ## Check-list - [ ] Ma branche est rebase sur main - [ ] Des tests ont été écrits pour tous les endpoints créés ou modifiés - [ ] Refacto "à la volée" des parties sur lesquelles j'ai codée - [ ] Plus de `console.log` - [ ] J'ai ajouté une validation de schéma sur la route que j'ai ajouté ou modifié - [ ] J'ai converti les fichiers vue en `<script lang="ts">` - [ ] Mon code est en Typescript (autant que possible) **Testing instructions** <!-- Explain how another dev can test this PR. Create a workflow using checkboxes to explain how to run your code and the expected outputs: ${{ Test the following }} - [x] ${{ QA Scenario 1 }} - [x] ${{ QA Scenario 2 }} - [x] ${{ QA Scenario 3 }} -->
2 parents 24570a0 + ed6d6bc commit e7a3271

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

packages/shared-bridge/src/utils/request.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ describe("buildRequestQueryString", () => {
1919
});
2020

2121
it("should return a query string with an undefined query param", () => {
22-
const query = { limit: undefined, page: 1 };
22+
const query = { limit: undefined, page: 1, test: "" };
2323
// @ts-expect-error undefined is not a valid query param
2424
expect(buildRequestQueryString(query)).toEqual("?page=1");
2525
});
2626

27+
it("should return a query string with an false query param", () => {
28+
const query = { limit: false, page: 1 };
29+
expect(buildRequestQueryString(query)).toEqual("?limit=false&page=1");
30+
});
31+
2732
it("should return a query string with multiple query params", () => {
2833
const query = { limit: 10, page: 1 };
2934
expect(buildRequestQueryString(query)).toEqual("?limit=10&page=1");

packages/shared-bridge/src/utils/request.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export function buildRequestQueryString(
1212
// les tableaux étant mal interpretés par query-string, on parse les sous objets ou tableaux en JSON
1313
if (Array.isArray(value) || typeof value === "object") {
1414
return { ...acc, [key]: JSON.stringify(value) };
15+
} else if (!value && value !== false && value !== 0) {
16+
return acc;
1517
} else {
1618
return { ...acc, [key]: value };
1719
}

0 commit comments

Comments
 (0)