tango-app-api-store-builder 1.0.16 → 1.0.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 +2 -2
- package/src/controllers/fixtureTemplate.controller.js +1 -0
- package/src/controllers/managePlano.controller.js +275 -33
- package/src/controllers/script.controller.js +110 -0
- package/src/controllers/storeBuilder.controller.js +982 -185
- package/src/routes/fixtureTemplate.routes.js +17 -17
- package/src/routes/managePlano.routes.js +21 -21
- package/src/routes/script.routes.js +2 -0
- package/src/routes/storeBuilder.routes.js +4 -3
- package/src/service/planoRevision.service.js +4 -0
|
@@ -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 } from 'tango-app-api-middleware';
|
|
4
|
+
import { logger, fileUpload, signedUrl, sendMessageToQueue, getOpenSearchData, download } 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,6 +26,7 @@ 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';
|
|
29
30
|
|
|
30
31
|
dayjs.extend( advancedFormat );
|
|
31
32
|
dayjs.extend( utc );
|
|
@@ -2780,7 +2781,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2780
2781
|
{ storeId: { $in: req.body.id } },
|
|
2781
2782
|
],
|
|
2782
2783
|
},
|
|
2783
|
-
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1, clientId: 1, validateShelfSections: 1 },
|
|
2784
|
+
{ storeId: 1, storeName: 1, planoId: '$_id', productResolutionLevel: 1, scanType: 1, clientId: 1, validateShelfSections: 1, layoutName: 1 },
|
|
2784
2785
|
);
|
|
2785
2786
|
|
|
2786
2787
|
if ( !planograms?.length ) return res.sendError( 'No data found', 204 );
|
|
@@ -2791,7 +2792,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2791
2792
|
planograms.map( async ( planogram ) => {
|
|
2792
2793
|
const floors = await storeBuilderService.find(
|
|
2793
2794
|
{ planoId: planogram._id, ...( req.body?.floorId && { _id: req.body.floorId } ) },
|
|
2794
|
-
{ floorName: 1, layoutPolygon: 1, planoId: 1, isEdited: 1, planoProgress: 1, updatedAt: 1 },
|
|
2795
|
+
{ floorName: 1, layoutPolygon: 1, planoId: 1, isEdited: 1, planoProgress: 1, updatedAt: 1, verificationStatus: 1, rolloutStatus: 1 },
|
|
2795
2796
|
);
|
|
2796
2797
|
|
|
2797
2798
|
const floorsWithFixtures = await Promise.all(
|
|
@@ -2839,7 +2840,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2839
2840
|
|
|
2840
2841
|
const shelfDetails = await Promise.all(
|
|
2841
2842
|
shelves.map( async ( shelf ) => {
|
|
2842
|
-
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf.
|
|
2843
|
+
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf._id, type: 'product' }, { _id: 1 } );
|
|
2843
2844
|
let productIdList = productDetails.map( ( ele ) => ele._id );
|
|
2844
2845
|
let complianceQuery = [
|
|
2845
2846
|
{
|
|
@@ -2866,7 +2867,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2866
2867
|
let complianceStatus = await planoComplianceService.aggregate( complianceQuery );
|
|
2867
2868
|
const compliance = complianceStatus?.[0]?.status?.length ? ( ( complianceStatus?.[0]?.status?.length != shelf.productPerShelf ) || complianceStatus?.[0]?.status.includes( 'misplaced' ) ) ? 'improper' : 'proper' : 'improper';
|
|
2868
2869
|
|
|
2869
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.
|
|
2870
|
+
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf._id, type: 'vm' } );
|
|
2870
2871
|
|
|
2871
2872
|
return {
|
|
2872
2873
|
...shelf.toObject(),
|
|
@@ -2969,7 +2970,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2969
2970
|
|
|
2970
2971
|
const shelfDetails = await Promise.all(
|
|
2971
2972
|
shelves.map( async ( shelf ) => {
|
|
2972
|
-
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf.
|
|
2973
|
+
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf._id, type: 'product' }, { _id: 1 } );
|
|
2973
2974
|
let productIdList = productDetails.map( ( ele ) => ele._id );
|
|
2974
2975
|
let complianceQuery = [
|
|
2975
2976
|
{
|
|
@@ -2997,7 +2998,7 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2997
2998
|
const compliance = complianceStatus?.[0]?.status.length ? ( ( complianceStatus?.[0]?.status?.length != shelf.productPerShelf ) || complianceStatus?.[0]?.status?.includes( 'misplaced' ) ) ? 'improper' : 'proper' : 'improper';
|
|
2998
2999
|
|
|
2999
3000
|
|
|
3000
|
-
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.
|
|
3001
|
+
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf._id, type: 'vm' } );
|
|
3001
3002
|
|
|
3002
3003
|
return {
|
|
3003
3004
|
...shelf.toObject(),
|
|
@@ -3488,6 +3489,134 @@ export async function fixtureShelfProductv2( req, res ) {
|
|
|
3488
3489
|
}
|
|
3489
3490
|
}
|
|
3490
3491
|
|
|
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
|
+
|
|
3491
3620
|
export async function fixtureShelfProductv3( req, res ) {
|
|
3492
3621
|
try {
|
|
3493
3622
|
const { planoId, fixtureId } = req.body;
|
|
@@ -5020,7 +5149,7 @@ export async function planoList( req, res ) {
|
|
|
5020
5149
|
let page = inputData?.offset - 1 || 0;
|
|
5021
5150
|
let skip = limit * page;
|
|
5022
5151
|
|
|
5023
|
-
let storeDetails = await storeService.find( { clientId: inputData.clientId, status: 'active', ...( inputData?.stores?.length && { storeId: { $in: inputData.stores } } ),
|
|
5152
|
+
let storeDetails = await storeService.find( { clientId: inputData.clientId, status: 'active', ...( inputData?.stores?.length && { storeId: { $in: inputData.stores }, ...( req.body.filter.country.length && { 'storeProfile.country': { $in: req.body.filter.country } } ), ...( req.body.filter.city.length && { 'storeProfile.city': { $in: req.body.city.country } } ) } ),
|
|
5024
5153
|
...( req.body?.assignedStores?.length && { storeId: { $in: req.body?.assignedStores } } ) }, { storeId: 1 } );
|
|
5025
5154
|
storeDetails = storeDetails.map( ( ele ) => ele.storeId );
|
|
5026
5155
|
|
|
@@ -5049,14 +5178,10 @@ export async function planoList( req, res ) {
|
|
|
5049
5178
|
id: '$_id',
|
|
5050
5179
|
floorName: 1,
|
|
5051
5180
|
floorNumber: 1,
|
|
5181
|
+
planoId: 1,
|
|
5182
|
+
verificationStatus: 1,
|
|
5052
5183
|
},
|
|
5053
5184
|
},
|
|
5054
|
-
// {
|
|
5055
|
-
// $group: {
|
|
5056
|
-
// _id: '',
|
|
5057
|
-
// layoutDetails: { $push: { k: '$_id', v: '$status', planoId: '$$plano' } },
|
|
5058
|
-
// },
|
|
5059
|
-
// },
|
|
5060
5185
|
],
|
|
5061
5186
|
as: 'layout',
|
|
5062
5187
|
},
|
|
@@ -5064,18 +5189,25 @@ export async function planoList( req, res ) {
|
|
|
5064
5189
|
{
|
|
5065
5190
|
$set: {
|
|
5066
5191
|
layoutCount: { $size: '$layout' },
|
|
5192
|
+
layoutStatus: {
|
|
5193
|
+
$map: {
|
|
5194
|
+
input: '$layout',
|
|
5195
|
+
as: 'lay',
|
|
5196
|
+
in: '$$lay.verificationStatus',
|
|
5197
|
+
},
|
|
5198
|
+
},
|
|
5067
5199
|
},
|
|
5068
5200
|
},
|
|
5069
|
-
{ $unwind: { path: '$layout', preserveNullAndEmptyArrays: true } },
|
|
5201
|
+
// { $unwind: { path: '$layout', preserveNullAndEmptyArrays: true } },
|
|
5070
5202
|
{
|
|
5071
5203
|
$lookup: {
|
|
5072
5204
|
from: 'storefixtures',
|
|
5073
|
-
let: {
|
|
5205
|
+
let: { plano: '$_id' },
|
|
5074
5206
|
pipeline: [
|
|
5075
5207
|
{
|
|
5076
5208
|
$match: {
|
|
5077
5209
|
$expr: {
|
|
5078
|
-
$eq: [ '$
|
|
5210
|
+
$eq: [ '$planoId', '$$plano' ],
|
|
5079
5211
|
},
|
|
5080
5212
|
},
|
|
5081
5213
|
},
|
|
@@ -5095,14 +5227,13 @@ export async function planoList( req, res ) {
|
|
|
5095
5227
|
{
|
|
5096
5228
|
$lookup: {
|
|
5097
5229
|
from: 'processedtasks',
|
|
5098
|
-
let: {
|
|
5230
|
+
let: { plano: '$_id' },
|
|
5099
5231
|
pipeline: [
|
|
5100
5232
|
{
|
|
5101
5233
|
$match: {
|
|
5102
5234
|
$expr: {
|
|
5103
5235
|
$and: [
|
|
5104
|
-
|
|
5105
|
-
{ $eq: [ '$floorId', '$$floor' ] },
|
|
5236
|
+
{ $eq: [ '$planoId', '$$plano' ] },
|
|
5106
5237
|
{ $eq: [ '$isPlano', true ] },
|
|
5107
5238
|
{
|
|
5108
5239
|
$lte: [ '$date_iso', new Date( dayjs().format( 'YYYY-MM-DD' ) ) ],
|
|
@@ -5153,14 +5284,14 @@ export async function planoList( req, res ) {
|
|
|
5153
5284
|
$lookup: {
|
|
5154
5285
|
from: 'planotaskcompliances',
|
|
5155
5286
|
let: {
|
|
5156
|
-
|
|
5287
|
+
plano: '$_id',
|
|
5157
5288
|
},
|
|
5158
5289
|
pipeline: [
|
|
5159
5290
|
{
|
|
5160
5291
|
$match: {
|
|
5161
5292
|
$expr: {
|
|
5162
5293
|
$and: [
|
|
5163
|
-
{ $eq: [ '$
|
|
5294
|
+
{ $eq: [ '$planoId', '$$plano' ] },
|
|
5164
5295
|
{ $in: [ '$type', [ 'layout', 'fixture', 'vm' ] ] },
|
|
5165
5296
|
],
|
|
5166
5297
|
},
|
|
@@ -5335,6 +5466,63 @@ export async function planoList( req, res ) {
|
|
|
5335
5466
|
},
|
|
5336
5467
|
},
|
|
5337
5468
|
},
|
|
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
|
+
},
|
|
5338
5526
|
{
|
|
5339
5527
|
$project: {
|
|
5340
5528
|
_id: 0,
|
|
@@ -5519,6 +5707,7 @@ export async function planoList( req, res ) {
|
|
|
5519
5707
|
lastUpdate: '$updatedAt',
|
|
5520
5708
|
planoTask: { $ifNull: [ '$planoTask', [] ] },
|
|
5521
5709
|
layoutCount: 1,
|
|
5710
|
+
layoutStatus: 1,
|
|
5522
5711
|
taskDetails: {
|
|
5523
5712
|
$let: {
|
|
5524
5713
|
vars: {
|
|
@@ -5556,7 +5745,7 @@ export async function planoList( req, res ) {
|
|
|
5556
5745
|
|
|
5557
5746
|
if ( inputData.filter.taskPending === 'layout' ) {
|
|
5558
5747
|
andQuery.push(
|
|
5559
|
-
{ 'taskDetails.layoutStatus': '
|
|
5748
|
+
{ 'taskDetails.layoutStatus': 'complete' },
|
|
5560
5749
|
);
|
|
5561
5750
|
}
|
|
5562
5751
|
|
|
@@ -5578,94 +5767,274 @@ export async function planoList( req, res ) {
|
|
|
5578
5767
|
},
|
|
5579
5768
|
} );
|
|
5580
5769
|
}
|
|
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
5770
|
let orQuery = [];
|
|
5604
5771
|
|
|
5605
|
-
|
|
5606
|
-
|
|
5772
|
+
|
|
5773
|
+
if ( inputData.filter.layout.length ) {
|
|
5774
|
+
if ( inputData.filter.layout.includes( 'taskAssigned' ) ) {
|
|
5607
5775
|
// orQuery.push( { 'planoTask.taskStatus.status': { $in: [ 'open', 'inprogress' ] } } );
|
|
5608
5776
|
orQuery.push( {
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5777
|
+
$and: [
|
|
5778
|
+
{
|
|
5779
|
+
$expr: {
|
|
5780
|
+
$eq: [
|
|
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
|
+
},
|
|
5613
5799
|
},
|
|
5614
|
-
|
|
5800
|
+
],
|
|
5615
5801
|
} );
|
|
5616
5802
|
}
|
|
5617
|
-
if ( inputData.filter.
|
|
5803
|
+
if ( inputData.filter.layout.includes( 'flag' ) ) {
|
|
5804
|
+
// orQuery.push( { 'planoTask.taskStatus.status': { $in: [ 'open', 'inprogress' ] } } );
|
|
5618
5805
|
orQuery.push( {
|
|
5619
5806
|
$and: [
|
|
5620
|
-
{
|
|
5621
|
-
$
|
|
5622
|
-
|
|
5623
|
-
|
|
5807
|
+
{
|
|
5808
|
+
$expr: {
|
|
5809
|
+
$eq: [
|
|
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
|
+
],
|
|
5624
5827
|
},
|
|
5625
|
-
}
|
|
5828
|
+
},
|
|
5626
5829
|
],
|
|
5627
5830
|
} );
|
|
5831
|
+
}
|
|
5832
|
+
if ( inputData.filter.layout.includes( 'reviewPending' ) ) {
|
|
5628
5833
|
orQuery.push( {
|
|
5629
5834
|
$and: [
|
|
5630
5835
|
{ 'planoTask.taskStatus': {
|
|
5631
5836
|
$elemMatch: {
|
|
5632
|
-
type: '
|
|
5837
|
+
type: 'layout',
|
|
5633
5838
|
status: 'submit',
|
|
5634
5839
|
},
|
|
5635
|
-
} }, { 'taskDetails.
|
|
5840
|
+
} }, { 'taskDetails.layoutStatus': 'pending' },
|
|
5636
5841
|
],
|
|
5637
5842
|
} );
|
|
5843
|
+
}
|
|
5844
|
+
if ( inputData.filter.layout.includes( 'completed' ) ) {
|
|
5638
5845
|
orQuery.push( {
|
|
5639
5846
|
$and: [
|
|
5640
5847
|
{ 'planoTask.taskStatus': {
|
|
5641
5848
|
$elemMatch: {
|
|
5642
|
-
type: '
|
|
5849
|
+
type: 'layout',
|
|
5643
5850
|
status: 'submit',
|
|
5644
5851
|
},
|
|
5645
|
-
} }, { 'taskDetails.
|
|
5852
|
+
} }, { 'taskDetails.layoutStatus': 'complete' },
|
|
5646
5853
|
],
|
|
5647
5854
|
} );
|
|
5648
5855
|
}
|
|
5649
|
-
if ( inputData.filter.
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5856
|
+
if ( inputData.filter.layout.includes( 'yetToAssign' ) ) {
|
|
5857
|
+
orQuery.push( { 'planoTask.taskStatus': {
|
|
5858
|
+
$not: {
|
|
5859
|
+
$elemMatch: {
|
|
5860
|
+
type: 'layout',
|
|
5861
|
+
},
|
|
5862
|
+
},
|
|
5863
|
+
} } );
|
|
5864
|
+
}
|
|
5865
|
+
}
|
|
5866
|
+
|
|
5867
|
+
if ( inputData.filter.fixture.length ) {
|
|
5868
|
+
if ( inputData.filter.fixture.includes( 'taskAssigned' ) ) {
|
|
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
|
+
],
|
|
5662
5892
|
},
|
|
5663
|
-
|
|
5893
|
+
},
|
|
5894
|
+
],
|
|
5664
5895
|
} );
|
|
5665
|
-
orQuery.push( { $and: andCondition } );
|
|
5666
5896
|
}
|
|
5667
|
-
if ( inputData.filter.
|
|
5668
|
-
orQuery.push( {
|
|
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',
|
|
6010
|
+
},
|
|
6011
|
+
} }, { 'taskDetails.fixtureStatus': 'complete' },
|
|
6012
|
+
{
|
|
6013
|
+
layoutStatus: { $in: [ false ] },
|
|
6014
|
+
},
|
|
6015
|
+
],
|
|
6016
|
+
} );
|
|
6017
|
+
}
|
|
6018
|
+
if ( inputData.filter.status.includes( 'publish' ) ) {
|
|
6019
|
+
orQuery.push( { $and: [
|
|
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
|
+
);
|
|
5669
6038
|
}
|
|
5670
6039
|
}
|
|
5671
6040
|
|
|
@@ -5711,7 +6080,9 @@ export async function planoList( req, res ) {
|
|
|
5711
6080
|
storeId: { $in: storeDetails } }, { _id: 1 } ),
|
|
5712
6081
|
] );
|
|
5713
6082
|
|
|
5714
|
-
|
|
6083
|
+
if ( req.body.export ) {
|
|
6084
|
+
await download( planoDetails[0].data );
|
|
6085
|
+
}
|
|
5715
6086
|
if ( !planoDetails[0].data.length ) {
|
|
5716
6087
|
return res.sendError( 'No data found', 204 );
|
|
5717
6088
|
}
|
|
@@ -5837,11 +6208,20 @@ export async function planoList( req, res ) {
|
|
|
5837
6208
|
],
|
|
5838
6209
|
},
|
|
5839
6210
|
},
|
|
6211
|
+
layoutComplete: {
|
|
6212
|
+
$sum: {
|
|
6213
|
+
$cond: [
|
|
6214
|
+
{ $and: [ { $eq: [ '$type', 'layout' ] }, { $eq: [ '$status', 'complete' ] } ] },
|
|
6215
|
+
1,
|
|
6216
|
+
0,
|
|
6217
|
+
],
|
|
6218
|
+
},
|
|
6219
|
+
},
|
|
5840
6220
|
},
|
|
5841
6221
|
},
|
|
5842
6222
|
{
|
|
5843
6223
|
$group: {
|
|
5844
|
-
_id:
|
|
6224
|
+
_id: '',
|
|
5845
6225
|
layoutPending: {
|
|
5846
6226
|
$sum: { $cond: {
|
|
5847
6227
|
if: {
|
|
@@ -5869,6 +6249,13 @@ export async function planoList( req, res ) {
|
|
|
5869
6249
|
else: 0,
|
|
5870
6250
|
} },
|
|
5871
6251
|
},
|
|
6252
|
+
layoutComplete: { $sum: { $cond: {
|
|
6253
|
+
if: {
|
|
6254
|
+
$gt: [ '$layoutComplete', 0 ],
|
|
6255
|
+
},
|
|
6256
|
+
then: 1,
|
|
6257
|
+
else: 0,
|
|
6258
|
+
} } },
|
|
5872
6259
|
},
|
|
5873
6260
|
},
|
|
5874
6261
|
{
|
|
@@ -5877,6 +6264,7 @@ export async function planoList( req, res ) {
|
|
|
5877
6264
|
layoutPending: '$layoutPending',
|
|
5878
6265
|
fixturePending: '$fixturePending',
|
|
5879
6266
|
vmPending: '$vmPending',
|
|
6267
|
+
layoutComplete: 1,
|
|
5880
6268
|
},
|
|
5881
6269
|
},
|
|
5882
6270
|
];
|
|
@@ -6379,7 +6767,14 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6379
6767
|
let page = req?.body?.offset || 1;
|
|
6380
6768
|
let limit = req.body?.limit || 10;
|
|
6381
6769
|
let skip = ( page -1 ) * limit;
|
|
6382
|
-
let storeDetails = await storeService.find( {
|
|
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
|
+
|
|
6383
6778
|
storeDetails = storeDetails.map( ( ele ) => ele.storeId );
|
|
6384
6779
|
let query = [
|
|
6385
6780
|
{
|
|
@@ -6389,15 +6784,31 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6389
6784
|
planoProgress: 100,
|
|
6390
6785
|
},
|
|
6391
6786
|
},
|
|
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
|
+
},
|
|
6392
6803
|
{
|
|
6393
6804
|
$lookup: {
|
|
6394
6805
|
from: 'storefixtures',
|
|
6395
|
-
let: {
|
|
6806
|
+
let: { plano: '$planoId' },
|
|
6396
6807
|
pipeline: [
|
|
6397
6808
|
{
|
|
6398
6809
|
$match: {
|
|
6399
6810
|
$expr: {
|
|
6400
|
-
$eq: [ '$
|
|
6811
|
+
$eq: [ '$planoId', '$$plano' ],
|
|
6401
6812
|
},
|
|
6402
6813
|
},
|
|
6403
6814
|
},
|
|
@@ -6429,7 +6840,7 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6429
6840
|
_id: 0,
|
|
6430
6841
|
planoId: 1,
|
|
6431
6842
|
layoutName: 1,
|
|
6432
|
-
floorId:
|
|
6843
|
+
floorId: 1,
|
|
6433
6844
|
floorNumber: 1,
|
|
6434
6845
|
floorName: 1,
|
|
6435
6846
|
planoProgress: 1,
|
|
@@ -6441,19 +6852,21 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6441
6852
|
lastUpdate: '$updatedAt',
|
|
6442
6853
|
merchEditedCount: '$fixtureDetails.merchEditedCount',
|
|
6443
6854
|
vmEditedCount: '$fixtureDetails.vmEditedCount',
|
|
6855
|
+
layoutCount: 1,
|
|
6856
|
+
layoutStatus: 1,
|
|
6444
6857
|
},
|
|
6445
6858
|
},
|
|
6446
6859
|
{
|
|
6447
6860
|
$lookup: {
|
|
6448
6861
|
from: 'processedtasks',
|
|
6449
|
-
let: {
|
|
6862
|
+
let: { planoId: '$planoId' },
|
|
6450
6863
|
pipeline: [
|
|
6451
6864
|
{
|
|
6452
6865
|
$match: {
|
|
6453
6866
|
$expr: {
|
|
6454
6867
|
$and: [
|
|
6455
6868
|
{ $lte: [ '$date_iso', new Date( dayjs().format( 'YYYY-MM-DD' ) ) ] },
|
|
6456
|
-
{ $eq: [ '$
|
|
6869
|
+
{ $eq: [ '$planoId', '$$planoId' ] },
|
|
6457
6870
|
{ $eq: [ '$isPlano', true ] },
|
|
6458
6871
|
{ $in: [ '$planoType', [ 'merchRollout', 'vmRollout' ] ] },
|
|
6459
6872
|
],
|
|
@@ -6496,13 +6909,13 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6496
6909
|
{
|
|
6497
6910
|
$lookup: {
|
|
6498
6911
|
from: 'planotaskcompliances',
|
|
6499
|
-
let: {
|
|
6912
|
+
let: { plano: '$planoId', taskId: '$taskDetails.taskId' },
|
|
6500
6913
|
pipeline: [
|
|
6501
6914
|
{
|
|
6502
6915
|
$match: {
|
|
6503
6916
|
$expr: {
|
|
6504
6917
|
$and: [
|
|
6505
|
-
{ $eq: [ '$
|
|
6918
|
+
{ $eq: [ '$planoId', '$$plano' ] },
|
|
6506
6919
|
{ $in: [ '$taskId', '$$taskId' ] },
|
|
6507
6920
|
{ $in: [ '$type', [ 'merchRollout', 'vmRollout' ] ] },
|
|
6508
6921
|
// { $eq: [ '$status', 'incomplete' ] },
|
|
@@ -6833,10 +7246,9 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6833
7246
|
} );
|
|
6834
7247
|
}
|
|
6835
7248
|
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
if ( req.body.filter.status.includes( 'yetToAssign' ) ) {
|
|
7249
|
+
const orCondition = [];
|
|
7250
|
+
if ( req.body.filter?.merch?.length ) {
|
|
7251
|
+
if ( req.body.filter.merch.includes( 'yetToAssign' ) ) {
|
|
6840
7252
|
orCondition.push(
|
|
6841
7253
|
{
|
|
6842
7254
|
$or: [
|
|
@@ -6846,12 +7258,12 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6846
7258
|
{ merchEditedCount: { $ne: 0 } },
|
|
6847
7259
|
],
|
|
6848
7260
|
},
|
|
6849
|
-
{
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
},
|
|
7261
|
+
// {
|
|
7262
|
+
// $and: [
|
|
7263
|
+
// { taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } },
|
|
7264
|
+
// { vmEditedCount: { $ne: 0 } },
|
|
7265
|
+
// ],
|
|
7266
|
+
// },
|
|
6855
7267
|
{
|
|
6856
7268
|
$expr: {
|
|
6857
7269
|
$lt: [ { $size: '$taskDetails' }, 2 ],
|
|
@@ -6870,6 +7282,87 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6870
7282
|
] },
|
|
6871
7283
|
],
|
|
6872
7284
|
},
|
|
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
|
+
},
|
|
6873
7366
|
{
|
|
6874
7367
|
$and: [
|
|
6875
7368
|
{ taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } },
|
|
@@ -6884,20 +7377,14 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6884
7377
|
);
|
|
6885
7378
|
}
|
|
6886
7379
|
|
|
6887
|
-
if ( req.body.filter.
|
|
7380
|
+
if ( req.body.filter.vm.includes( 'taskAssigned' ) ) {
|
|
6888
7381
|
orCondition.push( {
|
|
6889
|
-
taskDetails: { $elemMatch: { status: { $ne: 'submit' }, breach: false } },
|
|
7382
|
+
taskDetails: { $elemMatch: { type: 'vmRollout', status: { $ne: 'submit' }, breach: false } },
|
|
6890
7383
|
} );
|
|
6891
7384
|
}
|
|
6892
7385
|
|
|
6893
|
-
if ( req.body.filter.
|
|
7386
|
+
if ( req.body.filter.vm.includes( 'reviewPending' ) ) {
|
|
6894
7387
|
orCondition.push(
|
|
6895
|
-
{
|
|
6896
|
-
$and: [
|
|
6897
|
-
{ taskDetails: { $elemMatch: { type: 'merchRollout', status: 'submit' } } },
|
|
6898
|
-
{ 'taskFeedback.fixtureStatus': 'pending' },
|
|
6899
|
-
],
|
|
6900
|
-
},
|
|
6901
7388
|
{
|
|
6902
7389
|
$and: [
|
|
6903
7390
|
{ taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } },
|
|
@@ -6907,12 +7394,11 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6907
7394
|
);
|
|
6908
7395
|
}
|
|
6909
7396
|
|
|
6910
|
-
if ( req.body.filter.
|
|
7397
|
+
if ( req.body.filter.vm.includes( 'completed' ) ) {
|
|
6911
7398
|
orCondition.push( {
|
|
6912
7399
|
$and: [
|
|
6913
7400
|
{
|
|
6914
7401
|
$or: [
|
|
6915
|
-
{ $and: [ { taskDetails: { $elemMatch: { type: 'merchRollout', status: 'submit' } } }, { merchEditedCount: 0 }, { 'taskFeedback.fixtureStatus': 'complete' } ] },
|
|
6916
7402
|
{ $and: [ { taskDetails: { $elemMatch: { type: 'vmRollout', status: 'submit' } } }, { vmEditedCount: 0 }, { 'taskFeedback.vmStatus': 'complete' } ] },
|
|
6917
7403
|
],
|
|
6918
7404
|
},
|
|
@@ -6925,43 +7411,114 @@ export async function getRolloutDetails( req, res ) {
|
|
|
6925
7411
|
} );
|
|
6926
7412
|
}
|
|
6927
7413
|
|
|
6928
|
-
|
|
6929
|
-
|
|
7414
|
+
if ( req.body.filter.vm.includes( 'flag' ) ) {
|
|
7415
|
+
orCondition.push( {
|
|
7416
|
+
taskDetails: { $elemMatch: { type: 'vmRollout', status: { $ne: 'submit' }, breach: true } },
|
|
7417
|
+
} );
|
|
7418
|
+
}
|
|
6930
7419
|
|
|
6931
|
-
|
|
6932
|
-
query.push(
|
|
6933
|
-
{ $sort: { [req.body.sortColumnName]: req.body.sortBy } },
|
|
6934
|
-
);
|
|
7420
|
+
extraCondition.push( { $match: { $or: orCondition } } );
|
|
6935
7421
|
}
|
|
6936
7422
|
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
},
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
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
|
+
if ( req.body.sortColumnName && req.body.sortBy ) {
|
|
7488
|
+
query.push(
|
|
7489
|
+
{ $sort: { [req.body.sortColumnName]: req.body.sortBy } },
|
|
7490
|
+
);
|
|
7491
|
+
}
|
|
7492
|
+
|
|
7493
|
+
|
|
7494
|
+
query.push( {
|
|
7495
|
+
$facet: {
|
|
7496
|
+
totalStore: [
|
|
7497
|
+
// {
|
|
7498
|
+
// $group: {
|
|
7499
|
+
// _id: '',
|
|
7500
|
+
// storeList: { $addToSet: '$storeId' },
|
|
7501
|
+
// },
|
|
7502
|
+
// },
|
|
7503
|
+
// {
|
|
7504
|
+
// $project: {
|
|
7505
|
+
// _id: 0,
|
|
7506
|
+
// count: { $size: '$storeList' },
|
|
7507
|
+
// },
|
|
7508
|
+
// },
|
|
7509
|
+
{ $count: 'count' },
|
|
7510
|
+
],
|
|
7511
|
+
rollOutStore: [
|
|
7512
|
+
{
|
|
7513
|
+
$match: {
|
|
7514
|
+
$expr: { $gt: [ { $size: '$taskDetails' }, 0 ] },
|
|
7515
|
+
},
|
|
7516
|
+
},
|
|
7517
|
+
{ $count: 'count' },
|
|
7518
|
+
],
|
|
7519
|
+
merchPending: [
|
|
7520
|
+
{
|
|
7521
|
+
$match: {
|
|
6965
7522
|
$and: [
|
|
6966
7523
|
{
|
|
6967
7524
|
taskDetails: {
|
|
@@ -7013,36 +7570,36 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7013
7570
|
} );
|
|
7014
7571
|
|
|
7015
7572
|
|
|
7016
|
-
let floorQuery = [
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
|
|
7040
|
-
];
|
|
7041
|
-
|
|
7573
|
+
// let floorQuery = [
|
|
7574
|
+
// {
|
|
7575
|
+
// $match: {
|
|
7576
|
+
// clientId: req.body.clientId,
|
|
7577
|
+
// storeId: { $in: storeDetails },
|
|
7578
|
+
// },
|
|
7579
|
+
// },
|
|
7580
|
+
// {
|
|
7581
|
+
// $group: {
|
|
7582
|
+
// _id: '$storeId',
|
|
7583
|
+
// count: { $sum: 1 },
|
|
7584
|
+
// },
|
|
7585
|
+
// },
|
|
7586
|
+
// {
|
|
7587
|
+
// $match: {
|
|
7588
|
+
// count: { $gt: 1 },
|
|
7589
|
+
// },
|
|
7590
|
+
// },
|
|
7591
|
+
// {
|
|
7592
|
+
// $group: {
|
|
7593
|
+
// _id: '',
|
|
7594
|
+
// storeList: { $addToSet: '$_id' },
|
|
7595
|
+
// },
|
|
7596
|
+
// },
|
|
7597
|
+
// ];
|
|
7598
|
+
// doubleFloorList
|
|
7042
7599
|
|
|
7043
|
-
let [ rolloutDetails
|
|
7600
|
+
let [ rolloutDetails ] = await Promise.all( [
|
|
7044
7601
|
storeBuilderService.aggregate( query ),
|
|
7045
|
-
storeBuilderService.aggregate( floorQuery ),
|
|
7602
|
+
// storeBuilderService.aggregate( floorQuery ),
|
|
7046
7603
|
] );
|
|
7047
7604
|
let result = {
|
|
7048
7605
|
cardData: {
|
|
@@ -7052,7 +7609,7 @@ export async function getRolloutDetails( req, res ) {
|
|
|
7052
7609
|
vmPendingStore: rolloutDetails?.[0]?.vmPending?.[0]?.count || 0,
|
|
7053
7610
|
flagStore: rolloutDetails?.[0]?.flag?.[0]?.count || 0,
|
|
7054
7611
|
flagStore: rolloutDetails?.[0]?.flag?.[0]?.count || 0,
|
|
7055
|
-
doubleFloorStore: doubleFloorList[0]?.storeList|| [],
|
|
7612
|
+
// doubleFloorStore: doubleFloorList[0]?.storeList|| [],
|
|
7056
7613
|
},
|
|
7057
7614
|
tableData: {
|
|
7058
7615
|
count: rolloutDetails?.[0]?.count?.[0]?.total || 0,
|
|
@@ -7372,6 +7929,7 @@ export async function searchProduct( req, res ) {
|
|
|
7372
7929
|
export async function updateProductMapping( req, res ) {
|
|
7373
7930
|
try {
|
|
7374
7931
|
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' );
|
|
7375
7933
|
if ( !storeDetails.length ) {
|
|
7376
7934
|
return res.sendError( 'No data found', 204 );
|
|
7377
7935
|
}
|
|
@@ -7386,9 +7944,10 @@ export async function updateProductMapping( req, res ) {
|
|
|
7386
7944
|
await Promise.all( data.map( async ( ele ) => {
|
|
7387
7945
|
let fixtureDetails = await storeFixtureService.find( { readerId: ele.data.MAC } );
|
|
7388
7946
|
if ( fixtureDetails.length ) {
|
|
7389
|
-
let getShelfDetails = await fixtureShelfService.findOne( { fixtureId: { $in: fixtureDetails?.map( ( fixt ) => fixt._id ) }, antennaNo: ele.data.antenna } );
|
|
7947
|
+
let getShelfDetails = await fixtureShelfService.findOne( { fixtureId: { $in: fixtureDetails?.map( ( fixt ) => fixt._id ) }, antennaNo: { $in: [ ele.data.antenna ] } } );
|
|
7390
7948
|
if ( !getShelfDetails ) {
|
|
7391
|
-
|
|
7949
|
+
console.log( fixtureDetails );
|
|
7950
|
+
fixtureDetails = fixtureDetails.find( ( fixt ) => fixt?.footer?.antennaNo?.includes( ele.data.antenna ) );
|
|
7392
7951
|
if ( fixtureDetails ) {
|
|
7393
7952
|
getShelfDetails = { shelfType: 'storage' };
|
|
7394
7953
|
}
|
|
@@ -7410,6 +7969,9 @@ export async function updateProductMapping( req, res ) {
|
|
|
7410
7969
|
fixtureId: fixtureDetails._id,
|
|
7411
7970
|
...( getShelfDetails?.shelfType != 'storage' && { shelfId: getShelfDetails._id } ),
|
|
7412
7971
|
};
|
|
7972
|
+
if ( ele.data.antenna == 7 ) {
|
|
7973
|
+
console.log( data, 'getShelfDetails' );
|
|
7974
|
+
}
|
|
7413
7975
|
mappingData.push( data );
|
|
7414
7976
|
|
|
7415
7977
|
// let mappingDetails = await planoMappingService.create( data );
|
|
@@ -7618,7 +8180,7 @@ export async function calculateCompliance( req, res ) {
|
|
|
7618
8180
|
}
|
|
7619
8181
|
}
|
|
7620
8182
|
|
|
7621
|
-
export async function
|
|
8183
|
+
export async function getPlanogramListOld( req, res ) {
|
|
7622
8184
|
try {
|
|
7623
8185
|
const {
|
|
7624
8186
|
clientId,
|
|
@@ -7660,11 +8222,33 @@ export async function getPlanogramList( req, res ) {
|
|
|
7660
8222
|
storeId: { $in: allowedStoreIds },
|
|
7661
8223
|
},
|
|
7662
8224
|
},
|
|
7663
|
-
|
|
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
|
+
},
|
|
7664
8248
|
{
|
|
7665
8249
|
$lookup: {
|
|
7666
8250
|
from: 'storefixtures',
|
|
7667
|
-
let: { plano: '$
|
|
8251
|
+
let: { plano: '$_id', floor: '$_id' },
|
|
7668
8252
|
pipeline: [
|
|
7669
8253
|
{
|
|
7670
8254
|
$match: {
|
|
@@ -7686,18 +8270,17 @@ export async function getPlanogramList( req, res ) {
|
|
|
7686
8270
|
as: 'fixtureDetails',
|
|
7687
8271
|
},
|
|
7688
8272
|
},
|
|
7689
|
-
|
|
7690
8273
|
{
|
|
7691
8274
|
$lookup: {
|
|
7692
8275
|
from: 'planocompliances',
|
|
7693
|
-
let: { plano: '$
|
|
8276
|
+
let: { plano: '$_id' },
|
|
7694
8277
|
pipeline: [
|
|
7695
8278
|
{
|
|
7696
8279
|
$match: {
|
|
7697
8280
|
$expr: {
|
|
7698
8281
|
$and: [
|
|
7699
8282
|
{ $eq: [ '$planoId', '$$plano' ] },
|
|
7700
|
-
{ $eq: [ '$floorId', '$$floor' ] },
|
|
8283
|
+
// { $eq: [ '$floorId', '$$floor' ] },
|
|
7701
8284
|
{ $eq: [ '$date', today ] },
|
|
7702
8285
|
{ $eq: [ '$compliance', 'proper' ] },
|
|
7703
8286
|
],
|
|
@@ -7712,11 +8295,10 @@ export async function getPlanogramList( req, res ) {
|
|
|
7712
8295
|
as: 'complianceCount',
|
|
7713
8296
|
},
|
|
7714
8297
|
},
|
|
7715
|
-
|
|
7716
8298
|
{
|
|
7717
8299
|
$project: {
|
|
7718
|
-
_id:
|
|
7719
|
-
planoId:
|
|
8300
|
+
_id: { $ifNull: [ { $arrayElemAt: [ '$floorDetails.floorId', 0 ] }, '' ] },
|
|
8301
|
+
planoId: '$_id',
|
|
7720
8302
|
createdAt: 1,
|
|
7721
8303
|
updatedAt: 1,
|
|
7722
8304
|
floorName: 1,
|
|
@@ -7728,6 +8310,7 @@ export async function getPlanogramList( req, res ) {
|
|
|
7728
8310
|
storeName: 1,
|
|
7729
8311
|
fixtureDetails: 1,
|
|
7730
8312
|
complianceCount: 1,
|
|
8313
|
+
layoutCount: { $ifNull: [ { $arrayElemAt: [ '$floorDetails.layoutDetails', 0 ] }, 1 ] },
|
|
7731
8314
|
merchCompliance: {
|
|
7732
8315
|
$floor: [
|
|
7733
8316
|
{
|
|
@@ -7784,7 +8367,8 @@ export async function getPlanogramList( req, res ) {
|
|
|
7784
8367
|
},
|
|
7785
8368
|
} );
|
|
7786
8369
|
|
|
7787
|
-
const result = await layoutService.aggregate( pipeline );
|
|
8370
|
+
// const result = await layoutService.aggregate( pipeline );
|
|
8371
|
+
const result = await planoService.aggregate( pipeline );
|
|
7788
8372
|
|
|
7789
8373
|
let data = result?.[0]?.data || [];
|
|
7790
8374
|
const total = result?.[0]?.count?.[0]?.total || 0;
|
|
@@ -7810,7 +8394,220 @@ export async function getPlanogramList( req, res ) {
|
|
|
7810
8394
|
|
|
7811
8395
|
d.createdAt = dayjs.utc( d.createdAt ).format( 'DD MMM, YYYY' );
|
|
7812
8396
|
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 );
|
|
7813
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
|
+
|
|
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;
|
|
7814
8611
|
return d;
|
|
7815
8612
|
} );
|
|
7816
8613
|
|