tango-app-api-store-builder 1.0.0-beta-72 → 1.0.0-beta-74

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-72",
3
+ "version": "1.0.0-beta-74",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1967,7 +1967,122 @@ export async function updateFixtureFeedback( req, res ) {
1967
1967
  return res.sendError( 'Unauthorized', 401 );
1968
1968
  }
1969
1969
 
1970
-
1970
+ if ( !req.body.length ) {
1971
+ return res.sendError( 'Store List is required', 400 );
1972
+ }
1973
+
1974
+ const storeList = req.body;
1975
+
1976
+ for ( let i = 0; i < storeList.length; i++ ) {
1977
+ const store = storeList[i];
1978
+
1979
+ // const issueTypes = [
1980
+ // 'Fixture size is wrong',
1981
+ // 'Fixture type is wrong',
1982
+ // 'Fixture brand is wrong',
1983
+ // 'Fixture not in the store',
1984
+ // 'Shelves count/Product Category/Capacity is wrong',
1985
+ // 'Others',
1986
+ // ];
1987
+
1988
+ const planogram = await planoService.findOne( { storeName: store.storeName } );
1989
+
1990
+ const fixtureTaskList = await planoTaskService.find( { planoId: planogram.toObject()._id, type: 'fixture' } );
1991
+
1992
+ for ( let j = 0; j < fixtureTaskList.length; j++ ) {
1993
+ const fixtureTask = fixtureTaskList[j].toObject();
1994
+
1995
+ const [ q1 ] = fixtureTask.answers;
1996
+
1997
+ if ( q1.value === true ) {
1998
+ continue;
1999
+ }
2000
+
2001
+ const fixture = await storeFixtureService.findOne( { _id: fixtureTask.fixtureId } );
2002
+
2003
+ const fixtureDoc = fixture?.toObject();
2004
+
2005
+
2006
+ if ( q1.issues.includes( 'Shelves count/Product Category/Capacity is wrong' ) ) {
2007
+ const taskShelves = q1.data.shelves;
2008
+
2009
+ const fixtureShelves = await fixtureShelfService.findAndSort( { fixtureId: fixtureTask.fixtureId }, {}, { shelfNumber: 1 } );
2010
+
2011
+ const shelfCount = q1.data.shelves.length;
2012
+
2013
+ const fixtureCapacity = q1.data.shelves.reduce( ( sum, item ) => sum + ( item.productCapacity ? item.productCapacity : 0 ), 0 );
2014
+
2015
+ const updateFixture = await storeFixtureService.updateOne( { _id: fixtureDoc._id }, { shelfcount: shelfCount, fixtureCapacity: fixtureCapacity } );
2016
+
2017
+ console.log( updateFixture );
2018
+
2019
+ for ( let k = 0; k < taskShelves.length; k++ ) {
2020
+ const taskShelf = taskShelves[k];
2021
+ const productCapacity = taskShelf.productCapacity;
2022
+ const section = taskShelf.section;
2023
+ const subBrand = taskShelf.subBrand;
2024
+ const formattedsubBrand = subBrand.length ? ( subBrand.length > 1 ? subBrand.join( ' + ' ) : subBrand[0] ) : undefined;
2025
+ if ( taskShelves.length === fixtureShelves.length ) {
2026
+ const fixtureShelf = fixtureShelves.filter( ( shelf ) => {
2027
+ return shelf.toObject().shelfNumber === k+1;
2028
+ } );
2029
+
2030
+ const updateShelf = await fixtureShelfService.updateOne( { _id: fixtureShelf?.[0].toObject()._id }, { shelfCapacity: productCapacity, sectionName: formattedsubBrand, sectionZone: section } );
2031
+
2032
+ console.log( updateShelf );
2033
+ } else if ( taskShelves.length < fixtureShelves.length ) {
2034
+ const fixtureShelf = fixtureShelves.filter( ( shelf ) => {
2035
+ return shelf.toObject().shelfNumber === k+1;
2036
+ } );
2037
+
2038
+
2039
+ const updateShelf = await fixtureShelfService.updateOne( { _id: fixtureShelf?.[0].toObject()._id }, { shelfCapacity: productCapacity, sectionName: formattedsubBrand, sectionZone: section } );
2040
+
2041
+ console.log( updateShelf );
2042
+
2043
+
2044
+ const shelfDifference = fixtureShelves.length - taskShelves.length;
2045
+
2046
+ const shelvesToDelete = fixtureShelves.slice( -shelfDifference );
2047
+
2048
+ shelvesToDelete.map( async ( shelf ) => {
2049
+ await fixtureShelfService.deleteOne( { _id: shelf.toObject()._id } );
2050
+ } );
2051
+ } else if ( taskShelves.length > fixtureShelves.length ) {
2052
+ if ( k + 1 <= fixtureShelves.length ) {
2053
+ const fixtureShelf = fixtureShelves.filter( ( shelf ) => {
2054
+ return shelf.toObject().shelfNumber === k+1;
2055
+ } );
2056
+
2057
+
2058
+ const updateShelf = await fixtureShelfService.updateOne( { _id: fixtureShelf?.[0].toObject()._id }, { shelfCapacity: productCapacity, sectionName: formattedsubBrand, sectionZone: section } );
2059
+
2060
+ console.log( updateShelf );
2061
+ } else if ( k + 1 > fixtureShelves.length ) {
2062
+ const insertData = {
2063
+ 'clientId': planogram.toObject().clientId,
2064
+ 'storeName': planogram.toObject().storeName,
2065
+ 'storeId': planogram.toObject().storeId,
2066
+ 'planoId': planogram.toObject()._id,
2067
+ 'floorId': fixtureDoc.floorId,
2068
+ 'fixtureId': fixtureDoc._id,
2069
+ 'shelfNumber': k+1,
2070
+ 'shelfOrder': 'LTR',
2071
+ 'shelfCapacity': productCapacity,
2072
+ 'sectionName': formattedsubBrand,
2073
+ 'sectionZone': section,
2074
+ };
2075
+
2076
+
2077
+ await fixtureShelfService.create( insertData );
2078
+ }
2079
+ }
2080
+ }
2081
+ }
2082
+ }
2083
+ }
2084
+
2085
+ res.sendSuccess( 'Updated successfully' );
1971
2086
  } catch ( e ) {
1972
2087
  logger.error( { functionName: 'updatelayoutFeedback', error: e } );
1973
2088
  return res.sendError( e.message || 'Internal Server Error', 500 );
@@ -607,7 +607,7 @@ export async function storeFixturesv1( req, res ) {
607
607
  date: currentDate,
608
608
  } );
