Commit d58afb829f3848d71269a7c3cfd3b94ba985634b
1 parent
43555fba9f
Exists in
master
consulta post, devuelve articulos2
Showing
1 changed file
with
5 additions
and
3 deletions
Show diff stats
rutas/articulos.js
1 | 1 | ||
2 | var bookshelf = require('bookshelf')(knex); | 2 | var bookshelf = require('bookshelf')(knex); |
3 | bookshelf.plugin('pagination'); | 3 | bookshelf.plugin('pagination'); |
4 | 4 | ||
5 | const ArticuloImagen = bookshelf.Model.extend({ | 5 | const ArticuloImagen = bookshelf.Model.extend({ |
6 | tableName: 'ARTICULOS_IMAGEN' | 6 | tableName: 'ARTICULOS_IMAGEN' |
7 | }); | 7 | }); |
8 | 8 | ||
9 | const Articulo = bookshelf.Model.extend({ | 9 | const Articulo = bookshelf.Model.extend({ |
10 | tableName: 'ARTICULOS', | 10 | tableName: 'ARTICULOS', |
11 | imagenes: function () { | 11 | imagenes: function () { |
12 | return this.hasMany(ArticuloImagen, 'id_articulo', 'id'); | 12 | return this.hasMany(ArticuloImagen, 'id_articulo', 'id'); |
13 | } | 13 | } |
14 | }); | 14 | }); |
15 | 15 | ||
16 | router.get('/articulos/:page', (req, res) => { | 16 | router.post('/articulos', (req, res) => { |
17 | 17 | ||
18 | Articulo | 18 | Articulo |
19 | .query(() => {}) | 19 | .query((qb) => { |
20 | qb.where(`DET_LAR`, `like`, `%${req.body.search}%`); | ||
21 | }) | ||
20 | .orderBy('id') | 22 | .orderBy('id') |
21 | .fetchPage({ | 23 | .fetchPage({ |
22 | pageSize: 150, | 24 | pageSize: 150, |
23 | page: req.params.page, | 25 | page: req.body.page, |
24 | withRelated: ['imagenes'] | 26 | withRelated: ['imagenes'] |
25 | }) | 27 | }) |
26 | .then(data => { | 28 | .then(data => { |
27 | 29 | ||
28 | res.status(200).send( | 30 | res.status(200).send( |
29 | { | 31 | { |
30 | data: data, | 32 | data: data, |
31 | pagination: data.pagination, | 33 | pagination: data.pagination, |
32 | }); | 34 | }); |
33 | 35 | ||
34 | }); | 36 | }); |
35 | }); | 37 | }); |
36 | 38 | ||
37 | module.exports = router; | 39 | module.exports = router; |
38 | 40 |