Json-Server Delete, Update on Nested Object

Viewed 23

I have an example employee object,

  "employees": [
    {
      "id": 1,
      "address": "Lorem Ipsum is simply...",
      "name": "fat",
      "surname": "sum",
      "trainings": [
        {
          "id": 1,
          "training_name": "ddsadsa",
          "training_desc": "ewwe",
          "start_date": "15.06.2021",
          "end_date": "17.06.2021",
          "training_certification": "CRM Certified"
        },
        {
          "id": 2,
          "training_name": "aaasd",
          "training_desc": "3334",
          "start_date": "21.07.2022",
          "end_date": "-",
          "training_certification": ""
        },
      ]
    },
    {
      "id": 2,
      "address": "Lorem Ipsum is simply...",
      "name": "teve",
      "surname": "Thes",
      "trainings": [
        {
          "id": 1,
          "training_name": "ddsadsa",
          "training_desc": "ewwe",
          "start_date": "15.06.2021",
          "end_date": "17.06.2021",
          "training_certification": "CRM Certified"
        },
        {
          "id": 2,
          "training_name": "aaasd",
          "training_desc": "3334",
          "start_date": "21.07.2022",
          "end_date": "-",
          "training_certification": ""
        },
      ]
    },
  ],

I want to update or delete the items in the trainings object of each employee, I tried _embed in json-server like this but it didn't work:

Request URL: http://localhost:3000/employees/1?_embed=trainings/2
Request Method: DELETE
Status Code: 404 Not Found

(So, delete id:2 training item of id:1 employee item)

Thanks for helps,

0 Answers
Related