tango-app-api-store-builder 1.0.0-beta-1 → 1.0.0-beta-3

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-1",
3
+ "version": "1.0.0-beta-3",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "joi": "^17.13.3",
24
24
  "mongodb": "^6.12.0",
25
25
  "nodemon": "^3.1.9",
26
- "tango-api-schema": "^2.2.23",
26
+ "tango-api-schema": "^2.2.27",
27
27
  "tango-app-api-middleware": "^3.1.48",
28
28
  "winston": "^3.17.0",
29
29
  "winston-daily-rotate-file": "^5.0.0"
@@ -6,6 +6,11 @@ import dayjs from 'dayjs';
6
6
  import customParseFormat from 'dayjs/plugin/customParseFormat.js';
7
7
  import utc from 'dayjs/plugin/utc.js';
8
8
  import mongoose from 'mongoose';
9
+ import * as storeFixtureService from '../service/storeFixture.service.js';
10
+ import * as fixtureShelfService from '../service/fixtureShelf.service.js';
11
+ import * as planoProductService from '../service/planoProduct.service.js';
12
+ import * as planoMappingService from '../service/planoMapping.service.js';
13
+ import * as planoComplianceService from '../service/planoCompliance.service.js';
9
14
  dayjs.extend( utc );
10
15
  dayjs.extend( customParseFormat );
11
16
 
@@ -371,13 +376,13 @@ export async function getStoreDetails( req, res ) {
371
376
 
372
377
  export async function storeList( req, res ) {
373
378
  try {
374
- let idList = req.body.id.map( ( item ) => new mongoose.Types.ObjectId );
379
+ let idList = req.body.id.map( ( item ) => new mongoose.Types.ObjectId( item ) );
375
380
  let query = { _id: { $in: req.body.id } };
376
- let getStoreList = await planoService.find( query );
377
- if ( !getStoreList ) {
381
+ let getPlanoDetails = await planoService.find( query );
382
+ if ( !getPlanoDetails ) {
378
383
  return res.sendError( 'No data found', 204 );
379
384
  }
380
- idList = getStoreList.map( ( item ) => new mongoose.Types.ObjectId( item._id ) );
385
+ idList = getPlanoDetails.map( ( item ) => new mongoose.Types.ObjectId( item._id ) );
381
386
  query = [
382
387
  {
383
388
  $match: {
@@ -403,11 +408,20 @@ export async function storeList( req, res ) {
403
408
  },
404
409
  { $sort: { createdAt: -1 } },
405
410
  ];
406
- getStoreList = await storeBuilderService.aggregate( query );
411
+ let getStoreList = await storeBuilderService.aggregate( query );
407
412
  if ( !getStoreList.length ) {
408
413
  return res.sendError( 'No data found', 204 );
409
414
  }
410
- return res.sendSuccess( getStoreList );
415
+ let fixtureDetails = await storeFixtureService.find( { planoId: { $in: idList } } );
416
+ for ( let layout of getStoreList ) {
417
+ for ( let floor of layout.floor ) {
418
+ for ( let polygon of floor.layoutPolygon ) {
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
+ polygon.fixture = polygonfixtureDetails;
421
+ }
422
+ }
423
+ }
424
+ return res.sendSuccess( { FloorDetails: getStoreList, productResolutionLevel: getPlanoDetails?.productResolutionLevel || '', productResolutionFilters: getPlanoDetails?.productResolutionFilters || [] } );
411
425
  } catch ( e ) {
412
426
  logger.error( { functionName: 'storeList', error: e, message: req.body } );
413
427
  return res.sendError( e, 500 );
@@ -486,4 +500,141 @@ export async function updateStatus( req, res ) {
486
500
  }
487
501
  }
488
502
 
503
+ export async function fixtureShelfProduct( req, res ) {
504
+ try {
505
+ if ( !req.body.fixtureId ) {
506
+ return res.sendError( 'Fixture id is required', 400 );
507
+ }
489
508
 
509
+ let fixtureDetails = await storeFixtureService.findOne( { _id: req.body.fixtureId } );
510
+ if ( !fixtureDetails ) {
511
+ return res.sendError( 'Fixture not found', 204 );
512
+ }
513
+ let planoDetails = await planoService.findOne( { _id: fixtureDetails.planoId } );
514
+ let shelfDetails = await fixtureShelfService.find( { fixtureId: req.body.fixtureId } );
515
+ let query;
516
+ switch ( planoDetails.productResolutionLevel ) {
517
+ case 'L1':
518
+ query = { floorId: fixtureDetails.floorId };
519
+ break;
520
+ default:
521
+ query = { floorId: fixtureDetails.floorId, fixtureId: req.body.fixtureId };
522
+ break;
523
+ }
524
+ let shelfList = [];
525
+ for ( let shelf of shelfDetails ) {
526
+ let data = { ...shelf._doc, products: [] };
527
+ let productMappingDetails = await planoMappingService.find( { shelfId: shelf._id } );
528
+ let productIdList = productMappingDetails.map( ( item ) => item.productId );
529
+ let productDetails = await planoProductService.find( { _id: productIdList } );
530
+ query = {
531
+ ...query,
532
+ ...(['L3','L4'].includes(planoDetails.productResolutionLevel)) ? {shelfId:shelf._id} : {},
533
+ productId: { $in: productIdList },
534
+ createdAt: { $gte: dayjs().startOf( 'day' ).format(), $lte: dayjs().endOf( 'day' ).format() },
535
+ };
536
+ let productComplianceDetails = await planoComplianceService.find( query );
537
+ let product = [];
538
+ productDetails.forEach( ( item ) => {
539
+ let data = { ...item._doc, status: 'missing' };
540
+ let findCompliance = productComplianceDetails.find( ( ele ) => {
541
+ if()
542
+ });
543
+ if ( findCompliance ) {
544
+ data.status = findCompliance.compliance;
545
+ }
546
+ product.push( data );
547
+ } );
548
+ data.products = product;
549
+ shelfList.push( data );
550
+ }
551
+ fixtureDetails = { ...fixtureDetails._doc, shelves: shelfList };
552
+ return res.sendSuccess( fixtureDetails );
553
+ } catch ( e ) {
554
+ logger.error( { functionName: 'fixtureShelfProduct', error: e } );
555
+ return res.sendError( e, 500 );
556
+ }
557
+ }
558
+
559
+ export async function scan( req, res ) {
560
+ try {
561
+ if ( !req.body.planoId ) {
562
+ return res.sendError( 'Plano id is required', 400 );
563
+ }
564
+ if ( !req.body.rfId ) {
565
+ return res.sendError( 'RFID is required', 400 );
566
+ }
567
+ let planoDetails = await planoService.findOne( { _id: req.body.planoId } );
568
+ if ( !planoDetails ) {
569
+ return res.sendError( 'No data found', 204 );
570
+ }
571
+ let productCheck= await planoMappingService.findOne( { rfId: req.body.rfId } );
572
+ if ( !productCheck ) {
573
+ return res.sendError( 'Product not found', 400 );
574
+ }
575
+ let query;
576
+ switch ( planoDetails.productResolutionLevel ) {
577
+ case 'L1':
578
+ if ( !req.body.floorId ) {
579
+ return res.sendError( 'Floor id is required', 400 );
580
+ }
581
+ query = { floorId: req.body.floorId };
582
+ break;
583
+ case 'L2':
584
+ if ( !req.body.floorId ) {
585
+ return res.sendError( 'Floor id is required', 400 );
586
+ }
587
+ if ( !req.body.fixtureId ) {
588
+ return res.sendError( 'Fixture id is required', 400 );
589
+ }
590
+ query = { floorId: req.body.floorId, fixtureId: req.body.fixtureId };
591
+ break;
592
+ case 'L3':
593
+ if ( !req.body.floorId ) {
594
+ return res.sendError( 'Floor id is required', 400 );
595
+ }
596
+ if ( !req.body.fixtureId ) {
597
+ return res.sendError( 'Fixture id is required', 400 );
598
+ }
599
+ if ( !req.body.shelfId ) {
600
+ return res.sendError( 'Shelf id is required', 400 );
601
+ }
602
+ query = { floorId: req.body.floorId, fixtureId: req.body.fixtureId, shelfId: req.body.shelfId };
603
+ break;
604
+ case 'L4':
605
+ if ( !req.body.floorId ) {
606
+ return res.sendError( 'Floor id is required', 400 );
607
+ }
608
+ if ( !req.body.fixtureId ) {
609
+ return res.sendError( 'Fixture id is required', 400 );
610
+ }
611
+ if ( !req.body.shelfId ) {
612
+ return res.sendError( 'Shelf id is required', 400 );
613
+ }
614
+ if ( !req.body.shelfPosition ) {
615
+ return res.sendError( 'Shelf position is required', 400 );
616
+ }
617
+ query = { floorId: req.body.floorId, fixtureId: req.body.fixtureId, shelfId: req.body.shelfId, shelfPosition: req.body.shelfPosition };
618
+ break;
619
+ default:
620
+ break;
621
+ }
622
+ query = { ...query, rfId: req.body.rfId };
623
+
624
+ let planoProductDetails = await planoMappingService.findOne( query );
625
+ let data = {
626
+ ...( 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 },
627
+ rfId: req.body.rfId,
628
+ compliance: !planoProductDetails ? 'misplaced' : 'proper',
629
+ };
630
+ delete data._id;
631
+ await planoComplianceService.create( data );
632
+ if ( !planoProductDetails ) {
633
+ return res.sendSuccess( false );
634
+ }
635
+ return res.sendSuccess( true );
636
+ } catch ( e ) {
637
+ logger.error( { functonName: 'scan', error: e } );
638
+ return res.sendError( e, 500 );
639
+ }
640
+ }
@@ -17,6 +17,8 @@ storeBuilderRouter
17
17
  .delete( '/deleteStoreLayout/:id', isAllowedSessionHandler, validate( validateDtos.deleteStoreLayout ), storeBuilderController.deleteStoreLayout )
18
18
  .post( '/removeFile', isAllowedSessionHandler, storeBuilderController.deleteFile )
19
19
  .post( '/deleteFloor', isAllowedSessionHandler, storeBuilderController.deleteFloor )
20
- .post( '/updateStatus', isAllowedSessionHandler, validate( validateDtos.updateStatus ), storeBuilderController.updateStatus );
20
+ .post( '/updateStatus', isAllowedSessionHandler, validate( validateDtos.updateStatus ), storeBuilderController.updateStatus )
21
+ .post( '/FixtureShelfDetails', isAllowedSessionHandler, storeBuilderController.fixtureShelfProduct )
22
+ .post( '/scan', isAllowedSessionHandler, storeBuilderController.scan );
21
23
 
22
24
 
@@ -0,0 +1,21 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function find( query={}, field={} ) {
4
+ return model.fixtureConfigModel.find( query, field );
5
+ }
6
+
7
+ export async function findOne( query={}, field={} ) {
8
+ return model.fixtureConfigModel.findOne( query, field );
9
+ }
10
+
11
+ export async function insertMany( data ) {
12
+ return model.fixtureConfigModel.insertMany( data );
13
+ }
14
+
15
+ export async function aggregate( query ) {
16
+ return model.fixtureConfigModel.aggregate( query );
17
+ }
18
+
19
+ export async function updateOne( query, record ) {
20
+ return model.fixtureConfigModel.updateOne( query, { $set: record } );
21
+ }
@@ -0,0 +1,21 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function find( query={}, field={} ) {
4
+ return model.fixtureShelfModel.find( query, field );
5
+ }
6
+
7
+ export async function findOne( query={}, field={} ) {
8
+ return model.fixtureShelfModel.findOne( query, field );
9
+ }
10
+
11
+ export async function insertMany( data ) {
12
+ return model.fixtureShelfModel.insertMany( data );
13
+ }
14
+
15
+ export async function aggregate( query ) {
16
+ return model.fixtureShelfModel.aggregate( query );
17
+ }
18
+
19
+ export async function updateOne( query, record ) {
20
+ return model.fixtureShelfModel.updateOne( query, { $set: record } );
21
+ }
@@ -0,0 +1,25 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function find( query={}, field={} ) {
4
+ return model.planoComplianceModel.find( query, field );
5
+ }
6
+
7
+ export async function findOne( query={}, field={} ) {
8
+ return model.planoComplianceModel.findOne( query, field );
9
+ }
10
+
11
+ export async function insertMany( data ) {
12
+ return model.planoComplianceModel.insertMany( data );
13
+ }
14
+
15
+ export async function create( data ) {
16
+ return model.planoComplianceModel.create( data );
17
+ }
18
+
19
+ export async function aggregate( query ) {
20
+ return model.planoComplianceModel.aggregate( query );
21
+ }
22
+
23
+ export async function updateOne( query, record ) {
24
+ return model.planoComplianceModel.updateOne( query, { $set: record } );
25
+ }
@@ -0,0 +1,20 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function find( query={}, field={} ) {
4
+ return model.planoMappingModel.find( query, field );
5
+ }
6
+ export async function findOne( query={}, field={} ) {
7
+ return model.planoMappingModel.findOne( query, field );
8
+ }
9
+
10
+ export async function insertMany( data ) {
11
+ return model.planoMappingModel.insertMany( data );
12
+ }
13
+
14
+ export async function aggregate( query ) {
15
+ return model.planoMappingModel.aggregate( query );
16
+ }
17
+
18
+ export async function updateOne( query, record ) {
19
+ return model.planoMappingModel.updateOne( query, { $set: record } );
20
+ }
@@ -0,0 +1,26 @@
1
+ import model from 'tango-api-schema';
2
+
3
+
4
+ export async function find( query={}, field={} ) {
5
+ return model.planoProductModel.find( query, field );
6
+ }
7
+
8
+
9
+ export async function findOne( query={}, field={} ) {
10
+ return model.planoProductModel.findOne( query, field );
11
+ }
12
+
13
+
14
+ export async function insertMany( data ) {
15
+ return model.planoProductModel.insertMany( data );
16
+ }
17
+
18
+
19
+ export async function aggregate( query ) {
20
+ return model.planoProductModel.aggregate( query );
21
+ }
22
+
23
+
24
+ export async function updateOne( query, record ) {
25
+ return model.planoProductModel.updateOne( query, { $set: record } );
26
+ }
@@ -0,0 +1,21 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export async function find( query={}, field={} ) {
4
+ return model.storeFixtureModel.find( query, field );
5
+ }
6
+
7
+ export async function findOne( query={}, field={} ) {
8
+ return model.storeFixtureModel.findOne( query, field );
9
+ }
10
+
11
+ export async function insertMany( data ) {
12
+ return model.storeFixtureModel.insertMany( data );
13
+ }
14
+
15
+ export async function aggregate( query ) {
16
+ return model.storeFixtureModel.aggregate( query );
17
+ }
18
+
19
+ export async function updateOne( query, record ) {
20
+ return model.storeFixtureModel.updateOne( query, { $set: record } );
21
+ }