tango-app-api-store-builder 1.0.0-beta-194 → 1.0.0-beta-196
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
|
@@ -874,7 +874,33 @@ export async function replaceFixtureDetails( req, res ) {
|
|
|
874
874
|
}
|
|
875
875
|
if ( inputData.storeList.length == 0 && inputData.publishAll ) {
|
|
876
876
|
await fixtureConfigService.updateOne( { _id: inputData.replaceFixture }, { isEdited: false } );
|
|
877
|
-
|
|
877
|
+
let query = [
|
|
878
|
+
{
|
|
879
|
+
$match: {
|
|
880
|
+
fixtureConfigId: new ObjectId( inputData.findFixture ),
|
|
881
|
+
},
|
|
882
|
+
},
|
|
883
|
+
{
|
|
884
|
+
$group: {
|
|
885
|
+
_id: '$storeId',
|
|
886
|
+
floorDetails: {
|
|
887
|
+
$first: {
|
|
888
|
+
_id: '$floorId',
|
|
889
|
+
},
|
|
890
|
+
},
|
|
891
|
+
},
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
$project: {
|
|
895
|
+
storeId: '$_id',
|
|
896
|
+
floorDetails: 1,
|
|
897
|
+
_id: 0,
|
|
898
|
+
},
|
|
899
|
+
},
|
|
900
|
+
];
|
|
901
|
+
|
|
902
|
+
// inputData.storeList = await storeFixtureService.find( { fixtureConfigId: inputData.findFixture }, { storeId: 1 } );
|
|
903
|
+
inputData.storeList = await storeFixtureService.aggregate( query );
|
|
878
904
|
let data = {
|
|
879
905
|
templateId: inputData.replaceFixture,
|
|
880
906
|
data: replaceFixtureData,
|
|
@@ -890,45 +916,70 @@ export async function replaceFixtureDetails( req, res ) {
|
|
|
890
916
|
|
|
891
917
|
await Promise.all(
|
|
892
918
|
inputData.storeList.map( async ( store ) => {
|
|
893
|
-
const replaceFixture = await storeFixtureService.
|
|
919
|
+
const replaceFixture = await storeFixtureService.find( {
|
|
894
920
|
fixtureConfigId: inputData.findFixture,
|
|
921
|
+
...( store?.floorDetails?._id ) ? { floorId: store?.floorDetails?._id } : {},
|
|
895
922
|
storeId: store.storeId,
|
|
896
923
|
} );
|
|
897
924
|
|
|
898
|
-
|
|
925
|
+
// console.log( replaceFixture );
|
|
899
926
|
|
|
900
|
-
|
|
927
|
+
if ( !replaceFixture.length ) return;
|
|
928
|
+
|
|
929
|
+
// console.log( replaceFixture._id );
|
|
901
930
|
|
|
902
931
|
const deleteFixShelves = await fixtureShelfService.deleteMany( {
|
|
903
|
-
fixtureId: replaceFixture._id,
|
|
932
|
+
fixtureId: { $in: replaceFixture.map( ( ele ) => ele._id ) },
|
|
904
933
|
} );
|
|
905
934
|
console.log( deleteFixShelves );
|
|
906
935
|
|
|
907
936
|
await storeFixtureService.updateMany(
|
|
908
|
-
{ fixtureConfigId: inputData.findFixture, storeId: store.storeId },
|
|
937
|
+
{ fixtureConfigId: inputData.findFixture, ...( store?.floorDetails?._id ) ? { floorId: store?.floorDetails?._id } : {}, storeId: store.storeId },
|
|
909
938
|
updateData,
|
|
910
939
|
);
|
|
911
940
|
|
|
912
941
|
if ( replaceFixtureData.shelfConfig?.length ) {
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
942
|
+
replaceFixtureData.shelfConfig.forEach( async ( shelf ) => {
|
|
943
|
+
let shelfData = [];
|
|
944
|
+
shelf = { ...shelf.toObject() };
|
|
945
|
+
delete shelf._id;
|
|
946
|
+
replaceFixture.forEach( async ( data ) => {
|
|
947
|
+
shelfData.push( {
|
|
948
|
+
...shelf,
|
|
949
|
+
floorId: data.floorId,
|
|
950
|
+
planoId: data.planoId,
|
|
951
|
+
clientId: data.clientId,
|
|
952
|
+
fixtureId: data._id,
|
|
953
|
+
storeId: data.storeId,
|
|
954
|
+
storeName: data.storeName,
|
|
955
|
+
} );
|
|
956
|
+
} );
|
|
957
|
+
try {
|
|
958
|
+
await fixtureShelfService.insertMany( shelfData );
|
|
959
|
+
} catch ( err ) {
|
|
960
|
+
console.error( 'Insert failed:', err );
|
|
961
|
+
}
|
|
925
962
|
} );
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
963
|
+
// const shelfList = replaceFixtureData.shelfConfig.map( ( shelf ) => {
|
|
964
|
+
// const shelfData = {
|
|
965
|
+
// ...shelf.toObject(),
|
|
966
|
+
// floorId: replaceFixture.floorId,
|
|
967
|
+
// planoId: replaceFixture.planoId,
|
|
968
|
+
// clientId: replaceFixture.clientId,
|
|
969
|
+
// // fixtureId: replaceFixture._id,
|
|
970
|
+
// storeId: replaceFixture.storeId,
|
|
971
|
+
// storeName: replaceFixture.storeName,
|
|
972
|
+
// };
|
|
973
|
+
|
|
974
|
+
// delete shelfData._id;
|
|
975
|
+
// return shelfData;
|
|
976
|
+
// } );
|
|
977
|
+
|
|
978
|
+
// try {
|
|
979
|
+
// await fixtureShelfService.insertMany( shelfList );
|
|
980
|
+
// } catch ( err ) {
|
|
981
|
+
// console.error( 'Insert failed:', err );
|
|
982
|
+
// }
|
|
932
983
|
}
|
|
933
984
|
} ),
|
|
934
985
|
);
|