tango-app-api-store-builder 1.0.0-beta-20 → 1.0.0-beta-21

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-20",
3
+ "version": "1.0.0-beta-21",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -789,14 +789,14 @@ export async function fixtureShelfProductv1( req, res ) {
789
789
  if ( !planogram ) return res.sendError( 'Planogram not found', 204 );
790
790
  if ( !fixture ) return res.sendError( 'Fixture not found', 204 );
791
791
 
792
+ const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
793
+
792
794
  if ( fixture.toObject().productResolutionLevel === 'L1' ) {
793
795
  const productMappings = await planoMappingService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
794
796
  const productIds = productMappings.map( ( mapping ) => mapping.productId );
795
797
  const products = await planoProductService.find( { _id: { $in: productIds } } );
796
798
  const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
797
799
 
798
- const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
799
-
800
800
  const productDetails = await Promise.all(
801
801
  productMappings.map( async ( mapping ) => {
802
802
  const productData = productMap.get( mapping.productId.toString() ) || {};
@@ -811,7 +811,28 @@ export async function fixtureShelfProductv1( req, res ) {
811
811
  } ),
812
812
  );
813
813
 
814
- return res.sendSuccess( { ...fixture.toObject(), products: productDetails } );
814
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
815
+ planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
816
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
817
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
818
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
819
+ ] );
820
+
821
+ const fixtureMetrics = {
822
+ total: totalProducts,
823
+ scanned: scannedProducts,
824
+ misplaced: misplacedProducts,
825
+ missing: 0,
826
+ proper: properProducts,
827
+ };
828
+
829
+ if ( fixtureMetrics.scanned === 0 ) {
830
+ fixtureMetrics.missing = fixtureMetrics.total;
831
+ } else if ( fixtureMetrics.scanned > 0 ) {
832
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
833
+ }
834
+
835
+ return res.sendSuccess( { ...fixture.toObject(), products: productDetails, fixtureMetrics: fixtureMetrics } );
815
836
  }
