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