tango-app-api-task 3.4.0-alpha-4 → 3.4.0-beta-1

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": "3.4.0-alpha-4",
3
+ "version": "3.4.0-beta-1",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -191,8 +191,8 @@ export async function createUpdateTask( req, res ) {
191
191
  delete ans.answeroptionNumber;
192
192
  } );
193
193
  let compare = findDifferences( qn, question );
194
- if ( Object.keys( compare ).length && ( compare?.answerType || compare?.answers || compare?.linkType ) ) {
195
- questionList.questionEdit.push( { sectionName: ele.section, questions: [ { previous: qn }, { new: question } ] } );
194
+ if ( Object.keys( compare ).length && ( compare?.answerType || compare?.answers || compare?.linkType || compare?.qname ) ) {
195
+ questionList.questionEdit.push( { sectionName: ele.section, questions: [ { previous: qn, new: question } ] } );
196
196
  }
197
197
  } else {
198
198
  let sectionIndex = questionList.questionDelete.findIndex( ( sec ) => sec.sectionName === ele.section );
@@ -231,7 +231,7 @@ export async function createUpdateTask( req, res ) {
231
231
  sourceCheckList_id: inputBody._id,
232
232
  checkListName: inputBody.checklistName,
233
233
  fromCheckListName: '',
234
- type: 'checklist',
234
+ type: 'task',
235
235
  action: 'edited',
236
236
  storeName: '',
237
237
  store_id: '',
@@ -659,14 +659,14 @@ export const validateUserv1 = async ( req, res ) => {
659
659
  {
660
660
  $project: {
661
661
  newEmail: { $toLower: '$email' },
662
- isActive: 1,
662
+ // isActive: 1,
663
663
  clientId: 1,
664
664
  },
665
665
  },
666
666
  {
667
667
  $match: {
668
668
  newEmail: { $in: userEmailList },
669
- isActive: true,
669
+ // isActive: true,
670
670
  clientId: { $ne: req.body.clientId },
671
671
  },
672
672
  },
@@ -1095,7 +1095,7 @@ export async function taskConfig( req, res ) {
1095
1095
  checkListName: checklistDetails.checkListName,
1096
1096
  fromCheckListName: '',
1097
1097
  type: 'task',
1098
- action: 'updated',
1098
+ action: inputBody.publish ? 'updated' : 'draft',
1099
1099
  storeName: '',
1100
1100
  store_id: '',
1101
1101
  createdByEmail: req.user.email,
@@ -2190,7 +2190,7 @@ export async function approveTask( req, res ) {
2190
2190
  if ( req.body?.storeId?.length ) {
2191
2191
  query['store_id'] = { $in: req.body.storeId };
2192
2192
  }
2193
- let taskDetails = await taskProcessedService.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1 } );
2193
+ let taskDetails = await taskProcessedService.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1, client_id: 1, coverage: 1 } );
2194
2194
  if ( !taskDetails.length ) {
2195
2195
  return res.sendError( 'No data found', 204 );
2196
2196
  }
@@ -2199,7 +2199,7 @@ export async function approveTask( req, res ) {
2199
2199
  let updateResponse = await taskProcessedService.updateMany( { _id: { $in: idList } }, { approvalStatus: true } );
2200
2200
  if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
2201
2201
  let inputstores = taskDetails.filter( ( data ) => data.checklistStatus == 'submit' );
2202
-
2202
+ let storeNames = inputstores.map( ( data ) => data.storeName );
2203
2203
  let params = {
2204
2204
  'payload': {
2205
2205
  sourceCheckList_id: req.body.sourceCheckList_id,
@@ -2212,8 +2212,6 @@ export async function approveTask( req, res ) {
2212
2212
  approvalStatus: true,
2213
2213
  },
2214
2214
  };
2215
-
2216
-
2217
2215
  const requestOptions = {
2218
2216
  method: 'POST',
2219
2217
  headers: {
@@ -2224,7 +2222,26 @@ export async function approveTask( req, res ) {
2224
2222
  let url = JSON.parse( process.env.LAMBDAURL );
2225
2223
 
2226
2224
  let searchResponse = await fetch( url.approveTask, requestOptions );
2227
-
2225
+ let logData= {
2226
+ 'client_id': taskDetails[0].client_id,
2227
+ 'createAt': new Date(),
2228
+ 'sourceCheckList_id': req.body.sourceCheckList_id,
2229
+ 'checkListName': taskDetails[0].checkListName,
2230
+ 'fromCheckListName': taskDetails[0].checkListName,
2231
+ 'type': 'checklist',
2232
+ 'action': 'approved',
2233
+ 'storeName': '',
2234
+ 'store_id': '',
2235
+ 'createdByEmail': req.user.email,
2236
+ 'createdBy': req.user._id,
2237
+ 'coverage': taskDetails[0].coverage,
2238
+ 'logDetails': {
2239
+ 'approved': storeNames,
2240
+ },
2241
+ };
2242
+ let urlopensearch = JSON.parse( process.env.OPENSEARCH );
2243
+ console.log( 'logData', logData );
2244
+ await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
2228
2245
  if ( searchResponse.ok ) {
2229
2246
  let pendingstores = taskDetails.filter( ( data ) => data.checklistStatus != 'submit' );
2230
2247
  if ( pendingstores && pendingstores.length > 0 ) {
@@ -2972,6 +2989,22 @@ export const duplicateChecklist = async ( req, res ) => {
2972
2989
  sections.push( sectionDetails );
2973
2990
  }
2974
2991
  await taskQuestionService.insertMany( sections );
2992
+ let logObj = {
2993
+ client_id: checkDetails.client_id,
2994
+ createAt: new Date(),
2995
+ sourceCheckList_id: checkDetails._id,
2996
+ checkListName: checkDetails.checkListName,
2997
+ fromCheckListName: '',
2998
+ type: 'task',
2999
+ action: 'duplicated',
3000
+ storeName: '',
3001
+ store_id: '',
3002
+ createdByEmail: req.user.email,
3003
+ createdBy: req.user.userName,
3004
+ coverage: checkDetails.coverage,
3005
+ logDetails: {},
3006
+ };
3007
+ insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
2975
3008
  return res.sendSuccess( { message: 'Task Duplicated Successfully' } );
2976
3009
  } else {
2977
3010
  return res.sendSuccess( { message: 'Duplicated Successfully' } );
@@ -4350,7 +4383,7 @@ export async function updateAssign( req, res ) {
4350
4383
  },
4351
4384
  ];
4352
4385
  let assignUserDetails = await userService.aggregate( query );
4353
- await Promise.all( req.body.assignedList.map( async ( assign ) => {
4386
+ for ( let assign of req.body.assignedList ) {
4354
4387
  let userDetails = assignUserDetails.find( ( ele ) => ele.email.toLowerCase() == assign.userEmail.toLowerCase() );
4355
4388
  if ( !userDetails ) {
4356
4389
  let userData = {
@@ -4360,6 +4393,7 @@ export async function updateAssign( req, res ) {
4360
4393
  clientId: req.body.clientId,
4361
4394
  };
4362
4395
  userDetails = await createUser( userData );
4396
+ assignUserDetails.push( userDetails );
4363
4397
  }
4364
4398
  let data = {
4365
4399
  ...assign,
@@ -4373,7 +4407,7 @@ export async function updateAssign( req, res ) {
4373
4407
  };
4374
4408
  delete data._id;
4375
4409
  assignedUserList.push( data );
4376
- } ) );
4410
+ }
4377
4411
  let assignGroupDetails = [];
4378
4412
  if ( req.body.coverage == 'store' ) {
4379
4413
  assignGroupDetails = await clusterServices.findcluster( { _id: { $in: req.body.assignedGroup } } );
@@ -1,6 +1,6 @@
1
1
  import * as taskService from '../service/task.service.js';
2
2
  import * as processedTaskService from '../service/processedTaskList.service.js';
3
- import { logger, download } from 'tango-app-api-middleware'; // getChecklistUsers
3
+ import { logger, download, insertOpenSearchData } from 'tango-app-api-middleware'; // getChecklistUsers
4
4
  import dayjs from 'dayjs';
5
5
  import mongoose from 'mongoose';
6
6
  // const ObjectId = mongoose.Types.ObjectId;
@@ -961,7 +961,7 @@ export const taskDeleteV1 = async ( req, res ) => {
961
961
  return res.sendError( 'Missing taskId in request body', 400 );
962
962
  }
963
963
 
964
- const taskConfig = await taskService.findOne( { _id: new mongoose.Types.ObjectId( requestData.taskId ) }, { _id: 1 } );
964
+ const taskConfig = await taskService.findOne( { _id: new mongoose.Types.ObjectId( requestData.taskId ) } );
965
965
  if ( !taskConfig ) {
966
966
  // console.log( 'Task found:', taskConfig );
967
967
  return res.sendError( 'Task not found', 404 );
@@ -973,12 +973,29 @@ export const taskDeleteV1 = async ( req, res ) => {
973
973
  );
974
974
 
975
975
  if ( resultData ) {
976
+ let logObj = {
977
+ client_id: taskConfig.client_id,
978
+ createAt: new Date(),
979
+ sourceCheckList_id: taskConfig._id,
980
+ checkListName: taskConfig.checkListName,
981
+ fromCheckListName: '',
982
+ type: 'task',
983
+ action: 'deleted',
984
+ storeName: '',
985
+ store_id: '',
986
+ createdByEmail: req.user.email,
987
+ createdBy: req.user.userName,
988
+ coverage: taskConfig.coverage,
989
+ logDetails: {},
990
+ };
991
+ insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
976
992
  // console.log( 'Update result:', resultData );
977
993
  return res.sendSuccess( { message: 'Task deleted successfully' } );
978
994
  } else {
979
995
  return res.sendError( 'Something went wrong please try again', 500 );
980
996
  }
981
997
  } catch ( e ) {
998
+ // console.log( 'e', e );
982
999
  logger.error( 'taskDeleteV1 =>', e );
983
1000
  return res.sendError( e, 500 );
984
1001
  }