From c00505de9b888414135770193e62ac1972d6d680 Mon Sep 17 00:00:00 2001 From: Kariamos Date: Wed, 10 Dec 2025 11:19:39 +0100 Subject: [PATCH] feat: add handling for empty body in human resources PUT route --- .../campaignId/humanResources/_put/index.spec.ts | 13 +++++++++++++ .../campaignId/humanResources/_put/index.ts | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/routes/dossiers/campaignId/humanResources/_put/index.spec.ts b/src/routes/dossiers/campaignId/humanResources/_put/index.spec.ts index 14112af07..9656fa894 100644 --- a/src/routes/dossiers/campaignId/humanResources/_put/index.spec.ts +++ b/src/routes/dossiers/campaignId/humanResources/_put/index.spec.ts @@ -118,6 +118,19 @@ describe("Route PUT/dossiers/:campaignId/humanResources", () => { await tryber.tables.CampaignHumanResources.do().delete(); }); + it("Should return 200 if body is empty and simply delete all human resources", async () => { + const response = await request(app) + .put("/dossiers/1/humanResources") + .send([]) + .set("Authorization", 'Bearer tester olp {"appq_campaign":[1]}'); + const humanResources = await request(app) + .get("/dossiers/1/humanResources") + .set("Authorization", 'Bearer tester olp {"appq_campaign":[1]}') + .then((res) => res.body.items); + expect(humanResources).toHaveLength(0); + expect(response.status).toBe(200); + }); + it("Should remove the old records and update the human resources", async () => { const response = await request(app) .put("/dossiers/1/humanResources") diff --git a/src/routes/dossiers/campaignId/humanResources/_put/index.ts b/src/routes/dossiers/campaignId/humanResources/_put/index.ts index 1ab54ae16..ce8555cb3 100644 --- a/src/routes/dossiers/campaignId/humanResources/_put/index.ts +++ b/src/routes/dossiers/campaignId/humanResources/_put/index.ts @@ -66,6 +66,10 @@ export default class RouteItem extends CampaignRoute<{ .delete() .where("campaign_id", this.cp_id); + if (body.length === 0) { + return; + } + await tryber.tables.CampaignHumanResources.do().insert([ ...body.map((item) => ({ campaign_id: this.cp_id,