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

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-22",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -582,9 +582,17 @@ export async function storeFixturesv1( req, res ) {
582
582
  } ),
583
583
  );
584
584
 
585
+ const otherElements = await storeFixtureService.find( {
586
+ floorId: floor._id,
587
+ associatedElementType: element.elementType,
588
+ associatedElementNumber: element.elementNumber,
589
+ fixtureType: 'other',
590
+ } );
591
+
585
592
  return {
586
593
  ...element,
587
594
  fixtures: fixturesWithStatus,
595
+ otherElements: otherElements,
588
596
  };
589
597
  } ),
590
598
  );
@@ -616,6 +624,8 @@ export async function storeFixturesv1( req, res ) {
616
624
 
617
625
  const otherElements = await storeFixtureService.find( {
618
626
  floorId: floor._id,
627
+ associatedElementType: { $exists: false },
628
+ associatedElementNumber: { $exists: false },
619
629
  fixtureType: 'other',
620
630
  } );
621
631
 
@@ -789,14 +799,14 @@ export async function fixtureShelfProductv1( req, res ) {
789
799
  if ( !planogram ) return res.sendError( 'Planogram not found', 204 );
790
800
  if ( !fixture ) return res.sendError( 'Fixture not found', 204 );
791
801
 
802
+ const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
803
+
792
804
  if ( fixture.toObject().productResolutionLevel === 'L1' ) {
793
805
  const productMappings = await planoMappingService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ) } );
794
806
  const productIds = productMappings.map( ( mapping ) => mapping.productId );
795
807
  const products = await planoProductService.find( { _id: { $in: productIds } } );
796
808
  const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
797
809
 
798
- const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
799
-
800
810
  const productDetails = await Promise.all(
801
811
  productMappings.map( async ( mapping ) => {
802
812
  const productData = productMap.get( mapping.productId.toString() ) || {};
@@ -811,7 +821,28 @@ export async function fixtureShelfProductv1( req, res ) {
811
821
  } ),
812
822
  );
813
823
 
814
- return res.sendSuccess( { ...fixture.toObject(), products: productDetails } );
824
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
825
+ planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
826
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
827
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
828
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
829
+ ] );
830
+
831
+ const fixtureMetrics = {
832
+ total: totalProducts,
833
+ scanned: scannedProducts,
834
+ misplaced: misplacedProducts,
835
+ missing: 0,
836
+ proper: properProducts,
837
+ };
838
+
839
+ if ( fixtureMetrics.scanned === 0 ) {
840
+ fixtureMetrics.missing = fixtureMetrics.total;
841
+ } else if ( fixtureMetrics.scanned > 0 ) {
842
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
843
+ }
844
+
845
+ return res.sendSuccess( { ...fixture.toObject(), products: productDetails, fixtureMetrics: fixtureMetrics } );
815
846
  }
