tango-app-api-task 1.0.0-alpha.4 → 1.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-task",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.5",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "handlebars": "^4.7.8",
24
24
  "mongodb": "^6.10.0",
25
25
  "nodemon": "^3.1.7",
26
- "tango-api-schema": "^2.1.90",
26
+ "tango-api-schema": "^2.1.91",
27
27
  "tango-app-api-middleware": "^3.1.43-alpha.10",
28
28
  "winston": "^3.17.0",
29
29
  "winston-daily-rotate-file": "^5.0.0"
@@ -620,6 +620,7 @@ export async function taskConfig( req, res ) {
620
620
 
621
621
  let configDetails = { ...req.body };
622
622
  configDetails.scheduleEndTimeISO = dayjs.utc( configDetails.scheduleEndTime, 'hh:mm A' ).format();
623
+ configDetails.publishDate = dayjs().format();
623
624
 
624
625
  let response = await taskService.updateOne( { _id: inputBody._id }, configDetails );
625
626
  if ( inputBody?.approver.length ) {
@@ -1076,3 +1077,98 @@ export async function createChecklistTask( req, res ) {
1076
1077
  return res.sendError( e, 500 );
1077
1078
  }
1078
1079
  }
1080
+
1081
+ export async function approveTask( req, res ) {
1082
+ try {
1083
+ if ( !req.body.id ) {
1084
+ return res.sendError( 'id is required', 400 );
1085
+ }
1086
+ let taskDetails = await taskProcessedService.findOne( { _id: req.body.id }, { approvalEnable: 1, approvalStatus: 1 } );
1087
+ if ( !taskDetails ) {
1088
+ return res.sendError( 'No data found', 204 );
1089
+ }
1090
+ if ( !taskDetails.approvalEnable ) {
1091
+ return res.sendError( 'task has no approver', 400 );
1092
+ }
1093
+ taskDetails.approvalStatus = true;
1094
+ taskDetails.save().then( () => {
1095
+ return res.sendSuccess( 'task Approved Successfully' );
1096
+ } ).catch( ( e ) => {
1097
+ return res.sendError( e, 500 );
1098
+ } );
1099
+ } catch ( e ) {
1100
+ logger.error( { function: 'approveTask', error: e } );
1101
+ return res.sendError( e, 500 );
1102
+ }
1103
+ }
1104
+
1105
+ export async function redoTask( req, res ) {
1106
+ try {
1107
+ if ( !req.body.payload._id ) {
1108
+ return res.sendError( 'Id is Required', 400 );
1109
+ }
1110
+ if ( !req.body.payload.section_id ) {
1111
+ return res.sendError( 'Section id is Required', 400 );
1112
+ }
1113
+ if ( !req.body.payload.qno ) {
1114
+ return res.sendError( 'Question number is Required', 400 );
1115
+ }
1116
+
1117
+ let taskDetails = await taskProcessedService.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1 } );
1118
+ if ( !taskDetails ) {
1119
+ return res.sendError( 'No data found', 204 );
1120
+ }
1121
+ let question = taskDetails.questionAnswers;
1122
+ let sectionIndex = question.findIndex( ( sec ) => sec.section_id == req.body.payload.section_id );
1123
+ if ( sectionIndex == -1 ) {
1124
+ return res.sendError( 'section is not found', 400 );
1125
+ }
1126
+ let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true };
1127
+ let userAnswer = data.userAnswer;
1128
+ question[sectionIndex].questions[req.body.payload.qno - 1] = data;
1129
+ question[sectionIndex].questions[req.body.payload.qno - 1].userAnswer = [];
1130
+ taskDetails.questionAnswers = question;
1131
+ let updateData = {
1132
+ checklistStatus: 'open',
1133
+ redoStatus: true,
1134
+ questionAnswers: question,
1135
+ };
1136
+
1137
+ let response = await taskProcessedService.updateOne( { _id: req.body.payload._id }, updateData );
1138
+ if ( response.modifiedCount || response.matchedCount ) {
1139
+ data = {
1140
+ checklistId: taskDetails.sourceCheckList_id,
1141
+ checkListName: taskDetails.checkListName,
1142
+ sectionId: req.body.payload.section_id,
1143
+ sectionName: question[sectionIndex].sectionName,
1144
+ questionName: question[sectionIndex].questions[req.body.payload.qno - 1].qname,
1145
+ action: 'redo',
1146
+ store_id: taskDetails.store_id,
1147
+ storeName: taskDetails.storeName,
1148
+ client_id: taskDetails.client_id,
1149
+ processedChecklistId: taskDetails._id,
1150
+ type: taskDetails.checkListType,
1151
+ userAnswer: userAnswer,
1152
+ };
1153
+ await checklistLogs.create( data );
1154
+ const requestOptions = {
1155
+ method: 'POST',
1156
+ headers: {
1157
+ 'Content-Type': 'application/json',
1158
+ },
1159
+ body: JSON.stringify( req.body ),
1160
+ };
1161
+ let searchResponse = await fetch( 'https://ottrgmadjmqptsxdmlckjxdjuy0qvpnt.lambda-url.ap-south-1.on.aws/', requestOptions );
1162
+ if ( searchResponse.ok ) {
1163
+ return res.sendSuccess( 'Question redo successfully' );
1164
+ } else {
1165
+ return res.sendError( 'Something went wrong', 500 );
1166
+ }
1167
+ } else {
1168
+ return res.sendError( 'Something went wrong', 500 );
1169
+ }
1170
+ } catch ( e ) {
1171
+ logger.error( { function: 'redoChecklist', error: e } );
1172
+ return res.sendError( e, 500 );
1173
+ }
1174
+ }
@@ -14,7 +14,7 @@ export const overallCardsV1 = async ( req, res ) => {
14
14
  let clientId = req.user?.clientId;
15
15
  query = { client_id: clientId };
16
16
  } else {
17
- query = { userEmail: req.user.userEmail };
17
+ query = { userEmail: req.user.email };
18
18
  }
