Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda