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

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-73",
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 ) => {
@@ -1081,7 +1081,7 @@ export async function fixtureShelfProductv1( req, res ) {
1081
1081
  }
1082
1082
 
1083
1083
  if ( [ 'L2', 'L4' ].includes( fixture.toObject().productResolutionLevel ) ) {
1084
- const fixtureShelves = await fixtureShelfService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
1084
+ const fixtureShelves = await fixtureShelfService.findAndSort( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) }, {}, { shelfNumber: 1 } );
1085
1085
  // if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
1086
1086
  const productCount = await planoMappingService.count( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
1087
1087
  const shelfProducts = await Promise.all(
@@ -1095,7 +1095,7 @@ export async function fixtureShelfProductv1( req, res ) {
1095
1095
  }
1096
1096
 
1097
1097
  if ( fixture.toObject().productResolutionLevel === 'L3' ) {
1098
- const fixtureShelves = await fixtureShelfService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
1098
+ const fixtureShelves = await fixtureShelfService.findAndSort( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) }, {}, { shelfNumber: 1 } );
1099
1099
  // if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
1100
1100
  const productCount = await planoMappingService.count( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
1101
1101
  const groupedShelves = fixtureShelves.reduce( async ( accPromise, shelf ) => {
@@ -2048,7 +2048,7 @@ export async function storeFixturesTask( req, res ) {
2048
2048
  date_string: req.body?.date,
2049
2049
  }, { status: 1 } );
2050
2050
 
2051
- const shelves = await fixtureShelfService.find( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 } );
2051
+ const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 }, { shelfNumber: 1 } );
2052
2052
 
2053
2053
  const shelfDetails = await Promise.all(
2054
2054
  shelves.map( async ( shelf ) => {
@@ -2128,7 +2128,7 @@ export async function storeFixturesTask( req, res ) {
2128
2128
  date_string: req.body?.date,
2129
2129
  }, { status: 1 } );
2130
2130
 
2131
- const shelves = await fixtureShelfService.find( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 } );
2131
+ const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1 }, { shelfNumber: 1 } );
2132
2132
 
2133
2133
  const shelfDetails = await Promise.all(
2134
2134
  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
+ }