How to format neasted json array depends on conditions I have form request json for api
This is my front end json array I created this array using angular reactive forms
But Api need requires and not empty fields only
In above array is nested days->timings->breaks
conditions
1) if days not contain timings no need to sumbit(example: day-3 not contain timings so no need to submit)
2) if blocks, floors, room are empty no need to summit(example: day[1]-timing[1], timing[2], day[2]-timing[2])
3) if breaks are empty not need to submit the breaks array in days(example: day1[1]-> timings[3], day[2]->timings[2])
4
) in breks if mode is true (duration, quantity), if mode is true (start time, end times are required
5) api no need nesting(just need normal array)(example:[{}, {}, {}])
By floowing above conditions u can assume this array
I tried using for loops to solve it, but it's duplicate the things not well
Front end array
{
"startDate":"10-05-2018",
"endDate":"13-05-2018",
"days":[
{
"dayId":1,
"timings":[
{
"startTime":"10:00",
"endTime":"12:00",
"cycle":1,
"blocks":1,
"floors":2,
"rooms":3,
"breaks":[
{
"type":1,
"mode":false,
"startTime":"01:00",
"endTime":"02:00",
"duration":1,
"quantity":1
},
{
"type":1,
"mode":true,
"startTime":"01:00",
"endTime":"02:00",
"duration":1,
"quantity":1
}
]
},
{
"startTime":"10:00",
"endTime":"12:00",
"cycle":1,
"blocks":"",
"floors":"",
"rooms":"",
"breaks":[
{
"type":1,
"mode":false,
"startTime":"01:00",
"endTime":"02:00",
"duration":1,
"quantity":1
}
]
},
{
"startTime":"10:00",
"endTime":"12:00",
"cycle":1,
"blocks":"",
"floors":"",
"rooms":"",
"breaks":[
]
},
{
"startTime":"10:00",
"endTime":"12:00",
"cycle":1,
"blocks":2,
"floors":3,
"rooms":3,
"breaks":[
]
}
]
},
{
"dayId":2,
"timings":[
{
"startTime":"10:00",
"endTime":"12:00",
"cycle":1,
"blocks":1,
"floors":2,
"rooms":3,
"breaks":[
{
"type":1,
"mode":true,
"startTime":"01:00",
"endTime":"02:00",
"duration":1,
"quantity":1
}
]
},
{
"startTime":"10:00",
"endTime":"12:00",
"cycle":1,
"blocks":"",
"floors":"",
"rooms":"",
"breaks":[
]
}
]
},
{
"dayId":3,
"timings":[
]
}
]
}
requested array
{
"start_date":"05-05-2018",
"end_date":"31-07-2018",
"branch_id":"2",
"day":[
{
"id":"1",
"start_time":"10:00",
"end_time":"12:00",
"breaks":[
{
"type":1,
"mode":false,
"duration":1,
"quantity":1
},
{
"type":1,
"mode":true,
"startTime":"01:00",
"endTime":"02:00",
}
],
"gen_repeat_cycle_id":"1",
"room_id":"1",
"floor_id":"2",
"block_id":"3"
},
{
"id":"1",
"start_time":"10:00",
"end_time":"12:00",
"breaks":[
{
"type":1,
"mode":false,
"duration":1,
"quantity":1
}
],
"gen_repeat_cycle_id":"2"
},
{
"id":"1",
"start_time":"10:00",
"end_time":"12:00",
"gen_repeat_cycle_id":"1"
},
{
"id":"1",
"start_time":"10:00",
"end_time":"12:00",
"gen_repeat_cycle_id":"1",
"room_id":"1",
"floor_id":"2",
"block_id":"3"
},
{
"id":"2",
"start_time":"10:00",
"end_time":"12:00",
"breaks":[
{
"type":1,
"mode":true,
"startTime":"01:00",
"endTime":"02:00",
}
],
"gen_repeat_cycle_id":"1",
"room_id":"1",
"floor_id":"2",
"block_id":"3"
},
{
"id":"2",
"start_time":"10:00",
"end_time":"12:00",
"gen_repeat_cycle_id":"1"
}
]
}
Please help me