I'm encountering an issue with this block of code. While attempting to return a Promise, I've noticed that during debugging, it seems to "skip" the forEach loop and rejects the function instead. Can you help me identify what might be causing this behavior?
removeOldBookings(rooms: Room[]) {
return new Promise((resolve, reject) => {
const today = new Date();
const roomsHolder = [];
rooms.forEach(roomElement => {
const bookingFiltered = roomElement[1].filterRoom.filter(finder => finder.provider.toUpperCase() === 'SELF');
if (new Date(bookingFiltered.dateEnd) > today) {
const obj = {...roomElement[1], hostBookings: [...bookingFiltered]};
roomsHolder.push(obj);
}
});
if (roomsHolder.length) {
resolve(roomsHolder);
} else {
reject('error');
}
});
}