tango-app-api-store-builder 1.0.0-beta-207 → 1.0.0-beta-209
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
|
@@ -713,16 +713,38 @@ export async function updateStorePlano( req, res ) {
|
|
|
713
713
|
const currentWallFixtures = data.layoutPolygon.flatMap( ( element ) =>
|
|
714
714
|
( element.fixtures || [] ).map( ( fixture ) => fixture ),
|
|
715
715
|
);
|
|
716
|
-
|
|
717
716
|
const currentFloorFixtures = ( data.centerFixture || [] );
|
|
718
|
-
|
|
719
717
|
const currentFixtures = [ ...currentWallFixtures, ...currentFloorFixtures ];
|
|
720
718
|
|
|
721
|
-
const
|
|
719
|
+
const wallOtherElements = data.layoutPolygon.flatMap( ( element ) =>
|
|
720
|
+
( element.otherElements || [] ).map( ( el ) => el ),
|
|
721
|
+
);
|
|
722
|
+
const floorOtherElements = ( data.otherElements || [] );
|
|
723
|
+
const currentOtherElements = [...wallOtherElements, ...floorOtherElements];
|
|
724
|
+
|
|
725
|
+
const existingFixtures = await storeFixtureService.find({
|
|
726
|
+
floorId: new mongoose.Types.ObjectId(floorId),
|
|
727
|
+
fixtureType: { $ne: 'other' }
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
const existingOtherElements = await storeFixtureService.find({
|
|
731
|
+
floorId: new mongoose.Types.ObjectId(floorId),
|
|
732
|
+
fixtureType: 'other'
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
const currentOtherElementsIds = new Set( currentOtherElements.map( ( f ) => f._id ) );
|
|
736
|
+
const removedOtherElements = existingOtherElements.filter(
|
|
737
|
+
( f ) => f._id && !currentOtherElementsIds.has( f._id.toString()),
|
|
738
|
+
);
|
|
722
739
|
|
|
723
|
-
|
|
740
|
+
if(removedOtherElements.length){
|
|
741
|
+
const otherElementIds = removedOtherElements.map( ( ele ) => ele.toObject()._id );
|
|
742
|
+
await storeFixtureService.deleteMany( { _id: { $in: otherElementIds } } );
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
const currentFixtureIds = new Set( currentFixtures.map( ( f ) => f._id ) );
|
|
724
746
|
const removedFixtures = existingFixtures.filter(
|
|
725
|
-
( f ) => f._id && !
|
|
747
|
+
( f ) => f._id && !currentFixtureIds.has( f._id.toString()),
|
|
726
748
|
);
|
|
727
749
|
|
|
728
750
|
if ( removedFixtures.length ) {
|
|
@@ -731,10 +753,8 @@ export async function updateStorePlano( req, res ) {
|
|
|
731
753
|
await fixtureShelfService.deleteMany( { fixtureId: { $in: fixtureIds } } );
|
|
732
754
|
}
|
|
733
755
|
|
|
734
|
-
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
const newFloorFixtures = currentFloorFixtures.filter( ( fixture ) => fixture?._id?.startsWith( 'new' ) );
|
|
756
|
+
const newWallFixtures = currentWallFixtures.filter( ( fixture ) => fixture?._id?.startsWith( 'new' ));
|
|
757
|
+
const newFloorFixtures = currentFloorFixtures.filter( ( fixture ) => fixture?._id?.startsWith( 'new' ));
|
|
738
758
|
|
|
739
759
|
const newFixtures = [ ...newWallFixtures, ...newFloorFixtures ];
|
|
740
760
|
|
|
@@ -758,6 +778,29 @@ export async function updateStorePlano( req, res ) {
|
|
|
758
778
|
} );
|
|
759
779
|
} );
|
|
760
780
|
}
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
const newOtherElements = currentOtherElements.filter((ele) => ele?._id?.startsWith( 'new' ));
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
currentOtherElements.forEach(async (ele)=>{
|
|
788
|
+
if(ele?._id && mongoose.Types.ObjectId.isValid(ele._id)) {
|
|
789
|
+
await storeFixtureService.upsertOne({_id: new mongoose.Types.ObjectId(ele._id)}, ele);
|
|
790
|
+
}
|
|
791
|
+
})
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
if(newOtherElements.length){
|
|
795
|
+
newOtherElements.forEach(async(ele) =>{
|
|
796
|
+
delete ele._id
|
|
797
|
+
const payload = {
|
|
798
|
+
...ele,
|
|
799
|
+
...additionalMeta
|
|
800
|
+
}
|
|
801
|
+
await storeFixtureService.create(payload)
|
|
802
|
+
})
|
|
803
|
+
}
|
|
761
804
|
|
|
762
805
|
currentFixtures.forEach( async ( fixture ) => {
|
|
763
806
|
if ( mongoose.Types.ObjectId.isValid( fixture._id ) ) {
|
|
@@ -2811,11 +2811,12 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2811
2811
|
const masterTemplateIds = new Set();
|
|
2812
2812
|
const layoutPolygonWithFixtures = await Promise.all(
|
|
2813
2813
|
floor.layoutPolygon.map( async ( element ) => {
|
|
2814
|
-
|
|
2814
|
+
const fixtures = await storeFixtureService.findAndSort( {
|
|
2815
2815
|
floorId: floor._id,
|
|
2816
2816
|
associatedElementType: element.elementType,
|
|
2817
2817
|
associatedElementNumber: element.elementNumber,
|
|
2818
|
-
|
|
2818
|
+
fixtureType: { $ne: 'other' },
|
|
2819
|
+
}, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
|
|
2819
2820
|
|
|
2820
2821
|
const fixturesWithStatus = await Promise.all(
|
|
2821
2822
|
fixtures.map( async ( fixture ) => {
|
|
@@ -2916,6 +2917,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2916
2917
|
$and: [
|
|
2917
2918
|
{ associatedElementType: { $exists: false } },
|
|
2918
2919
|
{ associatedElementNumber: { $exists: false } },
|
|
2920
|
+
{ fixtureType: { $ne: 'other' } }
|
|
2919
2921
|
],
|
|
2920
2922
|
}, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
|
|
2921
2923
|
|
|
@@ -2996,7 +2998,6 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2996
2998
|
vmCount: vmCount,
|
|
2997
2999
|
shelfConfig: shelfDetails,
|
|
2998
3000
|
vmConfig: vmDetails,
|
|
2999
|
-
|
|
3000
3001
|
};
|
|
3001
3002
|
} ),
|
|
3002
3003
|
);
|
|
@@ -3494,6 +3495,7 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
3494
3495
|
floorId: floor._id,
|
|
3495
3496
|
associatedElementType: element.elementType,
|
|
3496
3497
|
associatedElementNumber: element.elementNumber,
|
|
3498
|
+
fixtureType: { $ne: 'other' }
|
|
3497
3499
|
}, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
|
|
3498
3500
|
|
|
3499
3501
|
const fixturesWithStatus = await Promise.all(
|
|
@@ -3595,6 +3597,7 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
3595
3597
|
$and: [
|
|
3596
3598
|
{ associatedElementType: { $exists: false } },
|
|
3597
3599
|
{ associatedElementNumber: { $exists: false } },
|
|
3600
|
+
{ fixtureType: { $ne: 'other' } }
|
|
3598
3601
|
],
|
|
3599
3602
|
}, { shelfcount: 0 }, { associatedElementFixtureNumber: 1 } );
|
|
3600
3603
|
|
|
@@ -68,3 +68,17 @@ export async function count( query ) {
|
|
|
68
68
|
export async function updateOneArrayItem( query, record, filter ) {
|
|
69
69
|
return model.storeFixtureModel.updateOne( query, record, filter );
|
|
70
70
|
}
|
|
71
|
+
|
|
72
|
+
export async function bulkUpsert(dataList = [], matchKey = '_id') {
|
|
73
|
+
if (!Array.isArray(dataList) || dataList.length === 0) return [];
|
|
74
|
+
|
|
75
|
+
const operations = dataList.map(item => ({
|
|
76
|
+
updateOne: {
|
|
77
|
+
filter: { [matchKey]: item[matchKey] },
|
|
78
|
+
update: { $set: item },
|
|
79
|
+
upsert: true,
|
|
80
|
+
},
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
return model.storeFixtureModel.bulkWrite(operations);
|
|
84
|
+
}
|