tango-app-api-store-builder 1.0.0-beta-80 → 1.0.0-beta-82

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-80",
3
+ "version": "1.0.0-beta-82",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "jszip": "^3.10.1",
25
25
  "mongodb": "^6.12.0",
26
26
  "nodemon": "^3.1.9",
27
- "tango-api-schema": "^2.2.99",
27
+ "tango-api-schema": "^2.2.102",
28
28
  "tango-app-api-middleware": "^3.1.48",
29
29
  "winston": "^3.17.0",
30
30
  "winston-daily-rotate-file": "^5.0.0",
@@ -18,6 +18,7 @@ import JSZip from 'jszip';
18
18
  import { signedUrl } from 'tango-app-api-middleware';
19
19
  import fs from 'fs';
20
20
  import https from 'https';
21
+ import dayjs from 'dayjs';
21
22
 
22
23
 
23
24
  export async function getStoreNames( req, res ) {
@@ -3288,3 +3289,535 @@ export async function updateCrestVms( req, res ) {
3288
3289
  }
3289
3290
  }
3290
3291
 
3292
+ export async function updatePlanoFixtureLayout( planoId, floorId ) {
3293
+ try {
3294
+ console.log( 'dfghj' );
3295
+ const constantFixtureLength = 1220;
3296
+ const constantDetailedFixtureLength = 1220;
3297
+
3298
+ const constantFixtureWidth = 610;
3299
+ const constantDetailedFixtureWidth = 1524;
3300
+
3301
+ const mmToFeet = 305;
3302
+
3303
+ function roundToTwo( num ) {
3304
+ return Math.round( num * 100 ) / 100;
3305
+ }
3306
+
3307
+ const insertedPlano = await planoService.findOne( { _id: planoId } );
3308
+
3309
+ const planoDoc = insertedPlano.toObject();
3310
+
3311
+ const fixtureData = await storeFixtureService.findAndSort( { planoId: planoId, floorId: floorId }, {}, { fixtureNumber: 1 } );
3312
+ console.log( fixtureData, 'data' );
3313
+
3314
+ const leftFixtures = fixtureData.filter( ( fixture ) => fixture.associatedElementType == 'wall' && fixture.associatedElementNumber == 1 );
3315
+ const rightFixtures = fixtureData.filter( ( fixture ) => fixture.associatedElementType == 'wall' && fixture.associatedElementNumber == 3 );
3316
+ const backFixtures = fixtureData.filter( ( fixture ) => fixture.associatedElementType == 'wall' && fixture.associatedElementNumber == 2 );
3317
+ const floorFixtures = fixtureData.filter( ( fixture ) => fixture.fixtureType == 'floor' );
3318
+
3319
+ // console.log( leftFixtures, 'left' );
3320
+ // console.log( rightFixtures, 'rightFixtures' );
3321
+ // console.log( backFixtures, 'backFixtures' );
3322
+ // console.log( floorFixtures, 'floorFixtures' );
3323
+
3324
+ const leftXDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
3325
+ const leftXDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( leftFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
3326
+
3327
+ const leftYDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantFixtureWidth / mmToFeet ) ) ) : 0;
3328
+ const leftYDetailedDistanceFeet = leftFixtures.length ? roundToTwo( ( ( constantDetailedFixtureWidth / mmToFeet ) ) ) : 0;
3329
+
3330
+ const rightXDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantFixtureLength / mmToFeet ) ) ) : 0;
3331
+ const rightXDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( rightFixtures.length * ( constantDetailedFixtureLength / mmToFeet ) ) ) : 0;
3332
+
3333
+ const rightYDistanceFeet = rightFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
3334
+ const rightYDetailedDistanceFeet = rightFixtures.length ? roundToTwo( ( constantDetailedFixtureWidth / mmToFeet ) ): 0;
3335
+
3336
+ const maxFixturesPerRow = floorFixtures.length/2;
3337
+ const totalRows = 2;
3338
+
3339
+ const floorXDistanceFeet = floorFixtures.length ? roundToTwo( ( ( floorFixtures.length/2 ) * ( constantFixtureLength / mmToFeet ) ) ) : 0;
3340
+ const floorXDetailedDistanceFeet = floorFixtures.length ? roundToTwo( ( ( floorFixtures.length/2 ) * ( constantDetailedFixtureLength / mmToFeet ) ) ): 0;
3341
+
3342
+ const floorYDistanceFeet = floorFixtures.length ? roundToTwo( ( 2 * ( constantFixtureWidth/ mmToFeet ) ) ): 0;
3343
+ const floorYDetailedDistanceFeet = floorFixtures.length ? roundToTwo( 2 * ( constantDetailedFixtureWidth/mmToFeet ) ): 0;
3344
+
3345
+ const backXDistanceFeet = backFixtures.length ? roundToTwo( ( constantFixtureWidth / mmToFeet ) ) : 0;
3346
+ const backXDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( constantDetailedFixtureLength / mmToFeet ) ) : 0;
3347
+
3348
+ const backYDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantFixtureLength / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantFixtureWidth )/mmToFeet ) ) ) : 0;
3349
+ const backYDetailedDistanceFeet = backFixtures.length ? roundToTwo( ( ( backFixtures.length * ( constantDetailedFixtureWidth / mmToFeet ) ) + ( ( ( leftFixtures.length ? 1 : 0 ) + ( rightFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth )/mmToFeet ) ) ): 0;
3350
+
3351
+ const maxXDistance = Math.max( leftXDistanceFeet, rightXDistanceFeet, floorXDistanceFeet );
3352
+ const maxXDetailedDistance = Math.max( leftXDetailedDistanceFeet, rightXDetailedDistanceFeet, floorXDetailedDistanceFeet );
3353
+
3354
+ const maxYDistance = Math.max( floorYDistanceFeet, backYDistanceFeet );
3355
+ const maxYDetailedDistance = Math.max( floorYDetailedDistanceFeet, backYDetailedDistanceFeet );
3356
+
3357
+ const finalXDistance = roundToTwo( ( maxXDistance < ( backXDistanceFeet + floorXDistanceFeet )? ( ( backXDistanceFeet + floorXDistanceFeet ) + ( ( 2 * constantFixtureLength )/mmToFeet ) ) : ( floorFixtures.length && backFixtures.length ) ? ( maxXDistance + ( ( 2 * constantFixtureLength )/mmToFeet ) ) : maxXDistance ) );
3358
+ const finalXDetailedDistance = roundToTwo( ( maxXDetailedDistance < ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet )? ( ( backXDetailedDistanceFeet + floorXDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureLength )/mmToFeet ) ) : ( floorFixtures.length && backFixtures.length ) ? ( maxXDetailedDistance + ( ( 2 * constantDetailedFixtureLength )/mmToFeet ) ) : maxXDetailedDistance ) );
3359
+
3360
+ const finalYDistance = roundToTwo( ( maxYDistance < ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) ? ( ( leftYDistanceFeet + rightYDistanceFeet + floorYDistanceFeet ) + ( ( 2 * constantFixtureWidth )/mmToFeet ) ) : ( maxYDistance + ( ( constantFixtureWidth )/mmToFeet ) ) ) );
3361
+ const finalYDetailedDistance = roundToTwo( ( maxYDetailedDistance < ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) ? ( ( leftYDetailedDistanceFeet + rightYDetailedDistanceFeet + floorYDetailedDistanceFeet ) + ( ( 2 * constantDetailedFixtureWidth )/mmToFeet ) ) : ( maxYDetailedDistance + ( ( constantDetailedFixtureWidth )/mmToFeet ) ) ) );
3362
+
3363
+ const floorInsertData = {
3364
+ storeName: planoDoc.storeName,
3365
+ storeId: planoDoc.storeId,
3366
+ layoutName: `${planoDoc.storeName} - Layout`,
3367
+ clientId: '11',
3368
+ floorNumber: 1,
3369
+ floorName: 'floor 1',
3370
+ layoutPolygon: [
3371
+ {
3372
+ elementType: 'wall',
3373
+ distance: finalXDistance,
3374
+ unit: 'ft',
3375
+ direction: 'right',
3376
+ angle: 90,
3377
+ elementNumber: 1,
3378
+ detailedDistance: finalXDetailedDistance,
3379
+ },
3380
+ {
3381
+ elementType: 'wall',
3382
+ distance: finalYDistance,
3383
+ unit: 'ft',
3384
+ direction: 'down',
3385
+ angle: 90,
3386
+ elementNumber: 2,
3387
+ detailedDistance: finalYDetailedDistance,
3388
+ },
3389
+ {
3390
+ elementType: 'wall',
3391
+ distance: finalXDistance,
3392
+ unit: 'ft',
3393
+ direction: 'left',
3394
+ angle: 90,
3395
+ elementNumber: 3,
3396
+ detailedDistance: finalXDetailedDistance,
3397
+ },
3398
+ {
3399
+ elementType: 'wall',
3400
+ distance: roundToTwo( ( ( finalYDistance * 40 ) / 100 ) ),
3401
+ unit: 'ft',
3402
+ direction: 'up',
3403
+ angle: 90,
3404
+ elementNumber: 4,
3405
+ detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 35 ) / 100 ) ),
3406
+ },
3407
+ {
3408
+ elementType: 'entrance',
3409
+ distance: roundToTwo( ( ( finalYDistance * 20 ) / 100 ) ),
3410
+ unit: 'ft',
3411
+ direction: 'up',
3412
+ angle: 90,
3413
+ elementNumber: 1,
3414
+ detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 30 ) / 100 ) ),
3415
+ },
3416
+ {
3417
+ elementType: 'wall',
3418
+ distance: roundToTwo( ( ( finalYDistance * 40 ) / 100 ) ),
3419
+ unit: 'ft',
3420
+ direction: 'up',
3421
+ angle: 90,
3422
+ elementNumber: 5,
3423
+ detailedDistance: roundToTwo( ( ( finalYDetailedDistance * 35 ) / 100 ) ),
3424
+ },
3425
+ ],
3426
+ createdBy: new mongoose.Types.ObjectId( '66a78cd82734f4f857cd6db6' ),
3427
+ createdByName: 'Bejan',
3428
+ createdByEmail: 'bejan@tangotech.co.in',
3429
+ status: 'completed',
3430
+ planoId: planoDoc._id,
3431
+ };
3432
+
3433
+ await storeBuilderService.upsertOne( { planoId: planoDoc._id }, floorInsertData );
3434
+
3435
+ for ( let index = 0; index < leftFixtures.length; index++ ) {
3436
+ const fixture = leftFixtures[index];
3437
+
3438
+ const fixtureData = {
3439
+ 'fixtureHeight': {
3440
+ 'value': 0,
3441
+ 'unit': 'mm',
3442
+ },
3443
+ 'fixtureLength': {
3444
+ 'value': constantFixtureLength,
3445
+ 'unit': 'mm',
3446
+ },
3447
+ 'fixtureWidth': {
3448
+ 'value': constantFixtureWidth,
3449
+ 'unit': 'mm',
3450
+ },
3451
+ 'relativePosition': {
3452
+ 'x': roundToTwo( ( index * ( constantFixtureLength / mmToFeet ) ) ),
3453
+ 'y': 0,
3454
+ 'unit': 'ft',
3455
+ },
3456
+ 'detailedFixtureLength': {
3457
+ 'value': constantDetailedFixtureLength,
3458
+ 'unit': 'mm',
3459
+ },
3460
+ 'detailedFixtureWidth': {
3461
+ 'value': constantDetailedFixtureWidth,
3462
+ 'unit': 'mm',
3463
+ },
3464
+ 'relativeDetailedPosition': {
3465
+ 'x': roundToTwo( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
3466
+ 'y': 0,
3467
+ 'unit': 'ft',
3468
+ },
3469
+ };
3470
+
3471
+ await storeFixtureService.updateOne(
3472
+ {
3473
+ _id: fixture._id,
3474
+ },
3475
+ fixtureData );
3476
+ }
3477
+
3478
+ for ( let index = 0; index < backFixtures.length; index++ ) {
3479
+ const fixture = backFixtures[index];
3480
+
3481
+ const fixtureData = {
3482
+ 'fixtureHeight': {
3483
+ 'value': 0,
3484
+ 'unit': 'mm',
3485
+ },
3486
+ 'fixtureLength': {
3487
+ 'value': constantFixtureWidth,
3488
+ 'unit': 'mm',
3489
+ },
3490
+ 'fixtureWidth': {
3491
+ 'value': constantFixtureLength,
3492
+ 'unit': 'mm',
3493
+ },
3494
+ 'relativePosition': {
3495
+ 'x': roundToTwo( ( finalXDistance - ( constantFixtureWidth/mmToFeet ) ) ),
3496
+ 'y': roundToTwo( ( ( index * ( ( constantFixtureLength/mmToFeet ) ) ) + ( ( leftFixtures.length ? 1 : 0 ) * constantFixtureWidth/mmToFeet ) ) ),
3497
+ 'unit': 'ft',
3498
+ },
3499
+ 'detailedFixtureLength': {
3500
+ 'value': constantDetailedFixtureLength,
3501
+ 'unit': 'mm',
3502
+ },
3503
+ 'detailedFixtureWidth': {
3504
+ 'value': constantDetailedFixtureWidth,
3505
+ 'unit': 'mm',
3506
+ },
3507
+ 'relativeDetailedPosition': {
3508
+ 'x': roundToTwo( ( finalXDetailedDistance - ( constantDetailedFixtureLength/mmToFeet ) ) ),
3509
+ 'y': roundToTwo( ( ( index * ( ( constantDetailedFixtureWidth/mmToFeet ) ) ) + ( ( leftFixtures.length ? 1 : 0 ) * constantDetailedFixtureWidth/mmToFeet ) ) ),
3510
+ 'unit': 'ft',
3511
+ },
3512
+ };
3513
+
3514
+ await storeFixtureService.updateOne(
3515
+ {
3516
+ _id: fixture._id,
3517
+ },
3518
+ fixtureData );
3519
+ }
3520
+
3521
+ for ( let index = 0; index < rightFixtures.length; index++ ) {
3522
+ const fixture = rightFixtures[index];
3523
+
3524
+ const fixtureData = {
3525
+ 'fixtureHeight': {
3526
+ 'value': 0,
3527
+ 'unit': 'mm',
3528
+ },
3529
+ 'fixtureLength': {
3530
+ 'value': constantFixtureLength,
3531
+ 'unit': 'mm',
3532
+ },
3533
+ 'fixtureWidth': {
3534
+ 'value': constantFixtureWidth,
3535
+ 'unit': 'mm',
3536
+ },
3537
+ 'relativePosition': {
3538
+ 'x': roundToTwo( ( index * ( constantFixtureLength / mmToFeet ) ) ),
3539
+ 'y': roundToTwo( ( finalYDistance - ( constantFixtureWidth / mmToFeet ) ) ),
3540
+ 'unit': 'ft',
3541
+ },
3542
+ 'detailedFixtureLength': {
3543
+ 'value': constantDetailedFixtureLength,
3544
+ 'unit': 'mm',
3545
+ },
3546
+ 'detailedFixtureWidth': {
3547
+ 'value': constantDetailedFixtureWidth,
3548
+ 'unit': 'mm',
3549
+ },
3550
+ 'relativeDetailedPosition': {
3551
+ 'x': roundToTwo( ( index * ( constantDetailedFixtureLength / mmToFeet ) ) ),
3552
+ 'y': roundToTwo( ( finalYDetailedDistance - ( constantDetailedFixtureWidth / mmToFeet ) ) ),
3553
+ 'unit': 'ft',
3554
+ },
3555
+ };
3556
+
3557
+ await storeFixtureService.updateOne(
3558
+ {
3559
+ _id: fixture._id,
3560
+ },
3561
+ fixtureData );
3562
+ }
3563
+
3564
+ for ( let index = 0; index < floorFixtures.length; index++ ) {
3565
+ const fixture = floorFixtures[index];
3566
+ const centerRow = Math.floor( totalRows / 2 );
3567
+
3568
+ const startingX =roundToTwo( ( ( finalXDistance / 2 ) - ( ( maxFixturesPerRow / 2 ) * ( constantFixtureLength / mmToFeet ) ) ) );
3569
+ const detailedStartingX = roundToTwo( ( ( finalXDetailedDistance / 2 ) - ( ( maxFixturesPerRow / 2 ) * ( constantDetailedFixtureLength / mmToFeet ) ) ) );
3570
+
3571
+ const startingY = ( finalYDistance / 2 ) - ( centerRow * ( constantFixtureWidth / mmToFeet ) );
3572
+ const detailedStartingY = ( finalYDetailedDistance / 2 ) - ( centerRow * ( constantDetailedFixtureWidth / mmToFeet ) );
3573
+
3574
+ const colIndex = Math.floor( index / 2 );
3575
+ const rowIndex = index % 2 === 0 ? 1 : 0;
3576
+
3577
+
3578
+ const xPos = roundToTwo( ( startingX + colIndex * ( constantFixtureLength / mmToFeet ) ) );
3579
+ const yPos = roundToTwo( ( startingY + rowIndex * ( constantFixtureWidth / mmToFeet ) ) );
3580
+
3581
+ const detailedXPos = roundToTwo( ( detailedStartingX + colIndex * ( constantDetailedFixtureLength / mmToFeet ) ) );
3582
+ const detailedYPos = roundToTwo( ( detailedStartingY + rowIndex * ( constantDetailedFixtureWidth / mmToFeet ) ) );
3583
+
3584
+
3585
+ const fixtureData = {
3586
+ 'fixtureHeight': {
3587
+ 'value': 0,
3588
+ 'unit': 'mm',
3589
+ },
3590
+ 'fixtureLength': {
3591
+ 'value': constantFixtureLength,
3592
+ 'unit': 'mm',
3593
+ },
3594
+ 'fixtureWidth': {
3595
+ 'value': constantFixtureWidth,
3596
+ 'unit': 'mm',
3597
+ },
3598
+ 'relativePosition': {
3599
+ 'x': xPos,
3600
+ 'y': yPos,
3601
+ 'unit': 'ft',
3602
+ },
3603
+ 'detailedFixtureLength': {
3604
+ 'value': constantDetailedFixtureLength,
3605
+ 'unit': 'mm',
3606
+ },
3607
+ 'detailedFixtureWidth': {
3608
+ 'value': constantDetailedFixtureWidth,
3609
+ 'unit': 'mm',
3610
+ },
3611
+ 'relativeDetailedPosition': {
3612
+ 'x': detailedXPos,
3613
+ 'y': detailedYPos,
3614
+ 'unit': 'ft',
3615
+ },
3616
+ };
3617
+
3618
+ await storeFixtureService.updateOne(
3619
+ {
3620
+ _id: fixture._id,
3621
+ },
3622
+ fixtureData );
3623
+ }
3624
+ } catch ( e ) {
3625
+ logger.error( { functionName: 'createCrestPlanogram', error: e } );
3626
+ return res.sendError( e.message || 'Internal Server Error', 500 );
3627
+ }
3628
+ }
3629
+
3630
+ export async function updatelayout( req, res ) {
3631
+ try {
3632
+ let getLayoutTaskDetails = await planoTaskService.find( { date_string: dayjs().format( 'YYYY-MM-DD' ), status: 'incomplete', type: 'layout' } );
3633
+ if ( !getLayoutTaskDetails.length ) {
3634
+ return res.sendError( 'No data found', 204 );
3635
+ }
3636
+ for ( let layout of getLayoutTaskDetails ) {
3637
+ let layoutAnswer = layout.answers[1];
3638
+ let planoDetails = await planoService.findOne( { _id: layout.planoId } );
3639
+ let fixtureDetails = await storeFixtureService.find( { planoId: layout.planoId, floorId: layout.floorId } );
3640
+ if ( layoutAnswer?.extraFixture?.length ) {
3641
+ let deletedFixtureList = layoutAnswer.extraFixture.map( ( fixture ) => fixture.fixtureId );
3642
+ fixtureDetails = fixtureDetails.filter( ( fixture ) => !deletedFixtureList.includes( fixture._id.toString() ) );
3643
+ await storeFixtureService.deleteMany( { _id: { $in: deletedFixtureList } } );
3644
+ await fixtureShelfService.deleteMany( { fixtureId: { $in: deletedFixtureList } } );
3645
+ await planoMappingService.deleteMany( { fixtureId: { $in: deletedFixtureList } } );
3646
+ }
3647
+ if ( layoutAnswer?.wronglyLocatedFixtures?.length ) {
3648
+ layoutAnswer.wronglyLocatedFixtures.sort( ( a, b ) => a.position - b.position );
3649
+ let elementsGroup = layoutAnswer.wronglyLocatedFixtures.reduce( ( acc, ele ) => {
3650
+ ele.location = ele?.location == 'centre' ? 'floor' : ele.location;
3651
+ if ( !acc[ele?.location] ) {
3652
+ acc[ele.location] = [ ele ];
3653
+ } else {
3654
+ acc[ele.location].push( ele );
3655
+ }
3656
+ return acc;
3657
+ }, {} );
3658
+ Object.entries( elementsGroup ).forEach( async ( [ key, values ] ) => {
3659
+ let matchingFixtures = [];
3660
+ let maxFixtureNumber = 0;
3661
+ let elementType = '';
3662
+ let elementNumber = 0;
3663
+ if ( key != 'floor' ) {
3664
+ elementType = key.split( ' ' )[0];
3665
+ elementNumber = key.split( ' ' )[1];
3666
+ matchingFixtures = fixtureDetails.filter(
3667
+ ( elementFixture ) =>
3668
+ elementFixture.associatedElementType === elementType &&
3669
+ elementFixture.associatedElementNumber === parseInt( elementNumber ),
3670
+ );
3671
+ } else {
3672
+ matchingFixtures = fixtureDetails.filter(
3673
+ ( elementFixture ) =>
3674
+ elementFixture.fixtureType === 'floor',
3675
+ );
3676
+ }
3677
+ if ( matchingFixtures.length ) {
3678
+ maxFixtureNumber = Math.max(
3679
+ ...matchingFixtures.map( ( f ) => f.associatedElementFixtureNumber ),
3680
+ );
3681
+ }
3682
+ for ( let fixture of values ) {
3683
+ let fixtureIndex = fixtureDetails.findIndex( ( fix ) => fix._id.toString() == fixture.fixtureId.toString() );
3684
+ if ( fixtureIndex != -1 ) {
3685
+ let details = {
3686
+ ...fixtureDetails[fixtureIndex].toObject(),
3687
+ fixtureType: key != 'floor' ? 'wall' : 'floor',
3688
+ associatedElementType: elementType, associatedElementNumber: elementNumber,
3689
+ ...( key == 'floor' ) ? { header: '', footer: '' } : {},
3690
+ };
3691
+ fixtureDetails.splice( fixtureIndex, 1 );
3692
+ if ( maxFixtureNumber < parseInt( fixture.position ) ) {
3693
+ details.associatedElementFixtureNumber = maxFixtureNumber + 1;
3694
+ matchingFixtures.splice( maxFixtureNumber, 0, details );
3695
+ maxFixtureNumber = maxFixtureNumber + 1;
3696
+ } else {
3697
+ details.associatedElementFixtureNumber = parseInt( fixture.position );
3698
+ matchingFixtures.splice( parseInt( fixture.position ) - 1, 0, details );
3699
+ }
3700
+ }
3701
+ }
3702
+ let fixIdList = matchingFixtures.map( ( mixFixture ) => mixFixture._id.toString() );
3703
+ fixtureDetails = fixtureDetails.filter( ( fixt ) => !fixIdList.includes( fixt._id.toString() ) );
3704
+ fixtureDetails.push( ...matchingFixtures );
3705
+ } );
3706
+ }
3707
+ if ( layoutAnswer?.correctedFixture?.length ) {
3708
+ for ( let [ fixtureIndex, fixture ] of layoutAnswer.correctedFixture.entries() ) {
3709
+ const matchingFixtures = fixtureDetails.filter(
3710
+ ( elementFixture ) =>
3711
+ elementFixture.associatedElementType === fixture.alignment.split( ' ' )[0] &&
3712
+ elementFixture.associatedElementNumber === parseInt( fixture.alignment.split( ' ' )[1] ),
3713
+ );
3714
+ const maxFixtureNumber = Math.max(
3715
+ ...matchingFixtures.map( ( f ) => f.associatedElementFixtureNumber ),
3716
+ );
3717
+ const fixtureConfig = await fixtureConfigService.findOne( { fixtureCategory: fixture.fixtureType } );
3718
+ if ( fixtureConfig ) {
3719
+ const fixtureConfigDoc = fixtureConfig.toObject();
3720
+ const constantFixtureLength = 1220;
3721
+ const constantFixtureWidth = 610;
3722
+ const fixtureData = {
3723
+ 'clientId': planoDetails.clientId,
3724
+ 'storeName': planoDetails.storeName,
3725
+ 'storeId': planoDetails.storeId,
3726
+ 'planoId': layout.planoId,
3727
+ 'floorId': layout.floorId,
3728
+ 'fixtureName': `Fixture ${fixtureDetails.length + 1} - ${fixture.fixtureType}`,
3729
+ 'fixtureCategory': fixtureConfigDoc.fixtureConfigType,
3730
+ 'fixtureBrandCategory': fixture.fixtureCategory.length ? ( fixture.fixtureCategory.length > 1 ? fixture.fixtureCategory.join( ' + ' ) : fixture.fixtureCategory[0] ) : undefined,
3731
+ 'fixtureBrandSubCategory': fixture.fixtureCategory.length ? ( fixture.fixtureCategory.length > 1 ? fixture.fixtureCategory.join( ' + ' ) : fixture.fixtureCategory[0] ) : undefined,
3732
+ 'fixtureCode': fixtureConfigDoc?.fixtureCode,
3733
+ 'fixtureCapacity': fixtureConfigDoc?.fixtureCapacity,
3734
+ 'fixtureType': fixture.alignment != 'centre' ? 'wall' : 'floor',
3735
+ 'fixtureHeight': {
3736
+ 'value': 0,
3737
+ 'unit': 'mm',
3738
+ },
3739
+ 'fixtureLength': {
3740
+ 'value': constantFixtureLength,
3741
+ 'unit': 'mm',
3742
+ },
3743
+ 'fixtureWidth': {
3744
+ 'value': constantFixtureWidth,
3745
+ 'unit': 'mm',
3746
+ },
3747
+ ...( fixture.alignment != 'centre' ) ? { 'associatedElementType': fixture.alignment.split( ' ' )[0] } :{},
3748
+ ...( fixture.alignment != 'centre' ) ? { 'associatedElementNumber': fixture.alignment.split( ' ' )[1] } :{},
3749
+ 'fixtureNumber': fixtureDetails.length + 1,
3750
+ 'productResolutionLevel': 'L2',
3751
+ 'associatedElementFixtureNumber': maxFixtureNumber + 1,
3752
+ ...( fixture.alignment != 'centre' ) ? { 'header': fixture.fixtureCategory.length ? ( fixture.fixtureCategory.length > 1 ? fixture.fixtureCategory.join( ' + ' ) : fixture.fixtureCategory[0] ) : undefined } : {},
3753
+ ...( fixture.alignment != 'centre' ) ? { 'footer': 'Storage Box' } : {},
3754
+ 'fixtureConfigId': fixtureConfigDoc._id,
3755
+ };
3756
+
3757
+ let fixtureDoc = await storeFixtureService.create( fixtureData );
3758
+ if ( fixtureDoc ) {
3759
+ let productCount = 0;
3760
+ fixtureDetails.splice( parseInt( fixture.position ) - 1, 0, JSON.parse( JSON.stringify( fixtureDoc ) ) );
3761
+ let shelfDetails = layoutAnswer.shlef[fixtureIndex];
3762
+ for ( let i=0; i<shelfDetails.count; i++ ) {
3763
+ const insertData = {
3764
+ 'clientId': planoDetails.clientId,
3765
+ 'storeName': planoDetails.storeName,
3766
+ 'storeId': planoDetails.storeId,
3767
+ 'planoId': planoDetails._id,
3768
+ 'floorId': layout.floorId,
3769
+ 'fixtureId': fixtureDoc._id,
3770
+ 'shelfNumber': i + 1,
3771
+ 'shelfOrder': 'LTR',
3772
+ 'shelfCapacity': shelfDetails.values.value[i],
3773
+ 'sectionName': shelfDetails.values.subCategory[i].length ? ( shelfDetails.values.subCategory[i].length > 1 ? shelfDetails.values.subCategory[i].join( ' + ' ) : shelfDetails.values.subCategory[i][0] ) : undefined,
3774
+ 'sectionZone': shelfDetails.values.section[i],
3775
+ };
3776
+ productCount = productCount + insertData.shelfCapacity;
3777
+ await fixtureShelfService.create( insertData );
3778
+ }
3779
+ await storeFixtureService.updateOne( { _id: fixtureDoc._id }, { fixtureCapacity: productCount } );
3780
+ }
3781
+ }
3782
+ }
3783
+ }
3784
+ let groupElements = fixtureDetails.reduce( ( acc, ele ) => {
3785
+ let elementDetails = ele?.associatedElementType ? ele?.associatedElementType +' '+ ele?.associatedElementNumber : 'floor';
3786
+ if ( !acc[elementDetails] ) {
3787
+ acc[elementDetails] = [ ele ];
3788
+ } else {
3789
+ acc[elementDetails].push( ele );
3790
+ }
3791
+ return acc;
3792
+ }, {} );
3793
+ let fixtureNumber = 0;
3794
+ for ( const [ key, values ] of Object.entries( groupElements ) ) {
3795
+ for ( let elementIndex = 0; elementIndex < values.length; elementIndex++ ) {
3796
+ const element = values[elementIndex];
3797
+
3798
+ let name = element.fixtureName.split( ' ' );
3799
+ name[1] = elementIndex + 1;
3800
+
3801
+ const data = {
3802
+ fixtureNumber: ++fixtureNumber,
3803
+ associatedElementFixtureNumber: elementIndex + 1,
3804
+ fixtureName: name.join( ' ' ),
3805
+ associatedElementType: element.associatedElementType,
3806
+ associatedElementNumber: element.associatedElementNumber,
3807
+ fixtureType: element.fixtureType,
3808
+ header: element.header,
3809
+ footer: element.footer,
3810
+ };
3811
+
3812
+ await storeFixtureService.updateOne( { _id: element._id }, data );
3813
+ }
3814
+ }
3815
+ await updatePlanoFixtureLayout( layout.planoId, layout.floorId );
3816
+ }
3817
+ return res.sendSuccess( 'Layout updated sucessfully' );
3818
+ } catch ( e ) {
3819
+ logger.error( { functionName: 'updatelayout', error: e } );
3820
+ return res.sendError( e, 500 );
3821
+ }
3822
+ }
3823
+
@@ -559,7 +559,7 @@ export async function storeFixturesv1( req, res ) {
559
559
  { storeId: { $in: req.body.id } },
560
560
  ],
561
561
  },
562
- { storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1, clientId: 1 },
562
+ { storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1, clientId: 1, validateShelfSections: 1 },
563
563
  );
564
564
 
565
565
  if ( !planograms?.length ) return res.sendError( 'No data found', 204 );
@@ -2005,7 +2005,7 @@ export async function storeFixturesTask( req, res ) {
2005
2005
  { storeId: { $in: req.body.id } },
2006
2006
  ],
2007
2007
  },
2008
- { storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1 },
2008
+ { storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1, validateShelfSections: 1 },
2009
2009
  );
2010
2010
 
2011
2011
  if ( !planograms?.length ) return res.sendError( 'No data found', 204 );
@@ -2864,4 +2864,3 @@ export async function storeLayoutElements( req, res ) {
2864
2864
  return res.sendError( e, 500 );
2865
2865
  }
2866
2866
  }
2867
-
@@ -596,7 +596,7 @@ export async function getFixtureDetails( req, res ) {
596
596
 
597
597
  export async function getVmDetails( req, res ) {
598
598
  try {
599
- let getVms = await planoProductService.find( { type: 'vm' }, { productName: 1 } );
599
+ let getVms = await planoProductService.find( { type: 'vm', productName: { $ne: ' ' } }, { productName: 1 } );
600
600
  if ( !getVms.length ) {
601
601
  return res.sendError( 'No data found', 204 );
602
602
  }
@@ -23,4 +23,5 @@ scriptRouter
23
23
  .post( '/getVmTaskData', scriptController.getVmTaskData )
24
24
  .post( '/updateVmData', scriptController.updateVmData )
25
25
  .post( '/createCrestPlanogram', scriptController.createCrestPlanogram )
26
+ .post( '/updatelayout', scriptController.updatelayout )
26
27
  .post( '/updateCrestVms', scriptController.updateCrestVms );
@@ -15,6 +15,10 @@ export async function insertMany( data ) {
15
15
  return model.planoProductModel.insertMany( data );
16
16
  }
17
17
 
18
+ export async function deleteMany( data ) {
19
+ return model.planoProductModel.deleteMany( data );
20
+ }
21
+
18
22
 
19
23
  export async function aggregate( query ) {
20
24
  return model.planoProductModel.aggregate( query );
@@ -36,6 +36,10 @@ export async function deleteOne( query ) {
36
36
  return model.storeFixtureModel.deleteOne( query );
37
37
  }
38
38
 
39
+ export async function deleteMany( query ) {
40
+ return model.storeFixtureModel.deleteMany( query );
41
+ }
42
+
39
43
  export async function findAndSort( query={}, field={}, sortField={} ) {
40
44
  return model.storeFixtureModel.find( query, field ).sort( sortField );
41
45
  }