tango-app-api-store-builder 1.0.0-beta-16 → 1.0.0-beta-17

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-16",
3
+ "version": "1.0.0-beta-17",
4
4
  "description": "storeBuilder",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1098,7 +1098,7 @@ export async function scanv1( req, res ) {
1098
1098
  const misplacedProductMapping = await planoMappingService.findOne( misplacedQuery );
1099
1099
 
1100
1100
  if ( !misplacedProductMapping ) {
1101
- return res.sendSuccess( { data: 'missing', status: false } );
1101
+ return res.sendSuccess( { data: null, status: 'missing' } );
1102
1102
  }
1103
1103
 
1104
1104
  const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'misplaced' };
@@ -1108,50 +1108,59 @@ export async function scanv1( req, res ) {
1108
1108
 
1109
1109
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
1110
1110
 
1111
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts ] = await Promise.all( [
1111
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1112
1112
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1113
1113
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1114
1114
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1115
1115
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1116
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1116
1117
  ] );
1117
1118
 
1118
- const metrics = {
1119
+ const fixtureMetrics = {
1119
1120
  total: totalProducts,
1120
1121
  scanned: scannedProducts,
1121
1122
  misplaced: misplacedProducts,
1122
1123
  missing: missingProducts,
1124
+ proper: properProducts,
1123
1125
  };
1124
1126
 
1125
- return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, metrics: metrics, status: false } );
1127
+ return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
1126
1128
  }
1127
1129
 
1128
1130
  const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
1129
1131
  delete complianceData._id;
1130
1132
 
1131
- let productDetails = await planoProductService.findOne( { _id: mappingQuery.productId } );
1133
+ let productDetails = await planoProductService.findOne( { _id: productMapping.productId } );
1132
1134
 
1133
1135
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1134
1136
 
1135
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts ] = await Promise.all( [
1137
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1136
1138
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1137
1139
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1138
1140
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1139
1141
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1142
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1140
1143
  ] );
1141
1144
 
1142
- const metrics = {
1145
+ const fixtureMetrics = {
1143
1146
  total: totalProducts,
1144
1147
  scanned: scannedProducts,
1145
1148
  misplaced: misplacedProducts,
1146
1149
  missing: missingProducts,
1150
+ proper: properProducts,
1147
1151
  };
1148
1152
 
1149
- return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, metrics: metrics, status: true } );
1153
+ return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'proper' } );
1150
1154
  } else if ( fixture.productResolutionLevel === 'L2' ) {
1151
1155
  if ( !req.body.shelfId && req.body.rfId ) {
1152
1156
  const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
1153
1157
  if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
1154
- return res.sendSuccess( { shelfId: shelf.toObject()._id } );
1158
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1159
+ planoMappingService.count( { shelfId: shelf.toObject()._id } ),
1160
+ planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
1161
+ ] );
1162
+ return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
1163
+ isScanned: shelfCompliance > shelfProducts/2 ? true : false } );
1155
1164
  }
1156
1165
 
1157
1166
  if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
@@ -1177,9 +1186,14 @@ export async function scanv1( req, res ) {
1177
1186
  if ( !misplacedProductMapping ) {
1178
1187
  const shelf = await fixtureShelfService.findOne( misplacedQuery );
1179
1188
  if ( !shelf ) {
1180
- return res.sendSuccess( { data: 'missing', status: false } );
1189
+ return res.sendSuccess( { data: null, status: 'missing' } );
1181
1190
  }
1182
- return res.sendSuccess( { shelfId: shelf.toObject()._id } );
1191
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1192
+ planoMappingService.count( { shelfId: shelf.toObject()._id } ),
1193
+ planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
1194
+ ] );
1195
+ return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
1196
+ isScanned: shelfCompliance > shelfProducts/2 ? true : false } );
1183
1197
  }
1184
1198
 
1185
1199
  const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'misplaced' };
@@ -1190,21 +1204,24 @@ export async function scanv1( req, res ) {
1190
1204
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
1191
1205
 
1192
1206
 
1193
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts ] = await Promise.all( [
1207
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1194
1208
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1195
1209
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1196
1210
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1197
1211
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1212
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1213
+
1198
1214
  ] );
1199
1215
 
1200
- const metrics = {
1216
+ const fixtureMetrics = {
1201
1217
  total: totalProducts,
1202
1218
  scanned: scannedProducts,
1203
1219
  misplaced: misplacedProducts,
1204
1220
  missing: missingProducts,
1221
+ proper: properProducts,
1205
1222
  };
1206
1223
 
1207
- return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, metrics: metrics, status: false } );
1224
+ return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
1208
1225
  }
