tango-app-api-store-builder 1.0.0-beta-193 → 1.0.0-beta-195

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-193",
3
+ "version": "1.0.0-beta-195",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -890,45 +890,70 @@ export async function replaceFixtureDetails( req, res ) {
890
890
 
891
891
  await Promise.all(
892
892
  inputData.storeList.map( async ( store ) => {
893
- const replaceFixture = await storeFixtureService.findOne( {
893
+ const replaceFixture = await storeFixtureService.find( {
894
894
  fixtureConfigId: inputData.findFixture,
895
+ ...( store?.floorDetails?._id ) ? { floorId: store?.floorDetails?._id } : {},
895
896
  storeId: store.storeId,
896
897
  } );
897
898
 
898
- if ( !replaceFixture ) return;
899
+ // console.log( replaceFixture );
899
900
 
900
- console.log( replaceFixture._id );
901
+ if ( !replaceFixture.length ) return;
902
+
903
+ // console.log( replaceFixture._id );
901
904
 
902
905
  const deleteFixShelves = await fixtureShelfService.deleteMany( {
903
- fixtureId: replaceFixture._id,
906
+ fixtureId: { $in: replaceFixture.map( ( ele ) => ele._id ) },
904
907
  } );
905
908
  console.log( deleteFixShelves );
906
909
 
907
910
  await storeFixtureService.updateMany(
908
- { fixtureConfigId: inputData.findFixture, storeId: store.storeId },
911
+ { fixtureConfigId: inputData.findFixture, ...( store?.floorDetails?._id ) ? { floorId: store?.floorDetails?._id } : {}, storeId: store.storeId },
909
912
  updateData,
910
913
  );
911
914
 
912
915
  if ( replaceFixtureData.shelfConfig?.length ) {
913
- const shelfList = replaceFixtureData.shelfConfig.map( ( shelf ) => {
914
- const shelfData = {
915
- ...shelf.toObject(),
916
- floorId: replaceFixture.floorId,
917
- planoId: replaceFixture.planoId,
918
- clientId: replaceFixture.clientId,
919
- fixtureId: replaceFixture._id,
920
- storeId: replaceFixture.storeId,
921
- storeName: replaceFixture.storeName,
922
- };
923
- delete shelfData._id;
924
- return shelfData;
916
+ replaceFixtureData.shelfConfig.forEach( async ( shelf ) => {
917
+ let shelfData = [];
918
+ shelf = { ...shelf.toObject() };
919
+ delete shelf._id;
920
+ replaceFixture.forEach( async ( data ) => {
921
+ shelfData.push( {
922
+ ...shelf,
923
+ floorId: data.floorId,
924
+ planoId: data.planoId,
925
+ clientId: data.clientId,
926
+ fixtureId: data._id,
927
+ storeId: data.storeId,
928
+ storeName: data.storeName,
929
+ } );
930
+ } );
931
+ try {
932
+ await fixtureShelfService.insertMany( shelfData );
933
+ } catch ( err ) {
934
+ console.error( 'Insert failed:', err );
935
+ }
925
936
  } );
926
-
927
- try {
928
- await fixtureShelfService.insertMany( shelfList );
929
- } catch ( err ) {
930
- console.error( 'Insert failed:', err );
931
- }
937
+ // const shelfList = replaceFixtureData.shelfConfig.map( ( shelf ) => {
938
+ // const shelfData = {
939
+ // ...shelf.toObject(),
940
+ // floorId: replaceFixture.floorId,
941
+ // planoId: replaceFixture.planoId,
942
+ // clientId: replaceFixture.clientId,
943
+ // // fixtureId: replaceFixture._id,
944
+ // storeId: replaceFixture.storeId,
945
+ // storeName: replaceFixture.storeName,
946
+ // };
947
+
948
+ // delete shelfData._id;
949
+ // return shelfData;
950
+ // } );
951
+
952
+ // try {
953
+ // await fixtureShelfService.insertMany( shelfList );
954
+ // } catch ( err ) {
955
+ // console.error( 'Insert failed:', err );
956
+ // }
932
957
  }
933
958
  } ),
934
959
  );
@@ -963,7 +988,7 @@ export async function getMasterList( req, res ) {
963
988
  } :
964
989
  {} ),
965
990
  ...( req.body?.filter?.category?.length ?
966
- { fixtureCategory: { $in: req.body.filter.category } } :
991
+ { fixtureCate: { $in: req.body.filter.category } } :
967
992
  {} ),
968
993
  ...( req.body?.filter?.subCategory?.length ?
969
994
  { productSubCategory: { $in: req.body.subCategory.category } } :
@@ -971,6 +996,18 @@ export async function getMasterList( req, res ) {
971
996
  };
972
997
 
973
998
  const query = [
999
+ {
1000
+ $addFields: {
1001
+ fixtureCate: {
1002
+ $concat: [
1003
+ '$fixtureCategory',
1004
+ ' - ',
1005
+ { $toString: '$fixtureWidth.value' },
1006
+ '$fixtureWidth.unit',
1007
+ ],
1008
+ },
1009
+ },
1010
+ },
974
1011
  { $match: matchStage },
975
1012
  {
976
1013
  $lookup: {
@@ -998,6 +1035,7 @@ export async function getMasterList( req, res ) {
998
1035
  {
999
1036
  $project: {
1000
1037
  fixtureCategory: 1,
1038
+ fixtureCate: 1,
1001
1039
  fixtureName: 1,
1002
1040
  fixtureWidth: 1,
1003
1041
  clientId: 1,
@@ -1392,11 +1392,12 @@ async function getMaxVMLibCode() {
1392
1392
 
1393
1393
  export async function fixtureNameList( req, res ) {
1394
1394
  try {
1395
- let getFixtureDetails = await planoLibraryService.aggregate( [
1395
+ // planoLibraryService
1396
+ let getFixtureDetails = await fixtureTemplateService.aggregate( [
1396
1397
  {
1397
1398
  $match: {
1398
1399
  clientId: req.query.clientId,
1399
- status: 'complete',
1400
+ templateType: 'master',
1400
1401
  },
1401
1402
  },
1402
1403
  {
@@ -1422,7 +1423,14 @@ export async function fixtureNameList( req, res ) {
1422
1423
  },
1423
1424
  ] );
1424
1425
 
1425
- return res.sendSuccess( getFixtureDetails?.[0]?.fixtureDetails || [] );
1426
+ let result = getFixtureDetails?.[0]?.fixtureDetails.reduce( ( acc, ele ) => {
1427
+ if ( !acc[ele.fixtureName] ) {
1428
+ acc[ele.fixtureName] = ele;
1429
+ }
1430
+ return acc;
1431
+ }, {} );
1432
+
1433
+ return res.sendSuccess( result ? Object.values( result ) : [] );
1426
1434
  } catch ( e ) {
1427
1435
  logger.error( { functionName: 'fixtureNameList', error: e } );
1428
1436
  return res.sendError( e, 500 );