From e5ae7992f09688de6d933d4c9c3fb1a34216d769 Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Tue, 1 Aug 2023 10:45:55 -0300 Subject: [PATCH] [FIX] Order --- src/libs/routes_v1/publication.js | 35 ++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/libs/routes_v1/publication.js b/src/libs/routes_v1/publication.js index da79c64e..1cad804b 100644 --- a/src/libs/routes_v1/publication.js +++ b/src/libs/routes_v1/publication.js @@ -30,7 +30,7 @@ function emailSyntax(email) { } pubApp.get('/', async (req, res, next) => { - const order = req.query.order || 'DESC'; + const ordenar = req.query.order || 'DESC'; const filter = req.query.filter || 'all' ; const page = parseInt(req.query.page) || 1; // Current page number const pageSize = parseInt(req.query.pageSize) || 5; // Number of items per page @@ -41,6 +41,9 @@ pubApp.get('/', async (req, res, next) => { const publis = await Publication.findAll({ offset, limit: pageSize, + order: [ + ['created_at', ordenar], + ], }); res.json({ @@ -57,7 +60,7 @@ pubApp.get('/', async (req, res, next) => { offset, limit: pageSize, order: [ - ['created_at', order], + ['created_at', ordenar], ], where:{ is_draft:filter @@ -140,7 +143,33 @@ pubApp.post('/edit', passport.authenticate('bearer', { session: false }), author console.log("NAO ARQUIVO");} let data = JSON.parse(req.body.data); console.log(data); - req.response = {'This is a test':'This is a test'}; + let pb = await Publication.findByPk(data.id).catch(function (err) { + log.error(err); + return next(err); + }); + pb.filter = data.categoria || pb.filter; + pb.title = data.title || pb.title; + pb.authors = data.autores || pb.authors; + pb.organization = data.organizacao || pb.organization; + pb.year = data.ano || pb.year; + pb.text = data.texto || pb.text; + pb.link = data.link || pb.link; + pb.is_homepage = data.homepage || pb.is_homepage; + pb.is_draft = data.rascunho || pb.is_draft; + + pb.save().catch(function (err) { + log.error(err); + let errors = []; + for (let errName in err.errors) { + errors.push(err.errors[errName].message); + } + log.error(errors); + res.statusCode = 400; + return res.json({ err, errors }); + // handle error; + }); + + req.result = pb.toJSON(); next(); }, response('publication')); -- GitLab