tango-app-api-task 3.2.1-beta-22 → 3.2.1-beta-25

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.2.1-beta-22",
3
+ "version": "3.2.1-beta-25",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -597,7 +597,7 @@ export async function userDetails( req, res ) {
597
597
  if ( ele?.clusterName ) {
598
598
  let clusterDetails = await clusterServices.findOneCluster( { _id: ele.assignId }, { stores: 1 } );
599
599
  if ( clusterDetails ) {
600
- let storeDetails = await storeService.find( { _id: { $in: clusterDetails.stores.map( ( item ) => item.store ) } } );
600
+ let storeDetails = await storeService.find( { _id: { $in: clusterDetails.stores.map( ( item ) => item.store ) }, status: 'active' } );
601
601
  storeDetails.forEach( ( item ) => {
602
602
  userDetails.push( {
603
603
  id: ele._id,
@@ -738,6 +738,7 @@ export async function taskConfig( req, res ) {
738
738
  checkListName: checklistDetails.checkListName,
739
739
  checklistId: checklistDetails._id,
740
740
  coverage: inputBody.coverage,
741
+ insert: true,
741
742
  };
742
743
  await assignUsers( data );
743
744
  } ) );
@@ -935,7 +936,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date,
935
936
  let clusterDetails = await clusterServices.findcluster( { _id: { $in: clusterList } } );
936
937
  if ( clusterDetails.length ) {
937
938
  let idList = clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) );
938
- let getStoreDetails = await storeService.find( { _id: { $in: idList } } );
939
+ let getStoreDetails = await storeService.find( { _id: { $in: idList }, status: 'active' } );
939
940
  if ( getStoreDetails.length ) {
940
941
  assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
941
942
  let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
@@ -3354,71 +3355,29 @@ export async function taskAssign( req, res ) {
3354
3355
  if ( !taskDetails ) {
3355
3356
  return res.sendError( 'No data found', 204 );
3356
3357
  }
3357
- let idList;
3358
- let assignList;
3359
- if ( req.body.coverage == 'store' ) {
3360
- let clusterDetails = await clusterServices.findcluster( { _id: { $in: req.body.idList } }, { stores: 1, clusterName: 1 } );
3361
- if ( clusterDetails.length ) {
3362
- let clusterList = clusterDetails.map( ( item ) => item._id.toString() );
3363
- idList = [
3364
- ...clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) ),
3365
- ...req.body.idList.filter( ( ele ) => !clusterList.includes( ele ) ),
3366
- ];
3367
- } else {
3368
- idList = req.body.idList;
3369
- }
3370
- let getStoreDetails = await storeService.find( { _id: { $in: idList } } );
3371
- if ( !getStoreDetails.length ) {
3372
- return res.sendError( 'No data found', 204 );
3373
- }
3374
- assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
3375
- let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
3376
- if ( !userDetails ) {
3377
- let data = {
3378
- clientId: store.clientId,
3379
- userName: store.spocDetails?.[0]?.name,
3380
- mobileNumber: store.spocDetails?.[0]?.phone || '',
3381
- email: store.spocDetails[0].email,
3382
- };
3383
- userDetails = await createUser( data );
3358
+ let assignList = [];
3359
+
3360
+ await Promise.all( req.body.idList.map( async ( data ) => {
3361
+ let assignedData = {
3362
+ ...data,
3363
+ clientId: req.body.clientId,
3364
+ checkListName: taskDetails.checkListName,
3365
+ checklistId: taskDetails._id,
3366
+ coverage: req.body.coverage,
3367
+ insert: false,
3368
+ };
3369
+ // console.log( assignedData, 'daterthj' );
3370
+ let uploadData = await assignUsers( assignedData );
3371
+ if ( uploadData ) {
3372
+ if ( Array.isArray( uploadData ) ) {
3373
+ assignList.push( ...uploadData );
3374
+ } else {
3375
+ assignList.push( uploadData );
3384
3376
  }
3385
- let data = {
3386
- store_id: store.storeId,
3387
- storeName: store.storeName,
3388
- userId: userDetails._id,
3389
- userName: userDetails.userName,
3390
- userEmail: userDetails.email,
3391
- userPhone: userDetails?.mobileNumber,
3392
- clusterName: clusterDetails?.clusterName,
3393
- };
3394
- return data;
3395
- } ) );
3396
- } else {
3397
- let teamDetails = await teamsServices.findteams( { _id: { $in: req.body.idList } }, { users: 1, teamName: 1 } );
3398
- if ( teamDetails.length ) {
3399
- let teamList = teamDetails.map( ( ele ) => ele._id.toString() );
3400
- idList = [
3401
- ...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ),
3402
- ...req.body.idList.filter( ( ele ) => !teamList.includes( ele._id ) ),
3403
- ];
3404
- } else {
3405
- idList = req.body.idList;
3406
3377
  }
3407
- let userDetails = await userService.find( { _id: { $in: idList } } );
3408
- if ( !userDetails.length ) {
3409
- return res.sendError( 'No data found', 204 );
3410
- }
3411
- assignList = [];
3412
- userDetails.forEach( ( user ) => {
3413
- assignList.push( {
3414
- userId: user._id,
3415
- userName: user.userName,
3416
- userEmail: user.email,
3417
- userPhone: user?.mobileNumber,
3418
- teamName: teamDetails?.teamName,
3419
- } );
3420
- } );
3421
- }
3378
+ } ) );
3379
+
3380
+
3422
3381
  return res.sendSuccess( { count: assignList.length, assignList } );
3423
3382
  } catch ( e ) {
3424
3383
  logger.error( { functionName: 'checklistAssign', error: e } );
@@ -3439,7 +3398,7 @@ async function assignUsers( data ) {
3439
3398
  {
3440
3399
  $match: {
3441
3400
  clientId: data.clientId,
3442
- ...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
3401
+ ...( !data?.clusterName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
3443
3402
  },
3444
3403
  },
3445
3404
  {
@@ -3451,7 +3410,7 @@ async function assignUsers( data ) {
3451
3410
  ];
3452
3411
  let clusterDetails = await clusterServices.aggregateCluster( query );
3453
3412
  if ( clusterDetails.length ) {
3454
- if ( !data.upload ) {
3413
+ if ( data.insert ) {
3455
3414
  assignedData = {
3456
3415
  checkFlag: true,
3457
3416
  checkListId: data.checklistId,
@@ -3463,13 +3422,13 @@ async function assignUsers( data ) {
3463
3422
  };
3464
3423
  } else {
3465
3424
  let clusterList = clusterDetails[0].stores.map( ( ele ) => ele.store );
3466
- let storeDetails = await storeService.find( { _id: clusterList } );
3425
+ let storeDetails = await storeService.find( { _id: { $in: clusterList }, status: 'active' } );
3467
3426
  assignedData = await Promise.all( storeDetails.map( async ( store ) => {
3468
3427
  let userDetails = await userService.findOne( { email: store.spocDetails?.[0]?.email, clientId: data.clientId } );
3469
- if ( !userDetails ) {
3428
+ if ( !userDetails && store?.spocDetails?.length ) {
3470
3429
  let userData = {
3471
3430
  userName: store.spocDetails?.[0]?.name,
3472
- email: store.spocDetails[0].email,
3431
+ email: store.spocDetails[0]?.email,
3473
3432
  mobileNumber: store.spocDetails?.[0]?.phone,
3474
3433
  clientId: data.clientId,
3475
3434
  };
@@ -3486,7 +3445,9 @@ async function assignUsers( data ) {
3486
3445
  client_id: data.clientId,
3487
3446
  assignId: data?.id || clusterDetails?.[0]?._id,
3488
3447
  coverage: 'store',
3489
- teamName: clusterDetails?.[0]?.clusterName,
3448
+ clusterName: clusterDetails?.[0]?.clusterName,
3449
+ storeId: store.storeId,
3450
+ storeName: store.storeName,
3490
3451
  };
3491
3452
  return userData;
3492
3453
  } ) );
@@ -3502,13 +3463,13 @@ async function assignUsers( data ) {
3502
3463
  {
3503
3464
  $match: {
3504
3465
  clientId: data.clientId,
3505
- ...( !data.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
3466
+ ...( !data.storeName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
3506
3467
  },
3507
3468
  },
3508
3469
  ];
3509
3470
  let storeDetails = await storeService.aggregate( query );
3510
3471
  if ( storeDetails.length ) {
3511
- let email = data?.upload ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
3472
+ let email = !data?.insert ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
3512
3473
  let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
3513
3474
  if ( !userDetails ) {
3514
3475
  let userData = {
@@ -3548,13 +3509,13 @@ async function assignUsers( data ) {
3548
3509
  {
3549
3510
  $match: {
3550
3511
  clientId: data.clientId,
3551
- ...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
3512
+ ...( !data?.teamName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
3552
3513
  },
3553
3514
  },
3554
3515
  ];
3555
3516
  let teamDetails = await teamsServices.aggregateTeams( query );
3556
3517
  if ( teamDetails.length ) {
3557
- if ( !data.upload ) {
3518
+ if ( data.insert ) {
3558
3519
  assignedData = {
3559
3520
  checkFlag: true,
3560
3521
  checkListId: data.checklistId,
@@ -3595,17 +3556,19 @@ async function assignUsers( data ) {
3595
3556
  {
3596
3557
  $match: {
3597
3558
  clientId: data.clientId,
3598
- ...( !data?.upload ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
3559
+ ...( !data?.userEmail ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
3599
3560
  },
3600
3561
  },
3601
3562
  ];
3563
+ // console.log( 'data?.userEmail=>', data.userEmail );
3602
3564
  let userDetails = await userService.aggregate( query );
3603
3565
  if ( !userDetails.length ) {
3604
3566
  let userData = {
3605
- userName: data.userEmail.split( '@' )[0],
3567
+ userName: data?.userEmail?.split( '@' )[0],
3606
3568
  email: data.userEmail,
3607
3569
  clientId: data.clientId,
3608
3570
  };
3571
+ // console.log( userData, 'userData', data );
3609
3572
  let details = await createUser( userData );
3610
3573
  userDetails = [ details ];
3611
3574
  }
@@ -3625,8 +3588,10 @@ async function assignUsers( data ) {
3625
3588
  }
3626
3589
  }
3627
3590
  }
3628
- if ( assignedData && !data.upload ) {
3629
- await taskAssignService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
3591
+
3592
+ // console.log( assignedData, 'test', data );
3593
+ if ( assignedData && !data.upload && data.insert ) {
3594
+ await assignedService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
3630
3595
  } else {
3631
3596
  return assignedData;
3632
3597
  }
@@ -3659,13 +3624,15 @@ export async function assignTaskUser( req, res ) {
3659
3624
  assign.clientId = inputBody.clientId;
3660
3625
  assign.upload = inputBody.type;
3661
3626
  let uploadData = await assignUsers( assign );
3662
- if ( Array.isArray( uploadData ) ) {
3663
- assignData.push( ...uploadData );
3664
- } else {
3665
- assignData.push( uploadData );
3627
+ if ( uploadData ) {
3628
+ if ( Array.isArray( uploadData ) ) {
3629
+ assignData.push( ...uploadData );
3630
+ } else {
3631
+ assignData.push( uploadData );
3632
+ }
3666
3633
  }
3667
3634
  } ) );
3668
- return res.sendSuccess( { idList: [ ...new Set( assignData.map( ( item ) => item.assignId ) ) ], assignData } );
3635
+ return res.sendSuccess( { idList: [ ...new Set( assignData.map( ( item ) => item?.assignId?.toString() ) ) ], assignData } );
3669
3636
  } catch ( e ) {
3670
3637
  logger.error( { functionName: 'assignTaskUser', error: e } );
3671
3638
  return res.sendError( e, 500 );