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