816
837
  if ( fixture.toObject().productResolutionLevel === 'L2' || fixture.toObject().productResolutionLevel === 'L4' ) {
817
838
  const fixtureShelves = await fixtureShelfService.find( {
@@ -832,8 +853,6 @@ export async function fixtureShelfProductv1( req, res ) {
832
853
  const products = await planoProductService.find( { _id: { $in: productIds } } );
833
854
  const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
834
855
 
835
- const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
836
-
837
856
  const productDetails = await Promise.all(
838
857
  productMappings.map( async ( mapping ) => {
839
858
  const productData = productMap.get( mapping.productId.toString() );
@@ -863,7 +882,28 @@ export async function fixtureShelfProductv1( req, res ) {
863
882
  } ),
864
883
  );
865
884
 
866
- return res.sendSuccess( { ...fixture.toObject(), shelves: shelfProducts } );
885
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
886
+ planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
887
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
888
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
889
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
890
+ ] );
891
+
892
+ const fixtureMetrics = {
893
+ total: totalProducts,
894
+ scanned: scannedProducts,
895
+ misplaced: misplacedProducts,
896
+ missing: 0,
897
+ proper: properProducts,
898
+ };
899
+
900
+ if ( fixtureMetrics.scanned === 0 ) {
901
+ fixtureMetrics.missing = fixtureMetrics.total;
902
+ } else if ( fixtureMetrics.scanned > 0 ) {
903
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
904
+ }
905
+
906
+ return res.sendSuccess( { ...fixture.toObject(), shelves: shelfProducts, fixtureMetrics: fixtureMetrics } );
867
907
  } else if ( fixture.toObject().productResolutionLevel === 'L3' ) {
868
908
  const fixtureShelves = await fixtureShelfService.find( {
869
909
  fixtureId: new mongoose.Types.ObjectId( fixtureId ),
@@ -883,7 +923,6 @@ export async function fixtureShelfProductv1( req, res ) {
883
923
  const products = await planoProductService.find( { _id: { $in: productIds } } );
884
924
  const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
885
925
 
886
- const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
887
926
 
888
927
  const productDetails = await Promise.all(
889
928
  productMappings.map( async ( mapping ) => {
@@ -923,7 +962,28 @@ export async function fixtureShelfProductv1( req, res ) {
923
962
  return acc;
924
963
  }, {} );
925
964
  } )();
926
- return res.sendSuccess( { ...fixture.toObject(), categories: groupedShelves } );
965
+
966
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
967
+ planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
968
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
969
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
970
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
971
+ ] );
972
+
973
+ const fixtureMetrics = {
974
+ total: totalProducts,
975
+ scanned: scannedProducts,
976
+ misplaced: misplacedProducts,
977
+ missing: 0,
978
+ proper: properProducts,
979
+ };
980
+
981
+ if ( fixtureMetrics.scanned === 0 ) {
982
+ fixtureMetrics.missing = fixtureMetrics.total;
983
+ } else if ( fixtureMetrics.scanned > 0 ) {
984
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
985
+ }
986
+ return res.sendSuccess( { ...fixture.toObject(), categories: groupedShelves, fixtureMetrics: fixtureMetrics } );
927
987
  } else {
928
988
  return res.sendError( 'Incorrect resolution level', 400 );
929
989
  }
@@ -1114,11 +1174,10 @@ export async function scanv1( req, res ) {
1114
1174
 
1115
1175
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
1116
1176
 
1117
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1177
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1118
1178
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1119
1179
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1120
1180
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1121
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1122
1181
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1123
1182
  ] );
1124
1183
 
@@ -1126,10 +1185,16 @@ export async function scanv1( req, res ) {
1126
1185
  total: totalProducts,
1127
1186
  scanned: scannedProducts,
1128
1187
  misplaced: misplacedProducts,
1129
- missing: missingProducts,
1188
+ missing: 0,
1130
1189
  proper: properProducts,
1131
1190
  };
1132
1191
 
1192
+ if ( fixtureMetrics.scanned === 0 ) {
1193
+ fixtureMetrics.missing = fixtureMetrics.total;
1194
+ } else if ( fixtureMetrics.scanned > 0 ) {
1195
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1196
+ }
1197
+
1133
1198
  return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
1134
1199
  }
1135
1200
 
@@ -1140,11 +1205,10 @@ export async function scanv1( req, res ) {
1140
1205
 
1141
1206
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1142
1207
 
1143
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1208
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1144
1209
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1145
1210
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1146
1211
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1147
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1148
1212
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1149
1213
  ] );
1150
1214
 
@@ -1152,10 +1216,16 @@ export async function scanv1( req, res ) {
1152
1216
  total: totalProducts,
1153
1217
  scanned: scannedProducts,
1154
1218
  misplaced: misplacedProducts,
1155
- missing: missingProducts,
1219
+ missing: 0,
1156
1220
  proper: properProducts,
1157
1221
  };
1158
1222
 
1223
+ if ( fixtureMetrics.scanned === 0 ) {
1224
+ fixtureMetrics.missing = fixtureMetrics.total;
1225
+ } else if ( fixtureMetrics.scanned > 0 ) {
1226
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1227
+ }
1228
+
1159
1229
  return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'proper' } );
1160
1230
  } else if ( fixture.productResolutionLevel === 'L2' ) {
1161
1231
  if ( !req.body.shelfId && req.body.rfId ) {
@@ -1212,23 +1282,27 @@ export async function scanv1( req, res ) {
1212
1282
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate, compliance: { $ne: 'proper' } }, complianceData );
1213
1283
  }
1214
1284
 
1215
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1285
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1216
1286
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1217
1287
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1218
1288
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1219
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1220
1289
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1221
-
1222
1290
  ] );
1223
1291
 
1224
1292
  const fixtureMetrics = {
1225
1293
  total: totalProducts,
1226
1294
  scanned: scannedProducts,
1227
1295
  misplaced: misplacedProducts,
1228
- missing: missingProducts,
1296
+ missing: 0,
1229
1297
  proper: properProducts,
1230
1298
  };
1231
1299
 
1300
+ if ( fixtureMetrics.scanned === 0 ) {
1301
+ fixtureMetrics.missing = fixtureMetrics.total;
1302
+ } else if ( fixtureMetrics.scanned > 0 ) {
1303
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1304
+ }
1305
+
1232
1306
  return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
1233
1307
  }
1234
1308
 
@@ -1239,23 +1313,27 @@ export async function scanv1( req, res ) {
1239
1313
 
1240
1314
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1241
1315
 
1242
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1316
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1243
1317
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1244
1318
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1245
1319
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1246
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1247
1320
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1248
-
1249
1321
  ] );
1250
1322
 
1251
1323
  const fixtureMetrics = {
1252
1324
  total: totalProducts,
1253
1325
  scanned: scannedProducts,
1254
1326
  misplaced: misplacedProducts,
1255
- missing: missingProducts,
1327
+ missing: 0,
1256
1328
  proper: properProducts,
1257
1329
  };
1258
1330
 
1331
+ if ( fixtureMetrics.scanned === 0 ) {
1332
+ fixtureMetrics.missing = fixtureMetrics.total;
1333
+ } else if ( fixtureMetrics.scanned > 0 ) {
1334
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1335
+ }
1336
+
1259
1337
  const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1260
1338
  planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1261
1339
  planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
@@ -1330,22 +1408,26 @@ export async function scanv1( req, res ) {
1330
1408
 
1331
1409
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
1332
1410
 
1333
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1411
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1334
1412
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1335
1413
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1336
1414
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1337
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1338
1415
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1339
-
1340
1416
  ] );
1341
1417
 
1342
1418
  const fixtureMetrics = {
1343
1419
  total: totalProducts,
1344
1420
  scanned: scannedProducts,
1345
1421
  misplaced: misplacedProducts,
1346
- missing: missingProducts,
1422
+ missing: 0,
1347
1423
  proper: properProducts,
1348
1424
  };
1425
+
1426
+ if ( fixtureMetrics.scanned === 0 ) {
1427
+ fixtureMetrics.missing = fixtureMetrics.total;
1428
+ } else if ( fixtureMetrics.scanned > 0 ) {
1429
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1430
+ }
1349
1431
  const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1350
1432
  planoMappingService.count( { shelfId: misplacedProductMapping.toObject().shelfId } ),
1351
1433
  planoComplianceService.count( { date: currentDate, shelfId: misplacedProductMapping.toObject().shelfId, compliance: 'proper' } ),
@@ -1370,11 +1452,10 @@ export async function scanv1( req, res ) {
1370
1452
 
1371
1453
  await planoComplianceService.updateOne( { ...mappingQuery, planoMappingId: productMapping.toObject()._id, date: currentDate }, complianceData );
1372
1454
 
1373
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1455
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1374
1456
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1375
1457
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1376
1458
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1377
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1378
1459
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1379
1460
  ] );
1380
1461
 
@@ -1382,10 +1463,16 @@ export async function scanv1( req, res ) {
1382
1463
  total: totalProducts,
1383
1464
  scanned: scannedProducts,
1384
1465
  misplaced: misplacedProducts,
1385
- missing: missingProducts,
1466
+ missing: 0,
1386
1467
  proper: properProducts,
1387
1468
  };
1388
1469
 
1470
+ if ( fixtureMetrics.scanned === 0 ) {
1471
+ fixtureMetrics.missing = fixtureMetrics.total;
1472
+ } else if ( fixtureMetrics.scanned > 0 ) {
1473
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1474
+ }
1475
+
1389
1476
  const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1390
1477
  planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1391
1478
  planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
@@ -1448,11 +1535,10 @@ export async function scanv1( req, res ) {
1448
1535
  }
1449
1536
 
1450
1537
 
1451
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1538
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1452
1539
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1453
1540
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1454
1541
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1455
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1456
1542
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1457
1543
  ] );
1458
1544
 
@@ -1460,10 +1546,16 @@ export async function scanv1( req, res ) {
1460
1546
  total: totalProducts,
1461
1547
  scanned: scannedProducts,
1462
1548
  misplaced: misplacedProducts,
1463
- missing: missingProducts,
1549
+ missing: 0,
1464
1550
  proper: properProducts,
1465
1551
  };
1466
1552
 