816
847
  if ( fixture.toObject().productResolutionLevel === 'L2' || fixture.toObject().productResolutionLevel === 'L4' ) {
817
848
  const fixtureShelves = await fixtureShelfService.find( {
@@ -832,8 +863,6 @@ export async function fixtureShelfProductv1( req, res ) {
832
863
  const products = await planoProductService.find( { _id: { $in: productIds } } );
833
864
  const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
834
865
 
835
- const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
836
-
837
866
  const productDetails = await Promise.all(
838
867
  productMappings.map( async ( mapping ) => {
839
868
  const productData = productMap.get( mapping.productId.toString() );
@@ -863,7 +892,28 @@ export async function fixtureShelfProductv1( req, res ) {
863
892
  } ),
864
893
  );
865
894
 
866
- return res.sendSuccess( { ...fixture.toObject(), shelves: shelfProducts } );
895
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
896
+ planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
897
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
898
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
899
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
900
+ ] );
901
+
902
+ const fixtureMetrics = {
903
+ total: totalProducts,
904
+ scanned: scannedProducts,
905
+ misplaced: misplacedProducts,
906
+ missing: 0,
907
+ proper: properProducts,
908
+ };
909
+
910
+ if ( fixtureMetrics.scanned === 0 ) {
911
+ fixtureMetrics.missing = fixtureMetrics.total;
912
+ } else if ( fixtureMetrics.scanned > 0 ) {
913
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
914
+ }
915
+
916
+ return res.sendSuccess( { ...fixture.toObject(), shelves: shelfProducts, fixtureMetrics: fixtureMetrics } );
867
917
  } else if ( fixture.toObject().productResolutionLevel === 'L3' ) {
868
918
  const fixtureShelves = await fixtureShelfService.find( {
869
919
  fixtureId: new mongoose.Types.ObjectId( fixtureId ),
@@ -883,7 +933,6 @@ export async function fixtureShelfProductv1( req, res ) {
883
933
  const products = await planoProductService.find( { _id: { $in: productIds } } );
884
934
  const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
885
935
 
886
- const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
887
936
 
888
937
  const productDetails = await Promise.all(
889
938
  productMappings.map( async ( mapping ) => {
@@ -923,7 +972,28 @@ export async function fixtureShelfProductv1( req, res ) {
923
972
  return acc;
924
973
  }, {} );
925
974
  } )();
926
- return res.sendSuccess( { ...fixture.toObject(), categories: groupedShelves } );
975
+
976
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
977
+ planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
978
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
979
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
980
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
981
+ ] );
982
+
983
+ const fixtureMetrics = {
984
+ total: totalProducts,
985
+ scanned: scannedProducts,
986
+ misplaced: misplacedProducts,
987
+ missing: 0,
988
+ proper: properProducts,
989
+ };
990
+
991
+ if ( fixtureMetrics.scanned === 0 ) {
992
+ fixtureMetrics.missing = fixtureMetrics.total;
993
+ } else if ( fixtureMetrics.scanned > 0 ) {
994
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
995
+ }
996
+ return res.sendSuccess( { ...fixture.toObject(), categories: groupedShelves, fixtureMetrics: fixtureMetrics } );
927
997
  } else {
928
998
  return res.sendError( 'Incorrect resolution level', 400 );
929
999
  }
@@ -1114,11 +1184,10 @@ export async function scanv1( req, res ) {
1114
1184
 
1115
1185
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
1116
1186
 
1117
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1187
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1118
1188
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1119
1189
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1120
1190
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1121
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1122
1191
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1123
1192
  ] );
1124
1193
 
@@ -1126,10 +1195,16 @@ export async function scanv1( req, res ) {
1126
1195
  total: totalProducts,
1127
1196
  scanned: scannedProducts,
1128
1197
  misplaced: misplacedProducts,
1129
- missing: missingProducts,
1198
+ missing: 0,
1130
1199
  proper: properProducts,
1131
1200
  };
1132
1201
 
1202
+ if ( fixtureMetrics.scanned === 0 ) {
1203
+ fixtureMetrics.missing = fixtureMetrics.total;
1204
+ } else if ( fixtureMetrics.scanned > 0 ) {
1205
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1206
+ }
1207
+
1133
1208
  return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
1134
1209
  }
1135
1210
 
@@ -1140,11 +1215,10 @@ export async function scanv1( req, res ) {
1140
1215
 
1141
1216
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1142
1217
 
1143
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1218
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1144
1219
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1145
1220
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1146
1221
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1147
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1148
1222
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1149
1223
  ] );
1150
1224
 
@@ -1152,10 +1226,16 @@ export async function scanv1( req, res ) {
1152
1226
  total: totalProducts,
1153
1227
  scanned: scannedProducts,
1154
1228
  misplaced: misplacedProducts,
1155
- missing: missingProducts,
1229
+ missing: 0,
1156
1230
  proper: properProducts,
1157
1231
  };
1158
1232
 
1233
+ if ( fixtureMetrics.scanned === 0 ) {
1234
+ fixtureMetrics.missing = fixtureMetrics.total;
1235
+ } else if ( fixtureMetrics.scanned > 0 ) {
1236
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1237
+ }
1238
+
1159
1239
  return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'proper' } );
1160
1240
  } else if ( fixture.productResolutionLevel === 'L2' ) {
1161
1241
  if ( !req.body.shelfId && req.body.rfId ) {
@@ -1212,23 +1292,27 @@ export async function scanv1( req, res ) {
1212
1292
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate, compliance: { $ne: 'proper' } }, complianceData );
1213
1293
  }
1214
1294
 
1215
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1295
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1216
1296
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1217
1297
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1218
1298
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1219
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1220
1299
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1221
-
1222
1300
  ] );
1223
1301
 
1224
1302
  const fixtureMetrics = {
1225
1303
  total: totalProducts,
1226
1304
  scanned: scannedProducts,
1227
1305
  misplaced: misplacedProducts,
1228
- missing: missingProducts,
1306
+ missing: 0,
1229
1307
  proper: properProducts,
1230
1308
  };
