tango-app-api-store-builder 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/controllers/fixtureTemplate.controller.js +0 -1
- package/src/controllers/managePlano.controller.js +897 -1010
- package/src/controllers/script.controller.js +2 -122
- package/src/controllers/storeBuilder.controller.js +163 -960
- package/src/controllers/task.controller.js +0 -1
- package/src/routes/fixtureTemplate.routes.js +17 -17
- package/src/routes/managePlano.routes.js +22 -21
- package/src/routes/script.routes.js +0 -2
- package/src/routes/storeBuilder.routes.js +3 -4
- package/src/service/planoProduct.service.js +0 -4
- package/src/service/planoRevision.service.js +0 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as storeBuilderService from '../service/storeBuilder.service.js';
|
|
2
2
|
import * as storeService from '../service/store.service.js';
|
|
3
3
|
import * as planoService from '../service/planogram.service.js';
|
|
4
|
-
import { logger, fileUpload, signedUrl, sendMessageToQueue, getOpenSearchData
|
|
4
|
+
import { logger, fileUpload, signedUrl, sendMessageToQueue, getOpenSearchData } from 'tango-app-api-middleware';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
6
|
import customParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
7
7
|
import utc from 'dayjs/plugin/utc.js';
|
|
@@ -26,7 +26,6 @@ import * as planoMappingDuplicateService from '../service/planoMappingDuplicate.
|
|
|
26
26
|
import * as fixtureConfigDuplicateService from '../service/fixtureConfigDuplicate.service.js';
|
|
27
27
|
import * as planoVmDuplicateService from '../service/planoVmDuplicate.service.js';
|
|
28
28
|
import advancedFormat from 'dayjs/plugin/advancedFormat.js';
|
|
29
|
-
import * as planoRevisionService from '../service/planoRevision.service.js';
|
|
30
29
|
|
|
31
30
|
dayjs.extend( advancedFormat );
|
|
32
31
|
dayjs.extend( utc );
|
|
@@ -2781,7 +2780,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2781
2780
|
{ storeId: { $in: req.body.id } },
|
|
2782
2781
|
],
|
|
2783
2782
|
},
|
|
2784
|
-
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1, clientId: 1, validateShelfSections: 1
|
|
2783
|
+
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1, clientId: 1, validateShelfSections: 1 },
|
|
2785
2784
|
);
|
|
2786
2785
|
|
|
2787
2786
|
if ( !planograms?.length ) return res.sendError( 'No data found', 204 );
|
|
@@ -2792,7 +2791,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2792
2791
|
planograms.map( async ( planogram ) => {
|
|
2793
2792
|
const floors = await storeBuilderService.find(
|
|
2794
2793
|
{ planoId: planogram._id, ...( req.body?.floorId && { _id: req.body.floorId } ) },
|
|
2795
|
-
{ floorName: 1, layoutPolygon: 1, planoId: 1, isEdited: 1, planoProgress: 1, updatedAt: 1
|
|
2794
|
+
{ floorName: 1, layoutPolygon: 1, planoId: 1, isEdited: 1, planoProgress: 1, updatedAt: 1 },
|
|
2796
2795
|
);
|
|
2797
2796
|
|
|
2798
2797
|
const floorsWithFixtures = await Promise.all(
|
|
@@ -2840,7 +2839,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2840
2839
|
|
|
2841
2840
|
const shelfDetails = await Promise.all(
|
|
2842
2841
|
shelves.map( async ( shelf ) => {
|
|
2843
|
-
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf.
|
|
2842
|
+
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'product' }, { _id: 1 } );
|
|
2844
2843
|
let productIdList = productDetails.map( ( ele ) => ele._id );
|
|
2845
2844
|
let complianceQuery = [
|
|
2846
2845
|
{
|
|
@@ -2867,7 +2866,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2867
2866
|
let complianceStatus = await planoComplianceService.aggregate( complianceQuery );
|
|
2868
2867
|
const compliance = complianceStatus?.[0]?.status?.length ? ( ( complianceStatus?.[0]?.status?.length != shelf.productPerShelf ) || complianceStatus?.[0]?.status.includes( 'misplaced' ) ) ? 'improper' : 'proper' : 'improper';
|
|
2869
2868
|
|
|
2870
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.
|
|
2869
|
+
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'vm' } );
|
|
2871
2870
|
|
|
2872
2871
|
return {
|
|
2873
2872
|
...shelf.toObject(),
|
|
@@ -2970,7 +2969,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2970
2969
|
|
|
2971
2970
|
const shelfDetails = await Promise.all(
|
|
2972
2971
|
shelves.map( async ( shelf ) => {
|
|
2973
|
-
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf.
|
|
2972
|
+
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'product' }, { _id: 1 } );
|
|
2974
2973
|
let productIdList = productDetails.map( ( ele ) => ele._id );
|
|
2975
2974
|
let complianceQuery = [
|
|
2976
2975
|
{
|
|
@@ -2998,7 +2997,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2998
2997
|
const compliance = complianceStatus?.[0]?.status.length ? ( ( complianceStatus?.[0]?.status?.length != shelf.productPerShelf ) || complianceStatus?.[0]?.status?.includes( 'misplaced' ) ) ? 'improper' : 'proper' : 'improper';
|
|
2999
2998
|
|
|
3000
2999
|
|
|
3001
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.
|
|
3000
|
+
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'vm' } );
|
|
3002
3001
|
|
|
3003
3002
|
return {
|
|
3004
3003
|
...shelf.toObject(),
|
|
@@ -3489,134 +3488,6 @@ export async function fixtureShelfProductv2( req, res ) {
|
|
|
3489
3488
|
}
|
|
3490
3489
|
}
|
|
3491
3490
|
|
|
3492
|
-
export async function shelfProduct( req, res ) {
|
|
3493
|
-
try {
|
|
3494
|
-
if ( !req.body.revisionId ) {
|
|
3495
|
-
return res.sendError( 'Revision id is required', 400 );
|
|
3496
|
-
}
|
|
3497
|
-
if ( !req.body.fixtureId ) {
|
|
3498
|
-
return res.sendError( 'Fixture id is required', 400 );
|
|
3499
|
-
}
|
|
3500
|
-
const { revisionId, fixtureId } = req.body;
|
|
3501
|
-
let shelfMapping = {};
|
|
3502
|
-
|
|
3503
|
-
let revisionDetails = await planoRevisionService.findOne( { _id: revisionId } );
|
|
3504
|
-
let wallFixtures = revisionDetails.floorData.layoutPolygon.flatMap( ( ele ) => ele.fixtures );
|
|
3505
|
-
let allFixtures = [ ...wallFixtures, ...revisionDetails.floorData.centerFixture ];
|
|
3506
|
-
let fixture = allFixtures.find( ( ele ) => ele._id.toString() == fixtureId.toString() );
|
|
3507
|
-
|
|
3508
|
-
if ( !revisionDetails ) return res.sendError( 'Planogram not found', 204 );
|
|
3509
|
-
if ( !fixture ) return res.sendError( 'Fixture not found', 204 );
|
|
3510
|
-
|
|
3511
|
-
let getImages = await planoTaskComplianceService.findOne( { fixtureId: fixtureId, type: 'fixture' } );
|
|
3512
|
-
|
|
3513
|
-
let fixtureImage = getImages?.answers?.[0]?.image ?? '';
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
if ( req.body?.compliance ) {
|
|
3517
|
-
const getFixtureDetails = allFixtures.filter( ( ele ) => ele._id.toString() == fixture._id.toString() );
|
|
3518
|
-
const getAllFixtures = getFixtureDetails.flatMap( ( shelf ) => shelf.shelfConfig );
|
|
3519
|
-
|
|
3520
|
-
shelfMapping = getAllFixtures.reduce( ( acc, ele ) => {
|
|
3521
|
-
let productList = ele.productBrandName?.toString()?.toLowerCase();
|
|
3522
|
-
if ( !acc?.[productList] ) {
|
|
3523
|
-
let findZone = acc?.[productList]?.find( ( prod ) => prod.zone == ele.zone && prod.shelfId.toString() == ele._id.toString() );
|
|
3524
|
-
if ( !findZone ) {
|
|
3525
|
-
let fixDetails = getFixtureDetails.find( ( fix ) => fix._id.toString() == ele.fixtureId.toString() );
|
|
3526
|
-
acc[productList] = [
|
|
3527
|
-
{
|
|
3528
|
-
zone: ele.zone,
|
|
3529
|
-
shelfId: ele._id,
|
|
3530
|
-
fixtureId: ele.fixtureId,
|
|
3531
|
-
fixtureName: fixDetails?.fixtureName,
|
|
3532
|
-
brandName: ele.productBrandName,
|
|
3533
|
-
},
|
|
3534
|
-
];
|
|
3535
|
-
}
|
|
3536
|
-
}
|
|
3537
|
-
return acc;
|
|
3538
|
-
}, {} );
|
|
3539
|
-
}
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
const currentDate = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
3543
|
-
|
|
3544
|
-
const getProducts = async ( mappings ) => {
|
|
3545
|
-
const productIds = mappings.map( ( mapping ) => mapping.productId );
|
|
3546
|
-
const products = await planoProductService.find( { _id: { $in: productIds }, type: 'product' } );
|
|
3547
|
-
const productMap = new Map( products.map( ( product ) => [ product._id.toString(), product.toObject() ] ) );
|
|
3548
|
-
|
|
3549
|
-
return await Promise.all(
|
|
3550
|
-
mappings.map( async ( mapping ) => {
|
|
3551
|
-
const productData = productMap.get( mapping?.productId?.toString() ) || {};
|
|
3552
|
-
delete productData._id;
|
|
3553
|
-
let mappingCompliance = await planoComplianceService.findLean( {
|
|
3554
|
-
planoMappingId: mapping._id,
|
|
3555
|
-
date: currentDate,
|
|
3556
|
-
} );
|
|
3557
|
-
if ( mappingCompliance?.compliance == 'misplaced' ) {
|
|
3558
|
-
Object.keys( shelfMapping ).forEach( ( ele ) => {
|
|
3559
|
-
let eleArr = ele.split( ',' );
|
|
3560
|
-
if ( eleArr.includes( productData.brandName.toLowerCase() ) ) {
|
|
3561
|
-
mappingCompliance = { ...mappingCompliance, fixtureDetails: shelfMapping[ele]?.[0] || {} };
|
|
3562
|
-
}
|
|
3563
|
-
} );
|
|
3564
|
-
}
|
|
3565
|
-
const status = mappingCompliance ? mappingCompliance.compliance : '';
|
|
3566
|
-
return { ...mapping.toObject(), ...productData, status, ...( mappingCompliance?.fixtureDetails &&{ fixtureDetails: mappingCompliance?.fixtureDetails } ) };
|
|
3567
|
-
} ),
|
|
3568
|
-
);
|
|
3569
|
-
};
|
|
3570
|
-
|
|
3571
|
-
const vmDetails = await Promise.all( fixture?.vmConfig?.map( async ( vm ) => {
|
|
3572
|
-
const vmInfo = await planoVmService.findOne( { _id: vm.vmId } );
|
|
3573
|
-
return {
|
|
3574
|
-
...vm,
|
|
3575
|
-
...vmInfo?.toObject(),
|
|
3576
|
-
};
|
|
3577
|
-
} ) );
|
|
3578
|
-
|
|
3579
|
-
// if ( fixture.toObject().productResolutionLevel === 'L1' ) {
|
|
3580
|
-
// const productMappings = await planoMappingService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
|
|
3581
|
-
// const productDetails = await getProducts( productMappings );
|
|
3582
|
-
// return res.sendSuccess( { ...fixture.toObject(), products: productDetails, vmConfig: vmDetails, productCount: productMappings.length } );
|
|
3583
|
-
// }
|
|
3584
|
-
|
|
3585
|
-
if ( [ 'L1', 'L2', 'L3', 'L4' ].includes( fixture.productResolutionLevel ) ) {
|
|
3586
|
-
const fixtureShelves = fixture.shelfConfig;
|
|
3587
|
-
const productCount = await planoMappingService.count( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'product' } );
|
|
3588
|
-
let shelfProducts = await Promise.all(
|
|
3589
|
-
fixtureShelves.map( async ( shelf ) => {
|
|
3590
|
-
const productMappings = await planoMappingService.find( { shelfId: shelf._id, type: 'product' } );
|
|
3591
|
-
const productDetails = await getProducts( productMappings );
|
|
3592
|
-
if ( req.body?.compliance ) {
|
|
3593
|
-
let count = shelf.shelfType == 'tray' ? ( shelf.productPerShelf * shelf.trayRows ) : shelf.productPerShelf;
|
|
3594
|
-
if ( count > productMappings.length ) {
|
|
3595
|
-
let extraProduct = count- productMappings.length;
|
|
3596
|
-
for ( let i=0; i<extraProduct; i++ ) {
|
|
3597
|
-
productDetails.unshift( {
|
|
3598
|
-
status: 'missing',
|
|
3599
|
-
} );
|
|
3600
|
-
}
|
|
3601
|
-
}
|
|
3602
|
-
}
|
|
3603
|
-
return { ...shelf, products: productDetails };
|
|
3604
|
-
} ),
|
|
3605
|
-
);
|
|
3606
|
-
|
|
3607
|
-
let storageProducts = await planoMappingService.find( { fixtureId: new mongoose.Types.ObjectId( fixtureId ), type: 'storageBox' } );
|
|
3608
|
-
storageProducts = await getProducts( storageProducts );
|
|
3609
|
-
return res.sendSuccess( { ...fixture, shelves: shelfProducts, vmConfig: vmDetails, productCount: productCount, storageProducts: storageProducts, fixtureImage: fixtureImage } );
|
|
3610
|
-
}
|
|
3611
|
-
|
|
3612
|
-
return res.sendError( 'Incorrect resolution level', 400 );
|
|
3613
|
-
} catch ( e ) {
|
|
3614
|
-
console.log( e );
|
|
3615
|
-
logger.error( { functionName: 'fixtureShelfProductv1', error: e, message: req.body } );
|
|
3616
|
-
return res.sendError( e, 500 );
|
|
3617
|
-
}
|
|
3618
|
-
}
|
|
3619
|
-
|
|
3620
3491
|
export async function fixtureShelfProductv3( req, res ) {
|
|
3621
3492
|
try {
|
|
3622
3493
|
const { planoId, fixtureId } = req.body;
|
|
@@ -5149,7 +5020,7 @@ export async function planoList( req, res ) {
|
|
|
5149
5020
|
let page = inputData?.offset - 1 || 0;
|
|
5150
5021
|
let skip = limit * page;
|
|
5151
5022
|
|
|
5152
|
-
let storeDetails = await storeService.find( { clientId: inputData.clientId, status: 'active', ...( inputData?.stores?.length && { storeId: { $in: inputData.stores }
|
|
5023
|
+
let storeDetails = await storeService.find( { clientId: inputData.clientId, status: 'active', ...( inputData?.stores?.length && { storeId: { $in: inputData.stores } } ),
|
|
5153
5024
|
...( req.body?.assignedStores?.length && { storeId: { $in: req.body?.assignedStores } } ) }, { storeId: 1 } );
|
|
5154
5025
|
storeDetails = storeDetails.map( ( ele ) => ele.storeId );
|
|
5155
5026
|
|
|
@@ -5178,10 +5049,14 @@ export async function planoList( req, res ) {
|
|
|
5178
5049
|
id: '$_id',
|
|
5179
5050
|
floorName: 1,
|
|
5180
5051
|
floorNumber: 1,
|
|
5181
|
-
planoId: 1,
|
|
5182
|
-
verificationStatus: 1,
|
|
5183
5052
|
},
|
|
5184
5053
|
},
|
|
5054
|
+
// {
|
|
5055
|
+
// $group: {
|
|
5056
|
+
// _id: '',
|
|
5057
|
+
// layoutDetails: { $push: { k: '$_id', v: '$status', planoId: '$$plano' } },
|
|
5058
|
+
// },
|
|
5059
|
+
// },
|
|
5185
5060
|
],
|
|
5186
5061
|
as: 'layout',
|
|
5187
5062
|
},
|
|
@@ -5189,25 +5064,18 @@ export async function planoList( req, res ) {
|
|
|
5189
5064
|
{
|
|
5190
5065
|
$set: {
|
|
5191
5066
|
layoutCount: { $size: '$layout' },
|
|
5192
|
-
layoutStatus: {
|
|
5193
|
-
$map: {
|
|
5194
|
-
input: '$layout',
|
|
5195
|
-
as: 'lay',
|
|
5196
|
-
in: '$$lay.verificationStatus',
|
|
5197
|
-
},
|
|
5198
|
-
},
|
|
5199
5067
|
},
|
|
5200
5068
|
},
|
|
5201
|
-
|
|
5069
|
+
{ $unwind: { path: '$layout', preserveNullAndEmptyArrays: true } },
|
|
5202
5070
|
{
|
|
5203
5071
|
$lookup: {
|
|
5204
5072
|
from: 'storefixtures',
|
|
5205
|
-
let: {
|
|
5073
|
+
let: { floor: '$layout.id' },
|
|
5206
5074
|
pipeline: [
|
|
5207
5075
|
{
|
|
5208
5076
|
$match: {
|
|
5209
5077
|
$expr: {
|
|
5210
|
-
$eq: [ '$
|
|
5078
|
+
$eq: [ '$floorId', '$$floor' ],
|
|
5211
5079
|
},
|
|
5212
5080
|
},
|
|
5213
5081
|
},
|
|
@@ -5227,13 +5095,14 @@ export async function planoList( req, res ) {
|
|
|
5227
5095
|
{
|
|
5228
5096
|
$lookup: {
|
|
5229
5097
|
from: 'processedtasks',
|
|
5230
|
-
let: {
|
|
5098
|
+
let: { floor: '$layout.id' },
|
|
5231
5099
|
pipeline: [
|
|
5232
5100
|
{
|
|
5233
5101
|
$match: {
|
|
5234
5102
|
$expr: {
|
|
5235
5103
|
$and: [
|
|
5236
|
-
{ $eq: [ '$planoId', '$$plano' ] },
|
|
5104
|
+
// { $eq: [ '$planoId', '$$plano' ] },
|
|
5105
|
+
{ $eq: [ '$floorId', '$$floor' ] },
|
|
5237
5106
|
{ $eq: [ '$isPlano', true ] },
|
|
5238
5107
|
{
|
|
5239
5108
|
$lte: [ '$date_iso', new Date( dayjs().format( 'YYYY-MM-DD' ) ) ],
|
|
@@ -5284,14 +5153,14 @@ export async function planoList( req, res ) {
|
|
|
5284
5153
|
$lookup: {
|
|
5285
5154
|
from: 'planotaskcompliances',
|
|
5286
5155
|
let: {
|
|
5287
|
-
|
|
5156
|
+
floor: '$layout.id',
|
|
5288
5157
|
},
|
|
5289
5158
|
pipeline: [
|
|
5290
5159
|
{
|
|
5291
5160
|
$match: {
|
|
5292
5161
|
$expr: {
|
|
5293
5162
|
$and: [
|
|
5294
|
-
{ $eq: [ '$
|
|
5163
|
+
{ $eq: [ '$floorId', '$$floor' ] },
|
|
5295
5164
|
{ $in: [ '$type', [ 'layout', 'fixture', 'vm' ] ] },
|
|
5296
5165
|
],
|
|
5297
5166
|
},
|
|
@@ -5466,63 +5335,6 @@ export async function planoList( req, res ) {
|
|
|
5466
5335
|
},
|
|
5467
5336
|
},
|
|
5468
5337
|
},
|
|
5469
|
-
{
|
|
5470
|
-
$group: {
|
|
5471
|
-
_id: '',
|
|
5472
|
-
layoutCount: {
|
|
5473
|
-
$sum: '$layoutCount',
|
|
5474
|
-
},
|
|
5475
|
-
fixtureCount: {
|
|
5476
|
-
$sum: '$fixtureCount',
|
|
5477
|
-
},
|
|
5478
|
-
vmCount: {
|
|
5479
|
-
$sum: '$vmCount',
|
|
5480
|
-
},
|
|
5481
|
-
layoutPending: {
|
|
5482
|
-
$sum: '$layoutPending',
|
|
5483
|
-
},
|
|
5484
|
-
fixturePending: {
|
|
5485
|
-
$sum: '$fixturePending' },
|
|
5486
|
-
fixtureApproved: {
|
|
5487
|
-
$push: '$fixtureApproved',
|
|
5488
|
-
},
|
|
5489
|
-
vmPending: {
|
|
5490
|
-
$sum: '$vmPending',
|
|
5491
|
-
},
|
|
5492
|
-
layoutDisagree: {
|
|
5493
|
-
$sum: '$layoutDisagree',
|
|
5494
|
-
},
|
|
5495
|
-
fixtureDisagree: {
|
|
5496
|
-
$sum: '$fixtureDisagree',
|
|
5497
|
-
},
|
|
5498
|
-
vmDisagree: {
|
|
5499
|
-
$sum: '$vmDisagree',
|
|
5500
|
-
},
|
|
5501
|
-
},
|
|
5502
|
-
},
|
|
5503
|
-
{
|
|
5504
|
-
$project: {
|
|
5505
|
-
_id: 0,
|
|
5506
|
-
layoutCount: 1,
|
|
5507
|
-
fixtureCount: 1,
|
|
5508
|
-
vmCount: 1,
|
|
5509
|
-
layoutPending: 1,
|
|
5510
|
-
fixturePending: 1,
|
|
5511
|
-
fixtureApproved: {
|
|
5512
|
-
$reduce: {
|
|
5513
|
-
input: '$fixtureApproved',
|
|
5514
|
-
initialValue: [],
|
|
5515
|
-
in: {
|
|
5516
|
-
$concatArrays: [ '$$value', '$$this' ],
|
|
5517
|
-
},
|
|
5518
|
-
},
|
|
5519
|
-
},
|
|
5520
|
-
vmPending: 1,
|
|
5521
|
-
layoutDisagree: 1,
|
|
5522
|
-
fixtureDisagree: 1,
|
|
5523
|
-
vmDisagree: 1,
|
|
5524
|
-
},
|
|
5525
|
-
},
|
|
5526
5338
|
{
|
|
5527
5339
|
$project: {
|
|
5528
5340
|
_id: 0,
|
|
@@ -5707,7 +5519,6 @@ export async function planoList( req, res ) {
|
|
|
5707
5519
|
lastUpdate: '$updatedAt',
|
|
5708
5520
|
planoTask: { $ifNull: [ '$planoTask', [] ] },
|
|
5709
5521
|
layoutCount: 1,
|
|
5710
|
-
layoutStatus: 1,
|
|
5711
5522
|
taskDetails: {
|
|
5712
5523
|
$let: {
|
|
5713
5524
|
vars: {
|
|
@@ -5745,7 +5556,7 @@ export async function planoList( req, res ) {
|
|
|
5745
5556
|
|
|
5746
5557
|
if ( inputData.filter.taskPending === 'layout' ) {
|
|
5747
5558
|
andQuery.push(
|
|
5748
|
-
{ 'taskDetails.layoutStatus': '
|
|
5559
|
+
{ 'taskDetails.layoutStatus': 'pending' },
|
|
5749
5560
|
);
|
|
5750
5561
|
}
|
|
5751
5562
|
|
|
@@ -5767,274 +5578,94 @@ export async function planoList( req, res ) {
|
|
|
5767
5578
|
},
|
|
5768
5579
|
} );
|
|
5769
5580
|
}
|
|
5770
|
-
let orQuery = [];
|
|
5771
5581
|
|
|
5582
|
+
if ( inputData?.filter?.flag?.length ) {
|
|
5583
|
+
let andQuery = [];
|
|
5584
|
+
andQuery.push(
|
|
5585
|
+
{
|
|
5586
|
+
'planoTask.taskStatus': {
|
|
5587
|
+
$elemMatch: {
|
|
5588
|
+
type: { $in: inputData.filter.flag },
|
|
5589
|
+
status: { $ne: 'submit' },
|
|
5590
|
+
breach: true,
|
|
5591
|
+
},
|
|
5592
|
+
},
|
|
5593
|
+
},
|
|
5594
|
+
// { 'taskDetails.layoutStatus': 'pending' },
|
|
5595
|
+
);
|
|
5596
|
+
query.push( {
|
|
5597
|
+
$match: {
|
|
5598
|
+
$and: andQuery,
|
|
5599
|
+
},
|
|
5600
|
+
} );
|
|
5601
|
+
}
|
|
5602
|
+
|
|
5603
|
+
let orQuery = [];
|
|
5772
5604
|
|
|
5773
|
-
if ( inputData.filter.
|
|
5774
|
-
if ( inputData.filter.
|
|
5605
|
+
if ( inputData.filter.status.length ) {
|
|
5606
|
+
if ( inputData.filter.status.includes( 'taskAssigned' ) ) {
|
|
5775
5607
|
// orQuery.push( { 'planoTask.taskStatus.status': { $in: [ 'open', 'inprogress' ] } } );
|
|
5776
5608
|
orQuery.push( {
|
|
5777
|
-
|
|
5778
|
-
{
|
|
5779
|
-
$
|
|
5780
|
-
|
|
5781
|
-
{
|
|
5782
|
-
$size: {
|
|
5783
|
-
$filter: {
|
|
5784
|
-
input: { $ifNull: [ { $arrayElemAt: [ '$planoTask.taskStatus', 0 ] }, [] ] },
|
|
5785
|
-
as: 'task',
|
|
5786
|
-
cond: {
|
|
5787
|
-
$and: [
|
|
5788
|
-
{ $eq: [ '$$task.type', 'layout' ] },
|
|
5789
|
-
{ $ne: [ '$$task.status', 'submit' ] },
|
|
5790
|
-
{ $eq: [ '$$task.breach', false ] },
|
|
5791
|
-
],
|
|
5792
|
-
},
|
|
5793
|
-
},
|
|
5794
|
-
},
|
|
5795
|
-
},
|
|
5796
|
-
'$layoutCount',
|
|
5797
|
-
],
|
|
5798
|
-
},
|
|
5609
|
+
'planoTask.taskStatus': {
|
|
5610
|
+
$elemMatch: {
|
|
5611
|
+
status: { $ne: 'submit' },
|
|
5612
|
+
breach: false,
|
|
5799
5613
|
},
|
|
5800
|
-
|
|
5614
|
+
},
|
|
5801
5615
|
} );
|
|
5802
5616
|
}
|
|
5803
|
-
if ( inputData.filter.
|
|
5804
|
-
// orQuery.push( { 'planoTask.taskStatus.status': { $in: [ 'open', 'inprogress' ] } } );
|
|
5617
|
+
if ( inputData.filter.status.includes( 'reviewPending' ) ) {
|
|
5805
5618
|
orQuery.push( {
|
|
5806
5619
|
$and: [
|
|
5807
|
-
{
|
|
5808
|
-
$
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
$size: {
|
|
5812
|
-
$filter: {
|
|
5813
|
-
input: { $ifNull: [ { $arrayElemAt: [ '$planoTask.taskStatus', 0 ] }, [] ] },
|
|
5814
|
-
as: 'task',
|
|
5815
|
-
cond: {
|
|
5816
|
-
$and: [
|
|
5817
|
-
{ $eq: [ '$$task.type', 'layout' ] },
|
|
5818
|
-
{ $ne: [ '$$task.status', 'submit' ] },
|
|
5819
|
-
{ $eq: [ '$$task.breach', true ] },
|
|
5820
|
-
],
|
|
5821
|
-
},
|
|
5822
|
-
},
|
|
5823
|
-
},
|
|
5824
|
-
},
|
|
5825
|
-
'$layoutCount',
|
|
5826
|
-
],
|
|
5620
|
+
{ 'planoTask.taskStatus': {
|
|
5621
|
+
$elemMatch: {
|
|
5622
|
+
type: 'layout',
|
|
5623
|
+
status: 'submit',
|
|
5827
5624
|
},
|
|
5828
|
-
},
|
|
5625
|
+
} }, { 'taskDetails.layoutStatus': 'pending' },
|
|
5829
5626
|
],
|
|
5830
5627
|
} );
|
|
5831
|
-
}
|
|
5832
|
-
if ( inputData.filter.layout.includes( 'reviewPending' ) ) {
|
|
5833
5628
|
orQuery.push( {
|
|
5834
5629
|
$and: [
|
|
5835
5630
|
{ 'planoTask.taskStatus': {
|
|
5836
5631
|
$elemMatch: {
|
|
5837
|
-
type: '
|
|
5632
|
+
type: 'fixture',
|
|
5838
5633
|
status: 'submit',
|
|
5839
5634
|
},
|
|
5840
|
-
} }, { 'taskDetails.
|
|
5635
|
+
} }, { 'taskDetails.fixtureStatus': 'pending' },
|
|
5841
5636
|
],
|
|
5842
5637
|
} );
|
|
5843
|
-
}
|
|
5844
|
-
if ( inputData.filter.layout.includes( 'completed' ) ) {
|
|
5845
5638
|
orQuery.push( {
|
|
5846
5639
|
$and: [
|
|
5847
5640
|
{ 'planoTask.taskStatus': {
|
|
5848
5641
|
$elemMatch: {
|
|
5849
|
-
type: '
|
|
5642
|
+
type: 'vm',
|
|
5850
5643
|
status: 'submit',
|
|
5851
5644
|
},
|
|
5852
|
-
} }, { 'taskDetails.
|
|
5645
|
+
} }, { 'taskDetails.vmStatus': 'pending' },
|
|
5853
5646
|
],
|
|
5854
5647
|
} );
|
|
5855
5648
|
}
|
|
5856
|
-
if ( inputData.filter.
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
// orQuery.push( { 'planoTask.taskStatus.status': { $in: [ 'open', 'inprogress' ] } } );
|
|
5870
|
-
orQuery.push( {
|
|
5871
|
-
$and: [
|
|
5872
|
-
{
|
|
5873
|
-
$expr: {
|
|
5874
|
-
$eq: [
|
|
5875
|
-
{
|
|
5876
|
-
$size: {
|
|
5877
|
-
$filter: {
|
|
5878
|
-
input: { $ifNull: [ { $arrayElemAt: [ '$planoTask.taskStatus', 0 ] }, [] ] },
|
|
5879
|
-
as: 'task',
|
|
5880
|
-
cond: {
|
|
5881
|
-
$and: [
|
|
5882
|
-
{ $eq: [ '$$task.type', 'fixture' ] },
|
|
5883
|
-
{ $ne: [ '$$task.status', 'submit' ] },
|
|
5884
|
-
{ $eq: [ '$$task.breach', false ] },
|
|
5885
|
-
],
|
|
5886
|
-
},
|
|
5887
|
-
},
|
|
5888
|
-
},
|
|
5889
|
-
},
|
|
5890
|
-
'$layoutCount',
|
|
5891
|
-
],
|
|
5892
|
-
},
|
|
5893
|
-
},
|
|
5894
|
-
],
|
|
5895
|
-
} );
|
|
5896
|
-
}
|
|
5897
|
-
if ( inputData.filter.fixture.includes( 'flag' ) ) {
|
|
5898
|
-
// orQuery.push( { 'planoTask.taskStatus.status': { $in: [ 'open', 'inprogress' ] } } );
|
|
5899
|
-
orQuery.push( {
|
|
5900
|
-
$and: [
|
|
5901
|
-
{
|
|
5902
|
-
$expr: {
|
|
5903
|
-
$eq: [
|
|
5904
|
-
{
|
|
5905
|
-
$size: {
|
|
5906
|
-
$filter: {
|
|
5907
|
-
input: { $ifNull: [ { $arrayElemAt: [ '$planoTask.taskStatus', 0 ] }, [] ] },
|
|
5908
|
-
as: 'task',
|
|
5909
|
-
cond: {
|
|
5910
|
-
$and: [
|
|
5911
|
-
{ $eq: [ '$$task.type', 'fixture' ] },
|
|
5912
|
-
{ $ne: [ '$$task.status', 'submit' ] },
|
|
5913
|
-
{ $eq: [ '$$task.breach', true ] },
|
|
5914
|
-
],
|
|
5915
|
-
},
|
|
5916
|
-
},
|
|
5917
|
-
},
|
|
5918
|
-
},
|
|
5919
|
-
'$layoutCount',
|
|
5920
|
-
],
|
|
5921
|
-
},
|
|
5922
|
-
},
|
|
5923
|
-
],
|
|
5924
|
-
} );
|
|
5925
|
-
}
|
|
5926
|
-
if ( inputData.filter.fixture.includes( 'reviewPending' ) ) {
|
|
5927
|
-
orQuery.push( {
|
|
5928
|
-
$and: [
|
|
5929
|
-
{ 'planoTask.taskStatus': {
|
|
5930
|
-
$elemMatch: {
|
|
5931
|
-
type: 'fixture',
|
|
5932
|
-
status: 'submit',
|
|
5933
|
-
},
|
|
5934
|
-
} }, { 'taskDetails.fixtureStatus': 'pending' },
|
|
5935
|
-
],
|
|
5936
|
-
} );
|
|
5937
|
-
}
|
|
5938
|
-
if ( inputData.filter.fixture.includes( 'completed' ) ) {
|
|
5939
|
-
orQuery.push( {
|
|
5940
|
-
$and: [
|
|
5941
|
-
{
|
|
5942
|
-
$expr: {
|
|
5943
|
-
$eq: [
|
|
5944
|
-
{
|
|
5945
|
-
$size: {
|
|
5946
|
-
$filter: {
|
|
5947
|
-
input: { $ifNull: [ { $arrayElemAt: [ '$planoTask.taskStatus', 0 ] }, [] ] },
|
|
5948
|
-
as: 'task',
|
|
5949
|
-
cond: {
|
|
5950
|
-
$and: [
|
|
5951
|
-
{ $eq: [ '$$task.type', 'fixture' ] },
|
|
5952
|
-
{ $eq: [ '$$task.status', 'submit' ] },
|
|
5953
|
-
],
|
|
5954
|
-
},
|
|
5955
|
-
},
|
|
5956
|
-
},
|
|
5957
|
-
},
|
|
5958
|
-
'$layoutCount',
|
|
5959
|
-
],
|
|
5960
|
-
},
|
|
5961
|
-
},
|
|
5962
|
-
{ 'taskDetails.fixtureStatus': 'complete' },
|
|
5963
|
-
],
|
|
5964
|
-
} );
|
|
5965
|
-
}
|
|
5966
|
-
if ( inputData.filter.fixture.includes( 'yetToAssign' ) ) {
|
|
5967
|
-
orQuery.push( { 'planoTask.taskStatus': {
|
|
5968
|
-
$not: {
|
|
5969
|
-
$elemMatch: {
|
|
5970
|
-
type: 'fixture',
|
|
5971
|
-
},
|
|
5972
|
-
},
|
|
5973
|
-
} } );
|
|
5974
|
-
}
|
|
5975
|
-
}
|
|
5976
|
-
|
|
5977
|
-
if ( inputData.filter.status.length ) {
|
|
5978
|
-
if ( inputData.filter.status.includes( 'inprogress' ) ) {
|
|
5979
|
-
orQuery.push(
|
|
5980
|
-
{ 'planoTask.taskStatus': {
|
|
5981
|
-
$elemMatch: {
|
|
5982
|
-
type: 'layout',
|
|
5983
|
-
status: { $ne: 'submit' },
|
|
5984
|
-
},
|
|
5985
|
-
} },
|
|
5986
|
-
{ 'taskDetails.layoutStatus': { $ne: 'complete' } },
|
|
5987
|
-
{ 'planoTask.taskStatus': {
|
|
5988
|
-
$elemMatch: {
|
|
5989
|
-
type: 'fixture',
|
|
5990
|
-
status: { $ne: 'submit' },
|
|
5991
|
-
},
|
|
5992
|
-
} },
|
|
5993
|
-
{ 'taskDetails.fixtureStatus': { $ne: 'complete' } },
|
|
5994
|
-
{ $expr: { $eq: [ { $size: '$planoTask' }, 0 ] } },
|
|
5995
|
-
);
|
|
5996
|
-
}
|
|
5997
|
-
if ( inputData.filter.status.includes( 'notPublished' ) ) {
|
|
5998
|
-
orQuery.push( {
|
|
5999
|
-
$and: [
|
|
6000
|
-
{ 'planoTask.taskStatus': {
|
|
6001
|
-
$elemMatch: {
|
|
6002
|
-
type: 'layout',
|
|
6003
|
-
status: 'submit',
|
|
6004
|
-
},
|
|
6005
|
-
} }, { 'taskDetails.layoutStatus': 'complete' },
|
|
6006
|
-
{ 'planoTask.taskStatus': {
|
|
6007
|
-
$elemMatch: {
|
|
6008
|
-
type: 'fixture',
|
|
6009
|
-
status: 'submit',
|
|
5649
|
+
if ( inputData.filter.status.includes( 'completed' ) ) {
|
|
5650
|
+
let taskType= [ 'fixture' ];
|
|
5651
|
+
let andCondition = [];
|
|
5652
|
+
taskType.forEach( ( type ) => {
|
|
5653
|
+
andCondition.push(
|
|
5654
|
+
{ 'planoTask.taskStatus': {
|
|
5655
|
+
$elemMatch: {
|
|
5656
|
+
type,
|
|
5657
|
+
status: 'submit',
|
|
5658
|
+
},
|
|
5659
|
+
} },
|
|
5660
|
+
{
|
|
5661
|
+
[`taskDetails.${type}Status`]: 'complete',
|
|
6010
5662
|
},
|
|
6011
|
-
|
|
6012
|
-
{
|
|
6013
|
-
layoutStatus: { $in: [ false ] },
|
|
6014
|
-
},
|
|
6015
|
-
],
|
|
5663
|
+
);
|
|
6016
5664
|
} );
|
|
5665
|
+
orQuery.push( { $and: andCondition } );
|
|
6017
5666
|
}
|
|
6018
|
-
if ( inputData.filter.status.includes( '
|
|
6019
|
-
orQuery.push( { $
|
|
6020
|
-
{ 'planoTask.taskStatus': {
|
|
6021
|
-
$elemMatch: {
|
|
6022
|
-
type: 'layout',
|
|
6023
|
-
status: 'submit',
|
|
6024
|
-
},
|
|
6025
|
-
} }, { 'taskDetails.layoutStatus': 'complete' },
|
|
6026
|
-
{ 'planoTask.taskStatus': {
|
|
6027
|
-
$elemMatch: {
|
|
6028
|
-
type: 'fixture',
|
|
6029
|
-
status: 'submit',
|
|
6030
|
-
},
|
|
6031
|
-
} }, { 'taskDetails.fixtureStatus': 'complete' },
|
|
6032
|
-
{
|
|
6033
|
-
layoutStatus: { $nin: [ false ] },
|
|
6034
|
-
},
|
|
6035
|
-
],
|
|
6036
|
-
},
|
|
6037
|
-
);
|
|
5667
|
+
if ( inputData.filter.status.includes( 'yetToAssign' ) ) {
|
|
5668
|
+
orQuery.push( { $expr: { $eq: [ { $size: '$planoTask' }, 0 ] } } );
|
|
6038
5669
|
}
|
|
6039
5670
|
}
|
|
6040
5671
|
|
|
@@ -6080,9 +5711,7 @@ export async function planoList( req, res ) {
|
|
|
6080
5711
|
storeId: { $in: storeDetails } }, { _id: 1 } ),
|
|
6081
5712
|
] );
|
|
6082
5713
|
|
|
6083
|
-
|
|
6084
|
-
await download( planoDetails[0].data );
|
|
6085
|
-
}
|
|
5714
|
+
|
|
6086
5715
|
if ( !planoDetails[0].data.length ) {
|
|
6087
5716
|
return res.sendError( 'No data found', 204 );
|
|
6088
5717
|
}
|
|
@@ -6208,20 +5837,11 @@ export async function planoList( req, res ) {
|
|
|
6208
5837
|
],
|
|
6209
5838
|
},
|
|
6210
5839
|
},
|
|
6211
|
-
layoutComplete: {
|
|
6212
|
-
$sum: {
|
|
6213
|
-
$cond: [
|
|
6214
|
-
{ $and: [ { $eq: [ '$type', 'layout' ] }, { $eq: [ '$status', 'complete' ] } ] },
|
|
6215
|
-
1,
|
|
6216
|
-
0,
|
|
6217
|
-
],
|
|
6218
|
-
},
|
|
6219
|
-
},
|
|
6220
5840
|
},
|
|
6221
5841
|
},
|
|
6222
5842
|
{
|
|
6223
5843
|
$group: {
|
|
6224
|
-
_id:
|
|
5844
|
+
_id: 0,
|
|
6225
5845
|
layoutPending: {
|
|
6226
5846
|
$sum: { $cond: {
|
|
6227
5847
|
if: {
|
|
@@ -6249,13 +5869,6 @@ export async function planoList( req, res ) {
|
|
|
6249
5869
|
else: 0,
|
|
6250
5870
|
} },
|
|
6251
5871
|
},
|
|
6252
|
-
layoutComplete: { $sum: { $cond: {
|
|
6253
|
-
if: {
|
|
6254
|
-
$gt: [ '$layoutComplete', 0 ],
|
|
6255
|
-
},
|
|
6256
|
-
then: 1,
|
|
6257
|
-
else: 0,
|
|
6258
|
-
} } },
|
|
6259
5872
|
},
|
|
6260
5873
|
},
|
|
6261
5874
|
{
|
|
@@ -6264,7 +5877,6 @@ export async function planoList( req, res ) {
|
|
|
6264
5877
|
layoutPending: '$layoutPending',
|
|
6265
5878
|
fixturePending: '$fixturePending',
|
|
6266
5879
|
vmPending: '$vmPending',
|
|
6267
|
-
layoutComplete: 1,
|
|
6268
5880
|
},
|
|
6269
5881
|
},
|
|
6270
5882
|
];
|
|
@@ -6767,14 +6379,7 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6767
6379
|
let page = req?.body?.offset || 1;
|
|
6768
6380
|
let limit = req.body?.limit || 10;
|
|
6769
6381
|
let skip = ( page -1 ) * limit;
|
|
6770
|
-
let storeDetails = await storeService.find( {
|
|
6771
|
-
clientId: req.body.clientId,
|
|
6772
|
-
status: 'active',
|
|
6773
|
-
...( req.body?.stores?.length && { storeId: { $in: req.body.stores } } ),
|
|
6774
|
-
...( req.body.filter.country.length && { 'storeProfile.country': { $in: req.body.filter.country } } ),
|
|
6775
|
-
...( req.body.filter.city.length && { 'storeProfile.city': { $in: req.body.filter.city } } ),
|
|
6776
|
-
...( req.body?.assignedStores?.length && { storeId: { $in: req.body?.assignedStores } } ) }, { storeId: 1 } );
|
|
6777
|
-
|
|
6382
|
+
let storeDetails = await storeService.find( { clientId: req.body.clientId, status: 'active', ...( req.body?.stores?.length && { storeId: { $in: req.body.stores } } ) }, { storeId: 1 } );
|
|
6778
6383
|
storeDetails = storeDetails.map( ( ele ) => ele.storeId );
|
|
6779
6384
|
let query = [
|
|
6780
6385
|
{
|
|
@@ -6784,31 +6389,15 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6784
6389
|
planoProgress: 100,
|
|
6785
6390
|
},
|
|
6786
6391
|
},
|
|
6787
|
-
{
|
|
6788
|
-
$group: {
|
|
6789
|
-
_id: '$planoId',
|
|
6790
|
-
planoId: { $first: '$planoId' },
|
|
6791
|
-
layoutName: { $first: '$layoutName' },
|
|
6792
|
-
floorId: { $first: '$_id' },
|
|
6793
|
-
floorName: { $first: '$floorName' },
|
|
6794
|
-
planoProgress: { $first: '$planoProgress' },
|
|
6795
|
-
storeId: { $first: '$storeId' },
|
|
6796
|
-
storeName: { $first: '$storeName' },
|
|
6797
|
-
updatedAt: { $first: '$updatedAt' },
|
|
6798
|
-
floorNumber: { $first: '$floorNumber' },
|
|
6799
|
-
layoutCount: { $sum: 1 },
|
|
6800
|
-
layoutStatus: { $push: '$rolloutStatus' },
|
|
6801
|
-
},
|
|
6802
|
-
},
|
|
6803
6392
|
{
|
|
6804
6393
|
$lookup: {
|
|
6805
6394
|
from: 'storefixtures',
|
|
6806
|
-
let: {
|
|
6395
|
+
let: { floor: '$_id' },
|
|
6807
6396
|
pipeline: [
|
|
6808
6397
|
{
|
|
6809
6398
|
$match: {
|
|
6810
6399
|
$expr: {
|
|
6811
|
-
$eq: [ '$
|
|
6400
|
+
$eq: [ '$floorId', '$$floor' ],
|
|
6812
6401
|
},
|
|
6813
6402
|
},
|
|
6814
6403
|
},
|
|
@@ -6840,7 +6429,7 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6840
6429
|
_id: 0,
|
|
6841
6430
|
planoId: 1,
|
|
6842
6431
|
layoutName: 1,
|
|
6843
|
-
floorId:
|
|
6432
|
+
floorId: '$_id',
|
|
6844
6433
|
floorNumber: 1,
|
|
6845
6434
|
floorName: 1,
|
|
6846
6435
|
planoProgress: 1,
|
|
@@ -6852,21 +6441,19 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6852
6441
|
lastUpdate: '$updatedAt',
|
|
6853
6442
|
merchEditedCount: '$fixtureDetails.merchEditedCount',
|
|
6854
6443
|
vmEditedCount: '$fixtureDetails.vmEditedCount',
|
|
6855
|
-
layoutCount: 1,
|
|
6856
|
-
layoutStatus: 1,
|
|
6857
6444
|
},
|
|
6858
6445
|
},
|
|
6859
6446
|
{
|
|
6860
6447
|
$lookup: {
|
|
6861
6448
|
from: 'processedtasks',
|
|
6862
|
-
let: {
|
|
6449
|
+
let: { floorId: '$floorId' },
|
|
6863
6450
|
pipeline: [
|
|
6864
6451
|
{
|
|
6865
6452
|
$match: {
|
|
6866
6453
|
$expr: {
|
|
6867
6454
|
$and: [
|
|
6868
6455
|
{ $lte: [ '$date_iso', new Date( dayjs().format( 'YYYY-MM-DD' ) ) ] },
|
|
6869
|
-
{ $eq: [ '$
|
|
6456
|
+
{ $eq: [ '$floorId', '$$floorId' ] },
|
|
6870
6457
|
{ $eq: [ '$isPlano', true ] },
|
|
6871
6458
|
{ $in: [ '$planoType', [ 'merchRollout', 'vmRollout' ] ] },
|
|
6872
6459
|
],
|
|
@@ -6909,13 +6496,13 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6909
6496
|
{
|
|
6910
6497
|
$lookup: {
|
|
6911
6498
|
from: 'planotaskcompliances',
|
|
6912
|
-
let: {
|
|
6499
|
+
let: { floorId: '$floorId', taskId: '$taskDetails.taskId' },
|
|
6913
6500
|
pipeline: [
|
|
6914
6501
|
{
|
|
6915
6502
|
$match: {
|
|
6916
6503
|
$expr: {
|
|
6917
6504
|
$and: [
|
|
6918
|
-
{ $eq: [ '$
|
|
6505
|
+
{ $eq: [ '$floorId', '$$floorId' ] },
|
|
6919
6506
|
{ $in: [ '$taskId', '$$taskId' ] },
|
|
6920
6507
|
{ $in: [ '$type', [ 'merchRollout', 'vmRollout' ] ] },
|
|
6921
6508
|
// { $eq: [ '$status', 'incomplete' ] },
|
|
@@ -7246,9 +6833,10 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7246
6833
|
} );
|
|
7247
6834
|
}
|
|
7248
6835
|
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
6836
|
+
if ( req.body.filter?.status?.length ) {
|
|
6837
|
+
const orCondition = [];
|
|
6838
|
+
|
|
6839
|
+
if ( req.body.filter.status.includes( 'yetToAssign' ) ) {
|
|
7252
6840
|
orCondition.push(
|
|
7253
6841
|
{
|
|
7254
6842
|
$or: [
|
|
@@ -7258,12 +6846,12 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7258
6846
|
{ merchEditedCount: { $ne: 0 } },
|
|
7259
6847
|
],
|
|
7260
6848
|
},
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
6849
|
+
{
|
|
6850
|
+
$and: [
|
|
6851
|
+
{ taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } },
|
|
6852
|
+
{ vmEditedCount: { $ne: 0 } },
|
|
6853
|
+
],
|
|
6854
|
+
},
|
|
7267
6855
|
{
|
|
7268
6856
|
$expr: {
|
|
7269
6857
|
$lt: [ { $size: '$taskDetails' }, 2 ],
|
|
@@ -7282,87 +6870,6 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7282
6870
|
] },
|
|
7283
6871
|
],
|
|
7284
6872
|
},
|
|
7285
|
-
// {
|
|
7286
|
-
// $and: [
|
|
7287
|
-
// { taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } },
|
|
7288
|
-
// { $or: [
|
|
7289
|
-
// { 'taskFeedback.vmStatus': 'disagree' },
|
|
7290
|
-
// { $and: [ { vmEditedCount: { $ne: 0 } }, { $expr: {
|
|
7291
|
-
// $eq: [ { $size: { $objectToArray: '$taskFeedback' } }, 0 ],
|
|
7292
|
-
// } } ] },
|
|
7293
|
-
// ] },
|
|
7294
|
-
// ],
|
|
7295
|
-
// },
|
|
7296
|
-
);
|
|
7297
|
-
}
|
|
7298
|
-
|
|
7299
|
-
if ( req.body.filter.merch.includes( 'taskAssigned' ) ) {
|
|
7300
|
-
orCondition.push( {
|
|
7301
|
-
taskDetails: { $elemMatch: { type: 'merchRollout', status: { $ne: 'submit' }, breach: false } },
|
|
7302
|
-
} );
|
|
7303
|
-
}
|
|
7304
|
-
|
|
7305
|
-
if ( req.body.filter.merch.includes( 'reviewPending' ) ) {
|
|
7306
|
-
orCondition.push(
|
|
7307
|
-
{
|
|
7308
|
-
$and: [
|
|
7309
|
-
{ taskDetails: { $elemMatch: { type: 'merchRollout', status: 'submit' } } },
|
|
7310
|
-
{ 'taskFeedback.fixtureStatus': 'pending' },
|
|
7311
|
-
],
|
|
7312
|
-
},
|
|
7313
|
-
// {
|
|
7314
|
-
// $and: [
|
|
7315
|
-
// { taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } },
|
|
7316
|
-
// { 'taskFeedback.vmStatus': 'pending' },
|
|
7317
|
-
// ],
|
|
7318
|
-
// },
|
|
7319
|
-
);
|
|
7320
|
-
}
|
|
7321
|
-
|
|
7322
|
-
if ( req.body.filter.merch.includes( 'completed' ) ) {
|
|
7323
|
-
orCondition.push( {
|
|
7324
|
-
$and: [
|
|
7325
|
-
{
|
|
7326
|
-
$or: [
|
|
7327
|
-
{ $and: [ { taskDetails: { $elemMatch: { type: 'merchRollout', status: 'submit' } } }, { merchEditedCount: 0 }, { 'taskFeedback.fixtureStatus': 'complete' } ] },
|
|
7328
|
-
// { $and: [ { taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } }, { vmEditedCount: 0 }, { 'taskFeedback.vmStatus': 'complete' } ] },
|
|
7329
|
-
],
|
|
7330
|
-
},
|
|
7331
|
-
// {
|
|
7332
|
-
// $expr: {
|
|
7333
|
-
// $eq: [ { $size: { $objectToArray: '$taskFeedback' } }, 0 ],
|
|
7334
|
-
// },
|
|
7335
|
-
// },
|
|
7336
|
-
],
|
|
7337
|
-
} );
|
|
7338
|
-
}
|
|
7339
|
-
|
|
7340
|
-
if ( req.body.filter.merch.includes( 'flag' ) ) {
|
|
7341
|
-
orCondition.push( {
|
|
7342
|
-
taskDetails: { $elemMatch: { type: 'merchRollout', status: { $ne: 'submit' }, breach: true } },
|
|
7343
|
-
} );
|
|
7344
|
-
}
|
|
7345
|
-
|
|
7346
|
-
extraCondition.push( { $match: { $or: orCondition } } );
|
|
7347
|
-
}
|
|
7348
|
-
if ( req.body.filter?.vm?.length ) {
|
|
7349
|
-
if ( req.body.filter.vm.includes( 'yetToAssign' ) ) {
|
|
7350
|
-
orCondition.push(
|
|
7351
|
-
{
|
|
7352
|
-
$or: [
|
|
7353
|
-
{
|
|
7354
|
-
$and: [
|
|
7355
|
-
{ taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } },
|
|
7356
|
-
{ vmEditedCount: { $ne: 0 } },
|
|
7357
|
-
],
|
|
7358
|
-
},
|
|
7359
|
-
{
|
|
7360
|
-
$expr: {
|
|
7361
|
-
$lt: [ { $size: '$taskDetails' }, 2 ],
|
|
7362
|
-
},
|
|
7363
|
-
},
|
|
7364
|
-
],
|
|
7365
|
-
},
|
|
7366
6873
|
{
|
|
7367
6874
|
$and: [
|
|
7368
6875
|
{ taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } },
|
|
@@ -7377,14 +6884,20 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7377
6884
|
);
|
|
7378
6885
|
}
|
|
7379
6886
|
|
|
7380
|
-
if ( req.body.filter.
|
|
6887
|
+
if ( req.body.filter.status.includes( 'taskAssigned' ) ) {
|
|
7381
6888
|
orCondition.push( {
|
|
7382
|
-
taskDetails: { $elemMatch: {
|
|
6889
|
+
taskDetails: { $elemMatch: { status: { $ne: 'submit' }, breach: false } },
|
|
7383
6890
|
} );
|
|
7384
6891
|
}
|
|
7385
6892
|
|
|
7386
|
-
if ( req.body.filter.
|
|
6893
|
+
if ( req.body.filter.status.includes( 'reviewPending' ) ) {
|
|
7387
6894
|
orCondition.push(
|
|
6895
|
+
{
|
|
6896
|
+
$and: [
|
|
6897
|
+
{ taskDetails: { $elemMatch: { type: 'merchRollout', status: 'submit' } } },
|
|
6898
|
+
{ 'taskFeedback.fixtureStatus': 'pending' },
|
|
6899
|
+
],
|
|
6900
|
+
},
|
|
7388
6901
|
{
|
|
7389
6902
|
$and: [
|
|
7390
6903
|
{ taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } },
|
|
@@ -7394,11 +6907,12 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7394
6907
|
);
|
|
7395
6908
|
}
|
|
7396
6909
|
|
|
7397
|
-
if ( req.body.filter.
|
|
6910
|
+
if ( req.body.filter.status.includes( 'completed' ) ) {
|
|
7398
6911
|
orCondition.push( {
|
|
7399
6912
|
$and: [
|
|
7400
6913
|
{
|
|
7401
6914
|
$or: [
|
|
6915
|
+
{ $and: [ { taskDetails: { $elemMatch: { type: 'merchRollout', status: 'submit' } } }, { merchEditedCount: 0 }, { 'taskFeedback.fixtureStatus': 'complete' } ] },
|
|
7402
6916
|
{ $and: [ { taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } }, { vmEditedCount: 0 }, { 'taskFeedback.vmStatus': 'complete' } ] },
|
|
7403
6917
|
],
|
|
7404
6918
|
},
|
|
@@ -7411,79 +6925,9 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7411
6925
|
} );
|
|
7412
6926
|
}
|
|
7413
6927
|
|
|
7414
|
-
if ( req.body.filter.vm.includes( 'flag' ) ) {
|
|
7415
|
-
orCondition.push( {
|
|
7416
|
-
taskDetails: { $elemMatch: { type: 'vmRollout', status: { $ne: 'submit' }, breach: true } },
|
|
7417
|
-
} );
|
|
7418
|
-
}
|
|
7419
|
-
|
|
7420
6928
|
extraCondition.push( { $match: { $or: orCondition } } );
|
|
7421
6929
|
}
|
|
7422
6930
|
|
|
7423
|
-
if ( req.body.filter.status.length ) {
|
|
7424
|
-
if ( inputData.filter.status.includes( 'inprogress' ) ) {
|
|
7425
|
-
orCondition.push(
|
|
7426
|
-
{ 'taskDetails': {
|
|
7427
|
-
$elemMatch: {
|
|
7428
|
-
type: 'merchRollout',
|
|
7429
|
-
status: { $ne: 'submit' },
|
|
7430
|
-
},
|
|
7431
|
-
} },
|
|
7432
|
-
{ 'taskDetails.fixtureStatus': { $ne: 'complete' } },
|
|
7433
|
-
{ 'taskDetails': {
|
|
7434
|
-
$elemMatch: {
|
|
7435
|
-
type: 'vmRollout',
|
|
7436
|
-
status: { $ne: 'submit' },
|
|
7437
|
-
},
|
|
7438
|
-
} },
|
|
7439
|
-
{ 'taskDetails.vmStatus': { $ne: 'complete' } },
|
|
7440
|
-
{ $expr: { $eq: [ { $size: '$taskDetails' }, 0 ] } },
|
|
7441
|
-
);
|
|
7442
|
-
}
|
|
7443
|
-
if ( inputData.filter.status.includes( 'notPublished' ) ) {
|
|
7444
|
-
orCondition.push( {
|
|
7445
|
-
$and: [
|
|
7446
|
-
{ 'taskDetails': {
|
|
7447
|
-
$elemMatch: {
|
|
7448
|
-
type: 'merchRollout',
|
|
7449
|
-
status: 'submit',
|
|
7450
|
-
},
|
|
7451
|
-
} }, { 'taskDetails.fixtureStatus': 'complete' },
|
|
7452
|
-
{ 'planoTask.taskStatus': {
|
|
7453
|
-
$elemMatch: {
|
|
7454
|
-
type: 'vmRollout',
|
|
7455
|
-
status: 'submit',
|
|
7456
|
-
},
|
|
7457
|
-
} }, { 'taskDetails.vmStatus': 'complete' },
|
|
7458
|
-
{
|
|
7459
|
-
layoutStatus: { $in: [ false ] },
|
|
7460
|
-
},
|
|
7461
|
-
],
|
|
7462
|
-
} );
|
|
7463
|
-
}
|
|
7464
|
-
if ( inputData.filter.status.includes( 'publish' ) ) {
|
|
7465
|
-
orCondition.push( { $and: [
|
|
7466
|
-
{ 'taskDetails': {
|
|
7467
|
-
$elemMatch: {
|
|
7468
|
-
type: 'merchRollout',
|
|
7469
|
-
status: 'submit',
|
|
7470
|
-
},
|
|
7471
|
-
} }, { 'taskDetails.fixtureStatus': 'complete' },
|
|
7472
|
-
{ 'planoTask.taskStatus': {
|
|
7473
|
-
$elemMatch: {
|
|
7474
|
-
type: 'vmRollout',
|
|
7475
|
-
status: 'submit',
|
|
7476
|
-
},
|
|
7477
|
-
} }, { 'taskDetails.vmStatus': 'complete' },
|
|
7478
|
-
{
|
|
7479
|
-
layoutStatus: { $nin: [ false ] },
|
|
7480
|
-
},
|
|
7481
|
-
],
|
|
7482
|
-
},
|
|
7483
|
-
);
|
|
7484
|
-
}
|
|
7485
|
-
}
|
|
7486
|
-
|
|
7487
6931
|
if ( req.body.sortColumnName && req.body.sortBy ) {
|
|
7488
6932
|
query.push(
|
|
7489
6933
|
{ $sort: { [req.body.sortColumnName]: req.body.sortBy } },
|
|
@@ -7494,19 +6938,18 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7494
6938
|
query.push( {
|
|
7495
6939
|
$facet: {
|
|
7496
6940
|
totalStore: [
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
{ $count: 'count' },
|
|
6941
|
+
{
|
|
6942
|
+
$group: {
|
|
6943
|
+
_id: '',
|
|
6944
|
+
storeList: { $addToSet: '$storeId' },
|
|
6945
|
+
},
|
|
6946
|
+
},
|
|
6947
|
+
{
|
|
6948
|
+
$project: {
|
|
6949
|
+
_id: 0,
|
|
6950
|
+
count: { $size: '$storeList' },
|
|
6951
|
+
},
|
|
6952
|
+
},
|
|
7510
6953
|
],
|
|
7511
6954
|
rollOutStore: [
|
|
7512
6955
|
{
|
|
@@ -7570,36 +7013,36 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7570
7013
|
} );
|
|
7571
7014
|
|
|
7572
7015
|
|
|
7573
|
-
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
// doubleFloorList
|
|
7016
|
+
let floorQuery = [
|
|
7017
|
+
{
|
|
7018
|
+
$match: {
|
|
7019
|
+
clientId: req.body.clientId,
|
|
7020
|
+
storeId: { $in: storeDetails },
|
|
7021
|
+
},
|
|
7022
|
+
},
|
|
7023
|
+
{
|
|
7024
|
+
$group: {
|
|
7025
|
+
_id: '$storeId',
|
|
7026
|
+
count: { $sum: 1 },
|
|
7027
|
+
},
|
|
7028
|
+
},
|
|
7029
|
+
{
|
|
7030
|
+
$match: {
|
|
7031
|
+
count: { $gt: 1 },
|
|
7032
|
+
},
|
|
7033
|
+
},
|
|
7034
|
+
{
|
|
7035
|
+
$group: {
|
|
7036
|
+
_id: '',
|
|
7037
|
+
storeList: { $addToSet: '$_id' },
|
|
7038
|
+
},
|
|
7039
|
+
},
|
|
7040
|
+
];
|
|
7599
7041
|
|
|
7600
|
-
|
|
7042
|
+
|
|
7043
|
+
let [ rolloutDetails, doubleFloorList ] = await Promise.all( [
|
|
7601
7044
|
storeBuilderService.aggregate( query ),
|
|
7602
|
-
|
|
7045
|
+
storeBuilderService.aggregate( floorQuery ),
|
|
7603
7046
|
] );
|
|
7604
7047
|
let result = {
|
|
7605
7048
|
cardData: {
|
|
@@ -7609,7 +7052,7 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7609
7052
|
vmPendingStore: rolloutDetails?.[0]?.vmPending?.[0]?.count || 0,
|
|
7610
7053
|
flagStore: rolloutDetails?.[0]?.flag?.[0]?.count || 0,
|
|
7611
7054
|
flagStore: rolloutDetails?.[0]?.flag?.[0]?.count || 0,
|
|
7612
|
-
|
|
7055
|
+
doubleFloorStore: doubleFloorList[0]?.storeList|| [],
|
|
7613
7056
|
},
|
|
7614
7057
|
tableData: {
|
|
7615
7058
|
count: rolloutDetails?.[0]?.count?.[0]?.total || 0,
|
|
@@ -7929,7 +7372,6 @@ export async function searchProduct( req, res ) {
|
|
|
7929
7372
|
export async function updateProductMapping( req, res ) {
|
|
7930
7373
|
try {
|
|
7931
7374
|
let storeDetails = await storeService.find( { clientId: req.body.clientId, ...( req.body.stores && { storeName: { $in: req.body.stores } } ), status: 'active' }, { storeId: 1, storeName: 1 } );
|
|
7932
|
-
console.log( storeDetails, 'storeDetails' );
|
|
7933
7375
|
if ( !storeDetails.length ) {
|
|
7934
7376
|
return res.sendError( 'No data found', 204 );
|
|
7935
7377
|
}
|
|
@@ -7944,10 +7386,9 @@ export async function updateProductMapping( req, res ) {
|
|
|
7944
7386
|
await Promise.all( data.map( async ( ele ) => {
|
|
7945
7387
|
let fixtureDetails = await storeFixtureService.find( { readerId: ele.data.MAC } );
|
|
7946
7388
|
if ( fixtureDetails.length ) {
|
|
7947
|
-
let getShelfDetails = await fixtureShelfService.findOne( { fixtureId: { $in: fixtureDetails?.map( ( fixt ) => fixt._id ) }, antennaNo:
|
|
7389
|
+
let getShelfDetails = await fixtureShelfService.findOne( { fixtureId: { $in: fixtureDetails?.map( ( fixt ) => fixt._id ) }, antennaNo: ele.data.antenna } );
|
|
7948
7390
|
if ( !getShelfDetails ) {
|
|
7949
|
-
|
|
7950
|
-
fixtureDetails = fixtureDetails.find( ( fixt ) => fixt?.footer?.antennaNo?.includes( ele.data.antenna ) );
|
|
7391
|
+
fixtureDetails = fixtureDetails.find( ( fixt ) => fixt.footer.antennaNo == ele.data.antenna );
|
|
7951
7392
|
if ( fixtureDetails ) {
|
|
7952
7393
|
getShelfDetails = { shelfType: 'storage' };
|
|
7953
7394
|
}
|
|
@@ -7969,9 +7410,6 @@ export async function updateProductMapping( req, res ) {
|
|
|
7969
7410
|
fixtureId: fixtureDetails._id,
|
|
7970
7411
|
...( getShelfDetails?.shelfType != 'storage' && { shelfId: getShelfDetails._id } ),
|
|
7971
7412
|
};
|
|
7972
|
-
if ( ele.data.antenna == 7 ) {
|
|
7973
|
-
console.log( data, 'getShelfDetails' );
|
|
7974
|
-
}
|
|
7975
7413
|
mappingData.push( data );
|
|
7976
7414
|
|
|
7977
7415
|
// let mappingDetails = await planoMappingService.create( data );
|
|
@@ -8180,7 +7618,7 @@ export async function calculateCompliance( req, res ) {
|
|
|
8180
7618
|
}
|
|
8181
7619
|
}
|
|
8182
7620
|
|
|
8183
|
-
export async function
|
|
7621
|
+
export async function getPlanogramList( req, res ) {
|
|
8184
7622
|
try {
|
|
8185
7623
|
const {
|
|
8186
7624
|
clientId,
|
|
@@ -8222,33 +7660,11 @@ export async function getPlanogramListOld( req, res ) {
|
|
|
8222
7660
|
storeId: { $in: allowedStoreIds },
|
|
8223
7661
|
},
|
|
8224
7662
|
},
|
|
8225
|
-
|
|
8226
|
-
$lookup: {
|
|
8227
|
-
from: 'storelayouts',
|
|
8228
|
-
let: { plano: '$_id' },
|
|
8229
|
-
pipeline: [
|
|
8230
|
-
{
|
|
8231
|
-
$match: {
|
|
8232
|
-
$expr: {
|
|
8233
|
-
$eq: [ '$planoId', '$$plano' ],
|
|
8234
|
-
},
|
|
8235
|
-
},
|
|
8236
|
-
},
|
|
8237
|
-
{
|
|
8238
|
-
$group: {
|
|
8239
|
-
_id: '$planoId',
|
|
8240
|
-
floorId: { $first: '$_id' },
|
|
8241
|
-
layoutDetails: { $sum: 1 },
|
|
8242
|
-
},
|
|
8243
|
-
},
|
|
8244
|
-
],
|
|
8245
|
-
as: 'floorDetails',
|
|
8246
|
-
},
|
|
8247
|
-
},
|
|
7663
|
+
|
|
8248
7664
|
{
|
|
8249
7665
|
$lookup: {
|
|
8250
7666
|
from: 'storefixtures',
|
|
8251
|
-
let: { plano: '$
|
|
7667
|
+
let: { plano: '$planoId', floor: '$_id' },
|
|
8252
7668
|
pipeline: [
|
|
8253
7669
|
{
|
|
8254
7670
|
$match: {
|
|
@@ -8270,17 +7686,18 @@ export async function getPlanogramListOld( req, res ) {
|
|
|
8270
7686
|
as: 'fixtureDetails',
|
|
8271
7687
|
},
|
|
8272
7688
|
},
|
|
7689
|
+
|
|
8273
7690
|
{
|
|
8274
7691
|
$lookup: {
|
|
8275
7692
|
from: 'planocompliances',
|
|
8276
|
-
let: { plano: '$_id' },
|
|
7693
|
+
let: { plano: '$planoId', floor: '$_id' },
|
|
8277
7694
|
pipeline: [
|
|
8278
7695
|
{
|
|
8279
7696
|
$match: {
|
|
8280
7697
|
$expr: {
|
|
8281
7698
|
$and: [
|
|
8282
7699
|
{ $eq: [ '$planoId', '$$plano' ] },
|
|
8283
|
-
|
|
7700
|
+
{ $eq: [ '$floorId', '$$floor' ] },
|
|
8284
7701
|
{ $eq: [ '$date', today ] },
|
|
8285
7702
|
{ $eq: [ '$compliance', 'proper' ] },
|
|
8286
7703
|
],
|
|
@@ -8295,10 +7712,11 @@ export async function getPlanogramListOld( req, res ) {
|
|
|
8295
7712
|
as: 'complianceCount',
|
|
8296
7713
|
},
|
|
8297
7714
|
},
|
|
7715
|
+
|
|
8298
7716
|
{
|
|
8299
7717
|
$project: {
|
|
8300
|
-
_id:
|
|
8301
|
-
planoId:
|
|
7718
|
+
_id: 1,
|
|
7719
|
+
planoId: 1,
|
|
8302
7720
|
createdAt: 1,
|
|
8303
7721
|
updatedAt: 1,
|
|
8304
7722
|
floorName: 1,
|
|
@@ -8310,7 +7728,6 @@ export async function getPlanogramListOld( req, res ) {
|
|
|
8310
7728
|
storeName: 1,
|
|
8311
7729
|
fixtureDetails: 1,
|
|
8312
7730
|
complianceCount: 1,
|
|
8313
|
-
layoutCount: { $ifNull: [ { $arrayElemAt: [ '$floorDetails.layoutDetails', 0 ] }, 1 ] },
|
|
8314
7731
|
merchCompliance: {
|
|
8315
7732
|
$floor: [
|
|
8316
7733
|
{
|
|
@@ -8367,8 +7784,7 @@ export async function getPlanogramListOld( req, res ) {
|
|
|
8367
7784
|
},
|
|
8368
7785
|
} );
|
|
8369
7786
|
|
|
8370
|
-
|
|
8371
|
-
const result = await planoService.aggregate( pipeline );
|
|
7787
|
+
const result = await layoutService.aggregate( pipeline );
|
|
8372
7788
|
|
|
8373
7789
|
let data = result?.[0]?.data || [];
|
|
8374
7790
|
const total = result?.[0]?.count?.[0]?.total || 0;
|
|
@@ -8394,220 +7810,7 @@ export async function getPlanogramListOld( req, res ) {
|
|
|
8394
7810
|
|
|
8395
7811
|
d.createdAt = dayjs.utc( d.createdAt ).format( 'DD MMM, YYYY' );
|
|
8396
7812
|
d.updatedAt = dayjs.utc( d.updatedAt ).format( 'DD MMM, YYYY' );
|
|
8397
|
-
d.merchCompliance = d.layoutCount > 1 ? d.merchCompliance/d.layoutCount : d.merchCompliance;
|
|
8398
|
-
return d;
|
|
8399
|
-
} );
|
|
8400
|
-
|
|
8401
|
-
return res.sendSuccess( { data, count: total } );
|
|
8402
|
-
} catch ( err ) {
|
|
8403
|
-
logger.error( { functionName: 'getLayoutList', error: err } );
|
|
8404
|
-
return res.sendError( err, 500 );
|
|
8405
|
-
}
|
|
8406
|
-
}
|
|
8407
|
-
|
|
8408
|
-
export async function getPlanogramList( req, res ) {
|
|
8409
|
-
try {
|
|
8410
|
-
const {
|
|
8411
|
-
clientId,
|
|
8412
|
-
limit = 10,
|
|
8413
|
-
offset = 1,
|
|
8414
|
-
searchValue = '',
|
|
8415
|
-
sortColumnName = '',
|
|
8416
|
-
sortBy = '',
|
|
8417
|
-
filter = {},
|
|
8418
|
-
} = req.body;
|
|
8419
|
-
|
|
8420
|
-
const page = Math.max( offset - 1, 0 );
|
|
8421
|
-
const skip = page * limit;
|
|
8422
|
-
|
|
8423
|
-
const today = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
8424
|
-
|
|
8425
|
-
const storeQuery = { clientId, status: 'active' };
|
|
8426
|
-
|
|
8427
|
-
if ( filter?.country?.length ) {
|
|
8428
|
-
storeQuery['storeProfile.country'] = { $in: filter.country };
|
|
8429
|
-
}
|
|
8430
|
-
|
|
8431
|
-
if ( filter?.city?.length ) {
|
|
8432
|
-
storeQuery['storeProfile.city'] = { $in: filter.city };
|
|
8433
|
-
}
|
|
8434
|
-
|
|
8435
|
-
const storeDocs = await storeService.find( storeQuery, { storeId: 1, storeProfile: 1 } );
|
|
8436
|
-
|
|
8437
|
-
if ( !storeDocs.length ) {
|
|
8438
|
-
return res.sendSuccess( { data: [], count: 0 } );
|
|
8439
|
-
}
|
|
8440
|
-
|
|
8441
|
-
const allowedStoreIds = storeDocs.map( ( s ) => s.storeId );
|
|
8442
|
-
|
|
8443
|
-
const pipeline = [
|
|
8444
|
-
{
|
|
8445
|
-
$match: {
|
|
8446
|
-
clientId,
|
|
8447
|
-
storeId: { $in: allowedStoreIds },
|
|
8448
|
-
},
|
|
8449
|
-
},
|
|
8450
|
-
{ $sort: { _id: -1 } },
|
|
8451
|
-
{
|
|
8452
|
-
$group: {
|
|
8453
|
-
_id: { plano: '$planoId', floorId: '$floorId' },
|
|
8454
|
-
lastUpdate: { $first: '$updatedAt' },
|
|
8455
|
-
storeName: { $first: '$storeName' },
|
|
8456
|
-
layoutName: { $first: '$layoutName' },
|
|
8457
|
-
floorData: { $first: '$floorData' },
|
|
8458
|
-
createdAt: { $first: '$createdAt' },
|
|
8459
|
-
storeId: { $first: '$storeId' },
|
|
8460
|
-
},
|
|
8461
|
-
},
|
|
8462
|
-
{
|
|
8463
|
-
$group: {
|
|
8464
|
-
_id: '$_id.plano',
|
|
8465
|
-
updatedAt: { $first: '$lastUpdate' },
|
|
8466
|
-
storeName: { $first: '$storeName' },
|
|
8467
|
-
layoutName: { $first: '$layoutName' },
|
|
8468
|
-
floorData: { $push: '$floorData' },
|
|
8469
|
-
createdAt: { $first: '$createdAt' },
|
|
8470
|
-
storeId: { $first: '$storeId' },
|
|
8471
|
-
},
|
|
8472
|
-
},
|
|
8473
|
-
{
|
|
8474
|
-
$set: {
|
|
8475
|
-
productCount: {
|
|
8476
|
-
$reduce: {
|
|
8477
|
-
input: '$floorData',
|
|
8478
|
-
initialValue: 0,
|
|
8479
|
-
in: {
|
|
8480
|
-
$add: [ '$$value', '$$this.planoProductCount' ],
|
|
8481
|
-
},
|
|
8482
|
-
},
|
|
8483
|
-
},
|
|
8484
|
-
},
|
|
8485
|
-
},
|
|
8486
|
-
{
|
|
8487
|
-
$lookup: {
|
|
8488
|
-
from: 'planocompliances',
|
|
8489
|
-
let: { plano: '$_id' },
|
|
8490
|
-
pipeline: [
|
|
8491
|
-
{
|
|
8492
|
-
$match: {
|
|
8493
|
-
$expr: {
|
|
8494
|
-
$and: [
|
|
8495
|
-
{ $eq: [ '$planoId', '$$plano' ] },
|
|
8496
|
-
// { $eq: [ '$floorId', '$$floor' ] },
|
|
8497
|
-
{ $eq: [ '$date', today ] },
|
|
8498
|
-
{ $eq: [ '$compliance', 'proper' ] },
|
|
8499
|
-
],
|
|
8500
|
-
},
|
|
8501
|
-
},
|
|
8502
|
-
},
|
|
8503
|
-
{ $group: { _id: '$createdAt', count: { $sum: 1 } } },
|
|
8504
|
-
{ $project: { _id: 0, date: '$_id', count: 1 } },
|
|
8505
|
-
{ $sort: { date: -1 } },
|
|
8506
|
-
{ $limit: 1 },
|
|
8507
|
-
],
|
|
8508
|
-
as: 'complianceCount',
|
|
8509
|
-
},
|
|
8510
|
-
},
|
|
8511
|
-
{
|
|
8512
|
-
$project: {
|
|
8513
|
-
_id: { $ifNull: [ { $arrayElemAt: [ '$floorData._id', 0 ] }, '' ] },
|
|
8514
|
-
planoId: '$_id',
|
|
8515
|
-
createdAt: 1,
|
|
8516
|
-
updatedAt: 1,
|
|
8517
|
-
// floorName: 1,
|
|
8518
|
-
layoutName: 1,
|
|
8519
|
-
// floorNumber: 1,
|
|
8520
|
-
// planoProgress: 1,
|
|
8521
|
-
// status: 1,
|
|
8522
|
-
storeId: 1,
|
|
8523
|
-
storeName: 1,
|
|
8524
|
-
// fixtureDetails: 1,
|
|
8525
|
-
complianceCount: 1,
|
|
8526
|
-
layoutCount: { $ifNull: [ { $arrayElemAt: [ '$floorDetails.layoutDetails', 0 ] }, 1 ] },
|
|
8527
|
-
merchCompliance: {
|
|
8528
|
-
$floor: [
|
|
8529
|
-
{
|
|
8530
|
-
$multiply: [
|
|
8531
|
-
{
|
|
8532
|
-
$divide: [
|
|
8533
|
-
{ $ifNull: [ { $arrayElemAt: [ '$complianceCount.count', 0 ] }, 0 ] },
|
|
8534
|
-
{ $ifNull: [ '$productCount', 1 ] },
|
|
8535
|
-
],
|
|
8536
|
-
},
|
|
8537
|
-
100,
|
|
8538
|
-
],
|
|
8539
|
-
},
|
|
8540
|
-
],
|
|
8541
|
-
},
|
|
8542
|
-
},
|
|
8543
|
-
},
|
|
8544
|
-
];
|
|
8545
|
-
|
|
8546
|
-
if ( filter?.compliance?.length === 2 ) {
|
|
8547
|
-
const [ minC, maxC ] = filter.compliance.map( Number );
|
|
8548
|
-
pipeline.push( {
|
|
8549
|
-
$match: {
|
|
8550
|
-
merchCompliance: { $gte: minC, $lte: maxC },
|
|
8551
|
-
},
|
|
8552
|
-
} );
|
|
8553
|
-
}
|
|
8554
|
-
|
|
8555
|
-
if ( searchValue?.trim() ) {
|
|
8556
|
-
const values = searchValue.split( ',' ).map( ( s ) => s.trim().toLowerCase() );
|
|
8557
|
-
|
|
8558
|
-
if ( values.length > 1 ) {
|
|
8559
|
-
pipeline.push(
|
|
8560
|
-
{ $addFields: { store: { $toLower: '$storeName' } } },
|
|
8561
|
-
{ $match: { store: { $in: values } } },
|
|
8562
|
-
);
|
|
8563
|
-
} else {
|
|
8564
|
-
pipeline.push( {
|
|
8565
|
-
$match: { storeName: { $regex: searchValue, $options: 'i' } },
|
|
8566
|
-
} );
|
|
8567
|
-
}
|
|
8568
|
-
}
|
|
8569
|
-
|
|
8570
|
-
if ( sortColumnName && sortBy ) {
|
|
8571
|
-
pipeline.push( { $sort: { [sortColumnName]: Number( sortBy ) } } );
|
|
8572
|
-
} else {
|
|
8573
|
-
pipeline.push( { $sort: { createdAt: -1 } } );
|
|
8574
|
-
}
|
|
8575
|
-
|
|
8576
|
-
pipeline.push( {
|
|
8577
|
-
$facet: {
|
|
8578
|
-
data: [ { $skip: skip }, { $limit: limit } ],
|
|
8579
|
-
count: [ { $count: 'total' } ],
|
|
8580
|
-
},
|
|
8581
|
-
} );
|
|
8582
|
-
|
|
8583
|
-
// const result = await layoutService.aggregate( pipeline );
|
|
8584
|
-
const result = await planoRevisionService.aggregate( pipeline );
|
|
8585
7813
|
|
|
8586
|
-
let data = result?.[0]?.data || [];
|
|
8587
|
-
const total = result?.[0]?.count?.[0]?.total || 0;
|
|
8588
|
-
|
|
8589
|
-
if ( !data.length ) {
|
|
8590
|
-
return res.sendError( 'No data found', 204 );
|
|
8591
|
-
}
|
|
8592
|
-
|
|
8593
|
-
const storeMap = {};
|
|
8594
|
-
storeDocs.forEach( ( st ) => {
|
|
8595
|
-
storeMap[st.storeId] = st;
|
|
8596
|
-
} );
|
|
8597
|
-
|
|
8598
|
-
data = data.map( ( d ) => {
|
|
8599
|
-
const st = storeMap[d.storeId];
|
|
8600
|
-
d.storeInfo = st ?
|
|
8601
|
-
{
|
|
8602
|
-
country: st.storeProfile?.country,
|
|
8603
|
-
state: st.storeProfile?.state,
|
|
8604
|
-
city: st.storeProfile?.city,
|
|
8605
|
-
} :
|
|
8606
|
-
null;
|
|
8607
|
-
|
|
8608
|
-
d.createdAt = dayjs.utc( d.createdAt ).format( 'DD MMM, YYYY' );
|
|
8609
|
-
d.updatedAt = dayjs.utc( d.updatedAt ).format( 'DD MMM, YYYY' );
|
|
8610
|
-
d.merchCompliance = d.layoutCount > 1 ? d.merchCompliance/d.layoutCount : d.merchCompliance;
|
|
8611
7814
|
return d;
|
|
8612
7815
|
} );
|
|
8613
7816
|
|