609
609
 
610
- const shelves = await fixtureShelfService.find( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 } );
610
+ const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 }, { shelfNumber: 1 } );
611
611
 
612
612
  const shelfDetails = await Promise.all(
613
613
  shelves.map( async ( shelf ) => {
@@ -702,7 +702,7 @@ export async function storeFixturesv1( req, res ) {
702
702
  date: currentDate,
703
703
  } );
704
704
 
705
- const shelves = await fixtureShelfService.find( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 } );
705
+ const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 }, { shelfNumber: 1 } );
706
706
 
707
707
  const shelfDetails = await Promise.all(
708
708
  shelves.map( async ( shelf ) => {
@@ -1072,7 +1072,10 @@ export async function fixtureShelfProductv1( req, res ) {
1072
1072
  }
1073
1073
  } ) );
1074
1074
  const vmMap = new Map( vms.map( ( vm ) => [ vm._id.toString(), vm.toObject() ] ) );
1075
- const vmDetails = vmMappings.map( ( mapping ) => vmMap.get( mapping.productId.toString() ) || {} );
1075
+ const vmDetails = vmMappings.map( ( mapping ) => ( {
1076
+ ...vmMap.get( mapping.productId.toString() ),
1077
+ _id: mapping._id,
1078
+ } ) );
1076
1079
 
1077
1080
  if ( fixture.toObject().productResolutionLevel === 'L1' ) {
1078
1081
  const productMappings = await planoMappingService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
@@ -1081,7 +1084,7 @@ export async function fixtureShelfProductv1( req, res ) {
1081
1084
  }
1082
1085
 
1083
1086
  if ( [ 'L2', 'L4' ].includes( fixture.toObject().productResolutionLevel ) ) {
1084
- const fixtureShelves = await fixtureShelfService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
1087
+ const fixtureShelves = await fixtureShelfService.findAndSort( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) }, {}, { shelfNumber: 1 } );
1085
1088
  // if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
1086
1089
  const productCount = await planoMappingService.count( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
1087
1090
  const shelfProducts = await Promise.all(
@@ -1095,7 +1098,7 @@ export async function fixtureShelfProductv1( req, res ) {
1095
1098
  }
1096
1099
 
1097
1100
  if ( fixture.toObject().productResolutionLevel === 'L3' ) {
1098
- const fixtureShelves = await fixtureShelfService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
1101
+ const fixtureShelves = await fixtureShelfService.findAndSort( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) }, {}, { shelfNumber: 1 } );
1099
1102
  // if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
1100
1103
  const productCount = await planoMappingService.count( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
1101
1104
  const groupedShelves = fixtureShelves.reduce( async ( accPromise, shelf ) => {
@@ -2048,7 +2051,7 @@ export async function storeFixturesTask( req, res ) {
2048
2051
  date_string: req.body?.date,
2049
2052
  }, { status: 1 } );
2050
2053
 
2051
- const shelves = await fixtureShelfService.find( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 } );
2054
+ const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 }, { shelfNumber: 1 } );
2052
2055
 
