1
- const taskQuery = require ( '../models/tasks' )
1
+ const tasks = require ( '../models/tasks' )
2
2
/**
3
3
* Creates new task
4
4
*
@@ -8,7 +8,7 @@ const taskQuery = require('../models/tasks')
8
8
*/
9
9
const addNewTask = async ( req , res ) => {
10
10
try {
11
- const task = await taskQuery . updateTask ( req . body )
11
+ const task = await tasks . updateTask ( req . body )
12
12
return res . json ( {
13
13
message : 'Task created successfully!' ,
14
14
task : task . taskDetails ,
@@ -27,14 +27,11 @@ const addNewTask = async (req, res) => {
27
27
*/
28
28
const fetchTasks = async ( req , res ) => {
29
29
try {
30
- const allTasks = await taskQuery . fetchTasks ( )
31
- if ( allTasks . length > 0 ) {
32
- return res . json ( {
33
- message : 'Tasks returned successfully!' ,
34
- tasks : allTasks
35
- } )
36
- }
37
- return res . boom . notFound ( 'No tasks found' )
30
+ const allTasks = await tasks . fetchTasks ( )
31
+ return res . json ( {
32
+ message : 'Tasks returned successfully!' ,
33
+ tasks : allTasks . length > 0 ? allTasks : [ ]
34
+ } )
38
35
} catch ( err ) {
39
36
logger . error ( `Error while fetching tasks ${ err } ` )
40
37
return res . boom . badImplementation ( 'An internal server error occurred' )
@@ -49,16 +46,16 @@ const fetchTasks = async (req, res) => {
49
46
*/
50
47
const updateTask = async ( req , res ) => {
51
48
try {
52
- const task = await taskQuery . fetchTask ( req . params . id )
49
+ const task = await tasks . fetchTask ( req . params . id )
53
50
if ( ! task . taskData ) {
54
51
return res . boom . notFound ( 'Task not found' )
55
52
}
56
53
57
- await taskQuery . updateTask ( req . body , req . params . id )
54
+ await tasks . updateTask ( req . body , req . params . id )
58
55
return res . status ( 204 ) . send ( )
59
56
} catch ( err ) {
60
57
logger . error ( `Error while updating user: ${ err } ` )
61
- return res . boom . serverUnavailable ( 'Something went wrong please contact admin ')
58
+ return res . boom . badImplementation ( 'An internal server error occurred ')
62
59
}
63
60
}
64
61
0 commit comments