Simplified some things

This commit is contained in:
Ben Elferink
2020-12-23 15:44:35 +02:00
parent 6c90e8dc28
commit 3dff3e6b96
3 changed files with 7 additions and 9 deletions

View File

@@ -2,16 +2,15 @@ import Example from './../models/model.js';
const getExamples = (request, response) => {
// what is .find() ??? ---> https://mongoosejs.com/docs/queries.html
Example.find((error, allExamples) => {
Example.find((error, data) => {
if (error) {
console.log(`${error}`);
return response.status(404).json(error); // 404 not found + catched error -> send to client
} else {
console.log('✅ -FOUND- :', data);
return response.status(200).json(data); // 200 ok + array of documents -> send to client
}
// more about response status codes ---> https://restapitutorial.com/httpstatuscodes.html
console.log('✅ -FOUND- :', allExamples);
return response.status(200).json(allExamples); // 200 ok + array of couments -> send to client
});
};