shell bypass 403
const Pi = require('../models/pi.model.js');
// Create and Save a new admin
exports.create = (req, res) => {
// Validate request
if (!req.body.nom) {
return res.status(400).send({
message: "PI content can not be empty"
});
}
// Create a admin
const pi = new Pi({
nom: req.body.nom || "Untitled PI",
email: req.body.email,
telephone: req.body.telephone,
premierResponsable: req.body.premierResponsable,
adresse: req.body.adresse,
});
// Save admin in the database
pi.save()
.then(data => {
res.send(data);
}).catch(err => {
res.status(500).send({
message: err.message || "Some error occurred while creating the PI."
});
});
};
// Retrieve and return all admin from the database.
exports.findAll = (req, res) => {
Pi.find()
.then(pis => {
res.send(pis);
}).catch(err => {
res.status(500).send({
message: err.message || "Some error occurred while retrieving PIs."
});
});
};
// Find a single admin with a adminId
exports.findOne = (req, res) => {
Pi.findById(req.params.piId)
.then(pi => {
if (!pi) {
return res.status(404).send({
message: "PI not found with id " + req.params.piId
});
}
res.send(pi);
}).catch(err => {
if (err.kind === 'ObjectId') {
return res.status(404).send({
message: "PI not found with id " + req.params.piId
});
}
return res.status(500).send({
message: "Error retrieving PI with id " + req.params.piId
});
});
};
// Update a admin identified by the adminId in the request
exports.update = (req, res) => {
// Validate Request
if (!req.body.nom) {
return res.status(400).send({
message: "PI content can not be empty"
});
}
// Find admin and update it with the request body
Pi.findByIdAndUpdate(req.params.piId, {
nom: req.body.nom || "Untitled PI",
email: req.body.email,
telephone: req.body.telephone,
premierResponsable: req.body.premierResponsable,
adresse: req.body.adresse,
}, { new: true })
.then(pi => {
if (!pi) {
return res.status(404).send({
message: "PI not found with id " + req.params.piId
});
}
res.send(pi);
}).catch(err => {
if (err.kind === 'ObjectId') {
return res.status(404).send({
message: "PI not found with id " + req.params.piId
});
}
return res.status(500).send({
message: "Error updating PI with id " + req.params.piId
});
});
};
// Delete a admin with the specified adminId in the request
exports.delete = (req, res) => {
Pi.findByIdAndRemove(req.params.piId)
.then(pi => {
if (!pi) {
return res.status(404).send({
message: "PI not found with id " + req.params.piId
});
}
res.send({ message: "PI deleted successfully!" });
}).catch(err => {
if (err.kind === 'ObjectId' || err.name === 'NotFound') {
return res.status(404).send({
message: "PI not found with id " + req.params.piId
});
}
return res.status(500).send({
message: "Could not delete PI with id " + req.params.piId
});
});
};