-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrollerperfil.js
116 lines (98 loc) · 3.46 KB
/
controllerperfil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var mongoose = require('mongoose');
var Perfil = mongoose.model('Perfil');
var fs = require('fs');
//#####################################################
//########### Controlador de modulo Perfil ############
//#####################################################
//GET
exports.findAllPerfil = function(req, res){
Perfil.find(function(err, perfil){
if(err){
res.send(500, err.message);
}
console.log('GET /perfil');
res.status(200).jsonp(perfil);
});
};
//GET
exports.findPerfilPorCorreo = function(req, res) {
Perfil.findOne({ 'correo': req.params.correo }, function(err, perfil) {
if(err){
res.send(500, err.message);
}else{
console.log('GET /perfil')
res.status(200).jsonp(perfil);
}
});
};
//POST
exports.addPerfil = function(req, res) {
console.log('POST');
//console.log(req.body);
var r = req.body;
var perfil = new Perfil({
"correo" : r.correo,
"nombrecompleto" : r.nombrecompleto,
"nacionalidad" : r.nacionalidad,
"contrasena" : r.contrasena,
"foto" : r.foto,
"bio" : r.bio,
"redessociales" : r.redessociales,
"aptitudes" : r.aptitudes,
"experiencias" : r.experiencias
});
console.log(perfil);
perfil.save(function(err, perfil) {
if(err){
return res.status(500).send( err.message);
}else {
res.status(200).jsonp(perfil);
}
});
};
exports.updatePerfil = function(req, res) {
Perfil.findOne({"correo": req.params.correo}, function (err, perfil) {
// Handle any possible database errors
if (err) {
res.status(500).send(err);
} else {
// Update each attribute with any possible attribute that may have been submitted in the body of the request
// If that attribute isn't in the request body, default back to whatever it was before.
perfil.contrasena = req.body.contrasena;
perfil.nacionalidad = req.body.nacionalidad;
perfil.foto = req.body.foto;
perfil.bio = req.body.bio;
perfil.experiencia = req.body.experiencia;
// Save the updated document back to the database
perfil.save(function (err, perfil) {
if (err) {
res.status(500).send(err)
}
res.send(perfil);
});
}
});
};
exports.updatePerfilAptitudes = function(req, res) {
if(req.params.admin!='somoslosmaspro'){
res.status(200).send("No hay permiso");
return;
}
Perfil.findOne({"correo": req.params.correo}, function (err, perfil) {
// Handle any possible database errors
if (err) {
res.status(500).send(err);
} else {
// Update each attribute with any possible attribute that may have been submitted in the body of the request
// If that attribute isn't in the request body, default back to whatever it was before.
perfil.aptitudes.push(req.body.aptitudes);
// Save the updated document back to the database
perfil.save(function (err, perfil) {
if (err) {
res.status(500).send(err)
}
res.send(perfil);
});
}
});
};