You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
// Import Etudiant model
|
|
Etudiant = require('./etudiantModel');
|
|
|
|
// Handle index actions (GET)
|
|
exports.index = function (req, res) {
|
|
Etudiant.get(function (err, etudiants) {
|
|
if (err) {
|
|
res.json({
|
|
status: "error",
|
|
message: err,
|
|
});
|
|
}
|
|
res.json({
|
|
status: "success",
|
|
message: "Voici la liste des etudiants",
|
|
data: etudiants
|
|
});
|
|
});
|
|
};
|
|
|
|
// Handle create etudiant actions (POST)
|
|
exports.new = function (req, res) {
|
|
var etudiant = new Etudiant();
|
|
etudiant.numEtudiant = req.body.numEtudiant ? req.body.numEtudiant : etudiant.numEtudiant;
|
|
etudiant.firstname = req.body.firstname;
|
|
etudiant.lastname = req.body.lastname;
|
|
etudiant.cycle = req.body.cycle;
|
|
etudiant.adresse = req.body.adresse;
|
|
|
|
// save the etudiant and check for errors
|
|
etudiant.save(function (err) {
|
|
// if (err)
|
|
// res.json(err);
|
|
res.json({
|
|
message: 'New etudiant created!',
|
|
data: etudiant
|
|
});
|
|
});
|
|
};
|