tango-app-api-store-builder 1.0.0-beta-4 → 1.0.0-beta-5
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
|
@@ -417,8 +417,58 @@ export async function storeList( req, res ) {
|
|
|
417
417
|
for ( let floor of layout.floor ) {
|
|
418
418
|
for ( let polygon of floor.layoutPolygon ) {
|
|
419
419
|
let polygonfixtureDetails = fixtureDetails.filter( ( ele ) => layout.planoId.toString() == ele.planoId.toString() && ele.floorId.toString() == floor.id.toString() && ele.associatedElementType == polygon.elementType && ele.associatedElementNumber == polygon.elementNumber );
|
|
420
|
-
|
|
420
|
+
let fixtures = [];
|
|
421
|
+
for ( let fixture of polygonfixtureDetails ) {
|
|
422
|
+
let data = { ...fixture._doc, status: '' };
|
|
423
|
+
let query = [
|
|
424
|
+
{
|
|
425
|
+
$match: {
|
|
426
|
+
fixtureId: fixture._id,
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
$group: {
|
|
431
|
+
_id: '',
|
|
432
|
+
count: { $sum: '$shelfCapacity' },
|
|
433
|
+
fixtureId: { $first: '$fixtureId' },
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
$lookup: {
|
|
438
|
+
from: 'planocompliances',
|
|
439
|
+
let: { 'id': '$fixtureId' },
|
|
440
|
+
pipeline: [
|
|
441
|
+
{
|
|
442
|
+
$match: {
|
|
443
|
+
$expr: {
|
|
444
|
+
$and: [
|
|
445
|
+
{ createdAt: { $gte: dayjs().startOf( 'day' ).format(), $lte: dayjs().endOf( 'day' ).format() } },
|
|
446
|
+
{ $eq: [ '$fixtureId', '$$id' ] },
|
|
447
|
+
{ $eq: [ '$compliance', 'proper' ] },
|
|
448
|
+
],
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
$group: {
|
|
454
|
+
_id: '',
|
|
455
|
+
count: { $sum: 1 },
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
],
|
|
459
|
+
as: 'planoCompliance',
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
];
|
|
463
|
+
let fixtureDetails = await fixtureShelfService.aggregate( query );
|
|
464
|
+
if ( fixtureDetails.length ) {
|
|
465
|
+
data.status = fixtureDetails[0]?.planoCompliance?.length ? fixtureDetails[0].count == fixtureDetails[0]?.planoCompliance?.count ? 'complete' : 'incomplete' : '';
|
|
466
|
+
}
|
|
467
|
+
fixtures.push( data );
|
|
468
|
+
}
|
|
469
|
+
polygon.fixture = fixtures;
|
|
421
470
|
}
|
|
471
|
+
floor.centerFixture = fixtureDetails.filter( ( ele ) => layout.planoId.toString() == ele.planoId.toString() && ele.floorId.toString() == floor.id.toString() && ele.fixtureType == 'floor' );
|
|
422
472
|
}
|
|
423
473
|
}
|
|
424
474
|
return res.sendSuccess( { FloorDetails: getStoreList, productResolutionLevel: getPlanoDetails?.productResolutionLevel || '', productResolutionFilters: getPlanoDetails?.productResolutionFilters || [] } );
|
|
@@ -512,22 +562,13 @@ export async function fixtureShelfProduct( req, res ) {
|
|
|
512
562
|
}
|
|
513
563
|
let planoDetails = await planoService.findOne( { _id: fixtureDetails.planoId } );
|
|
514
564
|
let shelfDetails = await fixtureShelfService.find( { fixtureId: req.body.fixtureId } );
|
|
515
|
-
let shelfId = shelfDetails.map( ( ele ) => ele._id );
|
|
516
565
|
let query;
|
|
517
566
|
switch ( planoDetails.productResolutionLevel ) {
|
|
518
567
|
case 'L1':
|
|
519
568
|
query = { floorId: fixtureDetails.floorId };
|
|
520
569
|
break;
|
|
521
|
-
case 'L2':
|
|
522
|
-
query = { floorId: fixtureDetails.floorId, fixtureId: req.body.fixtureId };
|
|
523
|
-
break;
|
|
524
|
-
case 'L3':
|
|
525
|
-
query = { floorId: fixtureDetails.floorId, fixtureId: req.body.fixtureId, shelfId: { $in: shelfId } };
|
|
526
|
-
break;
|
|
527
|
-
case 'L4':
|
|
528
|
-
query = { floorId: fixtureDetails.floorId, fixtureId: req.body.fixtureId, shelfId: { $in: shelfId } };
|
|
529
|
-
break;
|
|
530
570
|
default:
|
|
571
|
+
query = { floorId: fixtureDetails.floorId, fixtureId: req.body.fixtureId };
|
|
531
572
|
break;
|
|
532
573
|
}
|
|
533
574
|
let shelfList = [];
|
|
@@ -536,11 +577,24 @@ export async function fixtureShelfProduct( req, res ) {
|
|
|
536
577
|
let productMappingDetails = await planoMappingService.find( { shelfId: shelf._id } );
|
|
537
578
|
let productIdList = productMappingDetails.map( ( item ) => item.productId );
|
|
538
579
|
let productDetails = await planoProductService.find( { _id: productIdList } );
|
|
539
|
-
|
|
580
|
+
query = {
|
|
581
|
+
...query,
|
|
582
|
+
...( [ 'L3', 'L4' ].includes( planoDetails.productResolutionLevel ) ) ? { shelfId: shelf._id } : {},
|
|
583
|
+
productId: { $in: productIdList },
|
|
584
|
+
createdAt: { $gte: dayjs().startOf( 'day' ).format(), $lte: dayjs().endOf( 'day' ).format() },
|
|
585
|
+
};
|
|
586
|
+
let productComplianceDetails = await planoComplianceService.find( query );
|
|
540
587
|
let product = [];
|
|
541
588
|
productDetails.forEach( ( item ) => {
|
|
542
589
|
let data = { ...item._doc, status: 'missing' };
|
|
543
|
-
let
|
|
590
|
+
let getPosition = productMappingDetails.find( ( ele ) => ele.productId.toString() == item._id.toString() );
|
|
591
|
+
let findCompliance = productComplianceDetails.find( ( ele ) => {
|
|
592
|
+
if ( planoDetails.productResolutionLevel == 'L4' && getPosition ) {
|
|
593
|
+
return ( item._id.toString() == ele.productId.toString() && ele.shelfPosition == getPosition.shelfPosition );
|
|
594
|
+
} else {
|
|
595
|
+
return ( item._id.toString() == ele.productId.toString() );
|
|
596
|
+
}
|
|
597
|
+
} );
|
|
544
598
|
if ( findCompliance ) {
|
|
545
599
|
data.status = findCompliance.compliance;
|
|
546
600
|
}
|
|
@@ -569,6 +623,23 @@ export async function scan( req, res ) {
|
|
|
569
623
|
if ( !planoDetails ) {
|
|
570
624
|
return res.sendError( 'No data found', 204 );
|
|
571
625
|
}
|
|
626
|
+
if ( ![ 'L1', 'L2' ].includes( planoDetails.productResolutionLevel ) ) {
|
|
627
|
+
if ( !req.body.shelfId ) {
|
|
628
|
+
let shelfDetails = await fixtureShelfService.findOne( { rfId: req.body.rfId } );
|
|
629
|
+
if ( !shelfDetails ) {
|
|
630
|
+
return res.sendError( 'Please scan shelf first', 400 );
|
|
631
|
+
}
|
|
632
|
+
return res.sendSuccess( shelfDetails._id );
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if ( planoDetails.productResolutionLevel == 'L5' ) {
|
|
636
|
+
let shelfDetails = await fixtureShelfService.findOne( { _id: req.body.shelfId } );
|
|
637
|
+
if ( !shelfDetails ) {
|
|
638
|
+
return res.sendError( 'No data found', 204 );
|
|
639
|
+
}
|
|
640
|
+
shelfDetails = await fixtureShelfService.find( { sectionName: shelfDetails?.sectionName } );
|
|
641
|
+
req.body.shelfId = shelfDetails.map( ( ele ) => ele._id );
|
|
642
|
+
}
|
|
572
643
|
let productCheck= await planoMappingService.findOne( { rfId: req.body.rfId } );
|
|
573
644
|
if ( !productCheck ) {
|
|
574
645
|
return res.sendError( 'Product not found', 400 );
|
|
@@ -617,7 +688,20 @@ export async function scan( req, res ) {
|
|
|
617
688
|
}
|
|
618
689
|
query = { floorId: req.body.floorId, fixtureId: req.body.fixtureId, shelfId: req.body.shelfId, shelfPosition: req.body.shelfPosition };
|
|
619
690
|
break;
|
|
691
|
+
case 'L5':
|
|
692
|
+
if ( !req.body.floorId ) {
|
|
693
|
+
return res.sendError( 'Floor id is required', 400 );
|
|
694
|
+
}
|
|
695
|
+
if ( !req.body.fixtureId ) {
|
|
696
|
+
return res.sendError( 'Fixture id is required', 400 );
|
|
697
|
+
}
|
|
698
|
+
if ( !req.body.shelfId ) {
|
|
699
|
+
return res.sendError( 'Shelf id is required', 400 );
|
|
700
|
+
}
|
|
701
|
+
query = { floorId: req.body.floorId, fixtureId: req.body.fixtureId, shelfId: { $in: req.body.shelfId } };
|
|
702
|
+
break;
|
|
620
703
|
default:
|
|
704
|
+
return res.sendError( 'Product not found', 400 );
|
|
621
705
|
break;
|
|
622
706
|
}
|
|
623
707
|
query = { ...query, rfId: req.body.rfId };
|
|
@@ -627,9 +711,11 @@ export async function scan( req, res ) {
|
|
|
627
711
|
...( planoProductDetails ) ? { ...planoProductDetails._doc } : { planoId: req.body?.planoId, floorId: req.body?.floorId, fixtureId: req.body?.fixtureId, shelfId: req.body?.shelfId, clientId: planoDetails.clientId, storeName: planoDetails.storeName, storeId: planoDetails.storeId, shelfPosition: req.body?.shelfPosition },
|
|
628
712
|
rfId: req.body.rfId,
|
|
629
713
|
compliance: !planoProductDetails ? 'misplaced' : 'proper',
|
|
714
|
+
date: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
630
715
|
};
|
|
631
716
|
delete data._id;
|
|
632
|
-
|
|
717
|
+
query = { ...query, date: new Date( dayjs().format( 'YYYY-MM-DD' ) ) };
|
|
718
|
+
await planoComplianceService.updateOne( query, data );
|
|
633
719
|
if ( !planoProductDetails ) {
|
|
634
720
|
return res.sendSuccess( false );
|
|
635
721
|
}
|
|
@@ -21,5 +21,9 @@ export async function aggregate( query ) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export async function updateOne( query, record ) {
|
|
24
|
-
return model.planoComplianceModel.updateOne( query, { $set: record } );
|
|
24
|
+
return model.planoComplianceModel.updateOne( query, { $set: record }, { upsert: true } );
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function count( data ) {
|
|
28
|
+
return model.planoComplianceModel.countDocuments( data );
|
|
25
29
|
}
|