1231
1309
 
1310
+ if ( fixtureMetrics.scanned === 0 ) {
1311
+ fixtureMetrics.missing = fixtureMetrics.total;
1312
+ } else if ( fixtureMetrics.scanned > 0 ) {
1313
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1314
+ }
1315
+
1232
1316
  return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
1233
1317
  }
1234
1318
 
@@ -1239,23 +1323,27 @@ export async function scanv1( req, res ) {
1239
1323
 
1240
1324
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1241
1325
 
1242
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1326
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1243
1327
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1244
1328
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1245
1329
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1246
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1247
1330
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1248
-
1249
1331
  ] );
1250
1332
 
1251
1333
  const fixtureMetrics = {
1252
1334
  total: totalProducts,
1253
1335
  scanned: scannedProducts,
1254
1336
  misplaced: misplacedProducts,
1255
- missing: missingProducts,
1337
+ missing: 0,
1256
1338
  proper: properProducts,
1257
1339
  };
1258
1340
 
1341
+ if ( fixtureMetrics.scanned === 0 ) {
1342
+ fixtureMetrics.missing = fixtureMetrics.total;
1343
+ } else if ( fixtureMetrics.scanned > 0 ) {
1344
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1345
+ }
1346
+
1259
1347
  const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1260
1348
  planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1261
1349
  planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
@@ -1330,22 +1418,26 @@ export async function scanv1( req, res ) {
1330
1418
 
1331
1419
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
1332
1420
 
1333
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1421
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1334
1422
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1335
1423
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1336
1424
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1337
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1338
1425
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1339
-
1340
1426
  ] );
1341
1427
 
1342
1428
  const fixtureMetrics = {
1343
1429
  total: totalProducts,
1344
1430
  scanned: scannedProducts,
1345
1431
  misplaced: misplacedProducts,
1346
- missing: missingProducts,
1432
+ missing: 0,
1347
1433
  proper: properProducts,
1348
1434
  };
1435
+
1436
+ if ( fixtureMetrics.scanned === 0 ) {
1437
+ fixtureMetrics.missing = fixtureMetrics.total;
1438
+ } else if ( fixtureMetrics.scanned > 0 ) {
1439
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1440
+ }
1349
1441
  const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1350
1442
  planoMappingService.count( { shelfId: misplacedProductMapping.toObject().shelfId } ),
1351
1443
  planoComplianceService.count( { date: currentDate, shelfId: misplacedProductMapping.toObject().shelfId, compliance: 'proper' } ),
@@ -1370,11 +1462,10 @@ export async function scanv1( req, res ) {
1370
1462
 
1371
1463
  await planoComplianceService.updateOne( { ...mappingQuery, planoMappingId: productMapping.toObject()._id, date: currentDate }, complianceData );
1372
1464
 
1373
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1465
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1374
1466
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1375
1467
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1376
1468
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1377
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1378
1469
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1379
1470
  ] );
1380
1471
 
@@ -1382,10 +1473,16 @@ export async function scanv1( req, res ) {
1382
1473
  total: totalProducts,
1383
1474
  scanned: scannedProducts,
1384
1475
  misplaced: misplacedProducts,
1385
- missing: missingProducts,
1476
+ missing: 0,
1386
1477
  proper: properProducts,
1387
1478
  };
1388
1479
 
1480
+ if ( fixtureMetrics.scanned === 0 ) {
1481
+ fixtureMetrics.missing = fixtureMetrics.total;
1482
+ } else if ( fixtureMetrics.scanned > 0 ) {
1483
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1484
+ }
1485
+
1389
1486
  const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1390
1487
  planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1391
1488
  planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
@@ -1448,11 +1545,10 @@ export async function scanv1( req, res ) {
1448
1545
  }
1449
1546
 
1450
1547
 
1451
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1548
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1452
1549
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1453
1550
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1454
1551
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1455
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1456
1552
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1457
1553
  ] );
1458
1554
 
@@ -1460,10 +1556,16 @@ export async function scanv1( req, res ) {
1460
1556
  total: totalProducts,
1461
1557
  scanned: scannedProducts,
1462
1558
  misplaced: misplacedProducts,
1463
- missing: missingProducts,
1559
+ missing: 0,
1464
1560
  proper: properProducts,
1465
1561
  };
1466
1562
 
