tango-app-api-trax 3.3.1-beta-47 → 3.3.1-beta-49

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.3.1-beta-47",
3
+ "version": "3.3.1-beta-49",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -394,9 +394,21 @@ export const getConfigDetails = async ( req, res ) => {
394
394
  result.checkListDetails.scheduleStartTime = result.openTime;
395
395
  result.checkListDetails.scheduleEndTime = result.closeTime;
396
396
  }
397
- let assignedUsers = await assignedService.find( { checkListId: storechecklistdetails._id }, { _id: 1, assignId: 1 } );
398
- assignedUsers = assignedUsers?.map( ( item ) => item.assignId );
399
- result.checkListDetails = { ...result.checkListDetails, ...{ sections: sectionList }, ...{ assignedUsers: assignedUsers }, ...{ removedUsers: [] } };
397
+ let query = {
398
+ checkListId: storechecklistdetails._id,
399
+ ...( storechecklistdetails.coverage == 'store' ) ? { $or: [ { store_id: { $exists: true } }, { clusterName: { $exists: true } } ] } : { $or: [ { userEmail: { $exists: true } }, { teamsName: { $exists: true } } ] },
400
+ };
401
+ let assignList = await assignedService.find( query, { _id: 1, store_id: 1, clusterName: 1, userEmail: 1, teamName: 1, assignId: 1 } );
402
+ let singleAssign;
403
+ let groupAssign;
404
+ if ( storechecklistdetails.coverage == 'store' ) {
405
+ singleAssign = assignList.filter( ( item ) => typeof item?.store_id != 'undefined' && item?.store_id != '' ).map( ( item ) => item.assignId );
406
+ groupAssign = assignList.filter( ( item ) => typeof item?.clusterName != 'undefined' && item?.clusterName != '' ).map( ( item ) => item.assignId );
407
+ } else {
408
+ singleAssign = assignList.filter( ( item ) => typeof item?.userEmail != 'undefined' && item?.userEmail !='' ).map( ( item ) => item.assignId );
409
+ groupAssign = assignList.filter( ( item ) => typeof item?.teamName != 'undefined' && item?.teamName != '' ).map( ( item ) => item.assignId );
410
+ }
411
+ result.checkListDetails = { ...result.checkListDetails, ...{ sections: sectionList }, singleAssign, groupAssign };
400
412
  }
401
413
 
402
414
  return res.sendSuccess( result );
@@ -809,6 +821,7 @@ export const update = async ( req, res ) => {
809
821
  }
810
822
  }
811
823
  } ).catch( ( e ) => {
824
+ logger.error( 'update =>', e );
812
825
  return res.sendError( e, 500 );
813
826
  } );