2053
2056
  const shelfDetails = await Promise.all(
2054
2057
  shelves.map( async ( shelf ) => {
@@ -2128,7 +2131,7 @@ export async function storeFixturesTask( req, res ) {
2128
2131
  date_string: req.body?.date,
2129
2132
  }, { status: 1 } );
2130
2133
 
2131
- const shelves = await fixtureShelfService.find( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 } );
2134
+ const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 }, { shelfNumber: 1 } );
2132
2135
 
2133
2136
  const shelfDetails = await Promise.all(
2134
2137
  shelves.map( async ( shelf ) => {
@@ -23,13 +23,13 @@ storeBuilderRouter
23
23
  // .post( '/FixtureShelfDetails', storeBuilderController.fixtureShelfProduct )
24
24
  // .post( '/scan', storeBuilderController.scan )
25
25
  .post( '/storeLayout', isAllowedSessionHandler, validate( validateDtos.storeList ), storeBuilderController.storeLayout )
26
- .post( '/storeFixtures', isAllowedSessionHandler, validate( validateDtos.storeList ), storeBuilderController.storeFixturesv1 )
27
- .post( '/FixtureShelfDetails', isAllowedSessionHandler, validate( validateDtos.fixtureShelfProduct ), storeBuilderController.fixtureShelfProductv1 )
26
+ .post( '/storeFixtures', validate( validateDtos.storeList ), storeBuilderController.storeFixturesv1 )
27
+ .post( '/FixtureShelfDetails', validate( validateDtos.fixtureShelfProduct ), storeBuilderController.fixtureShelfProductv1 )
28
28
  .post( '/scan', isAllowedSessionHandler, storeBuilderController.scanv1 )
29
29
  .post( '/updateMissing', isAllowedSessionHandler, storeBuilderController.updateMissing )
30
30
  .post( '/bulkFixtureUpload', isAllowedSessionHandler, storeBuilderController.bulkFixtureUpload )
31
31
  .post( '/uploadImage', isAllowedSessionHandler, storeBuilderController.uploadImage )
32
- .post( '/storeFixturesTask', isAllowedSessionHandler, storeBuilderController.storeFixturesTask )
32
+ .post( '/storeFixturesTask', storeBuilderController.storeFixturesTask )
33
33
  .post( '/qrFileUpload', isAllowedSessionHandler, storeBuilderController.qrFileUpload )
34
34
  .post( '/updateQrCvProcessRequest', isAllowedSessionHandler, storeBuilderController.updateQrCvProcessRequest )
35
35
  .post( '/getQrCvProcessRequest', isAllowedSessionHandler, storeBuilderController.getQrCvProcessRequest )
@@ -40,6 +40,6 @@ storeBuilderRouter
40
40
  .post( '/getshelfSections', isAllowedSessionHandler, storeBuilderController.getShelfSections )
41
41
  .post( '/getFixtureTypes', isAllowedSessionHandler, storeBuilderController.getFixtureTypes )
42
42
  .post( '/getFixtureLengths', isAllowedSessionHandler, storeBuilderController.getFixtureLengths )
43
- .post( '/getFixtureBrands', isAllowedSessionHandler, storeBuilderController.getFixtureBrands )
43
+ .post( '/getFixtureBrands', storeBuilderController.getFixtureBrands )
44
44
  .post( '/checkPlanoExist', isAllowedSessionHandler, storeBuilderController.checkPlanoExist )
45
45
  .post( '/storeLayoutElements', isAllowedSessionHandler, storeBuilderController.storeLayoutElements );
@@ -4,6 +4,10 @@ export async function find( query={}, field={} ) {
4
4
  return model.fixtureShelfModel.find( query, field );
5
5
  }
6
6
 
7
+ export async function findAndSort( query={}, field={}, sortField={} ) {
8
+ return model.fixtureShelfModel.find( query, field ).sort( sortField );
9
+ }
10
+
7
11
  export async function findOne( query={}, field={} ) {
8
12
  return model.fixtureShelfModel.findOne( query, field );
9
13
  }
@@ -27,3 +31,7 @@ export async function create( data ) {
27
31
  export async function count( data ) {
28
32
  return model.fixtureShelfModel.countDocuments( data );
29
33
  }
34
+
35
+ export async function deleteOne( query ) {
36
+ return model.fixtureShelfModel.deleteOne( query );
37
+ }