mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-10 16:49:41 +00:00
bugfix
delete first event + error catching
This commit is contained in:
@@ -97,16 +97,25 @@ exports.eventsPut = async (req, res) => {
|
|||||||
// Create controller for DELETE request to '/events/'
|
// Create controller for DELETE request to '/events/'
|
||||||
// Returns -
|
// Returns -
|
||||||
exports.eventsDelete = async (req, res) => {
|
exports.eventsDelete = async (req, res) => {
|
||||||
if (req.params.id) {
|
if (!req.params.id) {
|
||||||
const itemIndex = events.findIndex((e) => e.id == req.params.id);
|
|
||||||
|
|
||||||
if (!itemIndex) res.sendStatus(400);
|
|
||||||
|
|
||||||
// Torbjorn: this syntax is very bad
|
|
||||||
const e = events.splice(itemIndex, 1);
|
|
||||||
events = [...events];
|
|
||||||
res.sendStatus(200);
|
|
||||||
} else {
|
|
||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const itemIndex = events.findIndex((e) => e.id == req.params.id);
|
||||||
|
|
||||||
|
console.log('found at index', itemIndex);
|
||||||
|
|
||||||
|
// Torbjorn: this syntax is very bad
|
||||||
|
if (itemIndex === -1) {
|
||||||
|
res.sendStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemIndex === 0) {
|
||||||
|
const e = events.shift();
|
||||||
|
} else {
|
||||||
|
const e = events.splice(itemIndex, 1);
|
||||||
|
}
|
||||||
|
events = [...events];
|
||||||
|
res.sendStatus(200);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user