articulos.js
704 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
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.get('/articulos/:page', (req, res) => {
Articulo
.query(() => {})
.orderBy('id')
.fetchPage({
pageSize: 150,
page: req.params.page,
withRelated: ['imagenes']
})
.then(data => {
res.status(200).send(
{
data: data,
pagination: data.pagination,
});
});
});
module.exports = router;