1563
+ if ( fixtureMetrics.scanned === 0 ) {
1564
+ fixtureMetrics.missing = fixtureMetrics.total;
1565
+ } else if ( fixtureMetrics.scanned > 0 ) {
1566
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1567
+ }
1568
+
1467
1569
  return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
1468
1570
  }
1469
1571
 
@@ -1474,11 +1576,10 @@ export async function scanv1( req, res ) {
1474
1576
 
1475
1577
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1476
1578
 
1477
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1579
+ const [ totalProducts, scannedProducts, misplacedProducts, properProducts ] = await Promise.all( [
1478
1580
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1479
1581
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1480
1582
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1481
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1482
1583
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1483
1584
  ] );
1484
1585
 
@@ -1486,10 +1587,16 @@ export async function scanv1( req, res ) {
1486
1587
  total: totalProducts,
1487
1588
  scanned: scannedProducts,
1488
1589
  misplaced: misplacedProducts,
1489
- missing: missingProducts,
1590
+ missing: 0,
1490
1591
  proper: properProducts,
1491
1592
  };
1492
1593
 
1594
+ if ( fixtureMetrics.scanned === 0 ) {
1595
+ fixtureMetrics.missing = fixtureMetrics.total;
1596
+ } else if ( fixtureMetrics.scanned > 0 ) {
1597
+ fixtureMetrics.missing = fixtureMetrics.total - ( fixtureMetrics.misplaced + fixtureMetrics.proper );
1598
+ }
1599
+
1493
1600
  const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1494
1601
  planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1495
1602
  planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
@@ -6286,3 +6393,55 @@ export async function bulkFixtureUpload( req, res ) {
6286
6393
 
6287
6394
  // const cleanedData = cleanData( data );
6288
6395
  // saveToFile( 'output.txt', cleanedData );
6396
+
6397
+
6398
+ // Find Duplicate Ids
6399
+
6400
+ import fs from 'fs';
6401
+
6402
+ async function findDuplicates() {
6403
+ try {
6404
+ const keys1 = await planoMappingService.find( { clientId: '11' }, { rfId: 1, _id: 0 } );
6405
+ const keys2 = await fixtureShelfService.find( { clientId: '11' }, { rfId: 1, _id: 0 } );
6406
+
6407
+ const keyArray1 = keys1.map( ( doc ) => doc.toObject().rfId );
6408
+ const keyArray2 = keys2.map( ( doc ) => doc.toObject().rfId );
6409
+
6410
+ const findDuplicatesInArray = ( arr ) => {
6411
+ const countMap = new Map();
6412
+ arr.forEach( ( key ) => countMap.set( key, ( countMap.get( key ) || 0 ) + 1 ) );
6413
+ return [ ...countMap.entries() ].filter( ( [ _, count ] ) => count > 1 ).map( ( [ key ] ) => key );
6414
+ };
6415
+
6416
+ const duplicatesInCollection1 = findDuplicatesInArray( keyArray1 );
6417
+ const duplicatesInCollection2 = findDuplicatesInArray( keyArray2 );
6418
+
6419
+ const set1 = new Set( keyArray1 );
6420
+ const set2 = new Set( keyArray2 );
6421
+ const duplicatesAcrossCollections = [ ...set1 ].filter( ( key ) => set2.has( key ) );
6422
+
6423
+ let output = '';
6424
+
6425
+ if ( duplicatesInCollection1.length > 0 ) {
6426
+ output += `Duplicates within product:\n${duplicatesInCollection1.join( '\n' )}\n\n`;
6427
+ }
6428
+ if ( duplicatesInCollection2.length > 0 ) {
6429
+ output += `Duplicates within shelf:\n${duplicatesInCollection2.join( '\n' )}\n\n`;
6430
+ }
6431
+ if ( duplicatesAcrossCollections.length > 0 ) {
6432
+ output += `Duplicates across product & shelf:\n${duplicatesAcrossCollections.join( '\n' )}\n\n`;
6433
+ }
6434
+
6435
+ if ( output ) {
6436
+ const filePath = 'duplicates.txt';
6437
+ fs.writeFileSync( filePath, output, 'utf8' );
6438
+ console.log( `Duplicates written to ${filePath}` );
6439
+ } else {
6440
+ console.log( 'No duplicates found.' );
6441
+ }
6442
+ } catch ( error ) {
6443
+ console.error( 'Error:', error );
6444
+ }
6445
+ }
6446
+
6447
+ // findDuplicates();