I am trying to figure out how an API works where we don't have the support anymore from the creator.
Basic set-up; We have a PostgreSQL table running which contains events data (date, subject, time, etc)
There is an API which lets us book new events. This works fine. I see there is also an option to DELETE an event, but this is not working as it should. Therefore I am trying to figure out where it's going wrong.
Here is an example of the POST new meeting in the API .js file (which works)
router.post('/meeting/post', (req, res) => {
Meeting.query().insertGraph(req.body)
.then(() => {
res.json("post ok");
});
});
So far, so good.
But the delete function is a puzzle for me(can't get it to work);
router.get('/meeting/delete', (req, res) => {
const date = moment().utc().subtract(3, "days").format();
Meeting.query().withGraphFetched(neededTables)
.where('id', '!=', 1)
.andWhere('end_time', '<', date)
.then(meetings => {
meetings.forEach(meeting => {
const folderPath = `${appConfig.backgroundsFilepath}resources/images/meeting-${meeting.id}`;
if (fs.existsSync(folderPath)) {
meeting.backgrounds.forEach(background => {
const sides = ['left', 'middle', 'right'];
sides.forEach((side) => {
const filePath = background[side].replace('./', appConfig.backgroundsFilepath);
if (fs.existsSync(filePath)) {
fs.rmSync(filePath);
}
});
});
fs.rmdirSync(folderPath);
}
});
});
Meeting.query().delete()
.where('id', '!=', 1)
.andWhere('end_time', '<', date)
.then(() => {
res.json("delete ok");
});
});
In postman, I post a GET to [localhost]/meeting/delete with a body containing;
"id": 5
}
Then I get a perfect return:
"delete ok"
Only when I look at the table data, the row with ID:5 is still there...
I am a bit of a noob with JS / PostgreSQL / API's so I am quite lost here. I hope someone has a good idea on what to check.