tango-app-api-store-builder 1.0.0-beta-122 → 1.0.0-beta-124

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-store-builder",
3
- "version": "1.0.0-beta-122",
3
+ "version": "1.0.0-beta-124",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -32,7 +32,7 @@
32
32
  "path": "^0.12.7",
33
33
  "selenium-webdriver": "^4.31.0",
34
34
  "sharp": "^0.34.1",
35
- "tango-api-schema": "2.2.155",
35
+ "tango-api-schema": "2.2.160",
36
36
  "tango-app-api-middleware": "3.1.48",
37
37
  "url": "^0.11.4",
38
38
  "winston": "^3.17.0",
@@ -458,7 +458,7 @@ export async function updateFixtureStatus( req, res ) {
458
458
  comment: req.body.comments,
459
459
  };
460
460
  console.log( comments );
461
- // return;
461
+
462
462
  let updateResponse = await planoTaskService.updateOnefilters(
463
463
  { _id: new mongoose.Types.ObjectId( req.body._id ) },
464
464
  {
@@ -470,8 +470,29 @@ export async function updateFixtureStatus( req, res ) {
470
470
  { 'det._id': new mongoose.Types.ObjectId( req.body.DetailsId ) },
471
471
 
472
472
  ] );
473
+ if ( updateResponse&&updateResponse.answers.length>0 ) {
474
+ console.log( updateResponse.answers[0] );
475
+ let findissuse= updateResponse.answers[0].issues.filter( ( data ) => data._id==req.body.issueId );
476
+ console.log( findissuse );
477
+ let findDetails = findissuse[0].Details.filter( ( det ) => det.status==='agree' );
478
+ console.log( '======', findDetails.length );
479
+ if ( findissuse[0].Details.length=== findDetails.length ) {
480
+ await planoTaskService.updateOnefilters(
481
+ { _id: new mongoose.Types.ObjectId( req.body._id ) },
482
+ {
483
+ $set: { 'answers.$[ans].issues.$[iss].status': 'completed' },
484
+ },
485
+ [
486
+ { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
487
+ { 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
488
+
489
+
490
+ ] );
491
+ }
492
+ }
493
+
473
494
  if ( req.body.taskType==='layout' ) {
474
- let updatecomment = await planoTaskService.updateOnefilters(
495
+ await planoTaskService.updateOnefilters(
475
496
  { _id: new mongoose.Types.ObjectId( req.body._id ) },
476
497
  {
477
498
  $push: { 'answers.$[ans].issues.$[iss].Details.$[det].comments': comments },
@@ -482,9 +503,8 @@ export async function updateFixtureStatus( req, res ) {
482
503
  { 'det._id': new mongoose.Types.ObjectId( req.body.DetailsId ) },
483
504
 
484
505
  ] );
485
- console.log( updatecomment );
486
506
  } else {
487
- let updatecomment = await planoTaskService.updateOnefilters(
507
+ await planoTaskService.updateOnefilters(
488
508
  { _id: new mongoose.Types.ObjectId( req.body._id ) },
489
509
  {
490
510
  $push: { 'answers.$[ans].issues.$[iss].comments': comments },
@@ -493,9 +513,8 @@ export async function updateFixtureStatus( req, res ) {
493
513
  { 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
494
514
  { 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
495
515
  ] );
496
- console.log( updatecomment );
497
516
  }
498
- console.log( updateResponse );
517
+
499
518
 
500
519
  res.sendSuccess( 'updated successfully' );
501
520
  } catch ( e ) {
@@ -1326,8 +1326,10 @@ export async function getVmDetails( req, res ) {
1326
1326
  if ( !getVmDetails ) {
1327
1327
  return res.sendError( 'No data found', 204 );
1328
1328
  }
1329
- let templateDetails = await fixtureTemplateService.findOne( { 'vmConfig.vmId': { $in: req.query.vmId } } );
1330
- if ( templateDetails && getVmDetails.status != 'draft' ) {
1329
+ getVmDetails = getVmDetails.toObject();
1330
+ let templateDetails = await fixtureTemplateService.find( { 'vmConfig.vmId': { $in: req.query.vmId } } );
1331
+ if ( templateDetails.length && getVmDetails.status != 'draft' ) {
1332
+ getVmDetails.templateCount = templateDetails.length;
1331
1333
  getVmDetails.status = 'inactive';
1332
1334
  }
1333
1335
  let fixtureDetails = await storeFixtureService.find( { 'vmConfig.vmId': { $in: req.query.vmId } }, { planoId: 1 } );
@@ -2323,9 +2323,9 @@ export async function updateVmData( req, res ) {
2323
2323
 
2324
2324
  // import https from 'https';
2325
2325
  // async function scrapeCrest() {
2326
- // const storeIds = [ 'LKST494' ];
2326
+ // const storeIds = [ 'LKST3020' ];
2327
2327
  // const apiUrl = 'https://api.getcrest.ai/api/ms_shelfsensei/layout/';
2328
- // const bearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzQ5NzkxNzUzLCJpYXQiOjE3NDk3ODgxNTMsImp0aSI6IjhmNDY4MTY0NTY5NTQ0YTU4OWJjMDU2NmU0ZGE0ZjI3IiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.wHQ2RPML7Jr6yE0V0mNvIrtUT8mFrvp7sBBtH6bhlSc';
2328
+ // const bearerToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzUwMDU1OTMxLCJpYXQiOjE3NTAwNTIzMzEsImp0aSI6IjY5MGM1YTVhYjc3NDRlMmQ5YjlhMmZkYThhODM2MGYxIiwidXNlcl9pZCI6MTA4NSwiaWQiOjEwODUsImlzX21lZXNlZWtfYWNjb3VudCI6ZmFsc2UsImN1c3RvbWVyX2dyb3VwIjozOTgsImxpY2VuY2Vfc2NvcGVzIjpbeyJyZXNvdXJjZV9zZXQiOiJwcF9zZXQiLCJzY29wZV9yb2xlIjoiY29udHJpYnV0b3IifSx7InJlc291cmNlX3NldCI6ImRwX3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9LHsicmVzb3VyY2Vfc2V0IjoiZGZfc2V0Iiwic2NvcGVfcm9sZSI6ImNvbnRyaWJ1dG9yIn0seyJyZXNvdXJjZV9zZXQiOiJkZWZhdWx0X3NldCIsInNjb3BlX3JvbGUiOiJjb250cmlidXRvciJ9XX0.juirYxGNCsCe75vwgL2AR9_LeFsr8r4cJmEdygRZGO0';
2329
2329
  // const filePath = 'response.json';
2330
2330
  // let allResults = [];
2331
2331
 
@@ -8619,3 +8619,38 @@ export async function migrateCrestv1( req, res ) {
8619
8619
  // exportFixtureJsonToExcel( fixtures, 'output.xlsx' );
8620
8620
 
8621
8621
 
8622
+ // import { readFile, writeFile } from 'fs/promises';
8623
+
8624
+
8625
+ // try {
8626
+ // const raw = await readFile('response.json', 'utf-8');
8627
+ // const json = JSON.parse(raw);
8628
+
8629
+ // const resultArray = json;
8630
+ // const uniqueTypes = new Set();
8631
+
8632
+ // for (const obj of resultArray) {
8633
+ // for (const item of obj.data?.result) {
8634
+ // if (Array.isArray(item.fixtures)) {
8635
+ // for (const fixture of item.fixtures) {
8636
+ // console.log(fixture)
8637
+ // const { fixtureName } = fixture;
8638
+ // if (fixtureName) {
8639
+ // const parts = fixtureName.split(' - ');
8640
+ // if (parts.length >= 3) {
8641
+ // const type = parts.slice(2).join(' - ');
8642
+ // uniqueTypes.add(type);
8643
+ // }
8644
+ // }
8645
+ // }
8646
+ // }
8647
+ // }
8648
+
8649
+
8650
+ // }
8651
+
8652
+ // await writeFile('unique.json', JSON.stringify([...uniqueTypes], null, 2), 'utf-8');
8653
+
8654
+ // } catch (err) {
8655
+ // console.error('Error processing file:', err);
8656
+ // }
@@ -2983,6 +2983,7 @@ export async function storeFixturesTaskv2( req, res ) {
2983
2983
  let productCapacity = 0;
2984
2984
  let fixtureCount = 0;
2985
2985
  let totalVmCount = 0;
2986
+ let redoCount = 0;
2986
2987
  const layoutPolygonWithFixtures = await Promise.all(
2987
2988
  floor.layoutPolygon.map( async ( element ) => {
2988
2989
  const fixtures = await storeFixtureService.findAndSort( {
@@ -3045,6 +3046,7 @@ export async function storeFixturesTaskv2( req, res ) {
3045
3046
  if ( compliance?.status && compliance.status == 'incomplete' ) {
3046
3047
  let issueDetails = compliance?.answers?.[0]?.issues.find( ( ele ) => ele.status == 'disagree' );
3047
3048
  if ( issueDetails ) {
3049
+ redoCount ++;
3048
3050
  disabled = false;
3049
3051
  }
3050
3052
  }
@@ -3134,6 +3136,7 @@ export async function storeFixturesTaskv2( req, res ) {
3134
3136
  if ( compliance?.status && compliance.status == 'incomplete' ) {
3135
3137
  let issueDetails = compliance?.answers?.[0]?.issues.find( ( ele ) => ele.status == 'disagree' );
3136
3138
  if ( issueDetails ) {
3139
+ redoCount++;
3137
3140
  disabled = false;
3138
3141
  }
3139
3142
  }
@@ -3146,7 +3149,7 @@ export async function storeFixturesTaskv2( req, res ) {
3146
3149
  disabled: req?.body?.redo ? disabled : false,
3147
3150
  vmCount: vmCount,
3148
3151
  shelfConfig: shelfDetails,
3149
- vms: vmDetails,
3152
+ vmConfig: vmDetails,
3150
3153
  };
3151
3154
  } ),
3152
3155
  );
@@ -3163,6 +3166,7 @@ export async function storeFixturesTaskv2( req, res ) {
3163
3166
  return {
3164
3167
  ...floor.toObject(),
3165
3168
  fixtureCount: fixtureCount,
3169
+ redoCount: redoCount,
3166
3170
  vmCount: totalVmCount,
3167
3171
  layoutPolygon: layoutPolygonWithFixtures,
3168
3172
  centerFixture: centerFixturesWithStatus,
@@ -3267,28 +3271,43 @@ export async function planoList( req, res ) {
3267
3271
  _id: '$planoType',
3268
3272
  dateString: { $last: '$date_string' },
3269
3273
  checklistStatus: { $last: '$checklistStatus' },
3274
+ taskId: { $last: '$_id' },
3270
3275
  },
3271
3276
  },
3272
3277
  ],
3273
3278
  as: 'planoTask',
3274
3279
  },
3275
3280
  },
3281
+ {
3282
+ $addFields: {
3283
+ taskIds: {
3284
+ $map: {
3285
+ input: '$planoTask',
3286
+ as: 'task',
3287
+ in: '$$task.taskId',
3288
+ },
3289
+ },
3290
+ },
3291
+ },
3276
3292
  {
3277
3293
  $lookup: {
3278
3294
  from: 'planotaskcompliances',
3279
- let: { plano: '$_id' },
3295
+ let: { plano: '$_id', taskId: '$taskIds' },
3280
3296
  pipeline: [
3281
3297
  {
3282
3298
  $match: {
3283
3299
  $expr: {
3284
- $eq: [ '$planoId', '$$plano' ],
3300
+ $and: [
3301
+ { $eq: [ '$planoId', '$$plano' ] },
3302
+ { $in: [ '$taskId', '$$taskId' ] },
3303
+ ],
3285
3304
  },
3286
3305
  },
3287
3306
  },
3288
3307
  { $sort: { _id: -1 } },
3289
3308
  {
3290
3309
  $group: {
3291
- _id: { planoId: '$planoId', type: '$type' },
3310
+ _id: { type: '$type', planoId: '$planoId' },
3292
3311
  layoutCount: {
3293
3312
  $sum: {
3294
3313
  $cond: {
@@ -3572,6 +3591,7 @@ export async function planoList( req, res ) {
3572
3591
  },
3573
3592
  {
3574
3593
  $project: {
3594
+ storeId: 1,
3575
3595
  storeName: 1,
3576
3596
  layoutName: 1,
3577
3597
  layoutDetails: '$layout.layoutDetails',
@@ -3639,14 +3659,6 @@ export async function planoList( req, res ) {
3639
3659
 
3640
3660
  query.push( {
3641
3661
  $facet: {
3642
- planoList: [
3643
- {
3644
- $group: {
3645
- _id: '',
3646
- planoIds: { $addToSet: '$_id' },
3647
- },
3648
- },
3649
- ],
3650
3662
  data: [
3651
3663
  { $skip: skip },
3652
3664
  { $limit: limit },
@@ -3665,222 +3677,228 @@ export async function planoList( req, res ) {
3665
3677
 
3666
3678
  let planoList = await planoService.find( { clientId: req.body.clientId }, { _id: 1 } );
3667
3679
  let idList = planoList?.map( ( ele ) => new mongoose.Types.ObjectId( ele._id ) );
3668
- let planoTaskDetails = await planotaskService.find( { planoId: { $in: idList }, checklistStatus: 'submit' } );
3669
- idList = planoTaskDetails.map( ( ele ) => new mongoose.Types.ObjectId( ele.planoId ) );
3670
3680
  let taskQuery = [
3671
3681
  {
3672
3682
  $match: {
3673
3683
  planoId: { $in: idList },
3684
+ isPlano: true,
3685
+ date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
3686
+ },
3687
+ },
3688
+ {
3689
+ $group: {
3690
+ _id: { store: '$storeName', type: '$planoType' },
3691
+ planoId: { $last: '$planoId' },
3692
+ checklistStatus: { $last: '$checklistStatus' },
3693
+ taskId: { $last: '$_id' },
3694
+ },
3695
+ },
3696
+ {
3697
+ $match: {
3674
3698
  checklistStatus: 'submit',
3675
3699
  },
3676
3700
  },
3677
3701
  {
3678
- $lookup: {
3679
- from: 'planotaskcompliances',
3680
- let: { plano: '$planoId', type: '$planoType' },
3681
- pipeline: [
3682
- {
3683
- $match: {
3684
- $expr: {
3702
+ $project: {
3703
+ _id: 0,
3704
+ type: '$_id.type',
3705
+ planoId: 1,
3706
+ checklistStatus: 1,
3707
+ taskId: 1,
3708
+ },
3709
+ },
3710
+ ];
3711
+
3712
+ let pendingDetails = await planotaskService.aggregate( taskQuery );
3713
+ query = [
3714
+ {
3715
+ $match: {
3716
+ taskId: { $in: pendingDetails.map( ( ele ) => ele.taskId ) },
3717
+ },
3718
+ },
3719
+ {
3720
+ $group: {
3721
+ _id: { type: '$type', planoId: '$planoId' },
3722
+ layoutPending: {
3723
+ $sum: {
3724
+ $cond: {
3725
+ if: {
3685
3726
  $and: [
3686
- { $eq: [ '$planoId', '$$plano' ] },
3687
- { $eq: [ '$type', '$$type' ] },
3688
- ],
3689
- },
3690
- },
3691
- },
3692
- {
3693
- $group: {
3694
- _id: { planoId: '$planoId', type: '$type' },
3695
- layoutPending: {
3696
- $sum: {
3697
- $cond: {
3698
- if: {
3699
- $and: [
3700
- {
3701
- $eq: [ '$type', 'layout' ],
3702
- },
3703
- {
3704
- $anyElementTrue: {
3705
- $map: {
3706
- input: {
3707
- $reduce: {
3708
- input: '$answers',
3709
- initialValue: [],
3710
- in: {
3711
- $concatArrays: [
3712
- '$$value',
3713
- {
3714
- $ifNull: [
3715
- '$$this.issues',
3716
- [],
3717
- ],
3718
- },
3719
- ],
3720
- },
3727
+ {
3728
+ $eq: [ '$type', 'layout' ],
3729
+ },
3730
+ {
3731
+ $anyElementTrue: {
3732
+ $map: {
3733
+ input: {
3734
+ $reduce: {
3735
+ input: '$answers',
3736
+ initialValue: [],
3737
+ in: {
3738
+ $concatArrays: [
3739
+ '$$value',
3740
+ {
3741
+ $ifNull: [
3742
+ '$$this.issues',
3743
+ [],
3744
+ ],
3721
3745
  },
3722
- },
3723
- as: 'issue',
3724
- in: {
3725
- $eq: [
3726
- '$$issue.status',
3727
- 'pending',
3728
- ],
3729
- },
3746
+ ],
3730
3747
  },
3731
3748
  },
3732
3749
  },
3733
- ],
3750
+ as: 'issue',
3751
+ in: {
3752
+ $eq: [
3753
+ '$$issue.status',
3754
+ 'pending',
3755
+ ],
3756
+ },
3757
+ },
3734
3758
  },
3735
- then: 1,
3736
- else: 0,
3737
3759
  },
3738
- },
3760
+ ],
3739
3761
  },
3740
- fixturePending: {
3741
- $sum: {
3742
- $cond: {
3743
- if: {
3744
- $and: [
3745
- {
3746
- $eq: [ '$type', 'fixture' ],
3747
- },
3748
- {
3749
- $anyElementTrue: {
3750
- $map: {
3751
- input: {
3752
- $reduce: {
3753
- input: '$answers',
3754
- initialValue: [],
3755
- in: {
3756
- $concatArrays: [
3757
- '$$value',
3758
- {
3759
- $ifNull: [
3760
- '$$this.issues',
3761
- [],
3762
- ],
3763
- },
3764
- ],
3765
- },
3762
+ then: 1,
3763
+ else: 0,
3764
+ },
3765
+ },
3766
+ },
3767
+ fixturePending: {
3768
+ $sum: {
3769
+ $cond: {
3770
+ if: {
3771
+ $and: [
3772
+ {
3773
+ $eq: [ '$type', 'fixture' ],
3774
+ },
3775
+ {
3776
+ $anyElementTrue: {
3777
+ $map: {
3778
+ input: {
3779
+ $reduce: {
3780
+ input: '$answers',
3781
+ initialValue: [],
3782
+ in: {
3783
+ $concatArrays: [
3784
+ '$$value',
3785
+ {
3786
+ $ifNull: [
3787
+ '$$this.issues',
3788
+ [],
3789
+ ],
3766
3790
  },
3767
- },
3768
- as: 'issue',
3769
- in: {
3770
- $eq: [
3771
- '$$issue.status',
3772
- 'pending',
3773
- ],
3774
- },
3791
+ ],
3775
3792
  },
3776
3793
  },
3777
3794
  },
3778
- ],
3795
+ as: 'issue',
3796
+ in: {
3797
+ $eq: [
3798
+ '$$issue.status',
3799
+ 'pending',
3800
+ ],
3801
+ },
3802
+ },
3779
3803
  },
3780
- then: 1,
3781
- else: 0,
3782
3804
  },
3783
- },
3805
+ ],
3784
3806
  },
3785
- vmPending: {
3786
- $sum: {
3787
- $cond: {
3788
- if: {
3789
- $and: [
3790
- {
3791
- $eq: [ '$type', 'vm' ],
3792
- },
3793
- {
3794
- $anyElementTrue: {
3795
- $map: {
3796
- input: {
3797
- $reduce: {
3798
- input: '$answers',
3799
- initialValue: [],
3800
- in: {
3801
- $concatArrays: [
3802
- '$$value',
3803
- {
3804
- $ifNull: [
3805
- '$$this.issues',
3806
- [],
3807
- ],
3808
- },
3809
- ],
3810
- },
3807
+ then: 1,
3808
+ else: 0,
3809
+ },
3810
+ },
3811
+ },
3812
+ vmPending: {
3813
+ $sum: {
3814
+ $cond: {
3815
+ if: {
3816
+ $and: [
3817
+ {
3818
+ $eq: [ '$type', 'vm' ],
3819
+ },
3820
+ {
3821
+ $anyElementTrue: {
3822
+ $map: {
3823
+ input: {
3824
+ $reduce: {
3825
+ input: '$answers',
3826
+ initialValue: [],
3827
+ in: {
3828
+ $concatArrays: [
3829
+ '$$value',
3830
+ {
3831
+ $ifNull: [
3832
+ '$$this.issues',
3833
+ [],
3834
+ ],
3811
3835
  },
3812
- },
3813
- as: 'issue',
3814
- in: {
3815
- $eq: [
3816
- '$$issue.status',
3817
- 'pending',
3818
- ],
3819
- },
3836
+ ],
3820
3837
  },
3821
3838
  },
3822
3839
  },
3823
- ],
3840
+ as: 'issue',
3841
+ in: {
3842
+ $eq: [
3843
+ '$$issue.status',
3844
+ 'pending',
3845
+ ],
3846
+ },
3847
+ },
3824
3848
  },
3825
- then: 1,
3826
- else: 0,
3827
- },
3828
- },
3829
- },
3830
- },
3831
- },
3832
- {
3833
- $group: {
3834
- _id: 0,
3835
- layoutPending: {
3836
- $sum: { $cond: {
3837
- if: {
3838
- $gt: [ '$layoutPending', 0 ],
3839
- },
3840
- then: 1,
3841
- else: 0,
3842
- } },
3843
- },
3844
- fixturePending: {
3845
- $sum: { $cond: {
3846
- if: {
3847
- $gt: [ '$fixturePending', 0 ],
3848
- },
3849
- then: 1,
3850
- else: 0,
3851
- } },
3852
- },
3853
- vmPending: {
3854
- $sum: { $cond: {
3855
- if: {
3856
- $gt: [ '$vmPending', 0 ],
3857
3849
  },
3858
- then: 1,
3859
- else: 0,
3860
- } },
3850
+ ],
3861
3851
  },
3852
+ then: 1,
3853
+ else: 0,
3862
3854
  },
3863
3855
  },
3864
- ],
3865
- as: 'taskFeedback',
3856
+ },
3866
3857
  },
3867
3858
  },
3868
3859
  {
3869
- $project: {
3860
+ $group: {
3870
3861
  _id: 0,
3871
- taskFeedback: { $ifNull: [ { $arrayElemAt: [ '$taskFeedback', 0 ] }, [] ] },
3862
+ layoutPending: {
3863
+ $sum: { $cond: {
3864
+ if: {
3865
+ $gt: [ '$layoutPending', 0 ],
3866
+ },
3867
+ then: 1,
3868
+ else: 0,
3869
+ } },
3870
+ },
3871
+ fixturePending: {
3872
+ $sum: { $cond: {
3873
+ if: {
3874
+ $gt: [ '$fixturePending', 0 ],
3875
+ },
3876
+ then: 1,
3877
+ else: 0,
3878
+ } },
3879
+ },
3880
+ vmPending: {
3881
+ $sum: { $cond: {
3882
+ if: {
3883
+ $gt: [ '$vmPending', 0 ],
3884
+ },
3885
+ then: 1,
3886
+ else: 0,
3887
+ } },
3888
+ },
3872
3889
  },
3873
3890
  },
3874
3891
  {
3875
3892
  $project: {
3876
- layoutPending: '$taskFeedback.layoutPending',
3877
- fixturePending: '$taskFeedback.fixturePending',
3878
- vmPending: '$taskFeedback.vmPending',
3893
+ _id: 0,
3894
+ layoutPending: '$layoutPending',
3895
+ fixturePending: '$fixturePending',
3896
+ vmPending: '$vmPending',
3879
3897
  },
3880
3898
  },
3881
3899
  ];
3882
3900
 
3883
- let pendingDetails = await planotaskService.aggregate( taskQuery );
3901
+ pendingDetails = await planoTaskComplianceService.aggregate( query );
3884
3902
  let result = {
3885
3903
  data: planoDetails[0].data,
3886
3904
  count: planoDetails?.[0]?.count?.[0]?.total || 0,
@@ -14,6 +14,8 @@ import mongoose from 'mongoose';
14
14
  // const ObjectId = mongoose.Types.ObjectId;
15
15
  import * as floorService from '../service/storeBuilder.service.js';
16
16
  import * as planoStaticService from '../service/planoStaticData.service.js';
17
+ import * as assignService from '../service/assignService.service.js';
18
+
17
19
 
18
20
  dayjs.extend( timeZone );
19
21
 
@@ -110,157 +112,196 @@ async function createUser( data ) {
110
112
 
111
113
  export async function createTask( req, res ) {
112
114
  try {
113
- let taskDetails = await taskService.find( { isPlano: true, client_id: req.body.clientId, ...( req.body.checkListName )? { checkListName: req.body.checkListName } : {} } );
114
- let storeList = req.body.stores.map( ( ele ) => ele.store.toLowerCase() );
115
- let userDetails;
116
- if ( !taskDetails.length ) {
117
- return res.sendError( 'No data found', 204 );
118
- }
119
- let endDate;
120
115
  let scheduleEndTime = '11:59 PM';
121
- let taskConfig = await planoStaticService.findOne( { clientId: req.body.clientId, type: 'task' } );
122
- if ( taskConfig && !req.body?.endTime ) {
123
- scheduleEndTime = taskConfig?.dueTime || '11:59 PM';
124
- req.body.days = taskConfig?.dueDay || 1;
125
- req.body.geoFencing = taskConfig?.allowedStoreLocation || false;
126
- }
127
- if ( req.body?.endTime ) {
128
- scheduleEndTime = req.body.endTime;
129
- }
130
- endDate = dayjs().add( req.body.days, 'day' ).format( 'YYYY-MM-DD' );
131
- let userEmailList = [ ...new Set( req.body.stores.map( ( ele ) => ele.email ) ) ];
132
- for ( let mail of userEmailList ) {
133
- let query = [
134
- {
135
- $addFields: {
136
- emailLower: { $toLower: '$email' },
116
+ if ( req.body?.redo ) {
117
+ if ( !req.body.taskId ) {
118
+ return res.sendError( 'Task id is required', 400 );
119
+ }
120
+ let taskInfo = await processedService.findOne( { _id: req.body.taskId } );
121
+ if ( !taskInfo ) {
122
+ return res.sendError( 'No data found', 204 );
123
+ }
124
+ await processedService.updateOne( { _id: req.body.taskId }, { checklistStatus: 'open', redoStatus: true, date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ), scheduleStartTime_iso: dayjs.utc( '12:00 AM', 'hh:mm A' ).format(), scheduleEndTime_iso: dayjs.utc( scheduleEndTime, 'hh:mm A' ).format(), date_string: dayjs().format( 'YYYY-MM-DD' ) } );
125
+ return res.sendSuccess( 'Task redo triggered successfully' );
126
+ } else {
127
+ let taskDetails = await taskService.find( { isPlano: true, client_id: req.body.clientId, ...( req.body.checkListName )? { checkListName: req.body.checkListName } : {} } );
128
+ if ( !taskDetails.length ) {
129
+ return res.sendError( 'No data found', 204 );
130
+ }
131
+ let userDetails;
132
+ let storeList;
133
+ let endDate;
134
+ let taskConfig = await planoStaticService.findOne( { clientId: req.body.clientId, type: 'task' } );
135
+ req.body.days = req.body?.days || 7;
136
+ if ( taskConfig && !req.body?.endTime ) {
137
+ scheduleEndTime = taskConfig?.dueTime || '11:59 PM';
138
+ req.body.days = taskConfig?.dueDay || 1;
139
+ req.body.geoFencing = taskConfig?.allowedStoreLocation || false;
140
+ }
141
+ if ( req.body?.endTime ) {
142
+ scheduleEndTime = req.body.endTime;
143
+ }
144
+ endDate = dayjs().add( req.body.days, 'day' ).format( 'YYYY-MM-DD' );
145
+ endDate = `${endDate} ${scheduleEndTime}`;
146
+ if ( !req.body?.stores?.length ) {
147
+ let assignQuery = [
148
+ {
149
+ $addFields: {
150
+ store: { $toLower: '$storeName' },
151
+ },
137
152
  },
138
- },
139
- {
140
- $match: {
141
- clientId: req.body.clientId,
142
- emailLower: mail.toLowerCase(),
153
+ {
154
+ $match: {
155
+ client_id: req.body.clientId,
156
+ store: req.body.store.toLowerCase(),
157
+ },
143
158
  },
144
- },
145
- ];
146
- userDetails = await userService.aggregate( query );
147
- if ( !userDetails.length ) {
148
- let userData = {
149
- clientId: req.body.clientId,
150
- mobileNumber: '',
151
- email: mail,
152
- userName: mail.split( '@' )[0],
153
- };
154
- await createUser( userData );
159
+ ];
160
+ let getUserDetails = await assignService.aggregate( assignQuery );
161
+ if ( !getUserDetails.length ) {
162
+ return res.sendError( 'Email is required' );
163
+ }
164
+ req.body.stores = [
165
+ {
166
+ store: getUserDetails[0].storeName,
167
+ email: req.body?.email ? req.body.email : getUserDetails[0].userEmail,
168
+ },
169
+ ];
155
170
  }
156
- }
157
- endDate = `${endDate} ${scheduleEndTime}`;
158
- await Promise.all( taskDetails.map( async ( task ) => {
159
- let splitName = task?.checkListName.split( ' ' );
160
- splitName.pop();
161
- let data = {
162
- client_id: req.body.clientId,
163
- date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
164
- date_string: dayjs().format( 'YYYY-MM-DD' ),
165
- sourceCheckList_id: task._id,
166
- checkListName: task.checkListName,
167
- checkListId: task._id,
168
- scheduleStartTime: '12:00 AM',
169
- scheduleEndTime: scheduleEndTime,
170
- scheduleStartTime_iso: dayjs.utc( '12:00 AM', 'hh:mm A' ).format(),
171
- scheduleEndTime_iso: dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format(),
172
- allowedOverTime: false,
173
- allowedStoreLocation: req.body?.geoFencing || false,
174
- createdBy: task.createdBy,
175
- createdByName: task.createdByName,
176
- questionAnswers: [],
177
- isdeleted: false,
178
- questionCount: 0,
179
- storeCount: 0,
180
- locationCount: 0,
181
- checkListType: 'task',
182
- country: '',
183
- store_id: '',
184
- storeName: '',
185
- userId: '',
186
- userName: '',
187
- userEmail: '',
188
- checklistStatus: 'open',
189
- timeFlagStatus: true,
190
- timeFlag: 0,
191
- questionFlag: 0,
192
- mobileDetectionFlag: 0,
193
- storeOpenCloseFlag: 0,
194
- reinitiateStatus: false,
195
- markasread: false,
196
- uniformDetectionFlag: 0,
197
- scheduleRepeatedType: 'daily',
198
- approvalStatus: false,
199
- approvalEnable: false,
200
- redoStatus: false,
201
- isPlano: true,
202
- planoType: splitName.length == 1 ? splitName[0].toLowerCase() : splitName[0].toLowerCase() + splitName[2],
203
- };
204
- let query = [
205
- {
206
- $addFields: {
207
- store: { $toLower: '$storeName' },
171
+ storeList = req.body.stores.map( ( ele ) => ele.store.toLowerCase() );
172
+ let userEmailList = [ ...new Set( req.body.stores.map( ( ele ) => ele.email ) ) ];
173
+ for ( let mail of userEmailList ) {
174
+ let query = [
175
+ {
176
+ $addFields: {
177
+ emailLower: { $toLower: '$email' },
178
+ },
208
179
  },
209
- },
210
- {
211
- $match: {
180
+ {
181
+ $match: {
182
+ clientId: req.body.clientId,
183
+ emailLower: mail.toLowerCase(),
184
+ },
185
+ },
186
+ ];
187
+ userDetails = await userService.aggregate( query );
188
+ if ( !userDetails.length ) {
189
+ let userData = {
212
190
  clientId: req.body.clientId,
213
- store: { $in: storeList },
191
+ mobileNumber: '',
192
+ email: mail,
193
+ userName: mail.split( '@' )[0],
194
+ };
195
+ await createUser( userData );
196
+ }
197
+ }
198
+ await Promise.all( taskDetails.map( async ( task ) => {
199
+ let splitName = task?.checkListName.split( ' ' );
200
+ splitName.pop();
201
+ let data = {
202
+ client_id: req.body.clientId,
203
+ date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
204
+ date_string: dayjs().format( 'YYYY-MM-DD' ),
205
+ sourceCheckList_id: task._id,
206
+ checkListName: task.checkListName,
207
+ checkListId: task._id,
208
+ scheduleStartTime: '12:00 AM',
209
+ scheduleEndTime: scheduleEndTime,
210
+ scheduleStartTime_iso: dayjs.utc( '12:00 AM', 'hh:mm A' ).format(),
211
+ scheduleEndTime_iso: dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format(),
212
+ allowedOverTime: false,
213
+ allowedStoreLocation: req.body?.geoFencing || false,
214
+ createdBy: task.createdBy,
215
+ createdByName: task.createdByName,
216
+ questionAnswers: [],
217
+ isdeleted: false,
218
+ questionCount: 0,
219
+ storeCount: 0,
220
+ locationCount: 0,
221
+ checkListType: 'task',
222
+ country: '',
223
+ store_id: '',
224
+ storeName: '',
225
+ userId: '',
226
+ userName: '',
227
+ userEmail: '',
228
+ checklistStatus: 'open',
229
+ timeFlagStatus: true,
230
+ timeFlag: 0,
231
+ questionFlag: 0,
232
+ mobileDetectionFlag: 0,
233
+ storeOpenCloseFlag: 0,
234
+ reinitiateStatus: false,
235
+ markasread: false,
236
+ uniformDetectionFlag: 0,
237
+ scheduleRepeatedType: 'daily',
238
+ approvalStatus: false,
239
+ approvalEnable: false,
240
+ redoStatus: false,
241
+ isPlano: true,
242
+ planoType: splitName.length == 1 ? splitName[0].toLowerCase() : splitName[0].toLowerCase() + splitName[2],
243
+ };
244
+ let query = [
245
+ {
246
+ $addFields: {
247
+ store: { $toLower: '$storeName' },
248
+ },
214
249
  },
215
- },
216
- ];
217
-
218
- let storeDetails = await storeService.aggregate( query );
219
- await Promise.all( storeDetails.map( async ( store ) => {
220
- let getUserEmail = req.body.stores.find( ( ele ) => ele.store.toLowerCase() == store.storeName.toLowerCase() );
221
- let planoDetails = await planoService.findOne( { storeName: store.storeName } );
222
- if ( planoDetails ) {
223
- let floorDetails = await floorService.find( { planoId: planoDetails._id }, { _id: 1, floorName: 1 } );
224
- for ( let i=0; i<floorDetails.length; i++ ) {
225
- if ( getUserEmail ) {
226
- let query = [
227
- {
228
- $addFields: {
229
- emailLower: { $toLower: '$email' },
250
+ {
251
+ $match: {
252
+ clientId: req.body.clientId,
253
+ store: { $in: storeList },
254
+ },
255
+ },
256
+ ];
257
+
258
+ let storeDetails = await storeService.aggregate( query );
259
+ await Promise.all( storeDetails.map( async ( store ) => {
260
+ let getUserEmail = req.body.stores.find( ( ele ) => ele.store.toLowerCase() == store.storeName.toLowerCase() );
261
+ let planoDetails = await planoService.findOne( { storeName: store.storeName } );
262
+ if ( planoDetails ) {
263
+ let floorDetails = await floorService.find( { planoId: planoDetails._id }, { _id: 1, floorName: 1 } );
264
+ for ( let i=0; i<floorDetails.length; i++ ) {
265
+ if ( getUserEmail ) {
266
+ let query = [
267
+ {
268
+ $addFields: {
269
+ emailLower: { $toLower: '$email' },
270
+ },
230
271
  },
231
- },
232
- {
233
- $match: {
234
- clientId: req.body.clientId,
235
- emailLower: getUserEmail.email.toLowerCase(),
272
+ {
273
+ $match: {
274
+ clientId: req.body.clientId,
275
+ emailLower: getUserEmail.email.toLowerCase(),
276
+ },
236
277
  },
237
- },
238
- ];
239
- userDetails = await userService.aggregate( query );
240
- userDetails = userDetails[0];
241
- }
242
- let taskData = { ...data };
243
- if ( floorDetails.length > 1 ) {
244
- taskData.checkListName = taskData.checkListName +' - '+ floorDetails[i].floorName;
245
- }
246
- taskData.floorId = floorDetails[i]._id;
247
- taskData.store_id = store.storeId;
248
- taskData.storeName = store.storeName;
249
- taskData.userId = userDetails._id;
250
- taskData.userName = userDetails.userName;
251
- taskData.userEmail = userDetails.email;
252
- taskData.planoId = planoDetails?._id;
253
- for ( let i=0; i<req.body.days; i++ ) {
254
- let currDate = dayjs().add( i, 'day' );
255
- let insertData = { ...taskData, date_string: currDate.format( 'YYYY-MM-DD' ), date_iso: new Date( currDate.format( 'YYYY-MM-DD' ) ), scheduleStartTime_iso: dayjs.utc( `${currDate.format( 'YYYY-MM-DD' )} 12:00 AM`, 'YYYY-MM-DD hh:mm A' ).format() };
256
- await processedService.updateOne( { date_string: currDate.format( 'YYYY-MM-DD' ), store_id: insertData.store_id, userEmail: insertData.userEmail, planoId: insertData.planoId, sourceCheckList_id: task._id, ...( taskData?.floorId ) ? { floorId: taskData.floorId }:{} }, insertData );
278
+ ];
279
+ userDetails = await userService.aggregate( query );
280
+ userDetails = userDetails[0];
281
+ }
282
+ let taskData = { ...data };
283
+ if ( floorDetails.length > 1 ) {
284
+ taskData.checkListName = taskData.checkListName +' - '+ floorDetails[i].floorName;
285
+ }
286
+ taskData.floorId = floorDetails[i]._id;
287
+ taskData.store_id = store.storeId;
288
+ taskData.storeName = store.storeName;
289
+ taskData.userId = userDetails._id;
290
+ taskData.userName = userDetails.userName;
291
+ taskData.userEmail = userDetails.email;
292
+ taskData.planoId = planoDetails?._id;
293
+ for ( let i=0; i<req.body.days; i++ ) {
294
+ let currDate = dayjs().add( i, 'day' );
295
+ let insertData = { ...taskData, date_string: currDate.format( 'YYYY-MM-DD' ), date_iso: new Date( currDate.format( 'YYYY-MM-DD' ) ), scheduleStartTime_iso: dayjs.utc( `${currDate.format( 'YYYY-MM-DD' )} 12:00 AM`, 'YYYY-MM-DD hh:mm A' ).format() };
296
+ let response = await processedService.updateOne( { date_string: currDate.format( 'YYYY-MM-DD' ), store_id: insertData.store_id, userEmail: insertData.userEmail, planoId: insertData.planoId, sourceCheckList_id: task._id, ...( taskData?.floorId ) ? { floorId: taskData.floorId }:{} }, insertData );
297
+ console.log( response );
298
+ }
257
299
  }
258
300
  }
259
- }
301
+ } ) );
260
302
  } ) );
261
- } ) );
262
-
263
- return res.sendSuccess( 'Task created successfully' );
303
+ return res.sendSuccess( 'Task created successfully' );
304
+ }
264
305
  } catch ( e ) {
265
306
  console.log( e );
266
307
  logger.error( { functionName: 'createTask', error: e } );
@@ -744,7 +785,7 @@ export async function generatetaskDetails( req, res ) {
744
785
  planoId: { $last: '$planoId' },
745
786
  taskId: { $push: '$_id' },
746
787
  checklistStatus: { $last: '$checklistStatus' },
747
- date_string: { $push: '$date_string' },
788
+ date_string: { $last: '$date_string' },
748
789
  },
749
790
  },
750
791
  {
@@ -760,7 +801,6 @@ export async function generatetaskDetails( req, res ) {
760
801
  },
761
802
  ];
762
803
  let taskDetails = await processedService.aggregate( query );
763
- console.log( taskDetails.flatMap( ( ele ) => ele.taskId ) );
764
804
  // ...( req.body.store.length ) ? { storeName: { $in: req.body.store } } : {}, taskId: { $in: taskDetails.flatMap( ( ele ) => ele.taskId ) } },
765
805
  let processedTaskDetails = await planoTaskService.find( { date_string: { $gte: req.body.fromDate, $lte: req.body.toDate }, type: 'layout' }, { status: 1, planoId: 1, date_string: 1, _id: 0, taskId: 1 } );
766
806
  console.log( processedTaskDetails.length );
@@ -778,8 +818,7 @@ export async function generatetaskDetails( req, res ) {
778
818
  } ) );
779
819
 
780
820
  processedTaskDetails.forEach( ( item ) => {
781
- let taskIndex = taskDetails.findIndex( ( taskItem ) => taskItem.checklistStatus =='submit' && taskItem.date_string.includes( item.date_string ) && item.planoId.toString() == taskItem.planoId.toString() );
782
- console.log( taskIndex, 'index' );
821
+ let taskIndex = taskDetails.findIndex( ( taskItem ) => taskItem.checklistStatus =='submit' && taskItem.date_string == item.date_string && item.planoId.toString() == taskItem.planoId.toString() );
783
822
  if ( taskIndex != -1 ) {
784
823
  taskDetails[taskIndex].storeStatus = item.status == 'complete' ? 'yes' : 'No';
785
824
  }
@@ -790,13 +829,14 @@ export async function generatetaskDetails( req, res ) {
790
829
  } );
791
830
 
792
831
 
793
- let completeStore = taskDetails.filter( ( ele ) => ele.checklistStatus.includes( 'submit' ) );
832
+ let completeStore = taskDetails.filter( ( ele ) => ele.checklistStatus == 'submit' );
794
833
  completeStore = completeStore.reduce( ( acc, ele ) => {
795
834
  if ( !acc[ele.storeName] ) {
796
835
  acc[ele.storeName] = {
797
836
  storeName: ele.storeName,
798
837
  status: 'submit',
799
838
  storeStatus: ele.storeStatus,
839
+ date: ele.date_string,
800
840
  };
801
841
  }
802
842
  return acc;
@@ -805,15 +845,17 @@ export async function generatetaskDetails( req, res ) {
805
845
  completeStore = Object.values( completeStore );
806
846
 
807
847
  let completeStoreList =completeStore.map( ( item ) => item.storeName );
848
+ console.log( taskDetails );
808
849
 
809
- let incompleteStore = taskDetails.filter( ( ele ) => !ele.checklistStatus.includes( 'submit' ) );
850
+ let incompleteStore = taskDetails.filter( ( ele ) => ele.checklistStatus != 'submit' );
810
851
 
811
852
  incompleteStore = incompleteStore.reduce( ( acc, ele ) => {
812
853
  if ( !acc[ele.storeName] ) {
813
854
  acc[ele.storeName] = {
814
855
  storeName: ele.storeName,
815
- status: ele.checklistStatus[ele.checklistStatus.length - 1],
856
+ status: ele.checklistStatus,
816
857
  storeStatus: ele.storeStatus,
858
+ date: ele.date_string,
817
859
  };
818
860
  }
819
861
  return acc;
@@ -0,0 +1,7 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function aggregate( query = [] ) {
4
+ return await model.checklistassignconfigModel.aggregate( query );
5
+ }
6
+
7
+