Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda