Skip to content

Commit ba355b7

Browse files
committed
Change response data while fetching tasks
1 parent da7875e commit ba355b7

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

controllers/tasksController.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const taskQuery = require('../models/tasks')
1+
const tasks = require('../models/tasks')
22
/**
33
* Creates new task
44
*
@@ -8,7 +8,7 @@ const taskQuery = require('../models/tasks')
88
*/
99
const addNewTask = async (req, res) => {
1010
try {
11-
const task = await taskQuery.updateTask(req.body)
11+
const task = await tasks.updateTask(req.body)
1212
return res.json({
1313
message: 'Task created successfully!',
1414
task: task.taskDetails,
@@ -27,14 +27,11 @@ const addNewTask = async (req, res) => {
2727
*/
2828
const fetchTasks = async (req, res) => {
2929
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+
})
3835
} catch (err) {
3936
logger.error(`Error while fetching tasks ${err}`)
4037
return res.boom.badImplementation('An internal server error occurred')
@@ -49,16 +46,16 @@ const fetchTasks = async (req, res) => {
4946
*/
5047
const updateTask = async (req, res) => {
5148
try {
52-
const task = await taskQuery.fetchTask(req.params.id)
49+
const task = await tasks.fetchTask(req.params.id)
5350
if (!task.taskData) {
5451
return res.boom.notFound('Task not found')
5552
}
5653

57-
await taskQuery.updateTask(req.body, req.params.id)
54+
await tasks.updateTask(req.body, req.params.id)
5855
return res.status(204).send()
5956
} catch (err) {
6057
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')
6259
}
6360
}
6461

0 commit comments

Comments
 (0)