1553
+ if ( fixtureMetrics.scanned === 0 ) {
1554
+ fixtureMetrics.missing = fixtureMetrics.total;
1555
+ } else if ( fixtureMetrics.scanned > 0 ) {
1556
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1557
+ }
1558
+
1467
1559
  return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
1468
1560
  }
1469
1561
 
@@ -1474,11 +1566,10 @@ export async function scanv1( req, res ) {
1474
1566
 
1475
1567
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1476
1568
 
1477
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1569
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1478
1570
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1479
1571
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1480
1572
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1481
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1482
1573
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1483
1574
  ] );
1484
1575
 
@@ -1486,10 +1577,16 @@ export async function scanv1( req, res ) {
1486
1577
  total: totalProducts,
1487
1578
  scanned: scannedProducts,
1488
1579
  misplaced: misplacedProducts,
1489
- missing: missingProducts,
1580
+ missing: 0,
1490
1581
  proper: properProducts,
1491
1582
  };
1492
1583
 
1584
+ if ( fixtureMetrics.scanned === 0 ) {
1585
+ fixtureMetrics.missing = fixtureMetrics.total;
1586
+ } else if ( fixtureMetrics.scanned > 0 ) {
1587
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1588
+ }
1589
+
1493
1590
  const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1494
1591
  planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1495
1592
  planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
@@ -6286,3 +6383,55 @@ export async function bulkFixtureUpload( req, res ) {
6286
6383
 
6287
6384
  // const cleanedData = cleanData( data );
6288
6385
  // saveToFile( 'output.txt', cleanedData );
6386
+
6387
+
6388
+ // Find Duplicate Ids
6389
+
6390
+ import fs from 'fs';
6391
+
6392
+ async function findDuplicates() {
6393
+ try {
6394
+ const keys1 = await planoMappingService.find( { clientId: '11' }, { rfId: 1, _id: 0 } );
6395
+ const keys2 = await fixtureShelfService.find( { clientId: '11' }, { rfId: 1, _id: 0 } );
6396
+
6397
+ const keyArray1 = keys1.map( ( doc ) => doc.toObject().rfId );
6398
+ const keyArray2 = keys2.map( ( doc ) => doc.toObject().rfId );
6399
+
6400
+ const findDuplicatesInArray = ( arr ) => {
6401
+ const countMap = new Map();
6402
+ arr.forEach( ( key ) => countMap.set( key, ( countMap.get( key ) || 0 ) + 1 ) );
6403
+ return [ ...countMap.entries() ].filter( ( [ _, count ] ) => count > 1 ).map( ( [ key ] ) => key );
6404
+ };
6405
+
6406
+ const duplicatesInCollection1 = findDuplicatesInArray( keyArray1 );
6407
+ const duplicatesInCollection2 = findDuplicatesInArray( keyArray2 );
6408
+
6409
+ const set1 = new Set( keyArray1 );
6410
+ const set2 = new Set( keyArray2 );
6411
+ const duplicatesAcrossCollections = [ ...set1 ].filter( ( key ) => set2.has( key ) );
6412
+
6413
+ let output = '';
6414
+
6415
+ if ( duplicatesInCollection1.length > 0 ) {
6416
+ output += `Duplicates within product:\n${duplicatesInCollection1.join( '\n' )}\n\n`;
6417
+ }
6418
+ if ( duplicatesInCollection2.length > 0 ) {
6419
+ output += `Duplicates within shelf:\n${duplicatesInCollection2.join( '\n' )}\n\n`;
6420
+ }
6421
+ if ( duplicatesAcrossCollections.length > 0 ) {
6422
+ output += `Duplicates across product & shelf:\n${duplicatesAcrossCollections.join( '\n' )}\n\n`;
6423
+ }
6424
+
6425
+ if ( output ) {
6426
+ const filePath = 'duplicates.txt';
6427
+ fs.writeFileSync( filePath, output, 'utf8' );
6428
+ console.log( `Duplicates written to ${filePath}` );
6429
+ } else {
6430
+ console.log( 'No duplicates found.' );
6431
+ }
6432
+ } catch ( error ) {
6433
+ console.error( 'Error:', error );
6434
+ }
6435
+ }
6436
+
6437
+ // findDuplicates();