@@ -11,6 +11,7 @@ const { transformQuery } = require("../utils/tasks");
11
11
const { getPaginatedLink } = require ( "../utils/helper" ) ;
12
12
const { updateUserStatusOnTaskUpdate, updateStatusOnTaskCompletion } = require ( "../models/userStatus" ) ;
13
13
const dataAccess = require ( "../services/dataAccessLayer" ) ;
14
+ const { parseSearchQuery } = require ( "../utils/tasks" ) ;
14
15
/**
15
16
* Creates new task
16
17
*
@@ -20,9 +21,6 @@ const dataAccess = require("../services/dataAccessLayer");
20
21
*/
21
22
const addNewTask = async ( req , res ) => {
22
23
try {
23
- // userStatusFlag is the Feature flag for status update based on task status. This flag is temporary and will be removed once the feature becomes stable.
24
- const { userStatusFlag } = req . query ;
25
- const isUserStatusEnabled = userStatusFlag === "true" ;
26
24
const { id : createdBy } = req . userData ;
27
25
const dependsOn = req . body . dependsOn ;
28
26
let userStatusUpdate ;
@@ -37,7 +35,7 @@ const addNewTask = async (req, res) => {
37
35
dependsOn,
38
36
} ;
39
37
const taskDependency = dependsOn && ( await dependencyModel . addDependency ( data ) ) ;
40
- if ( isUserStatusEnabled && req . body . assignee ) {
38
+ if ( req . body . assignee ) {
41
39
userStatusUpdate = await updateUserStatusOnTaskUpdate ( req . body . assignee ) ;
42
40
}
43
41
return res . json ( {
@@ -128,7 +126,7 @@ const fetchPaginatedTasks = async (query) => {
128
126
129
127
const fetchTasks = async ( req , res ) => {
130
128
try {
131
- const { dev, status, page, size, prev, next } = req . query ;
129
+ const { dev, status, page, size, prev, next, q : queryString } = req . query ;
132
130
const transformedQuery = transformQuery ( dev , status , size , page ) ;
133
131
134
132
if ( dev ) {
@@ -139,12 +137,39 @@ const fetchTasks = async (req, res) => {
139
137
} ) ;
140
138
}
141
139
140
+ if ( queryString !== undefined ) {
141
+ const searchParams = parseSearchQuery ( queryString ) ;
142
+ if ( ! searchParams . searchTerm ) {
143
+ return res . status ( 404 ) . json ( {
144
+ message : "No tasks found." ,
145
+ tasks : [ ] ,
146
+ } ) ;
147
+ }
148
+ const filterTasks = await tasks . fetchTasks ( searchParams . searchTerm ) ;
149
+ const tasksWithRdsAssigneeInfo = await fetchTasksWithRdsAssigneeInfo ( filterTasks ) ;
150
+ if ( tasksWithRdsAssigneeInfo . length === 0 ) {
151
+ return res . status ( 404 ) . json ( {
152
+ message : "No tasks found." ,
153
+ tasks : [ ] ,
154
+ } ) ;
155
+ }
156
+ return res . json ( {
157
+ message : "Filter tasks returned successfully!" ,
158
+ tasks : tasksWithRdsAssigneeInfo ,
159
+ } ) ;
160
+ }
161
+
142
162
const allTasks = await tasks . fetchTasks ( ) ;
143
163
const tasksWithRdsAssigneeInfo = await fetchTasksWithRdsAssigneeInfo ( allTasks ) ;
144
-
164
+ if ( tasksWithRdsAssigneeInfo . length === 0 ) {
165
+ return res . status ( 404 ) . json ( {
166
+ message : "No tasks found" ,
167
+ tasks : [ ] ,
168
+ } ) ;
169
+ }
145
170
return res . json ( {
146
171
message : "Tasks returned successfully!" ,
147
- tasks : tasksWithRdsAssigneeInfo . length > 0 ? tasksWithRdsAssigneeInfo : [ ] ,
172
+ tasks : tasksWithRdsAssigneeInfo ,
148
173
} ) ;
149
174
} catch ( err ) {
150
175
logger . error ( `Error while fetching tasks ${ err } ` ) ;
@@ -241,9 +266,6 @@ const getTask = async (req, res) => {
241
266
*/
242
267
const updateTask = async ( req , res ) => {
243
268
try {
244
- // userStatusFlag is the Feature flag for status update based on task status. This flag is temporary and will be removed once the feature becomes stable.
245
- const { userStatusFlag } = req . query ;
246
- const isUserStatusEnabled = userStatusFlag === "true" ;
247
269
const task = await tasks . fetchTask ( req . params . id ) ;
248
270
if ( ! task . taskData ) {
249
271
return res . boom . notFound ( "Task not found" ) ;
@@ -255,15 +277,14 @@ const updateTask = async (req, res) => {
255
277
}
256
278
}
257
279
await tasks . updateTask ( req . body , req . params . id ) ;
258
- if ( isUserStatusEnabled && req . body . assignee ) {
280
+ if ( req . body . assignee ) {
259
281
// New Assignee Status Update
260
282
await updateUserStatusOnTaskUpdate ( req . body . assignee ) ;
261
283
// Old Assignee Status Update if available
262
284
if ( task . taskData . assigneeId ) {
263
285
await updateStatusOnTaskCompletion ( task . taskData . assigneeId ) ;
264
286
}
265
287
}
266
-
267
288
return res . status ( 204 ) . send ( ) ;
268
289
} catch ( err ) {
269
290
if ( err . message . includes ( "Invalid dependency passed" ) ) {
@@ -283,9 +304,6 @@ const updateTask = async (req, res) => {
283
304
*/
284
305
const updateTaskStatus = async ( req , res , next ) => {
285
306
try {
286
- // userStatusFlag is the Feature flag for status update based on task status. This flag is temporary and will be removed once the feature becomes stable.
287
- const { userStatusFlag } = req . query ;
288
- const isUserStatusEnabled = userStatusFlag === "true" ;
289
307
let userStatusUpdate ;
290
308
const taskId = req . params . id ;
291
309
const { dev } = req . query ;
@@ -346,7 +364,7 @@ const updateTaskStatus = async (req, res, next) => {
346
364
}
347
365
}
348
366
349
- if ( isUserStatusEnabled && req . body . status ) {
367
+ if ( req . body . status ) {
350
368
userStatusUpdate = await updateStatusOnTaskCompletion ( userId ) ;
351
369
}
352
370
return res . json ( {
0 commit comments