Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
API function not working with PostgreSQL table when removing row

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.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!