Commit eae5ae86f34b73a9b38ce18c269ba30757b4db4b
1 parent
3f9f0e6ab3
Exists in
master
Agregado metodo delete.
Showing
1 changed file
with
20 additions
and
0 deletions
Show diff stats
rutas/imagenes.js
| ... | ... | @@ -56,4 +56,24 @@ router.post('/imagenes/guardar', (req, res) => { |
| 56 | 56 | |
| 57 | 57 | }); |
| 58 | 58 | |
| 59 | +router.post('/imagen/borrar', (req, res) => { | |
| 60 | + | |
| 61 | + let deleted = false | |
| 62 | + let path = `${__dirname}/../img/${req.body.name}`; | |
| 63 | + | |
| 64 | + knex('ARTICULOS_IMAGEN') | |
| 65 | + .where('id_articulo', req.body.id_articulo) | |
| 66 | + .andWhere('id', req.body.id) | |
| 67 | + .update({ | |
| 68 | + id_articulo: 0, | |
| 69 | + }) | |
| 70 | + .then(() => { | |
| 71 | + try { | |
| 72 | + require('fs').unlinkSync(path); | |
| 73 | + deleted = true; | |
| 74 | + res.status(200).send(deleted); | |
| 75 | + } catch (err) { } | |
| 76 | + }); | |
| 77 | +}); | |
| 78 | + | |
| 59 | 79 | module.exports = router; |