example: route, controller, model

This commit is contained in:
Ben Elferink
2020-12-22 02:11:43 +02:00
parent d389451be2
commit fedda7b932
4 changed files with 50 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
import Example from './../models/model.js';
const getExamples = (request, response) => {
// what is .find() ??? ---> https://mongoosejs.com/docs/queries.html
Example.find((error, allExamples) => {
if (error) {
console.log(`${error}`);
return response.status(404).json(error); // 404 not found + catched error -> 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
});
};
export default getExamples;