19
19
  let details = await traxApprover.find( query );
20
20
  if ( details.length ) {
@@ -34,7 +34,7 @@ export const overallCardsV1 = async ( req, res ) => {
34
34
  ].map( ( item ) => new ObjectId( item ) );
35
35
  }
36
36
 
37
- let toDate = new Date( req.body.date );
37
+ let toDate = new Date( req.body.toDate );
38
38
  let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
39
39
  toDate = new Date( toDate.getTime() - userTimezoneOffset );
40
40
  toDate.setUTCHours( 23, 59, 59, 59 );
@@ -48,8 +48,9 @@ export const overallCardsV1 = async ( req, res ) => {
48
48
  let taskQuery = [
49
49
  {
50
50
  $match: {
51
- date_iso: { $gte: new Date( req.body.date ), $lte: toDate },
51
+ date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
52
52
  sourceCheckList_id: { $in: taskIdList },
53
+ ...( req.body.storeId.length ) ? { store_id: { $in: req.body.storeId } } :{},
53
54
  approvalStatus: false,
54
55
  },
55
56
  },
@@ -59,8 +60,9 @@ export const overallCardsV1 = async ( req, res ) => {
59
60
  let checklistQuery = [
60
61
  {
61
62
  $match: {
62
- date_iso: { $gte: new Date( req.body.date ), $lte: toDate },
63
+ date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
63
64
  sourceCheckList_id: { $in: checklistIdList },
65
+ ...( req.body.storeId.length ) ? { store_id: { $in: req.body.storeId } } :{},
64
66
  approvalStatus: false,
65
67
  },
66
68
  },
@@ -72,8 +74,8 @@ export const overallCardsV1 = async ( req, res ) => {
72
74
  processedChecklist.aggregate( checklistQuery ),
73
75
  ] );
74
76
 
75
- resultData = { taskCount: taskCount?.[0]?.count || 0, checklistCount: checklistCount?.[0]?.count || 0 };
76
- return res.sendSuccess( resultData );
77
+ resultData = { taskApproval: { count: taskCount?.[0]?.count || 0 }, checklistApproval: { count: checklistCount?.[0]?.count || 0 } };
78
+ return res.sendSuccess( { cardData: resultData } );
77
79
  } catch ( error ) {
78
80
  console.log( 'error =>', error );
79
81
  logger.error( { error: error, function: 'overallCards' } );
@@ -91,7 +93,7 @@ export const approvalTableV1 = async ( req, res ) => {
91
93
  let clientId = req.user?.clientId;
92
94
  query = { client_id: clientId };
93
95
  } else {
94
- query = { userEmail: req.user.userEmail };
96
+ query = { userEmail: req.user.email };
95
97
  }
96
98
  let details = await traxApprover.find( query );
97
99
  if ( details.length ) {
@@ -112,7 +114,7 @@ export const approvalTableV1 = async ( req, res ) => {
112
114
  ].map( ( item ) => new ObjectId( item ) );
113
115
  }
114
116
 
115
- let toDate = new Date( req.body.date );
117
+ let toDate = new Date( req.body.toDate );
116
118
  let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
117
119
  toDate = new Date( toDate.getTime() - userTimezoneOffset );
118
120
  toDate.setUTCHours( 23, 59, 59, 59 );
@@ -167,12 +169,27 @@ export const approvalTableV1 = async ( req, res ) => {
167
169
  query = [
168
170
  {
169
171
  $match: {
170
- date_iso: { $gte: new Date( req.body.date ), $lte: toDate },
172
+ date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
171
173
  sourceCheckList_id: { $in: taskIdList },
174
+ ...( req.body.storeId.length ) ? { store_id: { $in: req.body.storeId } } :{},
172
175
  },
173
176
  },
174
177
  ...groupQuery,
175
178
  ];
179
+ if ( req.body?.searchValue?.trim() && req.body?.searchValue?.trim().length ) {
180
+ query.push( {
181
+ $match: {
182
+ checkListName: { $regex: req.body?.searchValue, $options: 'i' },
183
+ },
184
+ } );
185
+ }
186
+ if ( req.body?.filter?.trim() && req.body?.filter?.trim().length ) {
187
+ query.push( {
188
+ $match: {
189
+ priorityType: req.body?.filter,
190
+ },
191
+ } );
192
+ }
176
193
  promises.push( processedTask.aggregate( query ) );
177
194
  } else {
178
195
  promises.push( Promise.resolve( null ) );
@@ -183,20 +200,28 @@ export const approvalTableV1 = async ( req, res ) => {
183
200
  query = [
184
201
  {
185
202
  $match: {
186
- date_iso: { $gte: new Date( req.body.date ), $lte: toDate },
203
+ date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
187
204
  sourceCheckList_id: { $in: checklistIdList },
205
+ ...( req.body.storeId.length ) ? { store_id: { $in: req.body.storeId } } : {},
188
206
  },
189
207
  },
190
208
  ...groupQuery,
191
209
  ];
192
210
  promises.push( processedChecklist.aggregate( query ) );
211
+ if ( req.body?.searchValue.trim() && req.body?.searchValue.trim().length ) {
212
+ query.push( {
213
+ $match: {
214
+ checkListName: { $regex: req.body?.searchValue, $options: 'i' },
215
+ },
216
+ } );
217
+ }
193
218
  } else {
194
219
  promises.push( Promise.resolve( null ) );
195
220
  }
196
221
 
197
222
  const [ taskResult, checklistResult ] = await Promise.all( promises );
198
223
 
199
- const taskSummary = taskResult.reduce(
224
+ const taskSummary = taskResult?.reduce(
200
225
  ( acc, ele ) => {
201
226
  if ( ele.unApproveCount === ele.storeCount ) {
202
227
  acc.openTask.push( ele );
@@ -211,7 +236,7 @@ export const approvalTableV1 = async ( req, res ) => {
211
236
  );
212
237
  const { openTask, inprogressTask, doneTask } = taskSummary;
213
238
 
214
- const checklistSummary = checklistResult.reduce(
239
+ const checklistSummary = checklistResult?.reduce(
215
240
  ( acc, ele ) => {
216
241
  if ( ele.unApproveCount === ele.storeCount ) {
217
242
  acc.openChecklist.push( ele );
@@ -14,6 +14,8 @@ taskRouter
14
14
  .post( '/uploadImage', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.uploadImage )
15
15
  .post( '/config', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.taskConfig )
16
16
  .post( '/reinitiate', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.reinitiateTask )
17
- .post( '/checklistTask', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.createChecklistTask );
17
+ .post( '/checklistTask', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.createChecklistTask )
18
+ .post( '/updateApprove', isAllowedSessionHandler, taskController.approveTask )
19
+ .post( '/redo', isAllowedSessionHandler, taskController.redoTask );
18
20
 
19
21
 
@@ -12,6 +12,10 @@ export const updateMany = async ( query = {}, record={} ) => {
12
12
  return model.taskProcessedModel.updateMany( query, { $set: record } );
13
13
  };
14
14
 
15
+ export const updateOne = async ( query = {}, record={} ) => {
16
+ return model.taskProcessedModel.updateOne( query, { $set: record } );
17
+ };
18
+
15
19
  export const insertMany = async ( data = [] ) => {
16
20
  return model.taskProcessedModel.insertMany( data );
17
21
  };