Skip to content
Snippets Groups Projects
Commit 01f31301 authored by Fernando Gbur dos Santos's avatar Fernando Gbur dos Santos
Browse files

Merge branch 'development' into 'homologa'

dev -> homologa

See merge request !378
parents c3014f7b fd07e701
No related branches found
No related tags found
3 merge requests!407Master,!379homologa -> master,!378dev -> homologa
......@@ -26,3 +26,5 @@ docs/
package-lock.json
Dockerfile
DockerfileAntigo
src/libs/db/postgres.js
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)
module.exports = db
\ No newline at end of file
......@@ -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:{
......
......@@ -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',
......
......@@ -28,9 +28,11 @@ 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;
......@@ -38,7 +40,30 @@ activityApp.get('/', async (req, res, next) => {
offset,
limit: pageSize,
order: [
['date', 'DESC']]
['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({
......@@ -47,9 +72,6 @@ activityApp.get('/', async (req, res, next) => {
totalCount,
data: acts,
});
} catch (error) {
console.error(error);
res.status(500).json({ error: 'An error occurred' });
}
});
......@@ -57,9 +79,11 @@ 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: {
const totalCount = await Activity.count({
where: {
is_draft: true
}});
}
});
const offset = (page - 1) * pageSize;
const acts = await Activity.findAll({
......@@ -90,7 +114,13 @@ 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();
//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();
}
}).catch(function (err) {
......@@ -169,19 +199,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) {
......
......@@ -30,15 +30,20 @@ function emailSyntax(email) {
}
pubApp.get('/', async (req, res, next) => {
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
try {
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({
......@@ -47,43 +52,92 @@ pubApp.get('/', async (req, res, next) => {
totalCount,
data: publis,
});
} catch (error) {
console.error(error);
res.status(500).json({ error: 'An error occurred' });
}
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
}
});
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
res.json({
page,
pageSize,
totalCount,
data: publis,
});
}
});
try {
// Count total number of items
const totalCount = await Publication.count({ where: {
is_draft: true
}});
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,
});
});
// Calculate offset based on page and pageSize
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;
// Query the database with pagination options
const drafts = await Publication.findAll({
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: {
is_draft: true
filter: req.params.tp
}
});
res.json({
page,
pageSize,
totalCount,
data: drafts,
data: publis,
});
} catch (error) {
console.error(error);
res.status(500).json({ error: 'An error occurred' });
}
});
......@@ -91,7 +145,8 @@ 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);
return next(err);}
return next(err);
}
);
if (!pb) {
res.statusCode = 404;
......@@ -117,7 +172,8 @@ pubApp.post('/', passport.authenticate('bearer', { session: false }), authorized
if (req.file) {
_file_id = await fileWorker.uploadFile(req.file);
if (!_file_id)
console.log("NAO ARQUIVO");}
console.log("NAO ARQUIVO");
}
let data = JSON.parse(req.body.data);
let pb = await Publication.create({
id: 0,
......@@ -130,7 +186,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 = [];
......@@ -151,50 +209,43 @@ pubApp.post('/edit', passport.authenticate('bearer', { session: false }), author
if (req.file) {
_file_id = await fileWorker.uploadFile(req.file);
if (!_file_id)
console.log("NAO ARQUIVO");}
console.log("NAO ARQUIVO");
}
let data = JSON.parse(req.body.data);
console.log(data);
req.response = {'This is a test':'This is a test'};
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) {
let pb = await Publication.findByPk(data.id).catch(function (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) {
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.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);
return next({ message: 'Erro ao atualizar publicacao' });
let errors = [];
for (let errName in err.errors) {
errors.push(err.errors[errName].message);
}
})
let p = pb.toJSON();
res.json({ publication: p });
log.error(errors);
res.statusCode = 400;
return res.json({ err, errors });
// handle error;
});
req.result = pb.toJSON();
next();
}, 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) {
if (err) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment