tango-app-api-store-builder 1.0.0-beta-112 → 1.0.0-beta-113
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/index.js +1 -4
- package/package.json +2 -3
- package/src/controllers/script.controller.js +400 -1727
- package/src/controllers/storeBuilder.controller.js +318 -526
- package/src/controllers/task.controller.js +55 -169
- package/src/dtos/validation.dtos.js +0 -226
- package/src/routes/script.routes.js +1 -3
- package/src/routes/storeBuilder.routes.js +1 -5
- package/src/routes/task.routes.js +0 -1
- package/src/service/fixtureConfig.service.js +3 -26
- package/src/service/planoStaticData.service.js +0 -3
- package/src/service/planoTask.service.js +0 -3
- package/inputjson/layoutverification.json +0 -466
- package/response.json +0 -647
- package/src/controllers/fixtureTemplate.controller.js +0 -463
- package/src/controllers/managePlano.controller.js +0 -386
- package/src/controllers/planoLibrary.controller.js +0 -1399
- package/src/routes/fixtureTemplate.routes.js +0 -17
- package/src/routes/managePlano.routes.js +0 -16
- package/src/routes/planoLibrary.routes.js +0 -40
- package/src/service/planoLibrary.service.js +0 -37
- package/src/service/planoVm.service.js +0 -49
- package/src/service/planoproductCategory.service.js +0 -39
- package/src/service/vmType.service.js +0 -33
|
@@ -15,7 +15,6 @@ import * as planoTaskComplianceService from '../service/planoTask.service.js';
|
|
|
15
15
|
import * as planoQrConversionRequestService from '../service/planoQrConversionRequest.service.js';
|
|
16
16
|
import * as fixtureConfigService from '../service/fixtureConfig.service.js';
|
|
17
17
|
import * as planoStaticData from '../service/planoStaticData.service.js';
|
|
18
|
-
import * as planoVmService from '../service/planoVm.service.js';
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
dayjs.extend( utc );
|
|
@@ -574,6 +573,7 @@ export async function storeFixturesv1( req, res ) {
|
|
|
574
573
|
const floorsWithFixtures = await Promise.all(
|
|
575
574
|
floors.map( async ( floor ) => {
|
|
576
575
|
let productCapacity = 0;
|
|
576
|
+
let fixtureCount = 0;
|
|
577
577
|
const layoutPolygonWithFixtures = await Promise.all(
|
|
578
578
|
floor.layoutPolygon.map( async ( element ) => {
|
|
579
579
|
const fixtures = await storeFixtureService.findAndSort( {
|
|
@@ -595,6 +595,7 @@ export async function storeFixturesv1( req, res ) {
|
|
|
595
595
|
fixture.imageUrl = '';
|
|
596
596
|
}
|
|
597
597
|
productCapacity += fixture.toObject().fixtureCapacity;
|
|
598
|
+
fixtureCount += 1;
|
|
598
599
|
const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
|
|
599
600
|
|
|
600
601
|
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
|
|
@@ -696,6 +697,8 @@ export async function storeFixturesv1( req, res ) {
|
|
|
696
697
|
fixture.imageUrl = '';
|
|
697
698
|
}
|
|
698
699
|
productCapacity += fixture.toObject().fixtureCapacity;
|
|
700
|
+
fixtureCount += 1;
|
|
701
|
+
|
|
699
702
|
const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
|
|
700
703
|
|
|
701
704
|
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
|
|
@@ -741,10 +744,16 @@ export async function storeFixturesv1( req, res ) {
|
|
|
741
744
|
|
|
742
745
|
const vmDetails = await Promise.all( vms.map( async ( vm ) => {
|
|
743
746
|
const vmTemplate = await planoProductService.findOne( { _id: vm.toObject().productId } );
|
|
744
|
-
|
|
747
|
+
const params = {
|
|
748
|
+
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
749
|
+
file_path: vmTemplate?.productImageUrl,
|
|
750
|
+
};
|
|
751
|
+
const vmImage = await signedUrl( params );
|
|
745
752
|
return {
|
|
746
753
|
...vm.toObject(),
|
|
747
754
|
...vmTemplate?.toObject(),
|
|
755
|
+
...( typeof vmImage === 'string' && { productImageUrl: vmImage } ),
|
|
756
|
+
|
|
748
757
|
};
|
|
749
758
|
} ) );
|
|
750
759
|
|
|
@@ -760,7 +769,7 @@ export async function storeFixturesv1( req, res ) {
|
|
|
760
769
|
} ),
|
|
761
770
|
);
|
|
762
771
|
|
|
763
|
-
|
|
772
|
+
const productCount = await planoMappingService.count( { floorId: floor._id } );
|
|
764
773
|
|
|
765
774
|
const otherElements = await storeFixtureService.find( {
|
|
766
775
|
floorId: floor._id,
|
|
@@ -774,6 +783,7 @@ export async function storeFixturesv1( req, res ) {
|
|
|
774
783
|
layoutPolygon: layoutPolygonWithFixtures,
|
|
775
784
|
centerFixture: centerFixturesWithStatus,
|
|
776
785
|
productCount: productCapacity,
|
|
786
|
+
fixtureCount: fixtureCount,
|
|
777
787
|
// productCapacity: productCapacity,
|
|
778
788
|
otherElements: otherElements,
|
|
779
789
|
};
|
|
@@ -867,6 +877,158 @@ export async function updateStatus( req, res ) {
|
|
|
867
877
|
}
|
|
868
878
|
}
|
|
869
879
|
|
|
880
|
+
export async function fixtureShelfProduct( req, res ) {
|
|
881
|
+
try {
|
|
882
|
+
if ( !req.body.fixtureId ) {
|
|
883
|
+
return res.sendError( 'Fixture id is required', 400 );
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
let fixtureDetails = await storeFixtureService.findOne( { _id: req.body.fixtureId } );
|
|
887
|
+
if ( !fixtureDetails ) {
|
|
888
|
+
return res.sendError( 'Fixture not found', 204 );
|
|
889
|
+
}
|
|
890
|
+
// let planoDetails = await planoService.findOne( { _id: fixtureDetails.planoId } );
|
|
891
|
+
let shelfDetails = await fixtureShelfService.find( { fixtureId: req.body.fixtureId } );
|
|
892
|
+
// let query;
|
|
893
|
+
// switch ( planoDetails.productResolutionLevel ) {
|
|
894
|
+
// case 'L1':
|
|
895
|
+
// query = { floorId: fixtureDetails.floorId };
|
|
896
|
+
// break;
|
|
897
|
+
// default:
|
|
898
|
+
// query = { floorId: fixtureDetails.floorId, fixtureId: req.body.fixtureId };
|
|
899
|
+
// break;
|
|
900
|
+
// }
|
|
901
|
+
// query = {
|
|
902
|
+
// ...query,
|
|
903
|
+
// ...( [ 'L3', 'L4' ].includes( planoDetails.productResolutionLevel ) ) ? { shelfId: shelf._id } : {},
|
|
904
|
+
// productId: { $in: productIdList },
|
|
905
|
+
// date: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
906
|
+
// };
|
|
907
|
+
let shelfList = [];
|
|
908
|
+
for ( let shelf of shelfDetails ) {
|
|
909
|
+
let data = { ...shelf._doc, products: [] };
|
|
910
|
+
let productMappingDetails = await planoMappingService.find( { shelfId: shelf._id } );
|
|
911
|
+
let productIdList = productMappingDetails.map( ( item ) => item.productId );
|
|
912
|
+
let productDetails = await planoProductService.find( { _id: productIdList } );
|
|
913
|
+
let productComplianceDetails = await planoComplianceService.find( { date: new Date( dayjs().format( 'YYYY-MM-DD' ) ), shelfId: shelf._id } );
|
|
914
|
+
let product = [];
|
|
915
|
+
productDetails.forEach( ( item ) => {
|
|
916
|
+
let data = { ...item._doc, status: 'missing', rfId: '' };
|
|
917
|
+
let getPosition = productMappingDetails.find( ( ele ) => ele.productId.toString() == item._id.toString() );
|
|
918
|
+
let findCompliance = productComplianceDetails.find( ( ele ) => ele.shelfPosition == getPosition.shelfPosition );
|
|
919
|
+
if ( findCompliance ) {
|
|
920
|
+
data.status = findCompliance.compliance;
|
|
921
|
+
}
|
|
922
|
+
data.rfId = getPosition.rfId;
|
|
923
|
+
product.push( data );
|
|
924
|
+
} );
|
|
925
|
+
data.products = product;
|
|
926
|
+
shelfList.push( data );
|
|
927
|
+
}
|
|
928
|
+
fixtureDetails = { ...fixtureDetails._doc, shelves: shelfList };
|
|
929
|
+
return res.sendSuccess( fixtureDetails );
|
|
930
|
+
} catch ( e ) {
|
|
931
|
+
logger.error( { functionName: 'fixtureShelfProduct', error: e } );
|
|
932
|
+
return res.sendError( e, 500 );
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// export async function fixtureShelfProductv1( req, res ) {
|
|
937
|
+
// try {
|
|
938
|
+
// const { planoId, fixtureId } = req.body;
|
|
939
|
+
|
|
940
|
+
// const [ planogram, fixture ] = await Promise.all( [
|
|
941
|
+
// planoService.findOne(
|
|
942
|
+
// { _id: new mongoose.Types.ObjectId( planoId ) },
|
|
943
|
+
// { storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1 },
|
|
944
|
+
// ),
|
|
945
|
+
// storeFixtureService.findOne( {
|
|
946
|
+
// _id: new mongoose.Types.ObjectId( fixtureId ),
|
|
947
|
+
// } ),
|
|
948
|
+
// ] );
|
|
949
|
+
|
|
950
|
+
// if ( !planogram ) return res.sendError( 'Planogram not found', 204 );
|
|
951
|
+
// if ( !fixture ) return res.sendError( 'Fixture not found', 204 );
|
|
952
|
+
|
|
953
|
+
// const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
954
|
+
|
|
955
|
+
// const getProductsAndVms = async ( mappings ) => {
|
|
956
|
+
// const productIds = mappings.map( ( mapping ) => mapping.productId );
|
|
957
|
+
// const [ products, vms ] = await Promise.all( [
|
|
958
|
+
// planoProductService.find( { _id: { $in: productIds }, type: 'product' } ),
|
|
959
|
+
// planoProductService.find( { _id: { $in: productIds }, type: 'vm' } ),
|
|
960
|
+
// ] );
|
|
961
|
+
|
|
962
|
+
// const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
|
|
963
|
+
// const vmMap = new Map( vms.map( ( vm ) => [ vm._id.toString(), vm.toObject() ] ) );
|
|
964
|
+
|
|
965
|
+
// const productDetails = await Promise.all(
|
|
966
|
+
// mappings.filter( ( item ) => item.type === 'product' ).map( async ( mapping ) => {
|
|
967
|
+
// const productData = productMap.get( mapping.productId.toString() ) || {};
|
|
968
|
+
// const mappingCompliance = await planoComplianceService.findOne( {
|
|
969
|
+
// planoMappingId: mapping._id,
|
|
970
|
+
// date: currentDate,
|
|
971
|
+
// } );
|
|
972
|
+
// const status = mappingCompliance ? mappingCompliance.compliance : '';
|
|
973
|
+
// return { ...mapping.toObject(), ...productData, status };
|
|
974
|
+
// } ),
|
|
975
|
+
// );
|
|
976
|
+
|
|
977
|
+
// const vmDetails = await Promise.all(
|
|
978
|
+
// mappings.filter( ( item ) => item.type === 'vm' ).map( async ( mapping ) => {
|
|
979
|
+
// const vmData = vmMap.get( mapping.productId.toString() ) || {};
|
|
980
|
+
// return { ...mapping.toObject(), ...vmData };
|
|
981
|
+
// } ),
|
|
982
|
+
// );
|
|
983
|
+
|
|
984
|
+
// return { productDetails, vmDetails };
|
|
985
|
+
// };
|
|
986
|
+
|
|
987
|
+
// if ( fixture.toObject().productResolutionLevel === 'L1' ) {
|
|
988
|
+
// const productMappings = await planoMappingService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
|
|
989
|
+
// const { productDetails, vmDetails } = await getProductsAndVms( productMappings );
|
|
990
|
+
// return res.sendSuccess( { ...fixture.toObject(), products: productDetails, vms: vmDetails } );
|
|
991
|
+
// }
|
|
992
|
+
// if ( fixture.toObject().productResolutionLevel === 'L2' || fixture.toObject().productResolutionLevel === 'L4' ) {
|
|
993
|
+
// const fixtureShelves = await fixtureShelfService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
|
|
994
|
+
// if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
|
|
995
|
+
// const shelfProducts = await Promise.all(
|
|
996
|
+
// fixtureShelves.map( async ( shelf ) => {
|
|
997
|
+
// const productMappings = await planoMappingService.find( { shelfId: shelf._id } );
|
|
998
|
+
// const { productDetails, vmDetails } = await getProductsAndVms( productMappings );
|
|
999
|
+
// return { ...shelf.toObject(), products: productDetails, vms: vmDetails };
|
|
1000
|
+
// } ),
|
|
1001
|
+
// );
|
|
1002
|
+
// return res.sendSuccess( { ...fixture.toObject(), shelves: shelfProducts } );
|
|
1003
|
+
// }
|
|
1004
|
+
// if ( fixture.toObject().productResolutionLevel === 'L3' ) {
|
|
1005
|
+
// const fixtureShelves = await fixtureShelfService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
|
|
1006
|
+
// if ( !fixtureShelves.length ) return res.sendError( 'No shelves found for the fixture', 204 );
|
|
1007
|
+
// const groupedShelves = await ( async () => {
|
|
1008
|
+
// const shelfProducts = await Promise.all(
|
|
1009
|
+
// fixtureShelves.map( async ( shelf ) => {
|
|
1010
|
+
// const productMappings = await planoMappingService.find( { shelfId: shelf._id } );
|
|
1011
|
+
// const { productDetails, vmDetails } = await getProductsAndVms( productMappings );
|
|
1012
|
+
// return { ...shelf.toObject(), products: productDetails, vms: vmDetails };
|
|
1013
|
+
// } ),
|
|
1014
|
+
// );
|
|
1015
|
+
// return shelfProducts.reduce( ( acc, shelf ) => {
|
|
1016
|
+
// const sectionName = shelf.sectionName || 'Unknown';
|
|
1017
|
+
// if ( !acc[sectionName] ) {
|
|
1018
|
+
// acc[sectionName] = [];
|
|
1019
|
+
// }
|
|
1020
|
+
// acc[sectionName].push( shelf );
|
|
1021
|
+
// return acc;
|
|
1022
|
+
// }, {} );
|
|
1023
|
+
// } )();
|
|
1024
|
+
// return res.sendSuccess( { ...fixture.toObject(), categories: groupedShelves } );
|
|
1025
|
+
// }
|
|
1026
|
+
// return res.sendError( 'Incorrect resolution level', 400 );
|
|
1027
|
+
// } catch ( e ) {
|
|
1028
|
+
// logger.error( { functionName: 'fixtureShelfProductv1', error: e, message: req.body } );
|
|
1029
|
+
// return res.sendError( e, 500 );
|
|
1030
|
+
// }
|
|
1031
|
+
// }
|
|
870
1032
|
|
|
871
1033
|
export async function fixtureShelfProductv1( req, res ) {
|
|
872
1034
|
try {
|
|
@@ -974,6 +1136,140 @@ export async function fixtureShelfProductv1( req, res ) {
|
|
|
974
1136
|
}
|
|
975
1137
|
|
|
976
1138
|
|
|
1139
|
+
export async function scan( req, res ) {
|
|
1140
|
+
try {
|
|
1141
|
+
let shelfId;
|
|
1142
|
+
if ( !req.body.planoId ) {
|
|
1143
|
+
return res.sendError( 'Plano id is required', 400 );
|
|
1144
|
+
}
|
|
1145
|
+
if ( !req.body.rfId ) {
|
|
1146
|
+
return res.sendError( 'RFID is required', 400 );
|
|
1147
|
+
}
|
|
1148
|
+
let planoDetails = await planoService.findOne( { _id: req.body.planoId } );
|
|
1149
|
+
if ( !planoDetails ) {
|
|
1150
|
+
return res.sendError( 'No data found', 204 );
|
|
1151
|
+
}
|
|
1152
|
+
if ( ![ 'L1', 'L2' ].includes( planoDetails.productResolutionLevel ) ) {
|
|
1153
|
+
if ( !req.body.shelfId ) {
|
|
1154
|
+
let shelfDetails = await fixtureShelfService.findOne( { rfId: req.body.rfId } );
|
|
1155
|
+
if ( !shelfDetails ) {
|
|
1156
|
+
return res.sendError( 'Please scan shelf first', 400 );
|
|
1157
|
+
}
|
|
1158
|
+
return res.sendSuccess( shelfDetails._id );
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
if ( planoDetails.productResolutionLevel == 'L5' ) {
|
|
1162
|
+
let shelfDetails = await fixtureShelfService.findOne( { _id: req.body.shelfId } );
|
|
1163
|
+
if ( !shelfDetails ) {
|
|
1164
|
+
return res.sendError( 'No data found', 204 );
|
|
1165
|
+
}
|
|
1166
|
+
if ( shelfDetails.shelfCapacity < req.body.shelfPosition ) {
|
|
1167
|
+
return res.sendError( 'Shelf capacity exceeded', 400 );
|
|
1168
|
+
}
|
|
1169
|
+
shelfDetails = await fixtureShelfService.find( { sectionName: shelfDetails?.sectionName } );
|
|
1170
|
+
shelfId = req.body.shelfId;
|
|
1171
|
+
req.body.shelfId = shelfDetails.map( ( ele ) => ele._id );
|
|
1172
|
+
}
|
|
1173
|
+
let productCheck = await planoMappingService.findOne( { rfId: req.body.rfId } );
|
|
1174
|
+
if ( !productCheck ) {
|
|
1175
|
+
return res.sendError( 'Product not found', 400 );
|
|
1176
|
+
}
|
|
1177
|
+
let query;
|
|
1178
|
+
switch ( planoDetails.productResolutionLevel ) {
|
|
1179
|
+
case 'L1':
|
|
1180
|
+
if ( !req.body.floorId ) {
|
|
1181
|
+
return res.sendError( 'Floor id is required', 400 );
|
|
1182
|
+
}
|
|
1183
|
+
query = { floorId: req.body.floorId };
|
|
1184
|
+
break;
|
|
1185
|
+
case 'L2':
|
|
1186
|
+
if ( !req.body.floorId ) {
|
|
1187
|
+
return res.sendError( 'Floor id is required', 400 );
|
|
1188
|
+
}
|
|
1189
|
+
if ( !req.body.fixtureId ) {
|
|
1190
|
+
return res.sendError( 'Fixture id is required', 400 );
|
|
1191
|
+
}
|
|
1192
|
+
query = { floorId: req.body.floorId, fixtureId: req.body.fixtureId };
|
|
1193
|
+
break;
|
|
1194
|
+
case 'L3':
|
|
1195
|
+
if ( !req.body.floorId ) {
|
|
1196
|
+
return res.sendError( 'Floor id is required', 400 );
|
|
1197
|
+
}
|
|
1198
|
+
if ( !req.body.fixtureId ) {
|
|
1199
|
+
return res.sendError( 'Fixture id is required', 400 );
|
|
1200
|
+
}
|
|
1201
|
+
if ( !req.body.shelfId ) {
|
|
1202
|
+
return res.sendError( 'Shelf id is required', 400 );
|
|
1203
|
+
}
|
|
1204
|
+
query = { floorId: req.body.floorId, fixtureId: req.body.fixtureId, shelfId: req.body.shelfId };
|
|
1205
|
+
break;
|
|
1206
|
+
case 'L4':
|
|
1207
|
+
if ( !req.body.floorId ) {
|
|
1208
|
+
return res.sendError( 'Floor id is required', 400 );
|
|
1209
|
+
}
|
|
1210
|
+
if ( !req.body.fixtureId ) {
|
|
1211
|
+
return res.sendError( 'Fixture id is required', 400 );
|
|
1212
|
+
}
|
|
1213
|
+
if ( !req.body.shelfId ) {
|
|
1214
|
+
return res.sendError( 'Shelf id is required', 400 );
|
|
1215
|
+
}
|
|
1216
|
+
if ( !req.body.shelfPosition ) {
|
|
1217
|
+
return res.sendError( 'Shelf position is required', 400 );
|
|
1218
|
+
}
|
|
1219
|
+
query = { floorId: req.body.floorId, fixtureId: req.body.fixtureId, shelfId: req.body.shelfId, shelfPosition: req.body.shelfPosition };
|
|
1220
|
+
break;
|
|
1221
|
+
case 'L5':
|
|
1222
|
+
if ( !req.body.floorId ) {
|
|
1223
|
+
return res.sendError( 'Floor id is required', 400 );
|
|
1224
|
+
}
|
|
1225
|
+
if ( !req.body.fixtureId ) {
|
|
1226
|
+
return res.sendError( 'Fixture id is required', 400 );
|
|
1227
|
+
}
|
|
1228
|
+
if ( !req.body.shelfId ) {
|
|
1229
|
+
return res.sendError( 'Shelf id is required', 400 );
|
|
1230
|
+
}
|
|
1231
|
+
query = { floorId: req.body.floorId, fixtureId: req.body.fixtureId, shelfId: { $in: req.body.shelfId } };
|
|
1232
|
+
break;
|
|
1233
|
+
default:
|
|
1234
|
+
return res.sendError( 'Product not found', 400 );
|
|
1235
|
+
break;
|
|
1236
|
+
}
|
|
1237
|
+
query = { ...query, rfId: req.body.rfId };
|
|
1238
|
+
|
|
1239
|
+
let planoProductDetails = await planoMappingService.findOne( query );
|
|
1240
|
+
// let data = {
|
|
1241
|
+
// ...( planoProductDetails ) ? { ...planoProductDetails._doc } : { planoId: req.body?.planoId, floorId: req.body?.floorId, fixtureId: req.body?.fixtureId, shelfId: shelfId, clientId: planoDetails.clientId, storeName: planoDetails.storeName, storeId: planoDetails.storeId, shelfPosition: req.body?.shelfPosition },
|
|
1242
|
+
// rfId: req.body.rfId,
|
|
1243
|
+
// compliance: !planoProductDetails ? 'misplaced' : 'proper',
|
|
1244
|
+
// date: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
1245
|
+
// };
|
|
1246
|
+
let data = {
|
|
1247
|
+
planoId: req.body?.planoId,
|
|
1248
|
+
floorId: req.body?.floorId,
|
|
1249
|
+
fixtureId: req.body?.fixtureId,
|
|
1250
|
+
shelfId: shelfId,
|
|
1251
|
+
clientId: planoDetails.clientId,
|
|
1252
|
+
storeName: planoDetails.storeName,
|
|
1253
|
+
storeId: planoDetails.storeId,
|
|
1254
|
+
shelfPosition: req.body?.shelfPosition,
|
|
1255
|
+
rfId: req.body.rfId,
|
|
1256
|
+
compliance: !planoProductDetails ? 'misplaced' : 'proper',
|
|
1257
|
+
date: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
1258
|
+
};
|
|
1259
|
+
delete data._id;
|
|
1260
|
+
delete query.rfId;
|
|
1261
|
+
query = { ...query, date: new Date( dayjs().format( 'YYYY-MM-DD' ) ), shelfPosition: req.body.shelfPosition };
|
|
1262
|
+
await planoComplianceService.updateOne( query, data );
|
|
1263
|
+
if ( !planoProductDetails ) {
|
|
1264
|
+
return res.sendSuccess( false );
|
|
1265
|
+
}
|
|
1266
|
+
return res.sendSuccess( true );
|
|
1267
|
+
} catch ( e ) {
|
|
1268
|
+
logger.error( { functonName: 'scan', error: e } );
|
|
1269
|
+
return res.sendError( e, 500 );
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
|
|
977
1273
|
export async function scanv1( req, res ) {
|
|
978
1274
|
try {
|
|
979
1275
|
if ( !req.body.floorId ) return res.sendError( 'Floor id is required', 400 );
|
|
@@ -1626,6 +1922,7 @@ export async function storeFixturesTask( req, res ) {
|
|
|
1626
1922
|
const floorsWithFixtures = await Promise.all(
|
|
1627
1923
|
floors.map( async ( floor ) => {
|
|
1628
1924
|
let productCapacity = 0;
|
|
1925
|
+
let fixtureCount = 0;
|
|
1629
1926
|
const layoutPolygonWithFixtures = await Promise.all(
|
|
1630
1927
|
floor.layoutPolygon.map( async ( element ) => {
|
|
1631
1928
|
const fixtures = await storeFixtureService.findAndSort( {
|
|
@@ -1647,6 +1944,7 @@ export async function storeFixturesTask( req, res ) {
|
|
|
1647
1944
|
fixture.imageUrl = '';
|
|
1648
1945
|
}
|
|
1649
1946
|
productCapacity += fixture.toObject().fixtureCapacity;
|
|
1947
|
+
fixtureCount += 1;
|
|
1650
1948
|
const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
|
|
1651
1949
|
|
|
1652
1950
|
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
|
|
@@ -1677,9 +1975,16 @@ export async function storeFixturesTask( req, res ) {
|
|
|
1677
1975
|
|
|
1678
1976
|
const vmDetails = await Promise.all( vms.map( async ( vm ) => {
|
|
1679
1977
|
const vmTemplate = await planoProductService.findOne( { _id: vm.toObject().productId } );
|
|
1978
|
+
const params = {
|
|
1979
|
+
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
1980
|
+
file_path: vmTemplate?.productImageUrl,
|
|
1981
|
+
};
|
|
1982
|
+
const vmImage = await signedUrl( params );
|
|
1680
1983
|
return {
|
|
1681
1984
|
...vm.toObject(),
|
|
1682
1985
|
...vmTemplate?.toObject(),
|
|
1986
|
+
...( typeof vmImage === 'string' && { productImageUrl: vmImage } ),
|
|
1987
|
+
|
|
1683
1988
|
};
|
|
1684
1989
|
} ) );
|
|
1685
1990
|
|
|
@@ -1727,6 +2032,7 @@ export async function storeFixturesTask( req, res ) {
|
|
|
1727
2032
|
fixture.imageUrl = '';
|
|
1728
2033
|
}
|
|
1729
2034
|
productCapacity += fixture.toObject().fixtureCapacity;
|
|
2035
|
+
fixtureCount += 1;
|
|
1730
2036
|
const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
|
|
1731
2037
|
|
|
1732
2038
|
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
|
|
@@ -1758,9 +2064,16 @@ export async function storeFixturesTask( req, res ) {
|
|
|
1758
2064
|
const vmDetails = await Promise.all( vms.map( async ( vm ) => {
|
|
1759
2065
|
const vmTemplate = await planoProductService.findOne( { _id: vm.toObject().productId } );
|
|
1760
2066
|
|
|
2067
|
+
const params = {
|
|
2068
|
+
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
2069
|
+
file_path: vmTemplate?.productImageUrl,
|
|
2070
|
+
};
|
|
2071
|
+
const vmImage = await signedUrl( params );
|
|
1761
2072
|
return {
|
|
1762
2073
|
...vm.toObject(),
|
|
1763
2074
|
...vmTemplate?.toObject(),
|
|
2075
|
+
...( typeof vmImage === 'string' && { productImageUrl: vmImage } ),
|
|
2076
|
+
|
|
1764
2077
|
};
|
|
1765
2078
|
} ) );
|
|
1766
2079
|
|
|
@@ -1776,7 +2089,7 @@ export async function storeFixturesTask( req, res ) {
|
|
|
1776
2089
|
} ),
|
|
1777
2090
|
);
|
|
1778
2091
|
|
|
1779
|
-
|
|
2092
|
+
const productCount = await planoMappingService.count( { floorId: floor._id } );
|
|
1780
2093
|
|
|
1781
2094
|
const otherElements = await storeFixtureService.find( {
|
|
1782
2095
|
floorId: floor._id,
|
|
@@ -1790,6 +2103,7 @@ export async function storeFixturesTask( req, res ) {
|
|
|
1790
2103
|
layoutPolygon: layoutPolygonWithFixtures,
|
|
1791
2104
|
centerFixture: centerFixturesWithStatus,
|
|
1792
2105
|
productCount: productCapacity,
|
|
2106
|
+
fixtureCount: fixtureCount,
|
|
1793
2107
|
// productCapacity: productCapacity,
|
|
1794
2108
|
otherElements: otherElements,
|
|
1795
2109
|
};
|
|
@@ -2599,525 +2913,3 @@ export async function qrScan( req, res ) {
|
|
|
2599
2913
|
return res.sendError( e, 500 );
|
|
2600
2914
|
}
|
|
2601
2915
|
}
|
|
2602
|
-
|
|
2603
|
-
export async function storeFixturesv2( req, res ) {
|
|
2604
|
-
try {
|
|
2605
|
-
const planoIds = req.body.id
|
|
2606
|
-
.filter( ( id ) => mongoose.Types.ObjectId.isValid( id ) )
|
|
2607
|
-
.map( ( id ) => new mongoose.Types.ObjectId( id ) );
|
|
2608
|
-
|
|
2609
|
-
const planograms = await planoService.find(
|
|
2610
|
-
{
|
|
2611
|
-
$or: [
|
|
2612
|
-
{ _id: { $in: planoIds } },
|
|
2613
|
-
{ storeId: { $in: req.body.id } },
|
|
2614
|
-
],
|
|
2615
|
-
},
|
|
2616
|
-
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1, clientId: 1, validateShelfSections: 1 },
|
|
2617
|
-
);
|
|
2618
|
-
|
|
2619
|
-
if ( !planograms?.length ) return res.sendError( 'No data found', 204 );
|
|
2620
|
-
|
|
2621
|
-
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
2622
|
-
|
|
2623
|
-
const storeLayout = await Promise.all(
|
|
2624
|
-
planograms.map( async ( planogram ) => {
|
|
2625
|
-
const floors = await storeBuilderService.find(
|
|
2626
|
-
{ planoId: planogram._id },
|
|
2627
|
-
{ floorName: 1, layoutPolygon: 1, planoId: 1 },
|
|
2628
|
-
);
|
|
2629
|
-
|
|
2630
|
-
const floorsWithFixtures = await Promise.all(
|
|
2631
|
-
floors.map( async ( floor ) => {
|
|
2632
|
-
let productCapacity = 0;
|
|
2633
|
-
const layoutPolygonWithFixtures = await Promise.all(
|
|
2634
|
-
floor.layoutPolygon.map( async ( element ) => {
|
|
2635
|
-
const fixtures = await storeFixtureService.findAndSort( {
|
|
2636
|
-
floorId: floor._id,
|
|
2637
|
-
associatedElementType: element.elementType,
|
|
2638
|
-
associatedElementNumber: element.elementNumber,
|
|
2639
|
-
fixtureType: 'wall',
|
|
2640
|
-
}, { shelfcount: 0 }, { fixtureNumber: 1 } );
|
|
2641
|
-
|
|
2642
|
-
const fixturesWithStatus = await Promise.all(
|
|
2643
|
-
fixtures.map( async ( fixture ) => {
|
|
2644
|
-
if ( fixture?.imageUrl ) {
|
|
2645
|
-
let params = {
|
|
2646
|
-
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
2647
|
-
file_path: fixture.imageUrl,
|
|
2648
|
-
};
|
|
2649
|
-
fixture.imageUrl = await signedUrl( params );
|
|
2650
|
-
} else {
|
|
2651
|
-
fixture.imageUrl = '';
|
|
2652
|
-
}
|
|
2653
|
-
productCapacity += fixture.toObject().fixtureCapacity;
|
|
2654
|
-
const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
|
|
2655
|
-
|
|
2656
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
|
|
2657
|
-
|
|
2658
|
-
const complianceCount = await planoComplianceService.count( {
|
|
2659
|
-
fixtureId: fixture._id,
|
|
2660
|
-
compliance: 'proper',
|
|
2661
|
-
date: currentDate,
|
|
2662
|
-
} );
|
|
2663
|
-
|
|
2664
|
-
const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { }, { shelfNumber: 1 } );
|
|
2665
|
-
|
|
2666
|
-
const shelfDetails = await Promise.all(
|
|
2667
|
-
shelves.map( async ( shelf ) => {
|
|
2668
|
-
const productCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'product' } );
|
|
2669
|
-
|
|
2670
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'vm' } );
|
|
2671
|
-
|
|
2672
|
-
return {
|
|
2673
|
-
...shelf.toObject(),
|
|
2674
|
-
productCount: productCount,
|
|
2675
|
-
vmCount: vmCount,
|
|
2676
|
-
};
|
|
2677
|
-
} ),
|
|
2678
|
-
);
|
|
2679
|
-
|
|
2680
|
-
let fixtureStatus;
|
|
2681
|
-
|
|
2682
|
-
const cvProcessStatus = await planoQrConversionRequestService.count( { fixtureId: fixture._id, date: currentDate, status: 'initiated' } );
|
|
2683
|
-
|
|
2684
|
-
if ( cvProcessStatus ) {
|
|
2685
|
-
fixtureStatus = 'inprogress';
|
|
2686
|
-
} else {
|
|
2687
|
-
const missingCount = await planoComplianceService.count( {
|
|
2688
|
-
fixtureId: fixture._id,
|
|
2689
|
-
compliance: 'missing',
|
|
2690
|
-
date: currentDate,
|
|
2691
|
-
} );
|
|
2692
|
-
fixtureStatus = complianceCount === 0 && !missingCount ? '' : complianceCount === productCount ? 'complete' : 'incomplete';
|
|
2693
|
-
}
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
const vmDetails = await Promise.all( fixture.toObject()?.vmConfig?.map( async ( vm ) => {
|
|
2697
|
-
const vmInfo = await planoVmService.findOne( { _id: vm.vmId } );
|
|
2698
|
-
return {
|
|
2699
|
-
...vm,
|
|
2700
|
-
...vmInfo?.toObject(),
|
|
2701
|
-
};
|
|
2702
|
-
} ) );
|
|
2703
|
-
|
|
2704
|
-
return {
|
|
2705
|
-
...fixture.toObject(),
|
|
2706
|
-
status: fixtureStatus,
|
|
2707
|
-
shelfCount: shelves.length,
|
|
2708
|
-
productCount: productCount,
|
|
2709
|
-
vmCount: vmCount,
|
|
2710
|
-
shelfConfig: shelfDetails,
|
|
2711
|
-
vmConfig: vmDetails,
|
|
2712
|
-
};
|
|
2713
|
-
} ),
|
|
2714
|
-
);
|
|
2715
|
-
|
|
2716
|
-
const otherElements = await storeFixtureService.find( {
|
|
2717
|
-
floorId: floor._id,
|
|
2718
|
-
associatedElementType: element.elementType,
|
|
2719
|
-
associatedElementNumber: element.elementNumber,
|
|
2720
|
-
fixtureType: 'other',
|
|
2721
|
-
} );
|
|
2722
|
-
|
|
2723
|
-
return {
|
|
2724
|
-
...element,
|
|
2725
|
-
fixtures: fixturesWithStatus,
|
|
2726
|
-
otherElements: otherElements,
|
|
2727
|
-
};
|
|
2728
|
-
} ),
|
|
2729
|
-
);
|
|
2730
|
-
|
|
2731
|
-
const centerFixtures = await storeFixtureService.find( {
|
|
2732
|
-
floorId: floor._id,
|
|
2733
|
-
fixtureType: 'floor',
|
|
2734
|
-
} );
|
|
2735
|
-
|
|
2736
|
-
const centerFixturesWithStatus = await Promise.all(
|
|
2737
|
-
centerFixtures.map( async ( fixture ) => {
|
|
2738
|
-
if ( fixture?.imageUrl ) {
|
|
2739
|
-
let params = {
|
|
2740
|
-
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
2741
|
-
file_path: fixture.imageUrl,
|
|
2742
|
-
};
|
|
2743
|
-
fixture.imageUrl = await signedUrl( params );
|
|
2744
|
-
} else {
|
|
2745
|
-
fixture.imageUrl = '';
|
|
2746
|
-
}
|
|
2747
|
-
productCapacity += fixture.toObject().fixtureCapacity;
|
|
2748
|
-
const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
|
|
2749
|
-
|
|
2750
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
|
|
2751
|
-
|
|
2752
|
-
const complianceCount = await planoComplianceService.count( {
|
|
2753
|
-
fixtureId: fixture._id,
|
|
2754
|
-
compliance: 'proper',
|
|
2755
|
-
date: currentDate,
|
|
2756
|
-
} );
|
|
2757
|
-
|
|
2758
|
-
const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { }, { shelfNumber: 1 } );
|
|
2759
|
-
|
|
2760
|
-
const shelfDetails = await Promise.all(
|
|
2761
|
-
shelves.map( async ( shelf ) => {
|
|
2762
|
-
const productCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'product' } );
|
|
2763
|
-
|
|
2764
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'vm' } );
|
|
2765
|
-
|
|
2766
|
-
return {
|
|
2767
|
-
...shelf.toObject(),
|
|
2768
|
-
productCount: productCount,
|
|
2769
|
-
vmCount: vmCount,
|
|
2770
|
-
};
|
|
2771
|
-
} ),
|
|
2772
|
-
);
|
|
2773
|
-
|
|
2774
|
-
let fixtureStatus;
|
|
2775
|
-
|
|
2776
|
-
const cvProcessStatus = await planoQrConversionRequestService.count( { fixtureId: fixture._id, date: currentDate, status: 'initiated' } );
|
|
2777
|
-
|
|
2778
|
-
if ( cvProcessStatus ) {
|
|
2779
|
-
fixtureStatus = 'inprogress';
|
|
2780
|
-
} else {
|
|
2781
|
-
const missingCount = await planoComplianceService.count( {
|
|
2782
|
-
fixtureId: fixture._id,
|
|
2783
|
-
compliance: 'missing',
|
|
2784
|
-
date: currentDate,
|
|
2785
|
-
} );
|
|
2786
|
-
fixtureStatus = complianceCount === 0 && !missingCount ? '' : complianceCount === productCount ? 'complete' : 'incomplete';
|
|
2787
|
-
}
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
const vmDetails = await Promise.all( fixture.toObject().vmConfig.map( async ( vm ) => {
|
|
2791
|
-
const vmInfo = await planoVmService.findOne( { _id: vm.vmId } );
|
|
2792
|
-
|
|
2793
|
-
return {
|
|
2794
|
-
...vm,
|
|
2795
|
-
...vmInfo?.toObject(),
|
|
2796
|
-
};
|
|
2797
|
-
} ) );
|
|
2798
|
-
|
|
2799
|
-
return {
|
|
2800
|
-
...fixture.toObject(),
|
|
2801
|
-
status: fixtureStatus,
|
|
2802
|
-
shelfCount: shelves.shelves,
|
|
2803
|
-
productCount: productCount,
|
|
2804
|
-
vmCount: vmCount,
|
|
2805
|
-
shelfConfig: shelfDetails,
|
|
2806
|
-
vmConfig: vmDetails,
|
|
2807
|
-
|
|
2808
|
-
};
|
|
2809
|
-
} ),
|
|
2810
|
-
);
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
const otherElements = await storeFixtureService.find( {
|
|
2814
|
-
floorId: floor._id,
|
|
2815
|
-
associatedElementType: { $exists: false },
|
|
2816
|
-
associatedElementNumber: { $exists: false },
|
|
2817
|
-
fixtureType: 'other',
|
|
2818
|
-
} );
|
|
2819
|
-
|
|
2820
|
-
return {
|
|
2821
|
-
...floor.toObject(),
|
|
2822
|
-
layoutPolygon: layoutPolygonWithFixtures,
|
|
2823
|
-
centerFixture: centerFixturesWithStatus,
|
|
2824
|
-
productCount: productCapacity,
|
|
2825
|
-
// productCapacity: productCapacity,
|
|
2826
|
-
otherElements: otherElements,
|
|
2827
|
-
};
|
|
2828
|
-
} ),
|
|
2829
|
-
);
|
|
2830
|
-
|
|
2831
|
-
return {
|
|
2832
|
-
...planogram.toObject(),
|
|
2833
|
-
floors: floorsWithFixtures,
|
|
2834
|
-
};
|
|
2835
|
-
} ),
|
|
2836
|
-
);
|
|
2837
|
-
|
|
2838
|
-
return res.sendSuccess( storeLayout );
|
|
2839
|
-
} catch ( e ) {
|
|
2840
|
-
logger.error( { functionName: 'storeFixturesv1', error: e, message: req.body } );
|
|
2841
|
-
return res.sendError( e, 500 );
|
|
2842
|
-
}
|
|
2843
|
-
}
|
|
2844
|
-
|
|
2845
|
-
export async function fixtureShelfProductv2( req, res ) {
|
|
2846
|
-
try {
|
|
2847
|
-
const { planoId, fixtureId } = req.body;
|
|
2848
|
-
|
|
2849
|
-
const [ planogram, fixture ] = await Promise.all( [
|
|
2850
|
-
planoService.findOne(
|
|
2851
|
-
{ _id: new mongoose.Types.ObjectId( planoId ) },
|
|
2852
|
-
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1 },
|
|
2853
|
-
),
|
|
2854
|
-
storeFixtureService.findOne( { _id: new mongoose.Types.ObjectId( fixtureId ) } ),
|
|
2855
|
-
] );
|
|
2856
|
-
|
|
2857
|
-
if ( !planogram ) return res.sendError( 'Planogram not found', 204 );
|
|
2858
|
-
if ( !fixture ) return res.sendError( 'Fixture not found', 204 );
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
2862
|
-
|
|
2863
|
-
const getProducts = async ( mappings ) => {
|
|
2864
|
-
const productIds = mappings.map( ( mapping ) => mapping.productId );
|
|
2865
|
-
const products = await planoProductService.find( { _id: { $in: productIds }, type: 'product' } );
|
|
2866
|
-
const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
|
|
2867
|
-
|
|
2868
|
-
return await Promise.all(
|
|
2869
|
-
mappings.map( async ( mapping ) => {
|
|
2870
|
-
const productData = productMap.get( mapping?.productId?.toString() ) || {};
|
|
2871
|
-
delete productData._id;
|
|
2872
|
-
const mappingCompliance = await planoComplianceService.findOne( {
|
|
2873
|
-
planoMappingId: mapping._id,
|
|
2874
|
-
date: currentDate,
|
|
2875
|
-
} );
|
|
2876
|
-
const status = mappingCompliance ? mappingCompliance.compliance : '';
|
|
2877
|
-
return { ...mapping.toObject(), ...productData, status };
|
|
2878
|
-
} ),
|
|
2879
|
-
);
|
|
2880
|
-
};
|
|
2881
|
-
|
|
2882
|
-
const vmDetails = await Promise.all( fixture.toObject()?.vmConfig?.map( async ( vm ) => {
|
|
2883
|
-
const vmInfo = await planoVmService.findOne( { _id: vm.vmId } );
|
|
2884
|
-
return {
|
|
2885
|
-
...vm,
|
|
2886
|
-
...vmInfo?.toObject(),
|
|
2887
|
-
};
|
|
2888
|
-
} ) );
|
|
2889
|
-
|
|
2890
|
-
if ( fixture.toObject().productResolutionLevel === 'L1' ) {
|
|
2891
|
-
const productMappings = await planoMappingService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
|
|
2892
|
-
const productDetails = await getProducts( productMappings );
|
|
2893
|
-
return res.sendSuccess( { ...fixture.toObject(), products: productDetails, vmConfig: vmDetails, productCount: productMappings.length } );
|
|
2894
|
-
}
|
|
2895
|
-
|
|
2896
|
-
if ( [ 'L2', 'L3', 'L4' ].includes( fixture.toObject().productResolutionLevel ) ) {
|
|
2897
|
-
const fixtureShelves = await fixtureShelfService.findAndSort( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) }, {}, { shelfNumber: 1 } );
|
|
2898
|
-
const productCount = await planoMappingService.count( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
|
|
2899
|
-
const shelfProducts = await Promise.all(
|
|
2900
|
-
fixtureShelves.map( async ( shelf ) => {
|
|
2901
|
-
const productMappings = await planoMappingService.find( { shelfId: shelf._id, type: 'product' } );
|
|
2902
|
-
const productDetails = await getProducts( productMappings );
|
|
2903
|
-
return { ...shelf.toObject(), products: productDetails };
|
|
2904
|
-
} ),
|
|
2905
|
-
);
|
|
2906
|
-
return res.sendSuccess( { ...fixture.toObject(), shelves: shelfProducts, vmConfig: vmDetails, productCount: productCount } );
|
|
2907
|
-
}
|
|
2908
|
-
|
|
2909
|
-
return res.sendError( 'Incorrect resolution level', 400 );
|
|
2910
|
-
} catch ( e ) {
|
|
2911
|
-
logger.error( { functionName: 'fixtureShelfProductv1', error: e, message: req.body } );
|
|
2912
|
-
return res.sendError( e, 500 );
|
|
2913
|
-
}
|
|
2914
|
-
}
|
|
2915
|
-
|
|
2916
|
-
export async function storeFixturesTaskv2( req, res ) {
|
|
2917
|
-
try {
|
|
2918
|
-
const planoIds = req.body.id
|
|
2919
|
-
.filter( ( id ) => mongoose.Types.ObjectId.isValid( id ) )
|
|
2920
|
-
.map( ( id ) => new mongoose.Types.ObjectId( id ) );
|
|
2921
|
-
|
|
2922
|
-
const planograms = await planoService.find(
|
|
2923
|
-
{
|
|
2924
|
-
$or: [
|
|
2925
|
-
{ _id: { $in: planoIds } },
|
|
2926
|
-
{ storeId: { $in: req.body.id } },
|
|
2927
|
-
],
|
|
2928
|
-
},
|
|
2929
|
-
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1, validateShelfSections: 1 },
|
|
2930
|
-
);
|
|
2931
|
-
|
|
2932
|
-
if ( !planograms?.length ) return res.sendError( 'No data found', 204 );
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
const storeLayout = await Promise.all(
|
|
2936
|
-
planograms.map( async ( planogram ) => {
|
|
2937
|
-
const floors = await storeBuilderService.find(
|
|
2938
|
-
{ planoId: planogram._id },
|
|
2939
|
-
{ floorName: 1, layoutPolygon: 1, planoId: 1 },
|
|
2940
|
-
);
|
|
2941
|
-
|
|
2942
|
-
const floorsWithFixtures = await Promise.all(
|
|
2943
|
-
floors.map( async ( floor ) => {
|
|
2944
|
-
let productCapacity = 0;
|
|
2945
|
-
const layoutPolygonWithFixtures = await Promise.all(
|
|
2946
|
-
floor.layoutPolygon.map( async ( element ) => {
|
|
2947
|
-
const fixtures = await storeFixtureService.findAndSort( {
|
|
2948
|
-
floorId: floor._id,
|
|
2949
|
-
associatedElementType: element.elementType,
|
|
2950
|
-
associatedElementNumber: element.elementNumber,
|
|
2951
|
-
fixtureType: 'wall',
|
|
2952
|
-
}, { shelfcount: 0 }, { fixtureNumber: 1 } );
|
|
2953
|
-
|
|
2954
|
-
const fixturesWithStatus = await Promise.all(
|
|
2955
|
-
fixtures.map( async ( fixture ) => {
|
|
2956
|
-
if ( fixture?.imageUrl || fixture.vmImageUrl ) {
|
|
2957
|
-
let params = {
|
|
2958
|
-
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
2959
|
-
file_path: req.body.type == 'vm' ? fixture.vmImageUrl : fixture.imageUrl,
|
|
2960
|
-
};
|
|
2961
|
-
fixture.imageUrl = await signedUrl( params );
|
|
2962
|
-
} else {
|
|
2963
|
-
fixture.imageUrl = '';
|
|
2964
|
-
}
|
|
2965
|
-
productCapacity += fixture.toObject().fixtureCapacity;
|
|
2966
|
-
const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
|
|
2967
|
-
|
|
2968
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
|
|
2969
|
-
|
|
2970
|
-
const compliance = await planoTaskComplianceService.findOne( {
|
|
2971
|
-
fixtureId: fixture._id,
|
|
2972
|
-
type: req.body?.type ? req.body.type : 'fixture',
|
|
2973
|
-
date_string: req.body?.date,
|
|
2974
|
-
}, { status: 1 } );
|
|
2975
|
-
|
|
2976
|
-
const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1, shelfSplitup: 1 }, { shelfNumber: 1 } );
|
|
2977
|
-
|
|
2978
|
-
const shelfDetails = await Promise.all(
|
|
2979
|
-
shelves.map( async ( shelf ) => {
|
|
2980
|
-
const productCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'product' } );
|
|
2981
|
-
|
|
2982
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'vm' } );
|
|
2983
|
-
|
|
2984
|
-
return {
|
|
2985
|
-
...shelf.toObject(),
|
|
2986
|
-
productCount: productCount,
|
|
2987
|
-
vmCount: vmCount,
|
|
2988
|
-
};
|
|
2989
|
-
} ),
|
|
2990
|
-
);
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
const vmDetails = await Promise.all( fixture.toObject()?.vmConfig?.map( async ( vm ) => {
|
|
2994
|
-
const vmInfo = await planoVmService.findOne( { _id: vm.vmId } );
|
|
2995
|
-
return {
|
|
2996
|
-
...vm,
|
|
2997
|
-
...vmInfo?.toObject(),
|
|
2998
|
-
};
|
|
2999
|
-
} ) );
|
|
3000
|
-
|
|
3001
|
-
return {
|
|
3002
|
-
...fixture.toObject(),
|
|
3003
|
-
status: compliance?.status ? compliance.status : '',
|
|
3004
|
-
shelfCount: shelves.length,
|
|
3005
|
-
productCount: productCount,
|
|
3006
|
-
vmCount: vmCount,
|
|
3007
|
-
shelfConfig: shelfDetails,
|
|
3008
|
-
vmConfig: vmDetails,
|
|
3009
|
-
};
|
|
3010
|
-
} ),
|
|
3011
|
-
);
|
|
3012
|
-
|
|
3013
|
-
const otherElements = await storeFixtureService.find( {
|
|
3014
|
-
floorId: floor._id,
|
|
3015
|
-
associatedElementType: element.elementType,
|
|
3016
|
-
associatedElementNumber: element.elementNumber,
|
|
3017
|
-
fixtureType: 'other',
|
|
3018
|
-
} );
|
|
3019
|
-
|
|
3020
|
-
return {
|
|
3021
|
-
...element,
|
|
3022
|
-
fixtures: fixturesWithStatus,
|
|
3023
|
-
otherElements: otherElements,
|
|
3024
|
-
};
|
|
3025
|
-
} ),
|
|
3026
|
-
);
|
|
3027
|
-
|
|
3028
|
-
const centerFixtures = await storeFixtureService.find( {
|
|
3029
|
-
floorId: floor._id,
|
|
3030
|
-
fixtureType: 'floor',
|
|
3031
|
-
} );
|
|
3032
|
-
|
|
3033
|
-
const centerFixturesWithStatus = await Promise.all(
|
|
3034
|
-
centerFixtures.map( async ( fixture ) => {
|
|
3035
|
-
if ( fixture?.imageUrl || fixture.vmImageUrl ) {
|
|
3036
|
-
let params = {
|
|
3037
|
-
Bucket: JSON.parse( process.env.BUCKET ).storeBuilder,
|
|
3038
|
-
file_path: req.body.type == 'vm' ? fixture.vmImageUrl : fixture.imageUrl,
|
|
3039
|
-
};
|
|
3040
|
-
fixture.imageUrl = await signedUrl( params );
|
|
3041
|
-
} else {
|
|
3042
|
-
fixture.imageUrl = '';
|
|
3043
|
-
}
|
|
3044
|
-
productCapacity += fixture.toObject().fixtureCapacity;
|
|
3045
|
-
const productCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'product' } );
|
|
3046
|
-
|
|
3047
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, type: 'vm' } );
|
|
3048
|
-
|
|
3049
|
-
const compliance = await planoTaskComplianceService.findOne( {
|
|
3050
|
-
fixtureId: fixture._id,
|
|
3051
|
-
type: req.body?.type ? req.body.type : 'fixture',
|
|
3052
|
-
date_string: req.body?.date,
|
|
3053
|
-
}, { status: 1 } );
|
|
3054
|
-
|
|
3055
|
-
const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { shelfNumber: 1, sectionName: 1, sectionZone: 1, shelfCapacity: 1, shelfSplitup: 1 }, { shelfNumber: 1 } );
|
|
3056
|
-
|
|
3057
|
-
const shelfDetails = await Promise.all(
|
|
3058
|
-
shelves.map( async ( shelf ) => {
|
|
3059
|
-
const productCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'product' } );
|
|
3060
|
-
|
|
3061
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'vm' } );
|
|
3062
|
-
|
|
3063
|
-
return {
|
|
3064
|
-
...shelf.toObject(),
|
|
3065
|
-
productCount: productCount,
|
|
3066
|
-
vmCount: vmCount,
|
|
3067
|
-
};
|
|
3068
|
-
} ),
|
|
3069
|
-
);
|
|
3070
|
-
|
|
3071
|
-
const vmDetails = await Promise.all( fixture.toObject()?.vmConfig?.map( async ( vm ) => {
|
|
3072
|
-
const vmInfo = await planoVmService.findOne( { _id: vm.vmId } );
|
|
3073
|
-
return {
|
|
3074
|
-
...vm,
|
|
3075
|
-
...vmInfo?.toObject(),
|
|
3076
|
-
};
|
|
3077
|
-
} ) );
|
|
3078
|
-
|
|
3079
|
-
return {
|
|
3080
|
-
...fixture.toObject(),
|
|
3081
|
-
status: compliance?.status ? compliance.status : '',
|
|
3082
|
-
shelfCount: shelves.shelves,
|
|
3083
|
-
productCount: productCount,
|
|
3084
|
-
vmCount: vmCount,
|
|
3085
|
-
shelfConfig: shelfDetails,
|
|
3086
|
-
vms: vmDetails,
|
|
3087
|
-
};
|
|
3088
|
-
} ),
|
|
3089
|
-
);
|
|
3090
|
-
|
|
3091
|
-
// const productCount = await planoMappingService.count( { floorId: floor._id } );
|
|
3092
|
-
|
|
3093
|
-
const otherElements = await storeFixtureService.find( {
|
|
3094
|
-
floorId: floor._id,
|
|
3095
|
-
associatedElementType: { $exists: false },
|
|
3096
|
-
associatedElementNumber: { $exists: false },
|
|
3097
|
-
fixtureType: 'other',
|
|
3098
|
-
} );
|
|
3099
|
-
|
|
3100
|
-
return {
|
|
3101
|
-
...floor.toObject(),
|
|
3102
|
-
layoutPolygon: layoutPolygonWithFixtures,
|
|
3103
|
-
centerFixture: centerFixturesWithStatus,
|
|
3104
|
-
productCount: productCapacity,
|
|
3105
|
-
// productCapacity: productCapacity,
|
|
3106
|
-
otherElements: otherElements,
|
|
3107
|
-
};
|
|
3108
|
-
} ),
|
|
3109
|
-
);
|
|
3110
|
-
|
|
3111
|
-
return {
|
|
3112
|
-
...planogram.toObject(),
|
|
3113
|
-
floors: floorsWithFixtures,
|
|
3114
|
-
};
|
|
3115
|
-
} ),
|
|
3116
|
-
);
|
|
3117
|
-
|
|
3118
|
-
return res.sendSuccess( storeLayout );
|
|
3119
|
-
} catch ( e ) {
|
|
3120
|
-
logger.error( { functionName: 'storeFixturesTask', error: e, message: req.body } );
|
|
3121
|
-
return res.sendError( e, 500 );
|
|
3122
|
-
}
|
|
3123
|
-
}
|