814
827
  } catch ( e ) {
@@ -1486,6 +1499,7 @@ export const updateConfigurev1 =async ( req, res ) => {
1486
1499
  let configDetails = {
1487
1500
  ...inputBody?.checkListDetails,
1488
1501
  publishDate: inputBody.checkListDetails.publish ? new Date() : '',
1502
+ scheduleRepeatedType: inputBody?.checkListDetails?.schedule,
1489
1503
  scheduleStartTimeISO: dayjs.utc( inputBody?.checkListDetails?.scheduleStartTime, 'hh:mm A' ).format(),
1490
1504
  scheduleEndTimeISO: dayjs.utc( inputBody?.checkListDetails?.scheduleEndTime, 'hh:mm A' ).format(),
1491
1505
  scheduleDate: inputBody?.checkListDetails?.scheduleDate ? dayjs( inputBody.checkListDetails.scheduleDate ).format() : '',
@@ -3465,43 +3479,41 @@ export const selectAssign = async ( req, res ) => {
3465
3479
  let resuldData;
3466
3480
  if ( requestData.coverage == 'store' ) {
3467
3481
  // //Select Store and cluster
3468
- let storeQuery = [
3469
- { $match: { clientId: requestData.clientId, status: 'active' } },
3470
- { $project: { 'storeName': 1, 'storeId': 1, 'type': 'store' } },
3471
- ];
3472
- let clusterQuery = [
3473
- { $match: { clientId: requestData.clientId } },
3474
- { $project: { 'clusterName': 1, 'type': 'cluster' } },
3475
- ];
3476
-
3477
- const [ getStores, getClusters ] = await Promise.all( [
3478
- storeService.aggregate( storeQuery ),
3479
- clusterServices.aggregateCluster( clusterQuery ),
3480
- ] );
3482
+ if ( requestData.assignType == 'store' ) {
3483
+ let storeQuery = [
3484
+ { $match: { clientId: requestData.clientId, status: 'active' } },
3485
+ { $project: { 'storeName': 1, 'storeId': 1, 'type': 'store' } },
3486
+ ];
3487
+ resuldData = await storeService.aggregate( storeQuery );
3488
+ } else {
3489
+ let clusterQuery = [
3490
+ { $match: { clientId: requestData.clientId } },
3491
+ { $project: { 'clusterName': 1, 'type': 'cluster' } },
3492
+ ];
3493
+ resuldData = await clusterServices.aggregateCluster( clusterQuery );
3494
+ }
3481
3495
  // console.log( 'getStores =>', getStores );
3482
3496
  // console.log( 'getClusters =>', getClusters );
3483
- resuldData = [ ...getStores, ...getClusters ];
3484
- console.log( 'resuldData =>', resuldData );
3485
3497
  } else if ( requestData.coverage == 'user' ) {
3486
3498
  // //Select User and Teams
3487
- let userQuery = [
3488
- { $match: { clientId: requestData.clientId } },
3489
- { $project: { 'userEmail': 1, 'userName': 1, 'type': 'user' } },
3490
- ];
3499
+ if ( requestData.assignType == 'user' ) {
3500
+ let userQuery = [
3501
+ { $match: { clientId: requestData.clientId } },
3502
+ { $project: { 'userEmail': 1, 'userName': 1, 'type': 'user' } },
3503
+ ];
3504
+ resuldData = await userService.aggregate( userQuery );
3505
+ } else {
3506
+ let teamQuery = [
3507
+ { $match: { clientId: requestData.clientId } },
3508
+ { $project: { 'teamName': 1, 'type': 'teams' } },
3509
+ ];
3510
+ resuldData = await teamsServices.aggregateTeams( teamQuery );
3511
+ }
3491
3512
  // let getUsers = await userService.aggregate( userQuery );
3492
3513
  // console.log( 'getUsers =>', getUsers );
3493
- let teamQuery = [
3494
- { $match: { clientId: requestData.clientId } },
3495
- { $project: { 'teamName': 1, 'type': 'teams' } },
3496
- ];
3514
+
3497
3515
  // let getTeams = await teamsServices.aggregateTeams( teamQuery );
3498
3516
  // console.log( 'getTeams =>', getTeams );
3499
- const [ getUsers, getTeams ] = await Promise.all( [
3500
- userService.aggregate( userQuery ),
3501
- teamsServices.aggregateTeams( teamQuery ),
3502
- ] );
3503
- resuldData = [ ...getUsers, ...getTeams ];
3504
- console.log( 'resuldData =>', resuldData );
3505
3517
  }
3506
3518
  return res.sendSuccess( { 'totalCount': resuldData.length, 'data': resuldData } );
3507
3519
  } catch ( e ) {
@@ -3600,7 +3612,7 @@ async function assignUsers( data ) {
3600
3612
  if ( !userDetails ) {
3601
3613
  let userData = {
3602
3614
  userName: storeDetails?.[0]?.spocDetails?.[0]?.name,
3603
- email: storeDetails?.[0]?.spocDetails[0].email,
3615
+ email: data?.userEmail || storeDetails?.[0]?.spocDetails[0].email,
3604
3616
  mobileNumber: storeDetails?.[0]?.spocDetails?.[0]?.phone,
3605
3617
  clientId: data.clientId,
3606
3618
  };
@@ -3715,7 +3727,6 @@ async function assignUsers( data ) {
3715
3727
  }
3716
3728
  }
3717
3729
 
3718
- // console.log( assignedData, 'test', data );
3719
3730
  if ( assignedData && data?.insert ) {
3720
3731
  await assignedService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
3721
3732
  } else {
@@ -3740,7 +3751,7 @@ export async function checklistAssign( req, res ) {
3740
3751
  return res.sendError( 'No data found', 204 );
3741
3752
  }
3742
3753
 
3743
- let userData = [];
3754
+ let uniqueArr = [];
3744
3755
 
3745
3756
  await Promise.all( req.body.idList.map( async ( data ) => {
3746
3757
  let assignedData = {
@@ -3755,16 +3766,13 @@ export async function checklistAssign( req, res ) {
3755
3766
  let uploadData = await assignUsers( assignedData );
3756
3767
  if ( uploadData ) {
3757
3768
  if ( Array.isArray( uploadData ) ) {
3758
- userData.push( ...uploadData );
3769
+ uniqueArr.push( ...uploadData );
3759
3770
  } else {
3760
- userData.push( uploadData );
3771
+ uniqueArr.push( uploadData );
3761
3772
  }
3762
3773
  }
3763
3774
  } ) );
3764
3775
 
3765
- let uniqueArr = userData.filter( ( obj, index, self ) =>
3766
- index === self.findIndex( ( o ) => o.storeId === obj.storeId && o.userEmail === obj.userEmail ),
3767
- );
3768
3776
  return res.sendSuccess( { count: uniqueArr.length, uniqueArr } );
3769
3777
  } catch ( e ) {
3770
3778
  logger.error( { functionName: 'checklistAssign', error: e } );
@@ -149,6 +149,7 @@ export const startValidation = {
149
149
  export const selectAssignSchema = joi.object( {
150
150
  clientId: joi.string().required(),
151
151
  coverage: joi.string().required(),
152
+ assignType: joi.string().required(),
152
153
  } );
153
154
 
154
155
  export const selectAssign = {