tango-app-api-trax 3.5.2-alpha-11 → 3.5.2-alpha-13

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-trax",
3
- "version": "3.5.2-alpha-11",
3
+ "version": "3.5.2-alpha-13",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { logger, insertOpenSearchData } from 'tango-app-api-middleware';
3
+ import { logger, insertOpenSearchData, sendTeamsNotification } from 'tango-app-api-middleware';
4
4
  import * as storeService from '../services/store.service.js';
5
5
  import * as groupService from '../services/group.service.js';
6
6
  import * as clusterService from '../services/cluster.service.js';
@@ -298,7 +298,8 @@ export async function approveChecklist( req, res ) {
298
298
  if ( req.body?.userEmail?.length ) {
299
299
  query['userEmail'] = { $in: req.body?.userEmail };
300
300
  }
301
- let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1, client_id: 1, coverage: 1, checkListName: 1 } );
301
+ let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1, client_id: 1, coverage: 1, checkListName: 1, sourceCheckList_id: 1 } );
302
+ // console.log( 'checklistDetails =>', checklistDetails );
302
303
  if ( !checklistDetails.length ) {
303
304
  return res.sendError( 'No data found', 204 );
304
305
  }
@@ -313,7 +314,19 @@ export async function approveChecklist( req, res ) {
313
314
  approvalByEmail: req.user.email,
314
315
  };
315
316
  let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList }, approvalStatus: false }, approvalUpdateData );
317
+
318
+ let teamsMsg;
319
+ let teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
320
+ teamsMsg = 'ClientId: '+ checklistDetails[0].client_id + ', Type: Checklist, Process: started, Action: Approval, ChecklistId: '+ checklistDetails[0].sourceCheckList_id + ', Checklist Name: '+ checklistDetails[0].checkListName +', UpDatedBy: '+ req.user.email;
321
+ if ( teamsAlertUrls && teamsAlertUrls.approvalAlert ) {
322
+ sendTeamsNotification( teamsAlertUrls.approvalAlert, teamsMsg );
323
+ }
324
+
316
325
  if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
326
+ teamsMsg = 'ClientId: '+ checklistDetails[0].client_id + ', Type: Checklist, Process: Completed, Updated Count: '+updateResponse.modifiedCount+' Action: Approval, ChecklistId: '+ checklistDetails[0].sourceCheckList_id + ', Checklist Name: '+ checklistDetails[0].checkListName +', UpDatedBy: '+ req.user.email;
327
+ if ( teamsAlertUrls && teamsAlertUrls.approvalAlert ) {
328
+ sendTeamsNotification( teamsAlertUrls.approvalAlert, teamsMsg );
329
+ }
317
330
  let inputstores = checklistDetails.filter( ( data ) => data.checklistStatus == 'submit' );
318
331
  let storeNames = inputstores.map( ( data ) => data.storeName );
319
332
 
@@ -364,6 +377,7 @@ export async function approveChecklist( req, res ) {
364
377
  },
365
378
  'userType': req.user.userType,
366
379
  'requestedStores': filteredStoreIds,
380
+ 'requestedUsers': req.body.userEmail,
367
381
  };
368
382
  console.log( 'logData', logData );
369
383
  let urlopensearch = JSON.parse( process.env.OPENSEARCH );
@@ -1,4 +1,4 @@
1
- import { logger, download, getChecklistUsers } from 'tango-app-api-middleware';
1
+ import { logger, download, getChecklistUsers, insertOpenSearchData } from 'tango-app-api-middleware';
2
2
  import * as processedchecklistService from '../services/processedchecklist.services.js';
3
3
  import * as processedchecklistconfigService from '../services/processedchecklistconfig.services.js';
4
4
  import * as checklistconfigService from '../services/checklist.service.js';
@@ -1595,6 +1595,7 @@ export const checklistInfo = async ( req, res ) => {
1595
1595
  } },
1596
1596
  approvalByEmail: 1,
1597
1597
  approvalTime_string: 1,
1598
+ _id: 1,
1598
1599
  },
1599
1600
  } );
1600
1601
 
@@ -1645,6 +1646,7 @@ export const checklistInfo = async ( req, res ) => {
1645
1646
  submitCount: 1,
1646
1647
  approvalByEmail: 1,
1647
1648
  approvalTime_string: 1,
1649
+ _id: 1,
1648
1650
  },
1649
1651
  } );
1650
1652
 
