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,