Skip to content

Commit c6f856d

Browse files
committed
add code for random status
1 parent 001d24a commit c6f856d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

controllers/tasks.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const tasks = require('../models/tasks')
2+
const { TASK_STATUS } = require('../constants/tasks')
23
/**
34
* Creates new task
45
*
@@ -52,16 +53,16 @@ const fetchTasks = async (req, res) => {
5253
*/
5354
const getUserTasks = async (req, res) => {
5455
try {
55-
const status = req.query.status
56+
const { status } = req.query
5657
const { username } = req.params
5758
let allTasks = []
5859

59-
if (status) {
60-
allTasks = await tasks.fetchUserTasks(username, [status])
61-
} else {
62-
allTasks = await tasks.fetchUserTasks(username)
60+
if (!Object.values(TASK_STATUS).includes(status)) {
61+
return res.boom.notFound('Status not found!')
6362
}
6463

64+
allTasks = await tasks.fetchUserTasks(username, status ? [status] : [])
65+
6566
if (allTasks.userNotFound) {
6667
return res.boom.notFound('User doesn\'t exist')
6768
}

0 commit comments

Comments
 (0)