1209
1226
 
1210
1227
  const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
@@ -1214,26 +1231,44 @@ export async function scanv1( req, res ) {
1214
1231
 
1215
1232
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1216
1233
 
1217
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts ] = await Promise.all( [
1234
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1218
1235
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1219
1236
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1220
1237
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1221
1238
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1239
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1240
+
1222
1241
  ] );
1223
1242
 
1224
- const metrics = {
1243
+ const fixtureMetrics = {
1225
1244
  total: totalProducts,
1226
1245
  scanned: scannedProducts,
1227
1246
  misplaced: misplacedProducts,
1228
1247
  missing: missingProducts,
1248
+ proper: properProducts,
1229
1249
  };
1230
1250
 
1231
- return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, metrics: metrics, status: true } );
1251
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1252
+ planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1253
+ planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
1254
+ ] );
1255
+
1256
+ const shelfMetrics = {
1257
+ shelfId: productMapping.toObject().shelfId,
1258
+ isScanned: shelfCompliance > shelfProducts/2 ? true : false };
1259
+
1260
+
1261
+ return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
1232
1262
  } else if ( fixture.productResolutionLevel === 'L3' ) {
1233
1263
  if ( !req.body.shelfId && req.body.rfId ) {
1234
1264
  const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
1235
1265
  if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
1236
- return res.sendSuccess( { shelfId: shelf.toObject()._id } );
1266
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1267
+ planoMappingService.count( { shelfId: shelf.toObject()._id } ),
1268
+ planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
1269
+ ] );
1270
+ return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
1271
+ isScanned: shelfCompliance > shelfProducts/2 ? true : false } );
1237
1272
  }
1238
1273
 
1239
1274
  if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
@@ -1265,9 +1300,14 @@ export async function scanv1( req, res ) {
1265
1300
  if ( !misplacedProductMapping ) {
1266
1301
  const shelf = await fixtureShelfService.findOne( misplacedQuery );
1267
1302
  if ( !shelf ) {
1268
- return res.sendSuccess( { data: 'missing', status: false } );
1303
+ return res.sendSuccess( { data: null, status: 'missing' } );
1269
1304
  }
1270
- return res.sendSuccess( { shelfId: shelf.toObject()._id } );
1305
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1306
+ planoMappingService.count( { shelfId: shelf.toObject()._id } ),
1307
+ planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
1308
+ ] );
1309
+ return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
1310
+ isScanned: shelfCompliance > shelfProducts/2 ? true : false } );
1271
1311
  }
1272
1312
 
1273
1313
 
@@ -1281,42 +1321,35 @@ export async function scanv1( req, res ) {
1281
1321
 
1282
1322
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
1283
1323
 
1284
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts ] = await Promise.all( [
1324
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1285
1325
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1286
1326
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1287
1327
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1288
1328
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1329
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1330
+
1289
1331
  ] );
1290
1332
 
1291
- const metrics = {
1333
+ const fixtureMetrics = {
1292
1334
  total: totalProducts,
1293
1335
  scanned: scannedProducts,
1294
1336
  misplaced: misplacedProducts,
1295
1337
  missing: missingProducts,
1338
+ proper: properProducts,
1296
1339
  };
1297
- return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, metrics: metrics, status: true } );
1298
- } else {
1299
- if ( shelf.toObject()._id.toString() !== misplacedProductShelf.toObject()._id.toString() ) {
1300
- return res.sendError( 'RFID conflict with section', 400 );
1301
- }
1302
- const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'misplaced' };
1303
- delete complianceData._id;
1304
-
1305
- await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
1306
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts ] = await Promise.all( [
1307
- planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1308
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1309
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1310
- planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1340
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1341
+ planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1342
+ planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
1311
1343
  ] );
1312
1344
 
1313
- const metrics = {
1314
- total: totalProducts,
1315
- scanned: scannedProducts,
1316
- misplaced: misplacedProducts,
1317
- missing: missingProducts,
1318
- };
1319
- return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, metrics: metrics, status: false } );
1345
+ const shelfMetrics = {
1346
+ shelfId: productMapping.toObject().shelfId,
1347
+ isScanned: shelfCompliance > shelfProducts/2 ? true : false };
1348
+
1349
+ return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) },
1350
+ fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
1351
+ } else {
1352
+ return res.sendError( 'RFID conflict with section', 400 );
1320
1353
  }
1321
1354
  }
