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

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-18",
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,15 @@ 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
+
1310
+ return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
1311
+ isScanned: shelfCompliance >= shelfProducts/2 ? true : false } );
1271
1312
  }
1272
1313
 
1273
1314
 
@@ -1281,42 +1322,35 @@ export async function scanv1( req, res ) {
1281
1322
 
1282
1323
  await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
1283
1324
 
1284
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts ] = await Promise.all( [
1325
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1285
1326
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1286
1327
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1287
1328
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1288
1329
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1330
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1331
+
1289
1332
  ] );
1290
1333
 
1291
- const metrics = {
1334
+ const fixtureMetrics = {
1292
1335
  total: totalProducts,
1293
1336
  scanned: scannedProducts,
1294
1337
  misplaced: misplacedProducts,
1295
1338
  missing: missingProducts,
1339
+ proper: properProducts,
1296
1340
  };
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' } ),
1341
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1342
+ planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1343
+ planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
1311
1344
  ] );
1312
1345
 
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 } );
1346
+ const shelfMetrics = {
1347
+ shelfId: productMapping.toObject().shelfId,
1348
+ isScanned: shelfCompliance >= shelfProducts/2 ? true : false };
1349
+
1350
+ return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) },
1351
+ fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
1352
+ } else {
1353
+ return res.sendError( 'RFID conflict with section', 400 );
1320
1354
  }
1321
1355
  }
1322
1356
 
@@ -1328,27 +1362,42 @@ export async function scanv1( req, res ) {
1328
1362
 
1329
1363
  await planoComplianceService.updateOne( { ...mappingQuery, planoMappingId: productMapping.toObject()._id, date: currentDate }, complianceData );
1330
1364
 
1331
- const [ totalProducts, scannedProducts, misplacedProducts, missingProducts ] = await Promise.all( [
1365
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1332
1366
  planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1333
1367
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1334
1368
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1335
1369
  planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1370
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1336
1371
  ] );
1337
1372
 
1338
- const metrics = {
1373
+ const fixtureMetrics = {
1339
1374
  total: totalProducts,
1340
1375
  scanned: scannedProducts,
1341
1376
  misplaced: misplacedProducts,
1342
1377
  missing: missingProducts,
1378
+ proper: properProducts,
1343
1379
  };
1344
1380
 
1381
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1382
+ planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1383
+ planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
1384
+ ] );
1385
+
1386
+ const shelfMetrics = {
1387
+ shelfId: productMapping.toObject().shelfId,
1388
+ isScanned: shelfCompliance >= shelfProducts/2 ? true : false };
1345
1389
 
1346
- return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, metrics: metrics, status: true } );
1390
+ return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
1347
1391
  } else if ( fixture.productResolutionLevel === 'L4' ) {
1348
1392
  if ( !req.body.shelfId && req.body.rfId ) {
1349
1393
  const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
1350
1394
  if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
1351
- return res.sendSuccess( shelf.toObject()._id );
1395
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1396
+ planoMappingService.count( { shelfId: shelf.toObject()._id } ),
1397
+ planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
1398
+ ] );
1399
+ return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
1400
+ isScanned: shelfCompliance >= shelfProducts/2 ? true : false } );
1352
1401
  }
1353
1402
 
1354
1403
  if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
@@ -1368,25 +1417,77 @@ export async function scanv1( req, res ) {
1368
1417
  if ( !productMapping ) {
1369
1418
  shelf = await fixtureShelfService.findOne( misplacedQuery );
1370
1419
  if ( !shelf ) {
1371
- return res.sendSuccess( { data: 'missing', status: false } );
1420
+ return res.sendSuccess( { data: null, status: 'missing' } );
1372
1421
  }
1373
- return res.sendSuccess( { shelfId: shelf.toObject()._id } );
1422
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1423
+ planoMappingService.count( { shelfId: shelf.toObject()._id } ),
1424
+ planoComplianceService.count( { date: currentDate, shelfId: shelf.toObject()._id, compliance: 'proper' } ),
1425
+ ] );
1426
+ return res.sendSuccess( { shelfId: shelf.toObject()._id, shelfNumber: shelf.toObject().shelfNumber,
1427
+ isScanned: shelfCompliance >= shelfProducts/2 ? true : false } );
1374
1428
  }
1375
1429
 
1376
1430
  if ( productMapping.toObject().rfId !== req.body.rfId ) {
1377
1431
  const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'misplaced' };
1378
1432
  delete complianceData._id;
1379
1433
 
1434
+ let productDetails = await planoProductService.findOne( { _id: productMapping.toObject().productId } );
1435
+
1380
1436
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1381
- return res.sendSuccess( false );
1437
+
1438
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1439
+ planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1440
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1441
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1442
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1443
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1444
+
1445
+ ] );
1446
+
1447
+ const fixtureMetrics = {
1448
+ total: totalProducts,
1449
+ scanned: scannedProducts,
1450
+ misplaced: misplacedProducts,
1451
+ missing: missingProducts,
1452
+ proper: properProducts,
1453
+ };
1454
+
1455
+ return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
1382
1456
  }
1383
1457
 
1384
1458
  const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
1385
1459
  delete complianceData._id;
1386
1460
 
1461
+ let productDetails = await planoProductService.findOne( { _id: productMapping.toObject().productId } );
1462
+
1387
1463
  await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
1388
1464
 
1389
- return res.sendSuccess( true );
1465
+ const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
1466
+ planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
1467
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
1468
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
1469
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
1470
+ planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
1471
+ ] );
1472
+
1473
+ const fixtureMetrics = {
1474
+ total: totalProducts,
1475
+ scanned: scannedProducts,
1476
+ misplaced: misplacedProducts,
1477
+ missing: missingProducts,
1478
+ proper: properProducts,
1479
+ };
1480
+
1481
+ const [ shelfProducts, shelfCompliance ] = await Promise.all( [
1482
+ planoMappingService.count( { shelfId: productMapping.toObject().shelfId } ),
1483
+ planoComplianceService.count( { date: currentDate, shelfId: productMapping.toObject().shelfId, compliance: 'proper' } ),
1484
+ ] );
1485
+
1486
+ const shelfMetrics = {
1487
+ shelfId: productMapping.toObject().shelfId,
1488
+ isScanned: shelfCompliance >= shelfProducts/2 ? true : false };
1489
+
1490
+ return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
1390
1491
  } else {
1391
1492
  return res.sendError( 'Incorrect resolution level', 400 );
1392
1493
  }