File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 1
1
const tasks = require ( '../models/tasks' )
2
+ const { TASK_STATUS } = require ( '../constants/tasks' )
2
3
/**
3
4
* Creates new task
4
5
*
@@ -52,16 +53,16 @@ const fetchTasks = async (req, res) => {
52
53
*/
53
54
const getUserTasks = async ( req , res ) => {
54
55
try {
55
- const status = req . query . status
56
+ const { status } = req . query
56
57
const { username } = req . params
57
58
let allTasks = [ ]
58
59
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!' )
63
62
}
64
63
64
+ allTasks = await tasks . fetchUserTasks ( username , status ? [ status ] : [ ] )
65
+
65
66
if ( allTasks . userNotFound ) {
66
67
return res . boom . notFound ( 'User doesn\'t exist' )
67
68
}
You can’t perform that action at this time.
0 commit comments