|  |  | @ -1,7 +1,6 @@ | 
			
		
	
		
			
				
					|  |  |  | // Import Etudiant model
 | 
			
		
	
		
			
				
					|  |  |  | Etudiant = require('./etudiantModel'); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | // Handle index actions (GET)
 | 
			
		
	
		
			
				
					|  |  |  | // Handle index actions (method: GET)
 | 
			
		
	
		
			
				
					|  |  |  | exports.index = function (req, res) { | 
			
		
	
		
			
				
					|  |  |  |     Etudiant.get(function (err, etudiants) { | 
			
		
	
		
			
				
					|  |  |  |         if (err) { | 
			
		
	
	
		
			
				
					|  |  | @ -18,7 +17,7 @@ exports.index = function (req, res) { | 
			
		
	
		
			
				
					|  |  |  |     }); | 
			
		
	
		
			
				
					|  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | // Handle create etudiant actions (POST)
 | 
			
		
	
		
			
				
					|  |  |  | // Handling etudiant creation actions (method: POST)
 | 
			
		
	
		
			
				
					|  |  |  | exports.new = function (req, res) { | 
			
		
	
		
			
				
					|  |  |  |     var etudiant = new Etudiant(); | 
			
		
	
		
			
				
					|  |  |  |     etudiant.numEtudiant = req.body.numEtudiant ? req.body.numEtudiant : etudiant.numEtudiant; | 
			
		
	
	
		
			
				
					|  |  | @ -26,14 +25,75 @@ exports.new = function (req, res) { | 
			
		
	
		
			
				
					|  |  |  |     etudiant.lastname = req.body.lastname; | 
			
		
	
		
			
				
					|  |  |  |     etudiant.cycle = req.body.cycle; | 
			
		
	
		
			
				
					|  |  |  |     etudiant.adresse = req.body.adresse; | 
			
		
	
		
			
				
					|  |  |  |     etudiant.email = req.body.email; | 
			
		
	
		
			
				
					|  |  |  |     etudiant.cours = req.body.cours; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     // save the etudiant and check for errors
 | 
			
		
	
		
			
				
					|  |  |  |     // fait un save de notre etudiant envoyé à l'API (display l'erreur si il y en a une)
 | 
			
		
	
		
			
				
					|  |  |  |     etudiant.save(function (err) { | 
			
		
	
		
			
				
					|  |  |  |         // if (err)
 | 
			
		
	
		
			
				
					|  |  |  |         //     res.json(err);
 | 
			
		
	
		
			
				
					|  |  |  |          if (err){ | 
			
		
	
		
			
				
					|  |  |  |             res.json(err); | 
			
		
	
		
			
				
					|  |  |  |          } else { | 
			
		
	
		
			
				
					|  |  |  |             res.json({ | 
			
		
	
		
			
				
					|  |  |  |                 message: 'New etudiant created!', | 
			
		
	
		
			
				
					|  |  |  |                 data: etudiant | 
			
		
	
		
			
				
					|  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     }); | 
			
		
	
		
			
				
					|  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | // Handle view etudiant info ById
 | 
			
		
	
		
			
				
					|  |  |  | exports.view = function (req, res) { | 
			
		
	
		
			
				
					|  |  |  |     Etudiant.findById(req.params.etudiant_id, function (err, etudiant) { | 
			
		
	
		
			
				
					|  |  |  |         // NOTE: Etudiant.findById(..) revient à faire Etudiant.findOne({_id: id}, function (err, user) { ... });
 | 
			
		
	
		
			
				
					|  |  |  |         // directement dans le shell MongoDB tester: db.etudiant.find({_id:ObjectId("5e7b57286335730f8ae4aaed")}).pretty()
 | 
			
		
	
		
			
				
					|  |  |  |         if (err){ | 
			
		
	
		
			
				
					|  |  |  |             res.send(err); | 
			
		
	
		
			
				
					|  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |             res.json({ | 
			
		
	
		
			
				
					|  |  |  |                 message: 'loading etudiant details with _id: '+req.params.etudiant_id, | 
			
		
	
		
			
				
					|  |  |  |                 data: etudiant | 
			
		
	
		
			
				
					|  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     }); | 
			
		
	
		
			
				
					|  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | // Handle update etudiant info (method: PUT|PATCH)
 | 
			
		
	
		
			
				
					|  |  |  | exports.update = function (req, res) { | 
			
		
	
		
			
				
					|  |  |  |     Etudiant.findById(req.params.etudiant_id, function (err, etudiant) { | 
			
		
	
		
			
				
					|  |  |  |         if (err) | 
			
		
	
		
			
				
					|  |  |  |             res.send(err); | 
			
		
	
		
			
				
					|  |  |  |             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; | 
			
		
	
		
			
				
					|  |  |  |             etudiant.email = req.body.email; | 
			
		
	
		
			
				
					|  |  |  |             etudiant.cours = req.body.cours; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | // save the etudiant and check for errors
 | 
			
		
	
		
			
				
					|  |  |  |         etudiant.save(function (err) { | 
			
		
	
		
			
				
					|  |  |  |             if (err) | 
			
		
	
		
			
				
					|  |  |  |                 res.json(err); | 
			
		
	
		
			
				
					|  |  |  |             res.json({ | 
			
		
	
		
			
				
					|  |  |  |                 message: 'etudiant Info updated', | 
			
		
	
		
			
				
					|  |  |  |                 data: etudiant | 
			
		
	
		
			
				
					|  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |     }); | 
			
		
	
		
			
				
					|  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | // Handle delete etudiant (method: DELETE)
 | 
			
		
	
		
			
				
					|  |  |  | exports.delete = function (req, res) { | 
			
		
	
		
			
				
					|  |  |  |     Etudiant.remove({ | 
			
		
	
		
			
				
					|  |  |  |         _id: req.params.etudiant_id | 
			
		
	
		
			
				
					|  |  |  |     }, function (err, etudiant) { | 
			
		
	
		
			
				
					|  |  |  |         if (err){ | 
			
		
	
		
			
				
					|  |  |  |             res.send(err); | 
			
		
	
		
			
				
					|  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |             res.json({ | 
			
		
	
		
			
				
					|  |  |  |                 status: "success", | 
			
		
	
		
			
				
					|  |  |  |                 message: 'etudiant deleted' | 
			
		
	
		
			
				
					|  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     }); | 
			
		
	
		
			
				
					|  |  |  | }; |