app.post('/checkTimes', (req, res) => {
let date = req.body.date;
let times = [
"16:00",
"16:30",
"17:00",
"17:30",
"18:00",
"18:30",
"19:00",
"19:30",
"20:00",
"20:30",
"21:00",
];
connection.query("SELECT time FROM appointments WHERE date = ?", [date], (err, result) => {
if(err) throw err;
let timesToReturn = [];
// Get all times that are not between start time and end time
for(let i = 0; i < times.length; i++) {
let found = false;
for(let j = 0; j < result.length; j++) {
if(times[i] == result[j].time) {
found = true;
break;
}
}
if(!found) timesToReturn.push(times[i]);
}
res.status(200).send(timesToReturn);
});
});
So, I got this. It only checks start time right now, but I want it to remove all times that are between start and end. Not sure how to do that if anyone could help me i'd be much appreciated for example if I got an appointment between 16:00 and 17:30 I want it to remove 16:00, 16:30 and 17:00
app.post('/checkTimes', (req, res) => {
let date = req.body.date;
let times = [
"16:00",
"16:30",
"17:00",
"17:30",
"18:00",
"18:30",
"19:00",
"19:30",
"20:00",
"20:30",
"21:00",
];
connection.query("SELECT time, endTime FROM appointments WHERE date = ?", [date], (err, [result]) => {
if(err) throw err;
if(result) {
let timesToReturn = [...times.slice(0, times.indexOf(result.time)), ...times.slice(times.indexOf(result.endTime))];
res.status(200).send(timesToReturn);
} else {
res.status(200).send(times);
}
});
});