Skip to content
Snippets Groups Projects
Commit 6a345d17 authored by ems19's avatar ems19
Browse files

[FIX] Create and Update problems

parent 5dcdc130
No related branches found
No related tags found
4 merge requests!377prd_version of simcaq,!373merge dev -> homologa,!370Dev migration,!369Postgres migration
......@@ -14,6 +14,10 @@ var Publication = db.define("Publication",{
allowNull:false,
validate: {
notNull: { msg: "O campo categoria é obrigatória e aceita apenas os valores 'Artigo', 'Tese', 'Dissertação', 'Relatório', 'Periódico."},
isIn:{
args: [["Artigo", "Tese", "Dissertação", "Relatório", "Periódico"]],
msg: "O campo categoria é obrigatória e aceita apenas os valores 'Artigo', 'Tese', 'Dissertação', 'Relatório', 'Periódico'."
}
}
},
title:{
......@@ -37,6 +41,9 @@ var Publication = db.define("Publication",{
allowNull:false,
validate: {
notNull: { msg: "O campo origem é obrigatória e aceita apenas os valores 'Baixar', 'Acessar'."},
isIn:{
args: [["Baixar", "Acessar"]],
msg: "O campo origem é obrigatória e aceita apenas os valores 'Baixar', 'Acessar'."}
}
},
link:{
......
......@@ -18,6 +18,7 @@ var User = db.define("User",{
unique: true,
validate: {
notNull: { msg: "O campo Email é obrigatório." },
notEmpty: { msg: "O campo Email é obrigatório." }
}
},
password:{
......@@ -36,6 +37,7 @@ var User = db.define("User",{
allowNull: false,
validate: {
notNull: { msg: "O campo Nome é obrigatório." },
notEmpty: { msg: "O campo Nome é obrigatório." }
}
},
nickname:{
......@@ -43,6 +45,7 @@ var User = db.define("User",{
allowNull: false,
validate: {
notNull: { msg: "O campo Apelido é obrigatório." },
notEmpty: { msg: "O campo Apelido é obrigatório." }
}
},
cpf:{
......@@ -51,6 +54,7 @@ var User = db.define("User",{
unique: true,
validate: {
notNull: { msg: "O campo CPF é obrigatório." },
notEmpty: { msg: "O campo CPF é obrigatório." }
}
},
cep:{
......@@ -58,6 +62,7 @@ var User = db.define("User",{
allowNull: false,
validate: {
notNull: { msg: "O campo CEP é obrigatório." },
notEmpty: { msg: "O campo CEP é obrigatório." }
}
},
schooling:{
......@@ -65,6 +70,7 @@ var User = db.define("User",{
allowNull: false,
validate: {
notNull: { msg: "O campo Formação é obrigatório." },
notEmpty: { msg: "O campo Formação é obrigatório." }
}
},
course:{
......@@ -84,6 +90,7 @@ var User = db.define("User",{
allowNull: false,
validate: {
notNull: { msg: "O campo Segmento é obrigatório." },
notEmpty: { msg: "O campo Segmento é obrigatório." }
}
},
role:{
......@@ -91,6 +98,7 @@ var User = db.define("User",{
allowNull: false,
validate: {
notNull: { msg: "O campo Função é obrigatório." },
notEmpty: { msg: "O campo Função é obrigatório." }
}
},
institution_name:{
......@@ -98,6 +106,7 @@ var User = db.define("User",{
allowNull: false,
validate: {
notNull: { msg: "O campo Instituição em que trabalha ou estuda é obrigatório." },
notEmpty: { msg: "O campo Instituição em que trabalha ou estuda é obrigatório." }
}
},
state:{
......@@ -105,6 +114,7 @@ var User = db.define("User",{
allowNull: false,
validate: {
notNull: { msg: "O campo Estado é obrigatório." },
notEmpty: { msg: "O campo Estado é obrigatório." }
}
},
city:{
......@@ -112,6 +122,7 @@ var User = db.define("User",{
allowNull: false,
validate: {
notNull: { msg: "O campo Cidade é obrigatório." },
notEmpty: { msg: "O campo Cidade é obrigatório." }
}
},
receive_email:{
......@@ -126,6 +137,7 @@ var User = db.define("User",{
allowNull:false,
validate: {
notNull: { msg: "O campo origem é obrigatória e aceita apenas os valores 'LDE', 'SimCAQ' e 'MAPFOR'."},
notEmpty: { msg: "O campo origem é obrigatória e aceita apenas os valores 'LDE', 'SimCAQ' e 'MAPFOR'."}
}
},
verified:{
......@@ -169,10 +181,10 @@ User.generateObjectId = function(){
}
const setSaltAndPassword = user => {
// if (user.changed('password')) {
user.salt = User.generateSalt()
user.hashed_password = User.encryptPassword(user.password, user.salt).toString('hex');
// }
if (user.changed('password')) {
user.salt = User.generateSalt()
user.hashed_password = User.encryptPassword(user.password, user.salt).toString('hex');
}
}
const setObjectId = user => {
......
......@@ -108,6 +108,10 @@ userApp.get('/me', passport.authenticate('bearer', { session: false }), (req, re
next();
}, response('user'));
function isEmpty(str) {
return (!str || str.length === 0 );
}
userApp.get('/:id', (req, res, next) => {
User.findByPk(req.params.id).then((user) => {
if (!user) {
......@@ -136,7 +140,8 @@ userApp.post('/', async (req, res, next) => {
if (typeof req.body.password === 'undefined' || !req.body.password) {
res.statusCode = 400;
return res.json({ errors: ["O campo senha é obrigatório"] });
} else {
}
else {
let user = await User.create({
id: 0,
email: req.body.email,
......@@ -240,7 +245,8 @@ userApp.put('/:id', passport.authenticate('bearer', { session: false }), async (
user.citesegment = req.body.citesegment || user.citesegment;
user.citerole = req.body.citerole || user.citerole;
if ((req.body.password != "") && (req.body.newpassword != "")) {
if((!isEmpty(req.body.password)) && (!isEmpty(req.body.newpassword))){
console.log("ENTREI INFELIZMENTE")
if (req.body.password != req.body.newpassword) {
if (user.checkPassword(user, req.body.password)) {
await user.update({password:req.body.newpassword});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment