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