tango-app-api-store-builder 1.0.0-beta-133 → 1.0.0-beta-134

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-133",
3
+ "version": "1.0.0-beta-134",
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.169",
35
+ "tango-api-schema": "^2.2.173",
36
36
  "tango-app-api-middleware": "3.1.48",
37
37
  "url": "^0.11.4",
38
38
  "winston": "^3.17.0",
@@ -830,6 +830,7 @@ export async function updateGlobalComment( req, res ) {
830
830
  userId: req.user._id,
831
831
  userName: req.user.userName,
832
832
  comment: req.body.comment,
833
+ responsetype: req.body.responsetype,
833
834
  planoId: new mongoose.Types.ObjectId( req.body.planoId ),
834
835
  floorId: new mongoose.Types.ObjectId( req.body.floorId ),
835
836
  taskType: req.body.taskType,
@@ -242,7 +242,7 @@ export async function FixtureLibraryList( req, res ) {
242
242
  const matchStage = {
243
243
  clientId: req.body.clientId,
244
244
  ...( req.body?.searchValue ?
245
- { fixtureCategory: { $regex: req.body.searchValue, $options: 'i' } } :
245
+ { $or: [ { fixtureCategory: { $regex: req.body.searchValue, $options: 'i' } }, { fixtureCategorySize: { $regex: req.body.searchValue, $options: 'i' } } ] } :
246
246
  {} ),
247
247
  ...( req.body?.filter?.type?.length ?
248
248
  { fixtureType: { $in: req.body.filter.type } } :
@@ -253,6 +253,13 @@ export async function FixtureLibraryList( req, res ) {
253
253
  };
254
254
 
255
255
  const query = [
256
+ {
257
+ $addFields: {
258
+ fixtureCategorySize: {
259
+ $concat: [ '$fixtureCategory', ' - ', { $toString: '$fixtureWidth.value' }, { $toString: '$fixtureWidth.unit' } ],
260
+ },
261
+ },
262
+ },
256
263
  { $match: matchStage },
257
264
  {
258
265
  $lookup: {
@@ -284,6 +291,7 @@ export async function FixtureLibraryList( req, res ) {
284
291
  },
285
292
  {
286
293
  $project: {
294
+ fixtureCategorySize: 1,
287
295
  fixtureWidth: 1,
288
296
  fixtureHeight: 1,
289
297
  fixtureLength: 1,
@@ -3013,7 +3013,7 @@ export async function storeFixturesTaskv2( req, res ) {
3013
3013
  const compliance = await planoTaskComplianceService.findOne( {
3014
3014
  fixtureId: fixture._id,
3015
3015
  type: req.body?.type ? req.body.type : 'fixture',
3016
- }, { status: 1, answers: 1 } );
3016
+ }, { status: 1, answers: 1, taskType: 1 } );
3017
3017
 
3018
3018
  const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { }, { shelfNumber: 1 } );
3019
3019
 
@@ -3048,8 +3048,7 @@ export async function storeFixturesTaskv2( req, res ) {
3048
3048
  issue?.Details?.some( ( detail ) => detail.status === 'disagree' ),
3049
3049
  ),
3050
3050
  );
3051
-
3052
- if ( hasDisagree ) {
3051
+ if ( hasDisagree || compliance?.taskType == 'redo' ) {
3053
3052
  redoCount++;
3054
3053
  disabled = false;
3055
3054
  }
@@ -3108,7 +3107,7 @@ export async function storeFixturesTaskv2( req, res ) {
3108
3107
  const compliance = await planoTaskComplianceService.findOne( {
3109
3108
  fixtureId: fixture._id,
3110
3109
  type: req.body?.type ? req.body.type : 'fixture',
3111
- }, { status: 1 } );
3110
+ }, { status: 1, answers: 1, taskType: 1 } );
3112
3111
 
3113
3112
  const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { }, { shelfNumber: 1 } );
3114
3113
 
@@ -3143,7 +3142,7 @@ export async function storeFixturesTaskv2( req, res ) {
3143
3142
  ),
3144
3143
  );
3145
3144
 
3146
- if ( hasDisagree ) {
3145
+ if ( hasDisagree || compliance.taskType == 'redo' ) {
3147
3146
  redoCount++;
3148
3147
  disabled = false;
3149
3148
  }
@@ -3206,47 +3205,15 @@ export async function planoList( req, res ) {
3206
3205
  let limit = inputData?.limit || 10;
3207
3206
  let page = inputData?.offset - 1 || 0;
3208
3207
  let skip = limit * page;
3209
- let planoList = await planoService.find( { clientId: req.body.clientId }, { _id: 1 } );
3210
- let idList = planoList?.map( ( ele ) => new mongoose.Types.ObjectId( ele._id ) );
3211
- let taskQuery = [
3212
- {
3213
- $match: {
3214
- planoId: { $in: idList },
3215
- isPlano: true,
3216
- date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
3217
- },
3218
- },
3219
- {
3220
- $group: {
3221
- _id: { store: '$storeName', floorId: '$floorId', type: '$planoType' },
3222
- planoId: { $last: '$planoId' },
3223
- checklistStatus: { $last: '$checklistStatus' },
3224
- taskId: { $last: '$_id' },
3225
- },
3226
- },
3227
- {
3228
- $match: {
3229
- checklistStatus: 'submit',
3230
- },
3231
- },
3232
- {
3233
- $project: {
3234
- _id: 0,
3235
- type: '$_id.type',
3236
- planoId: 1,
3237
- checklistStatus: 1,
3238
- taskId: 1,
3239
- floorId: '$_id.floorId',
3240
- },
3241
- },
3242
- ];
3243
3208
 
3244
- let pendingDetails = await planotaskService.aggregate( taskQuery );
3245
- console.log( pendingDetails );
3209
+ let storeDetails = await storeService.find( { clientId: inputData.clientId, status: 'active' }, { storeId: 1 } );
3210
+ storeDetails = storeDetails.map( ( ele ) => ele.storeId );
3211
+
3246
3212
  let query = [
3247
3213
  {
3248
3214
  $match: {
3249
3215
  clientId: inputData.clientId,
3216
+ storeId: { $in: storeDetails },
3250
3217
  },
3251
3218
  },
3252
3219
  {
@@ -3354,7 +3321,7 @@ export async function planoList( req, res ) {
3354
3321
  $expr: {
3355
3322
  $and: [
3356
3323
  { $eq: [ '$planoId', '$$plano' ] },
3357
- { $in: [ '$taskId', pendingDetails.map( ( ele ) => ele.taskId ) ] },
3324
+ // { $in: [ '$taskId', pendingDetails.map( ( ele ) => ele.taskId ) ] },
3358
3325
  { $eq: [ '$taskType', 'initial' ] },
3359
3326
  ],
3360
3327
  },
@@ -3362,182 +3329,66 @@ export async function planoList( req, res ) {
3362
3329
  },
3363
3330
  { $sort: { _id: -1 } },
3364
3331
  {
3365
- $group: {
3366
- _id: '$floorId',
3367
- layoutCount: {
3368
- $sum: {
3369
- $cond: {
3370
- if: {
3371
- $and: [
3372
- { $eq: [ '$type', 'layout' ] },
3373
- ],
3332
+ $set: {
3333
+ hasPendingIssues: {
3334
+ $anyElementTrue: {
3335
+ $map: {
3336
+ input: {
3337
+ $reduce: {
3338
+ input: '$answers',
3339
+ initialValue: [],
3340
+ in: {
3341
+ $concatArrays: [
3342
+ '$$value',
3343
+ { $ifNull: [ '$$this.issues', [] ] },
3344
+ ],
3345
+ },
3346
+ },
3374
3347
  },
3375
- then: 1,
3376
- else: 0,
3348
+ as: 'issue',
3349
+ in: { $eq: [ '$$issue.status', 'pending' ] },
3377
3350
  },
3378
3351
  },
3379
3352
  },
3353
+ },
3354
+ },
3355
+ {
3356
+ $group: {
3357
+ _id: '$floorId',
3358
+ layoutCount: {
3359
+ $sum: { $cond: [ { $eq: [ '$type', 'layout' ] }, 1, 0 ] },
3360
+ },
3380
3361
  fixtureCount: {
3381
- $sum: {
3382
- $cond: {
3383
- if: {
3384
- $and: [
3385
- {
3386
- $eq: [ '$type', 'fixture' ],
3387
- },
3388
- ],
3389
- },
3390
- then: 1,
3391
- else: 0,
3392
- },
3393
- },
3362
+ $sum: { $cond: [ { $eq: [ '$type', 'fixture' ] }, 1, 0 ] },
3394
3363
  },
3395
3364
  vmCount: {
3396
- $sum: {
3397
- $cond: {
3398
- if: {
3399
- $and: [
3400
- { $eq: [ '$type', 'vm' ] },
3401
- ],
3402
- },
3403
- then: 1,
3404
- else: 0,
3405
- },
3406
- },
3365
+ $sum: { $cond: [ { $eq: [ '$type', 'vm' ] }, 1, 0 ] },
3407
3366
  },
3408
3367
  layoutPending: {
3409
3368
  $sum: {
3410
- $cond: {
3411
- if: {
3412
- $and: [
3413
- {
3414
- $eq: [ '$type', 'layout' ],
3415
- },
3416
- {
3417
- $anyElementTrue: {
3418
- $map: {
3419
- input: {
3420
- $reduce: {
3421
- input: '$answers',
3422
- initialValue: [],
3423
- in: {
3424
- $concatArrays: [
3425
- '$$value',
3426
- {
3427
- $ifNull: [
3428
- '$$this.issues',
3429
- [],
3430
- ],
3431
- },
3432
- ],
3433
- },
3434
- },
3435
- },
3436
- as: 'issue',
3437
- in: {
3438
- $eq: [
3439
- '$$issue.status',
3440
- 'pending',
3441
- ],
3442
- },
3443
- },
3444
- },
3445
- },
3446
- ],
3447
- },
3448
- then: 1,
3449
- else: 0,
3450
- },
3369
+ $cond: [
3370
+ { $and: [ { $eq: [ '$type', 'layout' ] }, '$hasPendingIssues' ] },
3371
+ 1,
3372
+ 0,
3373
+ ],
3451
3374
  },
3452
3375
  },
3453
3376
  fixturePending: {
3454
3377
  $sum: {
3455
- $cond: {
3456
- if: {
3457
- $and: [
3458
- {
3459
- $eq: [ '$type', 'fixture' ],
3460
- },
3461
- {
3462
- $anyElementTrue: {
3463
- $map: {
3464
- input: {
3465
- $reduce: {
3466
- input: '$answers',
3467
- initialValue: [],
3468
- in: {
3469
- $concatArrays: [
3470
- '$$value',
3471
- {
3472
- $ifNull: [
3473
- '$$this.issues',
3474
- [],
3475
- ],
3476
- },
3477
- ],
3478
- },
3479
- },
3480
- },
3481
- as: 'issue',
3482
- in: {
3483
- $eq: [
3484
- '$$issue.status',
3485
- 'pending',
3486
- ],
3487
- },
3488
- },
3489
- },
3490
- },
3491
- ],
3492
- },
3493
- then: 1,
3494
- else: 0,
3495
- },
3378
+ $cond: [
3379
+ { $and: [ { $eq: [ '$type', 'fixture' ] }, '$hasPendingIssues' ] },
3380
+ 1,
3381
+ 0,
3382
+ ],
3496
3383
  },
3497
3384
  },
3498
3385
  vmPending: {
3499
3386
  $sum: {
3500
- $cond: {
3501
- if: {
3502
- $and: [
3503
- {
3504
- $eq: [ '$type', 'vm' ],
3505
- },
3506
- {
3507
- $anyElementTrue: {
3508
- $map: {
3509
- input: {
3510
- $reduce: {
3511
- input: '$answers',
3512
- initialValue: [],
3513
- in: {
3514
- $concatArrays: [
3515
- '$$value',
3516
- {
3517
- $ifNull: [
3518
- '$$this.issues',
3519
- [],
3520
- ],
3521
- },
3522
- ],
3523
- },
3524
- },
3525
- },
3526
- as: 'issue',
3527
- in: {
3528
- $eq: [
3529
- '$$issue.status',
3530
- 'pending',
3531
- ],
3532
- },
3533
- },
3534
- },
3535
- },
3536
- ],
3537
- },
3538
- then: 1,
3539
- else: 0,
3540
- },
3387
+ $cond: [
3388
+ { $and: [ { $eq: [ '$type', 'vm' ] }, '$hasPendingIssues' ] },
3389
+ 1,
3390
+ 0,
3391
+ ],
3541
3392
  },
3542
3393
  },
3543
3394
  },
@@ -3765,6 +3616,7 @@ export async function planoList( req, res ) {
3765
3616
  } );
3766
3617
  }
3767
3618
 
3619
+
3768
3620
  query.push( {
3769
3621
  $facet: {
3770
3622
  data: [
@@ -3774,6 +3626,20 @@ export async function planoList( req, res ) {
3774
3626
  count: [
3775
3627
  { $count: 'total' },
3776
3628
  ],
3629
+ planoList: [
3630
+ {
3631
+ $group: {
3632
+ _id: '',
3633
+ idList: { $addToSet: '$_id' },
3634
+ },
3635
+ },
3636
+ {
3637
+ $project: {
3638
+ _id: 0,
3639
+ idList: 1,
3640
+ },
3641
+ },
3642
+ ],
3777
3643
  },
3778
3644
  } );
3779
3645
 
@@ -3783,149 +3649,100 @@ export async function planoList( req, res ) {
3783
3649
  return res.sendError( 'No data found', 204 );
3784
3650
  }
3785
3651
 
3786
- query = [
3652
+ let taskQuery = [
3653
+ {
3654
+ $match: {
3655
+ planoId: { $in: planoDetails?.[0]?.planoList?.[0]?.idList },
3656
+ isPlano: true,
3657
+ date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
3658
+ },
3659
+ },
3660
+ {
3661
+ $group: {
3662
+ _id: { store: '$storeName', floorId: '$floorId', type: '$planoType' },
3663
+ planoId: { $last: '$planoId' },
3664
+ checklistStatus: { $last: '$checklistStatus' },
3665
+ taskId: { $last: '$_id' },
3666
+ },
3667
+ },
3668
+ {
3669
+ $match: {
3670
+ checklistStatus: 'submit',
3671
+ },
3672
+ },
3673
+ {
3674
+ $project: {
3675
+ _id: 0,
3676
+ type: '$_id.type',
3677
+ planoId: 1,
3678
+ checklistStatus: 1,
3679
+ taskId: 1,
3680
+ floorId: '$_id.floorId',
3681
+ },
3682
+ },
3683
+ ];
3684
+
3685
+ let pendingDetails = await planotaskService.aggregate( taskQuery );
3686
+
3687
+ taskQuery = [
3787
3688
  {
3788
3689
  $match: {
3789
3690
  taskId: { $in: pendingDetails.map( ( ele ) => ele.taskId ) },
3790
3691
  taskType: 'initial',
3791
3692
  },
3792
3693
  },
3694
+ {
3695
+ $set: {
3696
+ hasPendingIssues: {
3697
+ $anyElementTrue: {
3698
+ $map: {
3699
+ input: {
3700
+ $reduce: {
3701
+ input: '$answers',
3702
+ initialValue: [],
3703
+ in: {
3704
+ $concatArrays: [
3705
+ '$$value',
3706
+ { $ifNull: [ '$$this.issues', [] ] },
3707
+ ],
3708
+ },
3709
+ },
3710
+ },
3711
+ as: 'issue',
3712
+ in: { $eq: [ '$$issue.status', 'pending' ] },
3713
+ },
3714
+ },
3715
+ },
3716
+ },
3717
+ },
3793
3718
  {
3794
3719
  $group: {
3795
3720
  _id: { type: '$type', planoId: '$planoId' },
3796
3721
  layoutPending: {
3797
3722
  $sum: {
3798
- $cond: {
3799
- if: {
3800
- $and: [
3801
- {
3802
- $eq: [ '$type', 'layout' ],
3803
- },
3804
- {
3805
- $anyElementTrue: {
3806
- $map: {
3807
- input: {
3808
- $reduce: {
3809
- input: '$answers',
3810
- initialValue: [],
3811
- in: {
3812
- $concatArrays: [
3813
- '$$value',
3814
- {
3815
- $ifNull: [
3816
- '$$this.issues',
3817
- [],
3818
- ],
3819
- },
3820
- ],
3821
- },
3822
- },
3823
- },
3824
- as: 'issue',
3825
- in: {
3826
- $eq: [
3827
- '$$issue.status',
3828
- 'pending',
3829
- ],
3830
- },
3831
- },
3832
- },
3833
- },
3834
- ],
3835
- },
3836
- then: 1,
3837
- else: 0,
3838
- },
3723
+ $cond: [
3724
+ { $and: [ { $eq: [ '$type', 'layout' ] }, '$hasPendingIssues' ] },
3725
+ 1,
3726
+ 0,
3727
+ ],
3839
3728
  },
3840
3729
  },
3841
3730
  fixturePending: {
3842
3731
  $sum: {
3843
- $cond: {
3844
- if: {
3845
- $and: [
3846
- {
3847
- $eq: [ '$type', 'fixture' ],
3848
- },
3849
- {
3850
- $anyElementTrue: {
3851
- $map: {
3852
- input: {
3853
- $reduce: {
3854
- input: '$answers',
3855
- initialValue: [],
3856
- in: {
3857
- $concatArrays: [
3858
- '$$value',
3859
- {
3860
- $ifNull: [
3861
- '$$this.issues',
3862
- [],
3863
- ],
3864
- },
3865
- ],
3866
- },
3867
- },
3868
- },
3869
- as: 'issue',
3870
- in: {
3871
- $eq: [
3872
- '$$issue.status',
3873
- 'pending',
3874
- ],
3875
- },
3876
- },
3877
- },
3878
- },
3879
- ],
3880
- },
3881
- then: 1,
3882
- else: 0,
3883
- },
3732
+ $cond: [
3733
+ { $and: [ { $eq: [ '$type', 'fixture' ] }, '$hasPendingIssues' ] },
3734
+ 1,
3735
+ 0,
3736
+ ],
3884
3737
  },
3885
3738
  },
3886
3739
  vmPending: {
3887
3740
  $sum: {
3888
- $cond: {
3889
- if: {
3890
- $and: [
3891
- {
3892
- $eq: [ '$type', 'vm' ],
3893
- },
3894
- {
3895
- $anyElementTrue: {
3896
- $map: {
3897
- input: {
3898
- $reduce: {
3899
- input: '$answers',
3900
- initialValue: [],
3901
- in: {
3902
- $concatArrays: [
3903
- '$$value',
3904
- {
3905
- $ifNull: [
3906
- '$$this.issues',
3907
- [],
3908
- ],
3909
- },
3910
- ],
3911
- },
3912
- },
3913
- },
3914
- as: 'issue',
3915
- in: {
3916
- $eq: [
3917
- '$$issue.status',
3918
- 'pending',
3919
- ],
3920
- },
3921
- },
3922
- },
3923
- },
3924
- ],
3925
- },
3926
- then: 1,
3927
- else: 0,
3928
- },
3741
+ $cond: [
3742
+ { $and: [ { $eq: [ '$type', 'vm' ] }, '$hasPendingIssues' ] },
3743
+ 1,
3744
+ 0,
3745
+ ],
3929
3746
  },
3930
3747
  },
3931
3748
  },
@@ -3976,11 +3793,10 @@ export async function planoList( req, res ) {
3976
3793
  let result = {
3977
3794
  data: planoDetails[0].data,
3978
3795
  count: planoDetails?.[0]?.count?.[0]?.total || 0,
3979
- pendingDetails: [ { ...pendingDetails?.[0], allStores: planoList?.length || 0 } ],
3796
+ pendingDetails: [ { ...pendingDetails?.[0], allStores: planoDetails?.[0]?.count?.[0]?.total || 0 } ],
3980
3797
  };
3981
3798
  return res.sendSuccess( result );
3982
3799
  } catch ( e ) {
3983
- console.log( e );
3984
3800
  logger.error( { functionName: 'planoList', error: e } );
3985
3801
  return res.sendError( e, 500 );
3986
3802
  }