File tree Expand file tree Collapse file tree 3 files changed +13
-20
lines changed Expand file tree Collapse file tree 3 files changed +13
-20
lines changed Original file line number Diff line number Diff line change @@ -28,25 +28,15 @@ const addNewTask = async (req, res) => {
28
28
taskId,
29
29
dependsOn,
30
30
} ;
31
- if ( data . dependsOn ) {
32
- const taskDependency = await dependencyModel . addDependency ( data ) ;
33
- return res . json ( {
34
- message : "Task created successfully!" ,
35
- task : {
36
- ...taskDetails ,
37
- dependsOn : taskDependency ,
38
- id : taskId ,
39
- } ,
40
- } ) ;
41
- } else {
42
- return res . json ( {
43
- message : "Task created successfully!" ,
44
- task : {
45
- ...taskDetails ,
46
- id : taskId ,
47
- } ,
48
- } ) ;
49
- }
31
+ const taskDependency = dependsOn && ( await dependencyModel . addDependency ( data ) ) ;
32
+ return res . json ( {
33
+ message : "Task created successfully!" ,
34
+ task : {
35
+ ...taskDetails ,
36
+ ...( taskDependency && { dependsOn : taskDependency } ) ,
37
+ id : taskId ,
38
+ } ,
39
+ } ) ;
50
40
} catch ( err ) {
51
41
logger . error ( `Error while creating new task: ${ err } ` ) ;
52
42
return res . boom . badImplementation ( INTERNAL_SERVER_ERROR ) ;
Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ const addDependency = async (data) => {
43
43
try {
44
44
const { taskId, dependsOn } = data ;
45
45
const batch = firestore . batch ( ) ;
46
+ if ( dependsOn . length > 500 ) {
47
+ throw new Error ( "Error cannot add more than 500 taskId" ) ;
48
+ }
46
49
for ( const dependsId of dependsOn ) {
47
50
const taskDependOn = {
48
51
taskId,
Original file line number Diff line number Diff line change @@ -106,8 +106,8 @@ describe("Tasks", function () {
106
106
expect ( res ) . to . have . status ( 200 ) ;
107
107
expect ( res . body ) . to . be . a ( "object" ) ;
108
108
expect ( res . body . message ) . to . equal ( "Task created successfully!" ) ;
109
- expect ( res . body . task . id ) . to . be . a ( "string" ) ;
110
109
expect ( res . body . task ) . to . be . a ( "object" ) ;
110
+ expect ( res . body . task . id ) . to . be . a ( "string" ) ;
111
111
expect ( res . body . task . createdBy ) . to . equal ( appOwner . username ) ;
112
112
expect ( res . body . task . assignee ) . to . equal ( appOwner . username ) ;
113
113
expect ( res . body . task . participants ) . to . be . a ( "array" ) ;
You can’t perform that action at this time.
0 commit comments