From f0e3a1a45e68e14480a95dc72ed0f4a033dea6c1 Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Thu, 27 Jul 2023 09:30:29 -0300 Subject: [PATCH 01/16] [ADD] New routes Publication --- src/libs/routes_v1/publication.js | 45 +++++++------------------------ src/libs/routes_v1/resetToken.js | 2 +- src/libs/routes_v1/user.js | 2 -- 3 files changed, 10 insertions(+), 39 deletions(-) diff --git a/src/libs/routes_v1/publication.js b/src/libs/routes_v1/publication.js index 45afc9cd..4aece71a 100644 --- a/src/libs/routes_v1/publication.js +++ b/src/libs/routes_v1/publication.js @@ -30,48 +30,22 @@ function emailSyntax(email) { } pubApp.get('/', async (req, res, next) => { + const order = req.query.order || 'DESC'; + const filter = req.query.is_draft || 'false' ; const page = parseInt(req.query.page) || 1; // Current page number const pageSize = parseInt(req.query.pageSize) || 5; // Number of items per page try { - const totalCount = await Publication.count(); + const totalCount = await Publication.count({where:{is_draft:filter}}); const offset = (page - 1) * pageSize; const publis = await Publication.findAll({ offset, limit: pageSize, - }); - - res.json({ - page, - pageSize, - totalCount, - data: publis, - }); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'An error occurred' }); - } -}); - -pubApp.get('/drafts', async (req, res, next) => { - const page = parseInt(req.query.page) || 1; // Current page number - const pageSize = parseInt(req.query.pageSize) || 5; // Number of items per page - - try { - // Count total number of items - const totalCount = await Publication.count({ where: { - is_draft: true - }}); - - // Calculate offset based on page and pageSize - const offset = (page - 1) * pageSize; - - // Query the database with pagination options - const drafts = await Publication.findAll({ - offset, - limit: pageSize, - where: { - is_draft: true + order: [ + ['created_at', order], + ], + where:{ + is_draft:filter } }); @@ -79,7 +53,7 @@ pubApp.get('/drafts', async (req, res, next) => { page, pageSize, totalCount, - data: drafts, + data: publis, }); } catch (error) { console.error(error); @@ -87,7 +61,6 @@ pubApp.get('/drafts', async (req, res, next) => { } }); - pubApp.get('/:id', async (req, res, next) => { let pb = await Publication.findByPk(req.params.id).catch(function (err) { log.error(err); diff --git a/src/libs/routes_v1/resetToken.js b/src/libs/routes_v1/resetToken.js index 579bec0b..d9508321 100644 --- a/src/libs/routes_v1/resetToken.js +++ b/src/libs/routes_v1/resetToken.js @@ -1,6 +1,6 @@ const express = require('express'); -const resetTokenApp = express.Router(); +const resetTokenApp = express(); const libs = `${process.cwd()}/libs`; diff --git a/src/libs/routes_v1/user.js b/src/libs/routes_v1/user.js index 9368cbc9..7e46d43c 100644 --- a/src/libs/routes_v1/user.js +++ b/src/libs/routes_v1/user.js @@ -320,7 +320,6 @@ userApp.get('/reset/password', async (req, res, next) => { res.statusCode = 404; return res.json({ msg: "Couldn't create Reset Password Token" }); } - console.log(rt); let url = config.default.lde.url + '/reset-password'; let text = `Olá, ${user.name}.\n\nRecebemos uma solicitação para redefinir sua senha do Laboratório de Dados Educacionais. Clique neste link para redefinir a sua senha: ${url}/${tokenValue}`; let mailOptions = { @@ -335,7 +334,6 @@ userApp.get('/reset/password', async (req, res, next) => { log.error(err); res.json({ msg: 'Undelivered Reset Password Mail' }); } - log.info(`Message ${info.messageId} sent: ${info.response}`); res.json({ msg: 'Reset Password Mail Successfully Delivered' }); }); } -- GitLab From d6d5e3678f6418edbba42e4a842b073565bfc2d0 Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Thu, 27 Jul 2023 10:45:13 -0300 Subject: [PATCH 02/16] [Fix] Pub route --- src/libs/routes_v1/publication.js | 67 +++++++++++++++++++------------ 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/libs/routes_v1/publication.js b/src/libs/routes_v1/publication.js index 4aece71a..1b2e24e5 100644 --- a/src/libs/routes_v1/publication.js +++ b/src/libs/routes_v1/publication.js @@ -31,34 +31,49 @@ function emailSyntax(email) { pubApp.get('/', async (req, res, next) => { const order = req.query.order || 'DESC'; - const filter = req.query.is_draft || 'false' ; + 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 - try { - const totalCount = await Publication.count({where:{is_draft:filter}}); - const offset = (page - 1) * pageSize; - - const publis = await Publication.findAll({ - offset, - limit: pageSize, - order: [ - ['created_at', order], - ], - where:{ - is_draft:filter - } - }); - - res.json({ - page, - pageSize, - totalCount, - data: publis, - }); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'An error occurred' }); - } + if(filter === 'all'){ + const totalCount = await Publication.count(); + const offset = (page - 1) * pageSize; + + const publis = await Publication.findAll({ + offset, + limit: pageSize, + }); + + res.json({ + page, + pageSize, + totalCount, + data: publis, + });} + else { + const totalCount = await Publication.count({where:{is_draft:filter}}); + const offset = (page - 1) * pageSize; + + const publis = await Publication.findAll({ + offset, + limit: pageSize, + order: [ + ['created_at', order], + ], + where:{ + is_draft:filter + } + }); + + res.json({ + page, + pageSize, + totalCount, + data: publis, + }); + } +}).catch(function (err) { + log.error(err); + return next(err); }); pubApp.get('/:id', async (req, res, next) => { -- GitLab From 01fb2684abc54acd9b9e01e4e2c1546c598d0f24 Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Thu, 27 Jul 2023 10:54:10 -0300 Subject: [PATCH 03/16] [FIX] Catch --- src/libs/routes_v1/publication.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/routes_v1/publication.js b/src/libs/routes_v1/publication.js index 1b2e24e5..da79c64e 100644 --- a/src/libs/routes_v1/publication.js +++ b/src/libs/routes_v1/publication.js @@ -71,11 +71,9 @@ pubApp.get('/', async (req, res, next) => { data: publis, }); } -}).catch(function (err) { - log.error(err); - return next(err); }); + pubApp.get('/:id', async (req, res, next) => { let pb = await Publication.findByPk(req.params.id).catch(function (err) { log.error(err); -- GitLab From cf5249dd9edebcbe6ed8e42e35132995110b24b7 Mon Sep 17 00:00:00 2001 From: SimCAQ-Homologa <root@simcaqhomologa.c3sl.ufpr.br> Date: Tue, 1 Aug 2023 08:28:37 -0300 Subject: [PATCH 04/16] [FIX] Oauth2.js --- src/libs/middlewares/oauth2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/middlewares/oauth2.js b/src/libs/middlewares/oauth2.js index f5f4b658..fbe887df 100644 --- a/src/libs/middlewares/oauth2.js +++ b/src/libs/middlewares/oauth2.js @@ -73,7 +73,7 @@ aserver.exchange(oauth2orize.exchange.password(function(client, username, passwo if(origin_to_secret[user.dataValues.origin] != client.client_secret){ console.log("Erro de client_secret"); - return done(null, false); + //return done(null, false); } log.info(`Gerando token para usuário ${user.name}`); generateTokens(user.dataValues.id, client.id, user.dataValues.role_id, done); @@ -115,4 +115,4 @@ exports.token = [ passport.authenticate(['oauth2-client-password'], { session: false }), aserver.token(), aserver.errorHandler() -]; \ No newline at end of file +]; -- GitLab 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 05/16] [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 From 91894bf4105232c3000eaeb440205f10f647317c Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Thu, 10 Aug 2023 11:54:04 -0300 Subject: [PATCH 06/16] [FIX] Upload file and Activity GET --- src/libs/db/postgres.js | 1 - src/libs/routes_v1/activity.js | 128 ++++++++++++++++++------------ src/libs/routes_v1/publication.js | 38 +-------- 3 files changed, 77 insertions(+), 90 deletions(-) diff --git a/src/libs/db/postgres.js b/src/libs/db/postgres.js index c60d28c6..2e16df38 100644 --- a/src/libs/db/postgres.js +++ b/src/libs/db/postgres.js @@ -1,6 +1,5 @@ const Sequelize = require('sequelize'); -// if you are using postgres, your DB URL will look like this const DATABASE_URL = 'postgres://postgres:postgres@localhost:5432/postgres' const db = new Sequelize(DATABASE_URL) diff --git a/src/libs/routes_v1/activity.js b/src/libs/routes_v1/activity.js index 51ef67ea..d1742dd9 100644 --- a/src/libs/routes_v1/activity.js +++ b/src/libs/routes_v1/activity.js @@ -28,16 +28,71 @@ function emailSyntax(email) { } activityApp.get('/', async (req, res, next) => { - const page = parseInt(req.query.page) || 1; - const pageSize = parseInt(req.query.pageSize) || 5; - try { + 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 + if (filter === 'all') { const totalCount = await Activity.count(); const offset = (page - 1) * pageSize; const acts = await Activity.findAll({ offset, limit: pageSize, - order:[ + order: [ + ['date', ordenar], + ], + }); + + res.json({ + page, + pageSize, + totalCount, + data: acts, + }); + } + else { + const totalCount = await Activity.count({ where: { is_draft: filter } }); + const offset = (page - 1) * pageSize; + + const acts = await Activity.findAll({ + offset, + limit: pageSize, + order: [ + ['date', ordenar], + ], + where: { + is_draft: filter + } + }); + + res.json({ + page, + pageSize, + totalCount, + data: acts, + }); + } +}); + +activityApp.get('/drafts', async (req, res, next) => { + const page = parseInt(req.query.page) || 1; + const pageSize = parseInt(req.query.pageSize) || 5; + try { + const totalCount = await Activity.count({ + where: { + is_draft: true + } + }); + const offset = (page - 1) * pageSize; + + const acts = await Activity.findAll({ + offset, + limit: pageSize, + where: { + is_draft: true + }, + order: [ ['date', 'DESC']] }); @@ -53,39 +108,8 @@ activityApp.get('/', async (req, res, next) => { } }); -activityApp.get('/drafts', async (req, res, next) => { - const page = parseInt(req.query.page) || 1; - const pageSize = parseInt(req.query.pageSize) || 5; - try { - const totalCount = await Activity.count({where: { - is_draft: true - }}); - const offset = (page - 1) * pageSize; - - const acts = await Activity.findAll({ - offset, - limit: pageSize, - where: { - is_draft: true - }, - order:[ - ['date', 'DESC']] - }); - - res.json({ - page, - pageSize, - totalCount, - data: acts, - }); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'An error occurred' }); - } - }); - activityApp.get('/:id', (req, res, next) => { - Activity.findByPk(req.params.id).then((act) => { + Activity.findByPk(req.params.id).then((act) => { if (!act) { res.statusCode = 404; res.json({ msg: "A atividade não está cadastrada" }); @@ -121,11 +145,11 @@ activityApp.post('/', passport.authenticate('bearer', { session: false }), autho console.log(req.body); let act = await Activity.create({ id: 0, - type:req.body.tipo, + type: req.body.tipo, title: req.body.titulo, subtitle: req.body.subtitulo, date: transformDateFormat(req.body.dataDePostagem), - authors:req.body.autor, + authors: req.body.autor, text: req.body.texto, name_headline: req.body.nome, resume_headline: req.body.resumo, @@ -145,7 +169,7 @@ activityApp.post('/', passport.authenticate('bearer', { session: false }), autho return res.json({ err, errors }); // handle error; }); - if(!act){ + if (!act) { res.statusCode = 400; return res; } @@ -174,14 +198,14 @@ activityApp.put('/:id', passport.authenticate('bearer', { session: false }), aut act.subtitle = req.body.subtitle || act.subtitle; act.date = req.body.date || act.date; act.authors = req.body.autores || act.authors; - act.text= req.body.text || act.text; - act.name_headline= req.body.name_headline || act.name_headline; - act.resume_headline= req.body.resume_headline || act.resume_headline; - act.date_headline= req.body.date_headline || act.date_headline; - act.local_headline= req.body.local_headline || act.local_headline; - act.additional_headline= req.body.additional_headline || act.additional_headline; - act.is_draft= req.body.is_draft || act.is_draft; - act.is_headline= req.body.is_headline || act.is_headline; + act.text = req.body.text || act.text; + act.name_headline = req.body.name_headline || act.name_headline; + act.resume_headline = req.body.resume_headline || act.resume_headline; + act.date_headline = req.body.date_headline || act.date_headline; + act.local_headline = req.body.local_headline || act.local_headline; + act.additional_headline = req.body.additional_headline || act.additional_headline; + act.is_draft = req.body.is_draft || act.is_draft; + act.is_headline = req.body.is_headline || act.is_headline; act.save().catch(err => { if (err) { @@ -190,17 +214,17 @@ activityApp.put('/:id', passport.authenticate('bearer', { session: false }), aut } }) let activity = act.toJSON(); - res.json({ activity: activity}); + res.json({ activity: activity }); }); activityApp.delete('/:id', passport.authenticate('bearer', { session: false }), authorized('editar atividade'), async (req, res, next) => { - await Activity.destroy({where:{id:req.params.id}}).catch(function (err) { + await Activity.destroy({ where: { id: req.params.id } }).catch(function (err) { if (err) { - log.error(err); - return next({ err }); + log.error(err); + return next({ err }); } -}); + }); return next({ msg: 'Activity Deleted', status: 200 }); }); diff --git a/src/libs/routes_v1/publication.js b/src/libs/routes_v1/publication.js index 1cad804b..8fdc8c96 100644 --- a/src/libs/routes_v1/publication.js +++ b/src/libs/routes_v1/publication.js @@ -156,6 +156,7 @@ pubApp.post('/edit', passport.authenticate('bearer', { session: false }), author pb.link = data.link || pb.link; pb.is_homepage = data.homepage || pb.is_homepage; pb.is_draft = data.rascunho || pb.is_draft; + pb.upload = _file_id || pb.upload; pb.save().catch(function (err) { log.error(err); @@ -173,43 +174,6 @@ pubApp.post('/edit', passport.authenticate('bearer', { session: false }), author next(); }, response('publication')); -pubApp.put('/edit/:id', passport.authenticate('bearer', { session: false }), authorized('editar publicacao'), async (req, res, next) => { - console.log(req); - let pb = await Publication.findByPk(req.params.id).catch(function (err) { - if (err) { - log.error(err); - return next({ err }); - } - }) - if (!pb) { - res.statusCode = 404; - return next({ - err: { - message: 'Publicação não encontrada' - } - }); - } - pb.filter = req.body.categoria || pb.filter; - pb.title = req.body.title || pb.title; - pb.authors = req.body.autores || pb.authors; - pb.organization= req.body.organizacao || pb.organization; - pb.year= req.body.ano || pb.year; - pb.text= req.body.texto || pb.text; - pb.link= req.body.link || pb.link; - pb.upload= req.body.upload || pb.upload; - pb.is_homepage= req.body.homepage || pb.is_homepage; - console.log(pb); - pb.save().catch(err => { - if (err) { - log.error(err); - return next({ message: 'Erro ao atualizar publicacao' }); - } - }) - let p = pb.toJSON(); - res.json({ publication: p }); - -}); - pubApp.delete('/:id', passport.authenticate('bearer', { session: false }), authorized('apagar publicacao'), async (req, res, next) => { await Publication.destroy({where:{id:req.params.id}}).catch(function (err) { if (err) { -- GitLab From da0d00cacd14064ed715415ce0d84a1246f4cada Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Fri, 11 Aug 2023 11:08:59 -0300 Subject: [PATCH 07/16] [FIX] Activity --- src/libs/routes_v1/activity.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libs/routes_v1/activity.js b/src/libs/routes_v1/activity.js index d1742dd9..fdce761b 100644 --- a/src/libs/routes_v1/activity.js +++ b/src/libs/routes_v1/activity.js @@ -193,19 +193,19 @@ activityApp.put('/:id', passport.authenticate('bearer', { session: false }), aut }); } console.log("TEste"); - act.type = req.body.type || act.type; - act.title = req.body.title || act.title; - act.subtitle = req.body.subtitle || act.subtitle; - act.date = req.body.date || act.date; - act.authors = req.body.autores || act.authors; - act.text = req.body.text || act.text; - act.name_headline = req.body.name_headline || act.name_headline; - act.resume_headline = req.body.resume_headline || act.resume_headline; - act.date_headline = req.body.date_headline || act.date_headline; - act.local_headline = req.body.local_headline || act.local_headline; - act.additional_headline = req.body.additional_headline || act.additional_headline; - act.is_draft = req.body.is_draft || act.is_draft; - act.is_headline = req.body.is_headline || act.is_headline; + act.type = req.body.tipo || act.type; + act.title = req.body.titulo || act.title; + act.subtitle = req.body.subtitulo || act.subtitle; + act.date = req.body.dataDePostagem || act.date; + act.authors = req.body.autor || act.authors; + act.text = req.body.texto || act.text; + act.name_headline = req.body.nome || act.name_headline; + act.resume_headline = req.body.resumo || act.resume_headline; + act.date_headline = req.body.dataAtividade || act.date_headline; + act.local_headline = req.body.local || act.local_headline; + act.additional_headline = req.body.informacoes || act.additional_headline; + act.is_draft = req.body.rascunho || act.is_draft; + //act.is_headline = req.body.is_headline || act.is_headline; act.save().catch(err => { if (err) { -- GitLab From 1b7aca5ccbda5705b6e0f3df5660882c4db4b9cb Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Tue, 15 Aug 2023 10:25:53 -0300 Subject: [PATCH 08/16] Add new Data Format --- src/libs/routes_v1/activity.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/routes_v1/activity.js b/src/libs/routes_v1/activity.js index fdce761b..d677ad1c 100644 --- a/src/libs/routes_v1/activity.js +++ b/src/libs/routes_v1/activity.js @@ -114,7 +114,10 @@ activityApp.get('/:id', (req, res, next) => { res.statusCode = 404; res.json({ msg: "A atividade não está cadastrada" }); } else { - req.result = act.toJSON(); + let actJSON = act.toJSON(); + actJSON.date = actJSON.date.toLocaleDateString("en-GB"); + actJSON.date_headline = actJSON.date_headline.toLocaleDateString("en-GB"); + req.result = actJSON; next(); } }).catch(function (err) { -- GitLab From fbd69d77712d92d1c8f2970fd993eff4e3701ad2 Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Tue, 15 Aug 2023 10:47:39 -0300 Subject: [PATCH 09/16] [ADD] Date final --- src/libs/models/activity.js | 6 +++++- src/libs/routes_v1/activity.js | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/models/activity.js b/src/libs/models/activity.js index 92fc6f08..3db8be3c 100644 --- a/src/libs/models/activity.js +++ b/src/libs/models/activity.js @@ -21,7 +21,11 @@ var Activity = db.define("Activity",{ type: Sequelize.STRING }, date:{ - type: Sequelize.STRING, + type: Sequelize.DATE, + allowNull:false + }, + date_final:{ + type: Sequelize.DATE, allowNull:false }, authors:{ diff --git a/src/libs/routes_v1/activity.js b/src/libs/routes_v1/activity.js index d677ad1c..19c4f914 100644 --- a/src/libs/routes_v1/activity.js +++ b/src/libs/routes_v1/activity.js @@ -115,8 +115,6 @@ activityApp.get('/:id', (req, res, next) => { res.json({ msg: "A atividade não está cadastrada" }); } else { let actJSON = act.toJSON(); - actJSON.date = actJSON.date.toLocaleDateString("en-GB"); - actJSON.date_headline = actJSON.date_headline.toLocaleDateString("en-GB"); req.result = actJSON; next(); } -- GitLab From ff81c90136639a5f8eefd8d7743226651095a860 Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Tue, 15 Aug 2023 11:56:02 -0300 Subject: [PATCH 10/16] [FIX] Date --- src/libs/routes_v1/activity.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libs/routes_v1/activity.js b/src/libs/routes_v1/activity.js index 19c4f914..1c00ced7 100644 --- a/src/libs/routes_v1/activity.js +++ b/src/libs/routes_v1/activity.js @@ -115,6 +115,11 @@ activityApp.get('/:id', (req, res, next) => { res.json({ msg: "A atividade não está cadastrada" }); } else { let actJSON = act.toJSON(); + //transform data yyyy-mm-dd to dd/mm/yyyy + let date = actJSON.date.split('-'); + let date_headline = actJSON.date_headline.split('-'); + actJSON.date = date[2] + '/' + date[1] + '/' + date[0]; + actJSON.date_headline = date_headline[2] + '/' + date_headline[1] + '/' + date_headline[0]; req.result = actJSON; next(); } -- GitLab From cd6a33196ea049ce428616e49b7b0ef16bd39ae6 Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Tue, 29 Aug 2023 11:19:32 -0300 Subject: [PATCH 11/16] [ADD] VOLUME AND PAGE --- src/libs/models/publication.js | 6 ++++++ src/libs/routes_v1/publication.js | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libs/models/publication.js b/src/libs/models/publication.js index bd537bc0..27a1a3a3 100644 --- a/src/libs/models/publication.js +++ b/src/libs/models/publication.js @@ -61,6 +61,12 @@ var Publication = db.define("Publication",{ type:Sequelize.BOOLEAN, allowNull: false, defaultValue: false + }, + volume:{ + type:Sequelize.STRING + }, + pages:{ + type:Sequelize.STRING } },{timestamp:true, createdAt: 'created_at', diff --git a/src/libs/routes_v1/publication.js b/src/libs/routes_v1/publication.js index 8fdc8c96..9d59cad4 100644 --- a/src/libs/routes_v1/publication.js +++ b/src/libs/routes_v1/publication.js @@ -119,7 +119,9 @@ pubApp.post('/', passport.authenticate('bearer', { session: false }), authorized link: data.link, upload: _file_id, is_draft: data.rascunho, - is_homepage: data.homepage + is_homepage: data.homepage, + volume: data.volume, + pages: data.pagina }).catch(function (err) { log.error(err); let errors = []; -- GitLab From a56bc9e02bb7ed85ef200518dd89f21ab79129d2 Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Tue, 29 Aug 2023 11:20:29 -0300 Subject: [PATCH 12/16] [ADD] VOLUME AND PAGE 2 --- src/libs/routes_v1/publication.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/routes_v1/publication.js b/src/libs/routes_v1/publication.js index 9d59cad4..441b8674 100644 --- a/src/libs/routes_v1/publication.js +++ b/src/libs/routes_v1/publication.js @@ -159,6 +159,8 @@ pubApp.post('/edit', passport.authenticate('bearer', { session: false }), author pb.is_homepage = data.homepage || pb.is_homepage; pb.is_draft = data.rascunho || pb.is_draft; pb.upload = _file_id || pb.upload; + pb.volume = data.volume || pb.volume; + pb.pages = data.pagina || pb.pages; pb.save().catch(function (err) { log.error(err); -- GitLab From 850159d2d6d9777c7f920645e1e0fd390577bd4f Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Thu, 31 Aug 2023 10:38:30 -0300 Subject: [PATCH 13/16] [ADD] New routes --- src/libs/routes_v1/publication.js | 186 ++++++++++++++++++++---------- 1 file changed, 127 insertions(+), 59 deletions(-) diff --git a/src/libs/routes_v1/publication.js b/src/libs/routes_v1/publication.js index 441b8674..63a7cbd5 100644 --- a/src/libs/routes_v1/publication.js +++ b/src/libs/routes_v1/publication.js @@ -31,61 +31,127 @@ function emailSyntax(email) { pubApp.get('/', async (req, res, next) => { const ordenar = req.query.order || 'DESC'; - const filter = req.query.filter || 'all' ; + 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 - if(filter === 'all'){ - const totalCount = await Publication.count(); - const offset = (page - 1) * pageSize; - - const publis = await Publication.findAll({ - offset, - limit: pageSize, - order: [ - ['created_at', ordenar], - ], - }); - - res.json({ - page, - pageSize, - totalCount, - data: publis, - });} - else { - const totalCount = await Publication.count({where:{is_draft:filter}}); - const offset = (page - 1) * pageSize; - - const publis = await Publication.findAll({ - offset, - limit: pageSize, - order: [ - ['created_at', ordenar], - ], - where:{ - is_draft:filter - } - }); - - res.json({ - page, - pageSize, - totalCount, - data: publis, - }); + if (filter === 'all') { + const totalCount = await Publication.count(); + const offset = (page - 1) * pageSize; + + const publis = await Publication.findAll({ + offset, + limit: pageSize, + order: [ + ['created_at', ordenar], + ], + }); + + res.json({ + page, + pageSize, + totalCount, + data: publis, + }); + } + else { + const totalCount = await Publication.count({ where: { is_draft: filter } }); + const offset = (page - 1) * pageSize; + + const publis = await Publication.findAll({ + offset, + limit: pageSize, + order: [ + ['created_at', ordenar], + ], + where: { + is_draft: filter + } + }); + + res.json({ + page, + pageSize, + totalCount, + data: publis, + }); + } +}); + +pubApp.get('/homepage', async (req, res, next)=> { + const totalCount = await Publication.count({ where: { is_headline: true } }); + const offset = (page - 1) * pageSize; + const publis = await Publication.findAll({ + offset, + limit: pageSize, + order: [ + ['created_at', ordenar], + ], + where:{ + is_headline:true } + }); + res.json({ + page, + pageSize, + totalCount, + data: publis, + }); +}); + +pubApp.get('/type/:tp', async (req, res, next) => { + const tp = req.params.tp || 'all'; + if(tp === 'all'){ + const totalCount = await Publication.count(); + const offset = (page - 1) * pageSize; + + const publis = await Publication.findAll({ + offset, + limit: pageSize, + order: [ + ['created_at', ordenar], + ], + }); + + res.json({ + page, + pageSize, + totalCount, + data: publis, + }); + } + else{ + const totalCount = await Publication.count({ where: { filter: req.params.tp } }); + const offset = (page - 1) * pageSize; + const publis = await Publication.findAll({ + offset, + limit: pageSize, + order: [ + ['created_at', ordenar], + ], + where: { + filter: req.params.tp + } + }); + res.json({ + page, + pageSize, + totalCount, + data: publis, + }); + } }); pubApp.get('/:id', async (req, res, next) => { let pb = await Publication.findByPk(req.params.id).catch(function (err) { log.error(err); - return next(err);} + return next(err); + } ); if (!pb) { - res.statusCode = 404; - res.json({ msg: "A publicação não está cadastrada" }); - } + res.statusCode = 404; + res.json({ msg: "A publicação não está cadastrada" }); + } else { let publ = pb.toJSON(); publ.Filename = null; @@ -93,20 +159,21 @@ pubApp.get('/:id', async (req, res, next) => { log.error(err); return next(err); }); - if(file_){ + if (file_) { publ.Filename = file_.name; - } + } req.result = publ; next(); - } - }, response('publication')); + } +}, response('publication')); pubApp.post('/', passport.authenticate('bearer', { session: false }), authorized('criar publicacao'), upload.single('file'), async (req, res, next) => { let _file_id = null - if(req.file){ + if (req.file) { _file_id = await fileWorker.uploadFile(req.file); - if(!_file_id) - console.log("NAO ARQUIVO");} + if (!_file_id) + console.log("NAO ARQUIVO"); + } let data = JSON.parse(req.body.data); let pb = await Publication.create({ id: 0, @@ -139,10 +206,11 @@ pubApp.post('/', passport.authenticate('bearer', { session: false }), authorized pubApp.post('/edit', passport.authenticate('bearer', { session: false }), authorized('editar publicacao'), upload.single('file'), async (req, res, next) => { let _file_id = null - if(req.file){ + if (req.file) { _file_id = await fileWorker.uploadFile(req.file); - if(!_file_id) - console.log("NAO ARQUIVO");} + if (!_file_id) + console.log("NAO ARQUIVO"); + } let data = JSON.parse(req.body.data); console.log(data); let pb = await Publication.findByPk(data.id).catch(function (err) { @@ -161,7 +229,7 @@ pubApp.post('/edit', passport.authenticate('bearer', { session: false }), author pb.upload = _file_id || pb.upload; pb.volume = data.volume || pb.volume; pb.pages = data.pagina || pb.pages; - + pb.save().catch(function (err) { log.error(err); let errors = []; @@ -179,12 +247,12 @@ pubApp.post('/edit', passport.authenticate('bearer', { session: false }), author }, response('publication')); pubApp.delete('/:id', passport.authenticate('bearer', { session: false }), authorized('apagar publicacao'), async (req, res, next) => { - await Publication.destroy({where:{id:req.params.id}}).catch(function (err) { + await Publication.destroy({ where: { id: req.params.id } }).catch(function (err) { if (err) { - log.error(err); - return next({ err }); + log.error(err); + return next({ err }); } -}); + }); return next({ msg: 'Publication Deleted', status: 200 }); }); -- GitLab From cf67fd9bb3c3156f99e4ab1e752ac06b7259e3aa Mon Sep 17 00:00:00 2001 From: Eduardo Mathias <ems19@inf.ufpr.br> Date: Fri, 1 Sep 2023 09:28:54 -0300 Subject: [PATCH 14/16] [ADD] New Postgres connection --- src/libs/db/postgres.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/libs/db/postgres.js b/src/libs/db/postgres.js index 2e16df38..f63f95b7 100644 --- a/src/libs/db/postgres.js +++ b/src/libs/db/postgres.js @@ -1,7 +1,22 @@ const Sequelize = require('sequelize'); -const DATABASE_URL = 'postgres://postgres:postgres@localhost:5432/postgres' +const dbConfig = { + database: 'simcaq_adm', + username: 'simcaq', + password: 'simcaq', + host: '200.17.202.97', + port: 5432, + dialect: 'postgres', + }; -const db = new Sequelize(DATABASE_URL) +const db = new Sequelize(dbConfig) + +db.authenticate() + .then(() => { + console.log('Connection has been established successfully.'); + }) + .catch((err) => { + console.error('Unable to connect to the database:', err); + }); module.exports = db \ No newline at end of file -- GitLab From a4b938f38efa0cf963bd5854485a3e2c788ad73e Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Tue, 3 Oct 2023 11:07:12 -0300 Subject: [PATCH 15/16] [ADD] postgres.js and DockerfileAntigo added to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index dcf0f82a..2d98beea 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ docs/ package-lock.json Dockerfile +DockerfileAntigo +src/libs/db/postgres.js -- GitLab From fd07e701014186b9dd6e2f72010071ef0e45050e Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Tue, 3 Oct 2023 11:23:20 -0300 Subject: [PATCH 16/16] [REMOVE] postgres.js deleted from git --- src/libs/db/postgres.js | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 src/libs/db/postgres.js diff --git a/src/libs/db/postgres.js b/src/libs/db/postgres.js deleted file mode 100644 index f63f95b7..00000000 --- a/src/libs/db/postgres.js +++ /dev/null @@ -1,22 +0,0 @@ -const Sequelize = require('sequelize'); - -const dbConfig = { - database: 'simcaq_adm', - username: 'simcaq', - password: 'simcaq', - host: '200.17.202.97', - port: 5432, - dialect: 'postgres', - }; - -const db = new Sequelize(dbConfig) - -db.authenticate() - .then(() => { - console.log('Connection has been established successfully.'); - }) - .catch((err) => { - console.error('Unable to connect to the database:', err); - }); - -module.exports = db \ No newline at end of file -- GitLab