@@ -3827,7 +3829,6 @@ export const reinitiatechecklist = async ( req, res ) => {
3827
3829
  let requestData = req.body;
3828
3830
  let findQuery = [];
3829
3831
  let findAndQuery = [];
3830
-
3831
3832
  if ( requestData._id ) {
3832
3833
  findAndQuery.push(
3833
3834
  { _id: new mongoose.Types.ObjectId( requestData._id ) },
@@ -3837,6 +3838,15 @@ export const reinitiatechecklist = async ( req, res ) => {
3837
3838
  $project: {
3838
3839
  _id: 1,
3839
3840
  reinitiateStatus: 1,
3841
+ store_id: 1,
3842
+ storeName: 1,
3843
+ userEmail: 1,
3844
+ action: 1,
3845
+ sourceCheckList_id: 1,
3846
+ checkListName: 1,
3847
+ client_id: 1,
3848
+ date_iso: 1,
3849
+ coverage: 1,
3840
3850
  },
3841
3851
  } );
3842
3852
  let getChecklist = await processedchecklistService.aggregate( findQuery );
@@ -3844,7 +3854,26 @@ export const reinitiatechecklist = async ( req, res ) => {
3844
3854
  let updateChecklist = await processedchecklistService.updateOne( { _id: new mongoose.Types.ObjectId( requestData._id ) }, { reinitiateStatus: true } );
3845
3855
  if ( updateChecklist ) {
3846
3856
  // Delete Time Flag Detection //
3847
-
3857
+ const data = getChecklist[0];
3858
+ let logObj = {
3859
+ client_id: data.client_id,
3860
+ createAt: new Date(),
3861
+ sourceCheckList_id: data.sourceCheckList_id,
3862
+ checkListName: data.checkListName,
3863
+ fromCheckListName: '',
3864
+ type: 'checklist',
3865
+ action: 'reinitiated',
3866
+ storeName: data.storeName,
3867
+ store_id: data.store_id,
3868
+ userEmail: data.userEmail,
3869
+ createdByEmail: req.user.email,
3870
+ createdBy: req.user.userName,
3871
+ coverage: data.coverage,
3872
+ logDetails: {},
3873
+ userType: req.user.userType,
3874
+ processedChecklistId: data._id,
3875
+ };
3876
+ insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
3848
3877
  return res.sendSuccess( 'Reinitiate Successfully' );
3849
3878
  } else {
3850
3879
  return res.sendError( { error: 'Something Went wrong Please Try Again' }, 400 );
@@ -3854,25 +3883,65 @@ export const reinitiatechecklist = async ( req, res ) => {
3854
3883
  }
3855
3884
  } else if ( requestData.sourceCheckList_id ) {
3856
3885
  findAndQuery.push(
3857
- { _id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
3886
+ {
3887
+ reinitiateStatus: false,
3888
+ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ),
3889
+ },
3858
3890
  );
3859
3891
  findQuery.push( { $match: { $and: findAndQuery } } );
3860
3892
  findQuery.push( {
3861
3893
  $project: {
3862
3894
  _id: 1,
3863
3895
  reinitiateStatus: 1,
3896
+ store_id: 1,
3897
+ storeName: 1,
3898
+ userEmail: 1,
3899
+ action: 1,
3900
+ sourceCheckList_id: 1,
3901
+ checkListName: 1,
3902
+ client_id: 1,
3903
+ date_iso: 1,
3904
+ coverage: 1,
3864
3905
  },
3865
3906
  } );
3866
3907
  let getChecklist = await processedchecklistService.aggregate( findQuery );
3867
3908
  if ( getChecklist.length>0 ) {
3868
3909
  let updateQuery = {
3869
- _id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ),
3910
+ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ),
3870
3911
  timeFlag: { $gt: 0 },
3912
+ reinitiateStatus: false,
3871
3913
  };
3872
3914
  let updateChecklist = await processedchecklistService.updateMany( updateQuery, { reinitiateStatus: true } );
3873
3915
  if ( updateChecklist ) {
3874
3916
  // Delete Time Flag Detection //
3875
-
3917
+ const data = getChecklist[0];
3918
+ // let stores = getChecklist.map( ( item ) => ( {
3919
+ // // store_id: item.store_id,
3920
+ // storeName: item.storeName,
3921
+ // } ) );
3922
+
3923
+ // let users = getChecklist.map( ( item ) => ( {
3924
+ // userEmail: item.userEmail,
3925
+ // } ) );
3926
+ let logObj = {
3927
+ client_id: data.client_id,
3928
+ createAt: new Date(),
3929
+ sourceCheckList_id: data.sourceCheckList_id,
3930
+ checkListName: data.checkListName,
3931
+ fromCheckListName: '',
3932
+ type: 'checklist',
3933
+ action: 'reinitiated',
3934
+ storeName: data.storeName,
3935
+ store_id: data.store_id,
3936
+ userEmail: data.userEmail,
3937
+ createdByEmail: req.user.email,
3938
+ createdBy: req.user.userName,
3939
+ coverage: data.coverage,
3940
+ logDetails: {},
3941
+ userType: req.user.userType,
3942
+ processedChecklistId: data._id,
3943
+ };
3944
+ insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, logObj );
3876
3945
  return res.sendSuccess( 'Reinitiate Successfully' );
3877
3946
  } else {
3878
3947
  return res.sendError( { error: 'Something Went wrong Please Try Again' }, 400 );