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