1
0
Fork 0
mirror of https://github.com/docker/awesome-compose.git synced 2025-04-29 07:38:02 +02:00

Sample React-Express-MongoDB (#59)

Signed-off-by: Afzal <sah.afzal@gmail.com>
This commit is contained in:
Syed Afzal 2020-05-12 00:40:39 +05:00 committed by GitHub
parent 3599a2e685
commit 2f750eb4f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 18779 additions and 0 deletions

View file

@ -0,0 +1,38 @@
const express = require('express');
const serverResponses = require('../utils/helpers/server.responses');
const messages = require('../config/messages');
var {Todo} = require('../models/todos/todo.model');
const routes = (app) => {
const router = express.Router();
router.post('/todos', (req,res)=>{
var todo = new Todo({
text: req.body.text
});
todo.save()
.then((result)=>{
serverResponses.sendSuccess(res,messages.SUCCESSFUL, result);
})
.catch((e) => {
serverResponses.sendError(res,messages.BAD_REQUEST,e)
})
});
router.get('/', (req,res) => {
Todo.find({}, {__v:0})
.then((todos)=>{
serverResponses.sendSuccess(res,messages.SUCCESSFUL, todos);
})
.catch((e) => {
serverResponses.sendError(res,messages.BAD_REQUEST,e)
})
});
//it's a prefix before api it is useful when you have many modules and you want to
//differentiate b/w each module you can use this technique
app.use('/api', router);
};
module.exports = routes;