Trying to delete child table row(s)

I have a child table called Meal Details. I want to delete rows which is not used in another table called capacity allocation.

What happens with me, when I’m trying to delete row which is not falls in capacity allocation that should be delete without fail. In my case when more then one meal continuously in row and after that those meals are there which is not falls in capacity allocation, then working fine.
But when meals some meals are continuously in row which is falls in Capacity Allocation then some meals are not falls after that again some meals are falls and deleting rows not deleting as expect.

Describe example :
Scenario 1 :
Meals Row

  1. Breakfast
  2. Lunch
  3. Extra Tea
  4. Dinner
  5. Evening Tea

I.e.
If Extra Tea & Dinner is not falls in Capacity allocation & I’m trying to delete all rows, here it should be delete Extra Tea & Dinner and should not be delete other meals (Breakfast, Lunch, Evening Tea) but while deleting all rows delete Extra Tea and Evening Tea as well and not deleting Dinner.

Scenario 2:
Meals Row

  1. Breakfast
  2. Lunch
  3. Dinner
  4. Evening Tea

If meals are like : Breakfast, Lunch, Evening Tea falls in Capacity Allocation and Dinner is not. Now trying to delete all rows, then delete working perfectly.

Here is my code:

frappe.ui.form.on(“Meal Details”, {
before_meal_details_remove: async function (frm, cdt, cdn) {
try {
const result = await new Promise((resolve, reject) => {
debugger
frappe.call({
method: “frappe.client.get_list”,
args: {
doctype: “Capacity Allocation”,
filters: {
meal: cdn
}
},
callback: function (result) {
resolve(result);
},
error: (err) => {
reject(err);
frappe.show_alert(“Something went wrong please try again”);
}
});
});
if (result.message && result.message.length > 0) {
const matchingRow = frm.doc.meal_details.find(row => row.name === cdn);

			if (matchingRow) {
				frappe.throw("Capacity Allocation is done against meal " + matchingRow.meal + ", deletion is not permitted.");
			}
		}
	} catch (error) {
		frappe.throw(error)// Display error message if the Promise rejects
	}
	return false;
},

})