articulos.js
763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var bookshelf = require('bookshelf')(knex);
bookshelf.plugin('pagination');
const ArticuloImagen = bookshelf.Model.extend({
tableName: 'ARTICULOS_IMAGEN'
});
const Articulo = bookshelf.Model.extend({
tableName: 'ARTICULOS',
imagenes: function () {
return this.hasMany(ArticuloImagen, 'id_articulo', 'id');
}
});
router.post('/articulos', (req, res) => {
Articulo
.query((qb) => {
qb.where(`DET_LAR`, `like`, `%${req.body.search}%`);
})
.orderBy('id')
.fetchPage({
pageSize: 150,
page: req.body.page,
withRelated: ['imagenes']
})
.then(data => {
res.status(200).send(
{
data: data,
pagination: data.pagination,
});
});
});
module.exports = router;