tango-app-api-store-builder 1.0.0-beta-15 → 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
|
@@ -1064,6 +1064,11 @@ export async function scan( req, res ) {
|
|
|
1064
1064
|
|
|
1065
1065
|
export async function scanv1( req, res ) {
|
|
1066
1066
|
try {
|
|
1067
|
+
if ( !req.body.floorId ) return res.sendError( 'Floor id is required', 400 );
|
|
1068
|
+
|
|
1069
|
+
if ( !req.body.fixtureId ) return res.sendError( 'Fixture id is required', 400 );
|
|
1070
|
+
|
|
1071
|
+
if ( !req.body.rfId ) return res.sendError( 'RFID is required', 400 );
|
|
1067
1072
|
const fixture = await storeFixtureService.findOne(
|
|
1068
1073
|
{ _id: new mongoose.Types.ObjectId( req.body.fixtureId ) },
|
|
1069
1074
|
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1 },
|
|
@@ -1071,13 +1076,10 @@ export async function scanv1( req, res ) {
|
|
|
1071
1076
|
|
|
1072
1077
|
if ( !fixture ) return res.sendError( 'No data found', 204 );
|
|
1073
1078
|
|
|
1074
|
-
|
|
1075
|
-
if ( !req.body.floorId ) return res.sendError( 'Floor id is required', 400 );
|
|
1076
|
-
|
|
1077
|
-
if ( !req.body.fixtureId ) return res.sendError( 'Fixture id is required', 400 );
|
|
1079
|
+
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
1078
1080
|
|
|
1079
|
-
if ( !req.body.rfId ) return res.sendError( 'RFID is required', 400 );
|
|
1080
1081
|
|
|
1082
|
+
if ( fixture.productResolutionLevel === 'L1' ) {
|
|
1081
1083
|
const mappingQuery = {
|
|
1082
1084
|
planoId: req.body.planoId,
|
|
1083
1085
|
floorId: req.body.floorId,
|
|
@@ -1087,8 +1089,6 @@ export async function scanv1( req, res ) {
|
|
|
1087
1089
|
|
|
1088
1090
|
const productMapping = await planoMappingService.findOne( mappingQuery );
|
|
1089
1091
|
|
|
1090
|
-
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
1091
|
-
|
|
1092
1092
|
if ( !productMapping ) {
|
|
1093
1093
|
const misplacedQuery = {
|
|
1094
1094
|
planoId: req.body.planoId,
|
|
@@ -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:
|
|
1101
|
+
return res.sendSuccess( { data: null, status: 'missing' } );
|
|
1102
1102
|
}
|
|
1103
1103
|
|
|
1104
1104
|
const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'misplaced' };
|
|
@@ -1107,28 +1107,60 @@ export async function scanv1( req, res ) {
|
|
|
1107
1107
|
let misplacedProductDetails = await planoProductService.findOne( { _id: misplacedProductMapping.toObject().productId } );
|
|
1108
1108
|
|
|
1109
1109
|
await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
|
|
1110
|
-
|
|
1110
|
+
|
|
1111
|
+
const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
|
|
1112
|
+
planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
|
|
1113
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
|
|
1114
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
|
|
1115
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
|
|
1116
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
|
|
1117
|
+
] );
|
|
1118
|
+
|
|
1119
|
+
const fixtureMetrics = {
|
|
1120
|
+
total: totalProducts,
|
|
1121
|
+
scanned: scannedProducts,
|
|
1122
|
+
misplaced: misplacedProducts,
|
|
1123
|
+
missing: missingProducts,
|
|
1124
|
+
proper: properProducts,
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
|
|
1111
1128
|
}
|
|
1112
1129
|
|
|
1113
1130
|
const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
|
|
1114
1131
|
delete complianceData._id;
|
|
1115
1132
|
|
|
1116
|
-
let productDetails = await planoProductService.findOne( { _id:
|
|
1133
|
+
let productDetails = await planoProductService.findOne( { _id: productMapping.productId } );
|
|
1117
1134
|
|
|
1118
1135
|
await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
|
|
1119
1136
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1137
|
+
const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
|
|
1138
|
+
planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
|
|
1139
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
|
|
1140
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
|
|
1141
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
|
|
1142
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
|
|
1143
|
+
] );
|
|
1144
|
+
|
|
1145
|
+
const fixtureMetrics = {
|
|
1146
|
+
total: totalProducts,
|
|
1147
|
+
scanned: scannedProducts,
|
|
1148
|
+
misplaced: misplacedProducts,
|
|
1149
|
+
missing: missingProducts,
|
|
1150
|
+
proper: properProducts,
|
|
1151
|
+
};
|
|
1127
1152
|
|
|
1153
|
+
return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'proper' } );
|
|
1154
|
+
} else if ( fixture.productResolutionLevel === 'L2' ) {
|
|
1128
1155
|
if ( !req.body.shelfId && req.body.rfId ) {
|
|
1129
1156
|
const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
|
|
1130
1157
|
if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
|
|
1131
|
-
|
|
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 } );
|
|
1132
1164
|
}
|
|
1133
1165
|
|
|
1134
1166
|
if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
|
|
@@ -1143,8 +1175,6 @@ export async function scanv1( req, res ) {
|
|
|
1143
1175
|
|
|
1144
1176
|
const productMapping = await planoMappingService.findOne( mappingQuery );
|
|
1145
1177
|
|
|
1146
|
-
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
1147
|
-
|
|
1148
1178
|
if ( !productMapping ) {
|
|
1149
1179
|
const misplacedQuery = {
|
|
1150
1180
|
planoId: req.body.planoId,
|
|
@@ -1156,9 +1186,14 @@ export async function scanv1( req, res ) {
|
|
|
1156
1186
|
if ( !misplacedProductMapping ) {
|
|
1157
1187
|
const shelf = await fixtureShelfService.findOne( misplacedQuery );
|
|
1158
1188
|
if ( !shelf ) {
|
|
1159
|
-
return res.sendSuccess( { data:
|
|
1189
|
+
return res.sendSuccess( { data: null, status: 'missing' } );
|
|
1160
1190
|
}
|
|
1161
|
-
|
|
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 } );
|
|
1162
1197
|
}
|
|
1163
1198
|
|
|
1164
1199
|
const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'misplaced' };
|
|
@@ -1167,7 +1202,26 @@ export async function scanv1( req, res ) {
|
|
|
1167
1202
|
let misplacedProductDetails = await planoProductService.findOne( { _id: misplacedProductMapping.toObject().productId } );
|
|
1168
1203
|
|
|
1169
1204
|
await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
|
|
1170
|
-
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
|
|
1208
|
+
planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
|
|
1209
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
|
|
1210
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
|
|
1211
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
|
|
1212
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
|
|
1213
|
+
|
|
1214
|
+
] );
|
|
1215
|
+
|
|
1216
|
+
const fixtureMetrics = {
|
|
1217
|
+
total: totalProducts,
|
|
1218
|
+
scanned: scannedProducts,
|
|
1219
|
+
misplaced: misplacedProducts,
|
|
1220
|
+
missing: missingProducts,
|
|
1221
|
+
proper: properProducts,
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, status: 'misplaced' } );
|
|
1171
1225
|
}
|
|
1172
1226
|
|
|
1173
1227
|
const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
|
|
@@ -1177,18 +1231,44 @@ export async function scanv1( req, res ) {
|
|
|
1177
1231
|
|
|
1178
1232
|
await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
|
|
1179
1233
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1234
|
+
const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
|
|
1235
|
+
planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
|
|
1236
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
|
|
1237
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
|
|
1238
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
|
|
1239
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
|
|
1240
|
+
|
|
1241
|
+
] );
|
|
1242
|
+
|
|
1243
|
+
const fixtureMetrics = {
|
|
1244
|
+
total: totalProducts,
|
|
1245
|
+
scanned: scannedProducts,
|
|
1246
|
+
misplaced: misplacedProducts,
|
|
1247
|
+
missing: missingProducts,
|
|
1248
|
+
proper: properProducts,
|
|
1249
|
+
};
|
|
1250
|
+
|
|
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
|
+
] );
|
|
1183
1255
|
|
|
1184
|
-
|
|
1256
|
+
const shelfMetrics = {
|
|
1257
|
+
shelfId: productMapping.toObject().shelfId,
|
|
1258
|
+
isScanned: shelfCompliance > shelfProducts/2 ? true : false };
|
|
1185
1259
|
|
|
1186
|
-
if ( !req.body.fixtureId ) return res.sendError( 'Fixture id is required', 400 );
|
|
1187
1260
|
|
|
1261
|
+
return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
|
|
1262
|
+
} else if ( fixture.productResolutionLevel === 'L3' ) {
|
|
1188
1263
|
if ( !req.body.shelfId && req.body.rfId ) {
|
|
1189
1264
|
const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
|
|
1190
1265
|
if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
|
|
1191
|
-
|
|
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 } );
|
|
1192
1272
|
}
|
|
1193
1273
|
|
|
1194
1274
|
if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
|
|
@@ -1203,8 +1283,6 @@ export async function scanv1( req, res ) {
|
|
|
1203
1283
|
|
|
1204
1284
|
const productMapping = await planoMappingService.findOne( mappingQuery );
|
|
1205
1285
|
|
|
1206
|
-
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
1207
|
-
|
|
1208
1286
|
if ( !productMapping ) {
|
|
1209
1287
|
const shelf = await fixtureShelfService.findOne( { _id: new mongoose.Types.ObjectId( req.body.shelfId ) } );
|
|
1210
1288
|
|
|
@@ -1222,9 +1300,14 @@ export async function scanv1( req, res ) {
|
|
|
1222
1300
|
if ( !misplacedProductMapping ) {
|
|
1223
1301
|
const shelf = await fixtureShelfService.findOne( misplacedQuery );
|
|
1224
1302
|
if ( !shelf ) {
|
|
1225
|
-
return res.sendSuccess( { data:
|
|
1303
|
+
return res.sendSuccess( { data: null, status: 'missing' } );
|
|
1226
1304
|
}
|
|
1227
|
-
|
|
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 } );
|
|
1228
1311
|
}
|
|
1229
1312
|
|
|
1230
1313
|
|
|
@@ -1237,16 +1320,36 @@ export async function scanv1( req, res ) {
|
|
|
1237
1320
|
delete complianceData._id;
|
|
1238
1321
|
|
|
1239
1322
|
await planoComplianceService.updateOne( { ...misplacedQuery, date: currentDate }, complianceData );
|
|
1240
|
-
return res.sendSuccess( { data: { ...misplacedProductMapping.toObject(), ...( misplacedProductDetails ? misplacedProductDetails?.toObject() : {} ) }, status: true } );
|
|
1241
|
-
} else {
|
|
1242
|
-
if ( shelf.toObject()._id.toString() !== misplacedProductShelf.toObject()._id.toString() ) {
|
|
1243
|
-
return res.sendError( 'RFID conflict with section', 400 );
|
|
1244
|
-
}
|
|
1245
|
-
const complianceData = { ...misplacedProductMapping.toObject(), planoMappingId: misplacedProductMapping.toObject()._id, compliance: 'misplaced' };
|
|
1246
|
-
delete complianceData._id;
|
|
1247
1323
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1324
|
+
const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
|
|
1325
|
+
planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
|
|
1326
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
|
|
1327
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
|
|
1328
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
|
|
1329
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
|
|
1330
|
+
|
|
1331
|
+
] );
|
|
1332
|
+
|
|
1333
|
+
const fixtureMetrics = {
|
|
1334
|
+
total: totalProducts,
|
|
1335
|
+
scanned: scannedProducts,
|
|
1336
|
+
misplaced: misplacedProducts,
|
|
1337
|
+
missing: missingProducts,
|
|
1338
|
+
proper: properProducts,
|
|
1339
|
+
};
|
|
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' } ),
|
|
1343
|
+
] );
|
|
1344
|
+
|
|
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 );
|
|
1250
1353
|
}
|
|
1251
1354
|
}
|
|
1252
1355
|
|
|
@@ -1258,18 +1361,42 @@ export async function scanv1( req, res ) {
|
|
|
1258
1361
|
|
|
1259
1362
|
await planoComplianceService.updateOne( { ...mappingQuery, planoMappingId: productMapping.toObject()._id, date: currentDate }, complianceData );
|
|
1260
1363
|
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1364
|
+
const [ totalProducts, scannedProducts, misplacedProducts, missingProducts, properProducts ] = await Promise.all( [
|
|
1365
|
+
planoMappingService.count( { fixtureId: fixture.toObject()._id } ),
|
|
1366
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate } ),
|
|
1367
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'misplaced' } ),
|
|
1368
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'missing' } ),
|
|
1369
|
+
planoComplianceService.count( { fixtureId: fixture.toObject()._id, date: currentDate, compliance: 'proper' } ),
|
|
1370
|
+
] );
|
|
1371
|
+
|
|
1372
|
+
const fixtureMetrics = {
|
|
1373
|
+
total: totalProducts,
|
|
1374
|
+
scanned: scannedProducts,
|
|
1375
|
+
misplaced: misplacedProducts,
|
|
1376
|
+
missing: missingProducts,
|
|
1377
|
+
proper: properProducts,
|
|
1378
|
+
};
|
|
1264
1379
|
|
|
1265
|
-
|
|
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
|
+
] );
|
|
1266
1384
|
|
|
1267
|
-
|
|
1385
|
+
const shelfMetrics = {
|
|
1386
|
+
shelfId: productMapping.toObject().shelfId,
|
|
1387
|
+
isScanned: shelfCompliance > shelfProducts/2 ? true : false };
|
|
1268
1388
|
|
|
1389
|
+
return res.sendSuccess( { data: { ...productMapping.toObject(), ...( productDetails ? productDetails?.toObject() : {} ) }, fixtureMetrics: fixtureMetrics, shelfMetrics: shelfMetrics, status: 'proper' } );
|
|
1390
|
+
} else if ( fixture.productResolutionLevel === 'L4' ) {
|
|
1269
1391
|
if ( !req.body.shelfId && req.body.rfId ) {
|
|
1270
1392
|
const shelf = await fixtureShelfService.findOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, rfId: req.body.rfId } );
|
|
1271
1393
|
if ( !shelf ) return res.sendError( 'No matching shelf for the rfId', 400 );
|
|
1272
|
-
|
|
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 } );
|
|
1273
1400
|
}
|
|
1274
1401
|
|
|
1275
1402
|
if ( !req.body.shelfId ) return res.sendError( 'Shelf id is required', 400 );
|
|
@@ -1289,27 +1416,77 @@ export async function scanv1( req, res ) {
|
|
|
1289
1416
|
if ( !productMapping ) {
|
|
1290
1417
|
shelf = await fixtureShelfService.findOne( misplacedQuery );
|
|
1291
1418
|
if ( !shelf ) {
|
|
1292
|
-
return res.sendSuccess( { data:
|
|
1419
|
+
return res.sendSuccess( { data: null, status: 'missing' } );
|
|
1293
1420
|
}
|
|
1294
|
-
|
|
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 } );
|
|
1295
1427
|
}
|
|
1296
1428
|
|
|
1297
|
-
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
1298
|
-
|
|
1299
1429
|
if ( productMapping.toObject().rfId !== req.body.rfId ) {
|
|
1300
1430
|
const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'misplaced' };
|
|
1301
1431
|
delete complianceData._id;
|
|
1302
1432
|
|
|
1433
|
+
let productDetails = await planoProductService.findOne( { _id: productMapping.toObject().productId } );
|
|
1434
|
+
|
|
1303
1435
|
await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
|
|
1304
|
-
|
|
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' } );
|
|
1305
1455
|
}
|
|
1306
1456
|
|
|
1307
1457
|
const complianceData = { ...productMapping.toObject(), planoMappingId: productMapping.toObject()._id, compliance: 'proper' };
|
|
1308
1458
|
delete complianceData._id;
|
|
1309
1459
|
|
|
1460
|
+
let productDetails = await planoProductService.findOne( { _id: productMapping.toObject().productId } );
|
|
1461
|
+
|
|
1310
1462
|
await planoComplianceService.updateOne( { ...mappingQuery, date: currentDate }, complianceData );
|
|
1311
1463
|
|
|
1312
|
-
|
|
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' } );
|
|
1313
1490
|
} else {
|
|
1314
1491
|
return res.sendError( 'Incorrect resolution level', 400 );
|
|
1315
1492
|
}
|