File tree Expand file tree Collapse file tree 7 files changed +43
-42
lines changed Expand file tree Collapse file tree 7 files changed +43
-42
lines changed Original file line number Diff line number Diff line change 11# Mongo DB
22# Local development
3- MONGODB_URI_DEV = ' mongodb+srv://admin:PASSWORD@eapi-g5m4h.mongodb.net/eapi '
3+ MONGODB_URI_DEV = ' YOUR PROD URL LIKNK FOR MONGODB '
44
55# Local development
6- MONGODB_URI_PROD = ' mongodb+srv://admin:PASSWORD@eapi-g5m4h.mongodb.net/eapi '
6+ MONGODB_URI_PROD = ' YOUR PROD URL LIKNK FOR MONGODB '
77
88# Port
9- PORT = 3000
9+ PORT = 5000
1010
1111# Debug
1212LOG_LEVEL = ' debug'
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ const config = {
1313 port : parseInt ( process . env . PORT , 10 ) ,
1414 database_URL : process . env . MONGODB_URI_DEV ,
1515 api : {
16- prefix : '/api'
16+ prefix : '/api-dev '
1717 }
1818 } ,
1919 prod : {
Original file line number Diff line number Diff line change @@ -37,11 +37,11 @@ const onError = error => {
3737} ;
3838
3939const onListening = ( ) => {
40- const bind = typeof port === 'string' ? 'pipe ' + port : 'port ' + port ;
40+ const bind = typeof port === 'string' ? 'pipe ' + port : 'port: ' + port ;
4141 debug ( 'Listening on ' + bind ) ;
4242 console . log ( `
4343 ************************************************
44- 🚀 Server listening on port: ${ bind } 🚀
44+ 🚀 Server listening on ${ bind } 🚀
4545 ************************************************
4646` ) ;
4747} ;
Original file line number Diff line number Diff line change 11const todoService = require ( '../services/todo' ) ;
22
3- exports . getTasks = async ( req , res , next ) => {
4- try {
5- const tasks = await todoService . getTasks ( ) ;
6- return res . status ( 201 ) . json ( {
7- message : 'Fetched posts successfully.' ,
8- tasks : tasks ,
9- status : 200
10- } ) ;
11- } catch ( err ) {
12- if ( ! err . statusCode ) {
13- err . statusCode = 500 ;
14- }
15- return err ;
16- }
17- } ;
18-
19- exports . getTasksById = async ( req , res , next ) => {
20- const taskId = req . params . id ;
21- const task = await todoService . getTasksById ( taskId ) ;
22- try {
23- if ( ! task ) {
24- throw new Error ( 'Task not found' ) ;
3+ module . exports = {
4+ getTasks : async ( req , res , next ) => {
5+ try {
6+ const tasks = await todoService . getTasks ( ) ;
7+ return res . status ( 201 ) . json ( {
8+ message : 'Fetched posts successfully.' ,
9+ tasks : tasks ,
10+ status : 200
11+ } ) ;
12+ } catch ( err ) {
13+ if ( ! err . statusCode ) {
14+ err . statusCode = 500 ;
15+ }
16+ return err ;
2517 }
18+ } ,
2619
27- return res . status ( 201 ) . json ( {
28- message : 'Task fetched' ,
29- task : task ,
30- status : 200
31- } ) ;
32- } catch ( err ) {
33- if ( ! err . statusCode ) {
34- err . statusCode = 500 ;
20+ createTask : async ( req , res , next ) => {
21+ try {
22+ const task = todoService . createTask ( req . body . title , req . body . status ) ;
23+ await task . save ( ) ;
24+ return res . status ( 201 ) . json ( {
25+ message : 'Fetched posts successfully.' ,
26+ status : 200
27+ } ) ;
28+ } catch ( err ) {
29+ if ( ! err . statusCode ) {
30+ err . statusCode = 500 ;
31+ }
32+ return err ;
3533 }
36- return err ;
3734 }
3835} ;
Original file line number Diff line number Diff line change 11/*
2- Database models
2+ Database model
33*/
44const mongoose = require ( 'mongoose' ) ;
55
88} catch ( error ) {
99 const taskSchema = mongoose . Schema ( {
1010 title : { type : String , required : true } ,
11- content : { type : String , required : true }
11+ status : { type : String , required : true }
1212 } ) ;
1313 module . exports = mongoose . model ( 'Task' , taskSchema ) ;
1414}
Original file line number Diff line number Diff line change @@ -3,6 +3,6 @@ const router = express.Router();
33const todoController = require ( '../controllers/todoController' ) ;
44//End points
55router . get ( '/tasks' , todoController . getTasks ) ;
6- router . get ( '/tasks/:id ' , todoController . getTasksById ) ;
6+ router . post ( '/tasks' , todoController . createTask ) ;
77
88module . exports = router ;
Original file line number Diff line number Diff line change @@ -5,8 +5,12 @@ class TodoService {
55 return Task . find ( ) ;
66 }
77
8- static getTasksById ( id ) {
9- return Task . findById ( id ) ;
8+ static createTask ( title , status ) {
9+ const task = new Task ( {
10+ title : title ,
11+ status : status
12+ } ) ;
13+ return task ;
1014 }
1115}
1216
You can’t perform that action at this time.
0 commit comments