1322
1355
 
@@ -1328,27 +1361,42 @@ export async function scanv1( req, res ) {
1328
1361
 
1329
1362
  await planoComplianceService.updateOne( { ...mappingQuery, planoMappingId: productMapping.toObject()._id, date: currentDate }, complianceData );
1330
1363
 
1331
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts ] = await Promise.all( [
1364
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1332
1365
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1333
1366
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1334
1367
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1335
1368
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1369
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1336
1370
  ] );
1337
1371
 
1338
- const metrics = {
1372
+ const fixtureMetrics = {
1339
1373
  total: totalProducts,
1340
1374
  scanned: scannedProducts,
1341
1375
  misplaced: misplacedProducts,
1342
1376
  missing: missingProducts,
1377
+ proper: properProducts,
1343
1378
  };
1344
1379
 
1380
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1381
+ planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1382
+ planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
1383
+ ] );
1384
+
1385
+ const shelfMetrics = {
1386
+ shelfId: productMapping.toObject().shelfId,
1387
+ isScanned: shelfCompliance > shelfProducts/2 ? true : false };
1345
1388
 
1346
- return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, metrics: metrics, status: true } );
1389
+ return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
1347
1390
  } else if ( fixture.productResolutionLevel === 'L4' ) {
1348
1391
  if ( !req.body.shelfId && req.body.rfId ) {
1349
1392
  const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
1350
1393
  if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
1351
- return res.sendSuccess( shelf.toObject()._id );
1394
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1395
+ planoMappingService.count( { shelfId: shelf.toObject()._id } ),
1396
+ planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
1397
+ ] );
1398
+ return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
1399
+ isScanned: shelfCompliance > shelfProducts/2 ? true : false } );
1352
1400
  }
1353
1401
 
1354
1402
  if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
@@ -1368,25 +1416,77 @@ export async function scanv1( req, res ) {
1368
1416
  if ( !productMapping ) {
1369
1417
  shelf = await fixtureShelfService.findOne( misplacedQuery );
1370
1418
  if ( !shelf ) {
1371
- return res.sendSuccess( { data: 'missing', status: false } );
1419
+ return res.sendSuccess( { data: null, status: 'missing' } );
1372
1420
  }
1373
- return res.sendSuccess( { shelfId: shelf.toObject()._id } );
1421
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1422
+ planoMappingService.count( { shelfId: shelf.toObject()._id } ),
1423
+ planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
1424
+ ] );
1425
+ return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
1426
+ isScanned: shelfCompliance > shelfProducts/2 ? true : false } );
1374
1427
  }
1375
1428
 
1376
1429
  if ( productMapping.toObject().rfId !== req.body.rfId ) {
1377
1430
  const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'misplaced' };
1378
1431
  delete complianceData._id;
1379
1432
 
1433
+ let productDetails = await planoProductService.findOne( { _id: productMapping.toObject().productId } );
1434
+
1380
1435
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1381
- return res.sendSuccess( false );
1436
+
1437
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1438
+ planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1439
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1440
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1441
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1442
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1443
+
1444
+ ] );
1445
+
1446
+ const fixtureMetrics = {
1447
+ total: totalProducts,
1448
+ scanned: scannedProducts,
1449
+ misplaced: misplacedProducts,
1450
+ missing: missingProducts,
1451
+ proper: properProducts,
1452
+ };
1453
+
1454
+ return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
1382
1455
  }
1383
1456
 
1384
1457
  const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
1385
1458
  delete complianceData._id;
1386
1459
 
1460
+ let productDetails = await planoProductService.findOne( { _id: productMapping.toObject().productId } );
1461
+
1387
1462
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1388
1463
 
1389
- return res.sendSuccess( true );
1464
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1465
+ planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1466
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1467
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1468
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1469
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1470
+ ] );
1471
+
1472
+ const fixtureMetrics = {
1473
+ total: totalProducts,
1474
+ scanned: scannedProducts,
1475
+ misplaced: misplacedProducts,
1476
+ missing: missingProducts,
1477
+ proper: properProducts,
1478
+ };
1479
+
1480
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1481
+ planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1482
+ planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
1483
+ ] );
1484
+
1485
+ const shelfMetrics = {
1486
+ shelfId: productMapping.toObject().shelfId,
1487
+ isScanned: shelfCompliance > shelfProducts/2 ? true : false };
1488
+
1489
+ return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
1390
1490
  } else {
1391
1491
  return res.sendError( 'Incorrect resolution level', 400 );
1392
1492
  }