tango-app-api-store-builder 1.0.1 → 1.0.2
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.
|
@@ -2841,9 +2841,30 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2841
2841
|
shelves.map( async ( shelf ) => {
|
|
2842
2842
|
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'product' }, { _id: 1 } );
|
|
2843
2843
|
let productIdList = productDetails.map( ( ele ) => ele._id );
|
|
2844
|
-
let
|
|
2845
|
-
|
|
2846
|
-
|
|
2844
|
+
let complianceQuery = [
|
|
2845
|
+
{
|
|
2846
|
+
$match: {
|
|
2847
|
+
fixtureId: fixture._id,
|
|
2848
|
+
shelfId: shelf._id,
|
|
2849
|
+
date: currentDate,
|
|
2850
|
+
planoMappingId: { $in: productIdList },
|
|
2851
|
+
},
|
|
2852
|
+
},
|
|
2853
|
+
{
|
|
2854
|
+
$group: {
|
|
2855
|
+
_id: '$createdAt',
|
|
2856
|
+
status: { $push: '$compliance' },
|
|
2857
|
+
},
|
|
2858
|
+
},
|
|
2859
|
+
{
|
|
2860
|
+
$sort: { _id: -1 },
|
|
2861
|
+
},
|
|
2862
|
+
{
|
|
2863
|
+
$limit: 1,
|
|
2864
|
+
},
|
|
2865
|
+
];
|
|
2866
|
+
let complianceStatus = await planoComplianceService.aggregate( complianceQuery );
|
|
2867
|
+
const compliance = complianceStatus?.[0]?.status?.length ? ( complianceStatus?.[0]?.status?.includes( 'missing' ) || complianceStatus?.[0]?.status.includes( 'misplaced' ) ) ? 'improper' : 'proper' : 'improper';
|
|
2847
2868
|
|
|
2848
2869
|
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'vm' } );
|
|
2849
2870
|
|
|
@@ -2950,9 +2971,30 @@ export async function storeFixturesv2( req, res ) {
|
|
|
2950
2971
|
shelves.map( async ( shelf ) => {
|
|
2951
2972
|
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'product' }, { _id: 1 } );
|
|
2952
2973
|
let productIdList = productDetails.map( ( ele ) => ele._id );
|
|
2953
|
-
let
|
|
2954
|
-
|
|
2955
|
-
|
|
2974
|
+
let complianceQuery = [
|
|
2975
|
+
{
|
|
2976
|
+
$match: {
|
|
2977
|
+
fixtureId: fixture._id,
|
|
2978
|
+
shelfId: shelf._id,
|
|
2979
|
+
date: currentDate,
|
|
2980
|
+
planoMappingId: { $in: productIdList },
|
|
2981
|
+
},
|
|
2982
|
+
},
|
|
2983
|
+
{
|
|
2984
|
+
$group: {
|
|
2985
|
+
_id: '$createdAt',
|
|
2986
|
+
status: { $push: '$compliance' },
|
|
2987
|
+
},
|
|
2988
|
+
},
|
|
2989
|
+
{
|
|
2990
|
+
$sort: { _id: -1 },
|
|
2991
|
+
},
|
|
2992
|
+
{
|
|
2993
|
+
$limit: 1,
|
|
2994
|
+
},
|
|
2995
|
+
];
|
|
2996
|
+
let complianceStatus = await planoComplianceService.aggregate( complianceQuery );
|
|
2997
|
+
const compliance = complianceStatus?.[0]?.status.length ? ( complianceStatus?.[0]?.status?.includes( 'missing' ) || complianceStatus?.[0]?.status?.includes( 'misplaced' ) ) ? 'improper' : 'proper' : 'improper';
|
|
2956
2998
|
|
|
2957
2999
|
|
|
2958
3000
|
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'vm' } );
|
|
@@ -3582,9 +3624,30 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
3582
3624
|
shelves.map( async ( shelf ) => {
|
|
3583
3625
|
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'product' }, { _id: 1 } );
|
|
3584
3626
|
let productIdList = productDetails.map( ( ele ) => ele._id );
|
|
3585
|
-
let
|
|
3586
|
-
|
|
3587
|
-
|
|
3627
|
+
let complianceQuery = [
|
|
3628
|
+
{
|
|
3629
|
+
$match: {
|
|
3630
|
+
fixtureId: fixture._id,
|
|
3631
|
+
shelfId: shelf._id,
|
|
3632
|
+
date: currentDate,
|
|
3633
|
+
planoMappingId: { $in: productIdList },
|
|
3634
|
+
},
|
|
3635
|
+
},
|
|
3636
|
+
{
|
|
3637
|
+
$group: {
|
|
3638
|
+
_id: '$createdAt',
|
|
3639
|
+
status: { $push: '$compliance' },
|
|
3640
|
+
},
|
|
3641
|
+
},
|
|
3642
|
+
{
|
|
3643
|
+
$sort: { $_id: -1 },
|
|
3644
|
+
},
|
|
3645
|
+
{
|
|
3646
|
+
$limit: 1,
|
|
3647
|
+
},
|
|
3648
|
+
];
|
|
3649
|
+
let complianceStatus = await planoComplianceService.aggregate( complianceQuery );
|
|
3650
|
+
const productCompliance = complianceStatus?.[0]?.status?.length ? ( complianceStatus?.[0]?.status?.length.includes( 'missing' ) || complianceStatus?.[0]?.status.length.includes( 'misplaced' ) ) ? 'improper' : 'proper' : 'improper';
|
|
3588
3651
|
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'vm' } );
|
|
3589
3652
|
|
|
3590
3653
|
return {
|
|
@@ -3692,9 +3755,30 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
3692
3755
|
const vmCount = await planoMappingService.count( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'vm' } );
|
|
3693
3756
|
const productDetails = await planoMappingService.find( { fixtureId: fixture._id, shelfId: shelf.toObject(), type: 'product' }, { _id: 1 } );
|
|
3694
3757
|
let productIdList = productDetails.map( ( ele ) => ele._id );
|
|
3695
|
-
let
|
|
3696
|
-
|
|
3697
|
-
|
|
3758
|
+
let complianceQuery = [
|
|
3759
|
+
{
|
|
3760
|
+
$match: {
|
|
3761
|
+
fixtureId: fixture._id,
|
|
3762
|
+
shelfId: shelf._id,
|
|
3763
|
+
date: currentDate,
|
|
3764
|
+
planoMappingId: { $in: productIdList },
|
|
3765
|
+
},
|
|
3766
|
+
},
|
|
3767
|
+
{
|
|
3768
|
+
$group: {
|
|
3769
|
+
_id: '$createdAt',
|
|
3770
|
+
status: { $push: '$compliance' },
|
|
3771
|
+
},
|
|
3772
|
+
},
|
|
3773
|
+
{
|
|
3774
|
+
$sort: { $_id: -1 },
|
|
3775
|
+
},
|
|
3776
|
+
{
|
|
3777
|
+
$limit: 1,
|
|
3778
|
+
},
|
|
3779
|
+
];
|
|
3780
|
+
let complianceStatus = await planoComplianceService.aggregate( complianceQuery );
|
|
3781
|
+
const productCompliance = complianceStatus?.[0]?.status?.length ? ( complianceStatus?.[0]?.status?.length.includes( 'missing' ) || complianceStatus?.[0]?.status.length.includes( 'misplaced' ) ) ? 'improper' : 'proper' : 'improper';
|
|
3698
3782
|
return {
|
|
3699
3783
|
...shelf.toObject(),
|
|
3700
3784
|
productCount: productDetails.length,
|
|
@@ -4036,643 +4120,894 @@ export async function storeFixturesTaskv3( req, res ) {
|
|
|
4036
4120
|
);
|
|
4037
4121
|
|
|
4038
4122
|
|
|
4039
|
-
return res.sendSuccess( storeLayout );
|
|
4123
|
+
return res.sendSuccess( storeLayout );
|
|
4124
|
+
} catch ( e ) {
|
|
4125
|
+
logger.error( { functionName: 'storeFixturesTask', error: e, message: req.body } );
|
|
4126
|
+
return res.sendError( e, 500 );
|
|
4127
|
+
}
|
|
4128
|
+
}
|
|
4129
|
+
|
|
4130
|
+
export async function planoListOld( req, res ) {
|
|
4131
|
+
try {
|
|
4132
|
+
let inputData = req.body;
|
|
4133
|
+
let limit = inputData?.limit || 10;
|
|
4134
|
+
let page = inputData?.offset - 1 || 0;
|
|
4135
|
+
let skip = limit * page;
|
|
4136
|
+
|
|
4137
|
+
let storeDetails = await storeService.find( { clientId: inputData.clientId, status: 'active', ...( inputData?.stores?.length && { storeId: { $in: inputData.stores } } ),
|
|
4138
|
+
...( req.body?.assignedStores?.length && { storeId: { $in: req.body?.assignedStores } } ) }, { storeId: 1 } );
|
|
4139
|
+
storeDetails = storeDetails.map( ( ele ) => ele.storeId );
|
|
4140
|
+
|
|
4141
|
+
let query = [
|
|
4142
|
+
{
|
|
4143
|
+
$match: {
|
|
4144
|
+
clientId: inputData.clientId,
|
|
4145
|
+
storeId: { $in: storeDetails },
|
|
4146
|
+
},
|
|
4147
|
+
},
|
|
4148
|
+
{
|
|
4149
|
+
$lookup: {
|
|
4150
|
+
from: 'storelayouts',
|
|
4151
|
+
let: { plano: '$_id' },
|
|
4152
|
+
pipeline: [
|
|
4153
|
+
{
|
|
4154
|
+
$match: {
|
|
4155
|
+
$expr: {
|
|
4156
|
+
$eq: [ '$planoId', '$$plano' ],
|
|
4157
|
+
},
|
|
4158
|
+
},
|
|
4159
|
+
},
|
|
4160
|
+
{
|
|
4161
|
+
$project: {
|
|
4162
|
+
_id: 0,
|
|
4163
|
+
id: '$_id',
|
|
4164
|
+
floorName: 1,
|
|
4165
|
+
floorNumber: 1,
|
|
4166
|
+
},
|
|
4167
|
+
},
|
|
4168
|
+
{
|
|
4169
|
+
$group: {
|
|
4170
|
+
_id: '',
|
|
4171
|
+
layoutDetails: { $push: { k: '$_id', v: '$status', planoId: '$$plano' } },
|
|
4172
|
+
},
|
|
4173
|
+
},
|
|
4174
|
+
],
|
|
4175
|
+
as: 'layout',
|
|
4176
|
+
},
|
|
4177
|
+
},
|
|
4178
|
+
{
|
|
4179
|
+
$set: {
|
|
4180
|
+
layoutCount: { $size: '$layout' },
|
|
4181
|
+
},
|
|
4182
|
+
},
|
|
4183
|
+
{ $unwind: { path: '$layout', preserveNullAndEmptyArrays: true } },
|
|
4184
|
+
{
|
|
4185
|
+
$lookup: {
|
|
4186
|
+
from: 'storefixtures',
|
|
4187
|
+
let: { floor: '$layout.id' },
|
|
4188
|
+
pipeline: [
|
|
4189
|
+
{
|
|
4190
|
+
$match: {
|
|
4191
|
+
$expr: {
|
|
4192
|
+
$eq: [ '$floorId', '$$floor' ],
|
|
4193
|
+
},
|
|
4194
|
+
},
|
|
4195
|
+
},
|
|
4196
|
+
{
|
|
4197
|
+
$group: {
|
|
4198
|
+
_id: '',
|
|
4199
|
+
fixtureCount: { $sum: 1 },
|
|
4200
|
+
vmCount: { $sum: { $size: '$vmConfig' } },
|
|
4201
|
+
fixtureCapacity: { $sum: '$fixtureCapacity' },
|
|
4202
|
+
},
|
|
4203
|
+
},
|
|
4204
|
+
],
|
|
4205
|
+
as: 'fixtureDetails',
|
|
4206
|
+
},
|
|
4207
|
+
},
|
|
4208
|
+
{ $unwind: { path: '$fixtureDetails', preserveNullAndEmptyArrays: true } },
|
|
4209
|
+
{
|
|
4210
|
+
$lookup: {
|
|
4211
|
+
from: 'processedtasks',
|
|
4212
|
+
let: { floor: '$layout.id' },
|
|
4213
|
+
pipeline: [
|
|
4214
|
+
{
|
|
4215
|
+
$match: {
|
|
4216
|
+
$expr: {
|
|
4217
|
+
$and: [
|
|
4218
|
+
{ $eq: [ '$planoId', '$$plano' ] },
|
|
4219
|
+
// { $eq: [ '$floorId', '$$floor' ] },
|
|
4220
|
+
{ $eq: [ '$isPlano', true ] },
|
|
4221
|
+
{
|
|
4222
|
+
$lte: [ '$date_iso', new Date( dayjs().format( 'YYYY-MM-DD' ) ) ],
|
|
4223
|
+
},
|
|
4224
|
+
{ $in: [ '$planoType', [ 'layout', 'fixture', 'vm' ] ] },
|
|
4225
|
+
],
|
|
4226
|
+
},
|
|
4227
|
+
},
|
|
4228
|
+
},
|
|
4229
|
+
{
|
|
4230
|
+
$group: {
|
|
4231
|
+
_id: { type: '$planoType', floorId: '$floorId' },
|
|
4232
|
+
dateString: { $last: '$date_string' },
|
|
4233
|
+
checklistStatus: { $last: '$checklistStatus' },
|
|
4234
|
+
taskId: { $last: '$_id' },
|
|
4235
|
+
scheduleEndTime_iso: { $last: '$scheduleEndTime_iso' },
|
|
4236
|
+
},
|
|
4237
|
+
},
|
|
4238
|
+
{
|
|
4239
|
+
$group: {
|
|
4240
|
+
_id: null,
|
|
4241
|
+
taskStatus: {
|
|
4242
|
+
$push: {
|
|
4243
|
+
type: '$_id.type',
|
|
4244
|
+
status: '$checklistStatus',
|
|
4245
|
+
date: '$dateString',
|
|
4246
|
+
floorId: '$_id.floorId',
|
|
4247
|
+
endTime: '$scheduleEndTime_iso',
|
|
4248
|
+
breach: {
|
|
4249
|
+
$cond: {
|
|
4250
|
+
if: {
|
|
4251
|
+
$gte: [ '$scheduleEndTime_iso', new Date() ],
|
|
4252
|
+
},
|
|
4253
|
+
then: false,
|
|
4254
|
+
else: true,
|
|
4255
|
+
},
|
|
4256
|
+
},
|
|
4257
|
+
},
|
|
4258
|
+
},
|
|
4259
|
+
taskIds: { $push: '$taskId' },
|
|
4260
|
+
},
|
|
4261
|
+
},
|
|
4262
|
+
],
|
|
4263
|
+
as: 'planoTask',
|
|
4264
|
+
},
|
|
4265
|
+
},
|
|
4266
|
+
{
|
|
4267
|
+
$lookup: {
|
|
4268
|
+
from: 'planotaskcompliances',
|
|
4269
|
+
let: {
|
|
4270
|
+
floor: '$layout.id',
|
|
4271
|
+
},
|
|
4272
|
+
pipeline: [
|
|
4273
|
+
{
|
|
4274
|
+
$match: {
|
|
4275
|
+
$expr: {
|
|
4276
|
+
$and: [
|
|
4277
|
+
{ $eq: [ '$floorId', '$$floor' ] },
|
|
4278
|
+
{ $in: [ '$type', [ 'layout', 'fixture', 'vm' ] ] },
|
|
4279
|
+
],
|
|
4280
|
+
},
|
|
4281
|
+
},
|
|
4282
|
+
},
|
|
4283
|
+
{ $sort: { _id: -1 } },
|
|
4284
|
+
{
|
|
4285
|
+
$set: {
|
|
4286
|
+
hasCompletedAnswers: {
|
|
4287
|
+
$anyElementTrue: {
|
|
4288
|
+
$map: {
|
|
4289
|
+
input: '$answers',
|
|
4290
|
+
as: 'ans',
|
|
4291
|
+
in: { $eq: [ { $ifNull: [ '$$ans.status', null ] }, null ] },
|
|
4292
|
+
},
|
|
4293
|
+
},
|
|
4294
|
+
},
|
|
4295
|
+
hasPendingIssues: {
|
|
4296
|
+
$anyElementTrue: {
|
|
4297
|
+
$map: {
|
|
4298
|
+
input: {
|
|
4299
|
+
$reduce: {
|
|
4300
|
+
input: '$answers',
|
|
4301
|
+
initialValue: [],
|
|
4302
|
+
in: {
|
|
4303
|
+
$concatArrays: [
|
|
4304
|
+
'$$value',
|
|
4305
|
+
{
|
|
4306
|
+
$reduce: {
|
|
4307
|
+
input: { $ifNull: [ '$$this.issues', [] ] },
|
|
4308
|
+
initialValue: [],
|
|
4309
|
+
in: {
|
|
4310
|
+
$concatArrays: [
|
|
4311
|
+
'$$value',
|
|
4312
|
+
{ $ifNull: [ '$$this.Details', [] ] },
|
|
4313
|
+
],
|
|
4314
|
+
},
|
|
4315
|
+
},
|
|
4316
|
+
},
|
|
4317
|
+
],
|
|
4318
|
+
},
|
|
4319
|
+
},
|
|
4320
|
+
},
|
|
4321
|
+
as: 'detail',
|
|
4322
|
+
in: {
|
|
4323
|
+
$or: [
|
|
4324
|
+
{ $eq: [ '$$detail.status', 'pending' ] },
|
|
4325
|
+
],
|
|
4326
|
+
},
|
|
4327
|
+
},
|
|
4328
|
+
},
|
|
4329
|
+
},
|
|
4330
|
+
hasDisagreeIssues: {
|
|
4331
|
+
$anyElementTrue: {
|
|
4332
|
+
$map: {
|
|
4333
|
+
input: {
|
|
4334
|
+
$concatArrays: [
|
|
4335
|
+
'$answers',
|
|
4336
|
+
{
|
|
4337
|
+
$reduce: {
|
|
4338
|
+
input: '$answers',
|
|
4339
|
+
initialValue: [],
|
|
4340
|
+
in: {
|
|
4341
|
+
$concatArrays: [
|
|
4342
|
+
'$$value',
|
|
4343
|
+
{
|
|
4344
|
+
$reduce: {
|
|
4345
|
+
input: { $ifNull: [ '$$this.issues', [] ] },
|
|
4346
|
+
initialValue: [],
|
|
4347
|
+
in: {
|
|
4348
|
+
$concatArrays: [
|
|
4349
|
+
'$$value',
|
|
4350
|
+
{ $ifNull: [ '$$this.Details', [] ] },
|
|
4351
|
+
],
|
|
4352
|
+
},
|
|
4353
|
+
},
|
|
4354
|
+
},
|
|
4355
|
+
],
|
|
4356
|
+
},
|
|
4357
|
+
},
|
|
4358
|
+
},
|
|
4359
|
+
],
|
|
4360
|
+
},
|
|
4361
|
+
as: 'detail',
|
|
4362
|
+
in: {
|
|
4363
|
+
$or: [ { $eq: [ '$$detail.status', 'disagree' ] } ],
|
|
4364
|
+
},
|
|
4365
|
+
},
|
|
4366
|
+
},
|
|
4367
|
+
},
|
|
4368
|
+
},
|
|
4369
|
+
},
|
|
4370
|
+
{
|
|
4371
|
+
$group: {
|
|
4372
|
+
_id: '$floorId',
|
|
4373
|
+
layoutCount: {
|
|
4374
|
+
$sum: { $cond: [ { $eq: [ '$type', 'layout' ] }, 1, 0 ] },
|
|
4375
|
+
},
|
|
4376
|
+
fixtureCount: {
|
|
4377
|
+
$sum: { $cond: [ { $eq: [ '$type', 'fixture' ] }, 1, 0 ] },
|
|
4378
|
+
},
|
|
4379
|
+
vmCount: {
|
|
4380
|
+
$sum: { $cond: [ { $eq: [ '$type', 'vm' ] }, 1, 0 ] },
|
|
4381
|
+
},
|
|
4382
|
+
layoutPending: {
|
|
4383
|
+
$sum: {
|
|
4384
|
+
$cond: [
|
|
4385
|
+
{ $and: [ { $eq: [ '$type', 'layout' ] }, '$hasPendingIssues' ] },
|
|
4386
|
+
1,
|
|
4387
|
+
0,
|
|
4388
|
+
],
|
|
4389
|
+
},
|
|
4390
|
+
},
|
|
4391
|
+
fixturePending: {
|
|
4392
|
+
$sum: {
|
|
4393
|
+
$cond: [
|
|
4394
|
+
{ $and: [ { $eq: [ '$type', 'fixture' ] }, { $or: [ '$hasPendingIssues', '$hasCompletedAnswers' ] } ] },
|
|
4395
|
+
1,
|
|
4396
|
+
0,
|
|
4397
|
+
],
|
|
4398
|
+
},
|
|
4399
|
+
},
|
|
4400
|
+
fixtureApproved: {
|
|
4401
|
+
$push: {
|
|
4402
|
+
$cond: [
|
|
4403
|
+
{
|
|
4404
|
+
$and: [
|
|
4405
|
+
{ $eq: [ '$type', 'fixture' ] },
|
|
4406
|
+
{ $eq: [ '$approvalStatus', 'approved' ] },
|
|
4407
|
+
],
|
|
4408
|
+
},
|
|
4409
|
+
'$approvalStatus',
|
|
4410
|
+
'$$REMOVE',
|
|
4411
|
+
],
|
|
4412
|
+
},
|
|
4413
|
+
},
|
|
4414
|
+
vmPending: {
|
|
4415
|
+
$sum: {
|
|
4416
|
+
$cond: [
|
|
4417
|
+
{ $and: [ { $eq: [ '$type', 'vm' ] }, '$hasPendingIssues' ] },
|
|
4418
|
+
1,
|
|
4419
|
+
0,
|
|
4420
|
+
],
|
|
4421
|
+
},
|
|
4422
|
+
},
|
|
4423
|
+
layoutDisagree: {
|
|
4424
|
+
$sum: {
|
|
4425
|
+
$cond: [
|
|
4426
|
+
{ $and: [ { $eq: [ '$type', 'layout' ] }, '$hasDisagreeIssues' ] },
|
|
4427
|
+
1,
|
|
4428
|
+
0,
|
|
4429
|
+
],
|
|
4430
|
+
},
|
|
4431
|
+
},
|
|
4432
|
+
fixtureDisagree: {
|
|
4433
|
+
$sum: {
|
|
4434
|
+
$cond: [
|
|
4435
|
+
{ $and: [ { $eq: [ '$type', 'fixture' ] }, '$hasDisagreeIssues' ] },
|
|
4436
|
+
1,
|
|
4437
|
+
0,
|
|
4438
|
+
],
|
|
4439
|
+
},
|
|
4440
|
+
},
|
|
4441
|
+
vmDisagree: {
|
|
4442
|
+
$sum: {
|
|
4443
|
+
$cond: [
|
|
4444
|
+
{ $and: [ { $eq: [ '$type', 'vm' ] }, '$hasDisagreeIssues' ] },
|
|
4445
|
+
1,
|
|
4446
|
+
0,
|
|
4447
|
+
],
|
|
4448
|
+
},
|
|
4449
|
+
},
|
|
4450
|
+
},
|
|
4451
|
+
},
|
|
4452
|
+
{
|
|
4453
|
+
$project: {
|
|
4454
|
+
_id: 0,
|
|
4455
|
+
layoutStatus: {
|
|
4456
|
+
$cond: {
|
|
4457
|
+
if: {
|
|
4458
|
+
$and: [
|
|
4459
|
+
{ $gt: [ '$layoutCount', 0 ] },
|
|
4460
|
+
{ $eq: [ '$layoutPending', 0 ] },
|
|
4461
|
+
{ $eq: [ '$layoutDisagree', 0 ] },
|
|
4462
|
+
],
|
|
4463
|
+
},
|
|
4464
|
+
then: 'complete',
|
|
4465
|
+
else: {
|
|
4466
|
+
$cond: {
|
|
4467
|
+
if: {
|
|
4468
|
+
$and: [
|
|
4469
|
+
{
|
|
4470
|
+
$gt: [ '$layoutCount', 0 ],
|
|
4471
|
+
},
|
|
4472
|
+
{
|
|
4473
|
+
$gt: [
|
|
4474
|
+
'$layoutPending',
|
|
4475
|
+
0,
|
|
4476
|
+
],
|
|
4477
|
+
},
|
|
4478
|
+
],
|
|
4479
|
+
},
|
|
4480
|
+
then: 'pending',
|
|
4481
|
+
else: {
|
|
4482
|
+
$cond: {
|
|
4483
|
+
if: {
|
|
4484
|
+
$and: [
|
|
4485
|
+
{
|
|
4486
|
+
$gt: [ '$layoutCount', 0 ],
|
|
4487
|
+
},
|
|
4488
|
+
{
|
|
4489
|
+
$gt: [
|
|
4490
|
+
'$layoutDisagree',
|
|
4491
|
+
0,
|
|
4492
|
+
],
|
|
4493
|
+
},
|
|
4494
|
+
],
|
|
4495
|
+
},
|
|
4496
|
+
then: 'disagree',
|
|
4497
|
+
else: '',
|
|
4498
|
+
},
|
|
4499
|
+
},
|
|
4500
|
+
},
|
|
4501
|
+
},
|
|
4502
|
+
},
|
|
4503
|
+
},
|
|
4504
|
+
fixtureStatus: {
|
|
4505
|
+
$cond: {
|
|
4506
|
+
if: {
|
|
4507
|
+
$and: [
|
|
4508
|
+
{ $gt: [ '$fixtureCount', 0 ] },
|
|
4509
|
+
{
|
|
4510
|
+
$eq: [ '$fixturePending', 0 ],
|
|
4511
|
+
},
|
|
4512
|
+
{
|
|
4513
|
+
$eq: [ '$fixtureDisagree', 0 ],
|
|
4514
|
+
},
|
|
4515
|
+
{
|
|
4516
|
+
$eq: [ { $size: '$fixtureApproved' }, '$fixtureCount' ],
|
|
4517
|
+
},
|
|
4518
|
+
],
|
|
4519
|
+
},
|
|
4520
|
+
then: 'complete',
|
|
4521
|
+
else: {
|
|
4522
|
+
$cond: {
|
|
4523
|
+
if: {
|
|
4524
|
+
$and: [
|
|
4525
|
+
{
|
|
4526
|
+
$gt: [
|
|
4527
|
+
'$fixtureCount',
|
|
4528
|
+
0,
|
|
4529
|
+
],
|
|
4530
|
+
},
|
|
4531
|
+
{
|
|
4532
|
+
$gt: [
|
|
4533
|
+
'$fixturePending',
|
|
4534
|
+
0,
|
|
4535
|
+
],
|
|
4536
|
+
},
|
|
4537
|
+
],
|
|
4538
|
+
},
|
|
4539
|
+
then: 'pending',
|
|
4540
|
+
else: {
|
|
4541
|
+
$cond: {
|
|
4542
|
+
if: {
|
|
4543
|
+
$and: [
|
|
4544
|
+
{
|
|
4545
|
+
$gt: [ '$fixtureCount', 0 ],
|
|
4546
|
+
},
|
|
4547
|
+
{
|
|
4548
|
+
$gt: [
|
|
4549
|
+
'$fixtureDisagree',
|
|
4550
|
+
0,
|
|
4551
|
+
],
|
|
4552
|
+
},
|
|
4553
|
+
],
|
|
4554
|
+
},
|
|
4555
|
+
then: 'disagree',
|
|
4556
|
+
else: '',
|
|
4557
|
+
},
|
|
4558
|
+
},
|
|
4559
|
+
},
|
|
4560
|
+
},
|
|
4561
|
+
},
|
|
4562
|
+
},
|
|
4563
|
+
vmStatus: {
|
|
4564
|
+
$cond: {
|
|
4565
|
+
if: {
|
|
4566
|
+
$and: [
|
|
4567
|
+
{ $gt: [ '$vmCount', 0 ] },
|
|
4568
|
+
{ $eq: [ '$vmPending', 0 ] },
|
|
4569
|
+
{ $eq: [ '$vmDisagree', 0 ] },
|
|
4570
|
+
],
|
|
4571
|
+
},
|
|
4572
|
+
then: 'complete',
|
|
4573
|
+
else: {
|
|
4574
|
+
$cond: {
|
|
4575
|
+
if: {
|
|
4576
|
+
$and: [
|
|
4577
|
+
{ $gt: [ '$vmCount', 0 ] },
|
|
4578
|
+
{ $gt: [ '$vmPending', 0 ] },
|
|
4579
|
+
],
|
|
4580
|
+
},
|
|
4581
|
+
then: 'pending',
|
|
4582
|
+
else: {
|
|
4583
|
+
$cond: {
|
|
4584
|
+
if: {
|
|
4585
|
+
$and: [
|
|
4586
|
+
{
|
|
4587
|
+
$gt: [ '$vmCount', 0 ],
|
|
4588
|
+
},
|
|
4589
|
+
{
|
|
4590
|
+
$gt: [
|
|
4591
|
+
'$vmDisagree',
|
|
4592
|
+
0,
|
|
4593
|
+
],
|
|
4594
|
+
},
|
|
4595
|
+
],
|
|
4596
|
+
},
|
|
4597
|
+
then: 'disagree',
|
|
4598
|
+
else: '',
|
|
4599
|
+
},
|
|
4600
|
+
},
|
|
4601
|
+
},
|
|
4602
|
+
},
|
|
4603
|
+
},
|
|
4604
|
+
},
|
|
4605
|
+
layoutPending: 1,
|
|
4606
|
+
fixturePending: 1,
|
|
4607
|
+
vmPending: 1,
|
|
4608
|
+
layoutCount: 1,
|
|
4609
|
+
fixtureCount: 1,
|
|
4610
|
+
vmCount: 1,
|
|
4611
|
+
// completeLayout: 1,
|
|
4612
|
+
layoutDisagree: 1,
|
|
4613
|
+
fixtureDisagree: 1,
|
|
4614
|
+
vmDisagree: 1,
|
|
4615
|
+
},
|
|
4616
|
+
},
|
|
4617
|
+
],
|
|
4618
|
+
as: 'taskDetails',
|
|
4619
|
+
},
|
|
4620
|
+
},
|
|
4621
|
+
{
|
|
4622
|
+
$project: {
|
|
4623
|
+
storeId: 1,
|
|
4624
|
+
storeName: 1,
|
|
4625
|
+
layoutName: 1,
|
|
4626
|
+
layoutDetails: '$layout',
|
|
4627
|
+
fixtureCount: '$fixtureDetails.fixtureCount',
|
|
4628
|
+
vmCount: '$fixtureDetails.vmCount',
|
|
4629
|
+
fixtureCapacity: '$fixtureDetails.fixtureCapacity',
|
|
4630
|
+
status: 1,
|
|
4631
|
+
planoProgress: 1,
|
|
4632
|
+
createdAt: 1,
|
|
4633
|
+
lastUpdate: '$updatedAt',
|
|
4634
|
+
planoTask: { $ifNull: [ '$planoTask', [] ] },
|
|
4635
|
+
layoutCount: 1,
|
|
4636
|
+
taskDetails: {
|
|
4637
|
+
$let: {
|
|
4638
|
+
vars: {
|
|
4639
|
+
task: { $arrayElemAt: [ '$taskDetails', 0 ] },
|
|
4640
|
+
},
|
|
4641
|
+
in: {
|
|
4642
|
+
layoutStatus: { $ifNull: [ '$$task.layoutStatus', '' ] },
|
|
4643
|
+
fixtureStatus: { $ifNull: [ '$$task.fixtureStatus', '' ] },
|
|
4644
|
+
vmStatus: { $ifNull: [ '$$task.vmStatus', '' ] },
|
|
4645
|
+
},
|
|
4646
|
+
},
|
|
4647
|
+
},
|
|
4648
|
+
},
|
|
4649
|
+
},
|
|
4650
|
+
];
|
|
4651
|
+
if ( inputData.sortColumnName && inputData.sortBy ) {
|
|
4652
|
+
query.push( { $sort: { [inputData.sortColumnName]: inputData.sortBy } } );
|
|
4653
|
+
}
|
|
4654
|
+
if ( inputData.searchValue ) {
|
|
4655
|
+
query.push( {
|
|
4656
|
+
$match: {
|
|
4657
|
+
storeName: { $regex: inputData.searchValue, $options: 'i' },
|
|
4658
|
+
},
|
|
4659
|
+
} );
|
|
4660
|
+
}
|
|
4661
|
+
if ( inputData?.filter?.taskPending?.length && inputData?.filter?.taskPending !== 'all' ) {
|
|
4662
|
+
let andQuery = [ {
|
|
4663
|
+
'planoTask.taskStatus': {
|
|
4664
|
+
$elemMatch: {
|
|
4665
|
+
type: inputData.filter.taskPending,
|
|
4666
|
+
status: 'submit',
|
|
4667
|
+
},
|
|
4668
|
+
},
|
|
4669
|
+
} ];
|
|
4670
|
+
|
|
4671
|
+
if ( inputData.filter.taskPending === 'layout' ) {
|
|
4672
|
+
andQuery.push(
|
|
4673
|
+
{ 'taskDetails.layoutStatus': 'pending' },
|
|
4674
|
+
);
|
|
4675
|
+
}
|
|
4676
|
+
|
|
4677
|
+
if ( inputData.filter.taskPending === 'fixture' ) {
|
|
4678
|
+
andQuery.push(
|
|
4679
|
+
{ 'taskDetails.fixtureStatus': 'pending' },
|
|
4680
|
+
);
|
|
4681
|
+
}
|
|
4682
|
+
|
|
4683
|
+
if ( inputData.filter.taskPending === 'vm' ) {
|
|
4684
|
+
andQuery.push(
|
|
4685
|
+
{ 'taskDetails.vmStatus': 'pending' },
|
|
4686
|
+
);
|
|
4687
|
+
}
|
|
4688
|
+
|
|
4689
|
+
query.push( {
|
|
4690
|
+
$match: {
|
|
4691
|
+
$and: andQuery,
|
|
4692
|
+
},
|
|
4693
|
+
} );
|
|
4694
|
+
}
|
|
4695
|
+
|
|
4696
|
+
if ( inputData?.filter?.flag?.length ) {
|
|
4697
|
+
let andQuery = [];
|
|
4698
|
+
andQuery.push(
|
|
4699
|
+
{
|
|
4700
|
+
'planoTask.taskStatus': {
|
|
4701
|
+
$elemMatch: {
|
|
4702
|
+
type: { $in: inputData.filter.flag },
|
|
4703
|
+
status: { $ne: 'submit' },
|
|
4704
|
+
breach: true,
|
|
4705
|
+
},
|
|
4706
|
+
},
|
|
4707
|
+
},
|
|
4708
|
+
// { 'taskDetails.layoutStatus': 'pending' },
|
|
4709
|
+
);
|
|
4710
|
+
query.push( {
|
|
4711
|
+
$match: {
|
|
4712
|
+
$and: andQuery,
|
|
4713
|
+
},
|
|
4714
|
+
} );
|
|
4715
|
+
}
|
|
4716
|
+
|
|
4717
|
+
let orQuery = [];
|
|
4718
|
+
|
|
4719
|
+
if ( inputData.filter.status.length ) {
|
|
4720
|
+
if ( inputData.filter.status.includes( 'taskAssigned' ) ) {
|
|
4721
|
+
// orQuery.push( { 'planoTask.taskStatus.status': { $in: [ 'open', 'inprogress' ] } } );
|
|
4722
|
+
orQuery.push( {
|
|
4723
|
+
'planoTask.taskStatus': {
|
|
4724
|
+
$elemMatch: {
|
|
4725
|
+
status: { $ne: 'submit' },
|
|
4726
|
+
breach: false,
|
|
4727
|
+
},
|
|
4728
|
+
},
|
|
4729
|
+
} );
|
|
4730
|
+
}
|
|
4731
|
+
if ( inputData.filter.status.includes( 'reviewPending' ) ) {
|
|
4732
|
+
orQuery.push( {
|
|
4733
|
+
$and: [
|
|
4734
|
+
{ 'planoTask.taskStatus': {
|
|
4735
|
+
$elemMatch: {
|
|
4736
|
+
type: 'layout',
|
|
4737
|
+
status: 'submit',
|
|
4738
|
+
},
|
|
4739
|
+
} }, { 'taskDetails.layoutStatus': 'pending' },
|
|
4740
|
+
],
|
|
4741
|
+
} );
|
|
4742
|
+
orQuery.push( {
|
|
4743
|
+
$and: [
|
|
4744
|
+
{ 'planoTask.taskStatus': {
|
|
4745
|
+
$elemMatch: {
|
|
4746
|
+
type: 'fixture',
|
|
4747
|
+
status: 'submit',
|
|
4748
|
+
},
|
|
4749
|
+
} }, { 'taskDetails.fixtureStatus': 'pending' },
|
|
4750
|
+
],
|
|
4751
|
+
} );
|
|
4752
|
+
orQuery.push( {
|
|
4753
|
+
$and: [
|
|
4754
|
+
{ 'planoTask.taskStatus': {
|
|
4755
|
+
$elemMatch: {
|
|
4756
|
+
type: 'vm',
|
|
4757
|
+
status: 'submit',
|
|
4758
|
+
},
|
|
4759
|
+
} }, { 'taskDetails.vmStatus': 'pending' },
|
|
4760
|
+
],
|
|
4761
|
+
} );
|
|
4762
|
+
}
|
|
4763
|
+
if ( inputData.filter.status.includes( 'completed' ) ) {
|
|
4764
|
+
let taskType= [ 'fixture' ];
|
|
4765
|
+
let andCondition = [];
|
|
4766
|
+
taskType.forEach( ( type ) => {
|
|
4767
|
+
andCondition.push(
|
|
4768
|
+
{ 'planoTask.taskStatus': {
|
|
4769
|
+
$elemMatch: {
|
|
4770
|
+
type,
|
|
4771
|
+
status: 'submit',
|
|
4772
|
+
},
|
|
4773
|
+
} },
|
|
4774
|
+
{
|
|
4775
|
+
[`taskDetails.${type}Status`]: 'complete',
|
|
4776
|
+
},
|
|
4777
|
+
);
|
|
4778
|
+
} );
|
|
4779
|
+
orQuery.push( { $and: andCondition } );
|
|
4780
|
+
}
|
|
4781
|
+
if ( inputData.filter.status.includes( 'yetToAssign' ) ) {
|
|
4782
|
+
orQuery.push( { $expr: { $eq: [ { $size: '$planoTask' }, 0 ] } } );
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
|
|
4786
|
+
if ( orQuery.length ) {
|
|
4787
|
+
query.push( {
|
|
4788
|
+
$match: {
|
|
4789
|
+
$or: orQuery,
|
|
4790
|
+
},
|
|
4791
|
+
} );
|
|
4792
|
+
}
|
|
4793
|
+
|
|
4794
|
+
|
|
4795
|
+
query.push( {
|
|
4796
|
+
$facet: {
|
|
4797
|
+
data: [
|
|
4798
|
+
{ $skip: skip },
|
|
4799
|
+
{ $limit: limit },
|
|
4800
|
+
],
|
|
4801
|
+
count: [
|
|
4802
|
+
{ $count: 'total' },
|
|
4803
|
+
],
|
|
4804
|
+
planoList: [
|
|
4805
|
+
{
|
|
4806
|
+
$group: {
|
|
4807
|
+
_id: '',
|
|
4808
|
+
idList: { $addToSet: '$_id' },
|
|
4809
|
+
},
|
|
4810
|
+
},
|
|
4811
|
+
{
|
|
4812
|
+
$project: {
|
|
4813
|
+
_id: 0,
|
|
4814
|
+
idList: 1,
|
|
4815
|
+
},
|
|
4816
|
+
},
|
|
4817
|
+
],
|
|
4818
|
+
},
|
|
4819
|
+
} );
|
|
4820
|
+
|
|
4821
|
+
const [ planoDetails, planoIdList ] = await Promise.all( [
|
|
4822
|
+
|
|
4823
|
+
await planoService.aggregate( query ),
|
|
4824
|
+
await planoService.find( { clientId: inputData.clientId,
|
|
4825
|
+
storeId: { $in: storeDetails } }, { _id: 1 } ),
|
|
4826
|
+
] );
|
|
4827
|
+
|
|
4828
|
+
|
|
4829
|
+
if ( !planoDetails[0].data.length ) {
|
|
4830
|
+
return res.sendError( 'No data found', 204 );
|
|
4831
|
+
}
|
|
4832
|
+
|
|
4833
|
+
|
|
4834
|
+
let taskQuery = [
|
|
4835
|
+
{
|
|
4836
|
+
$match: {
|
|
4837
|
+
planoId: { $in: planoIdList.map( ( ele ) => ele._id ) },
|
|
4838
|
+
isPlano: true,
|
|
4839
|
+
date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
|
|
4840
|
+
planoType: { $in: [ 'layout', 'fixture', 'vm' ] },
|
|
4841
|
+
},
|
|
4842
|
+
},
|
|
4843
|
+
{
|
|
4844
|
+
$group: {
|
|
4845
|
+
_id: { store: '$storeName', floorId: '$floorId', type: '$planoType' },
|
|
4846
|
+
planoId: { $last: '$planoId' },
|
|
4847
|
+
checklistStatus: { $last: '$checklistStatus' },
|
|
4848
|
+
taskId: { $last: '$_id' },
|
|
4849
|
+
},
|
|
4850
|
+
},
|
|
4851
|
+
{
|
|
4852
|
+
$match: {
|
|
4853
|
+
checklistStatus: 'submit',
|
|
4854
|
+
},
|
|
4855
|
+
},
|
|
4856
|
+
{
|
|
4857
|
+
$project: {
|
|
4858
|
+
_id: 0,
|
|
4859
|
+
type: '$_id.type',
|
|
4860
|
+
planoId: 1,
|
|
4861
|
+
checklistStatus: 1,
|
|
4862
|
+
taskId: 1,
|
|
4863
|
+
floorId: '$_id.floorId',
|
|
4864
|
+
},
|
|
4865
|
+
},
|
|
4866
|
+
];
|
|
4867
|
+
|
|
4868
|
+
let pendingDetails = await planotaskService.aggregate( taskQuery );
|
|
4869
|
+
taskQuery = [
|
|
4870
|
+
{
|
|
4871
|
+
$match: {
|
|
4872
|
+
taskId: { $in: pendingDetails.map( ( ele ) => ele.taskId ) },
|
|
4873
|
+
// taskType: 'initial',
|
|
4874
|
+
},
|
|
4875
|
+
},
|
|
4876
|
+
{
|
|
4877
|
+
$set: {
|
|
4878
|
+
hasCompletedAnswers: {
|
|
4879
|
+
$anyElementTrue: {
|
|
4880
|
+
$map: {
|
|
4881
|
+
input: '$answers',
|
|
4882
|
+
as: 'ans',
|
|
4883
|
+
in: { $eq: [ { $ifNull: [ '$$ans.status', null ] }, null ] },
|
|
4884
|
+
},
|
|
4885
|
+
},
|
|
4886
|
+
},
|
|
4887
|
+
hasPendingIssues: {
|
|
4888
|
+
$anyElementTrue: {
|
|
4889
|
+
$map: {
|
|
4890
|
+
input: {
|
|
4891
|
+
$reduce: {
|
|
4892
|
+
input: '$answers',
|
|
4893
|
+
initialValue: [],
|
|
4894
|
+
in: {
|
|
4895
|
+
$concatArrays: [
|
|
4896
|
+
'$$value',
|
|
4897
|
+
{
|
|
4898
|
+
$reduce: {
|
|
4899
|
+
input: { $ifNull: [ '$$this.issues', [] ] },
|
|
4900
|
+
initialValue: [],
|
|
4901
|
+
in: {
|
|
4902
|
+
$concatArrays: [
|
|
4903
|
+
'$$value',
|
|
4904
|
+
{ $ifNull: [ '$$this.Details', [] ] },
|
|
4905
|
+
],
|
|
4906
|
+
},
|
|
4907
|
+
},
|
|
4908
|
+
},
|
|
4909
|
+
],
|
|
4910
|
+
},
|
|
4911
|
+
},
|
|
4912
|
+
},
|
|
4913
|
+
as: 'detail',
|
|
4914
|
+
in: {
|
|
4915
|
+
$or: [
|
|
4916
|
+
{ $eq: [ '$$detail.status', 'pending' ] },
|
|
4917
|
+
],
|
|
4918
|
+
},
|
|
4919
|
+
},
|
|
4920
|
+
},
|
|
4921
|
+
},
|
|
4922
|
+
},
|
|
4923
|
+
},
|
|
4924
|
+
{
|
|
4925
|
+
$group: {
|
|
4926
|
+
_id: { type: '$type', planoId: '$planoId' },
|
|
4927
|
+
layoutPending: {
|
|
4928
|
+
$sum: {
|
|
4929
|
+
$cond: [
|
|
4930
|
+
{ $and: [ { $eq: [ '$type', 'layout' ] }, '$hasPendingIssues' ] },
|
|
4931
|
+
1,
|
|
4932
|
+
0,
|
|
4933
|
+
],
|
|
4934
|
+
},
|
|
4935
|
+
},
|
|
4936
|
+
fixturePending: {
|
|
4937
|
+
$sum: {
|
|
4938
|
+
$cond: [
|
|
4939
|
+
{ $and: [ { $eq: [ '$type', 'fixture' ] }, { $or: [ '$hasPendingIssues', '$hasCompletedAnswers' ] } ] },
|
|
4940
|
+
1,
|
|
4941
|
+
0,
|
|
4942
|
+
],
|
|
4943
|
+
},
|
|
4944
|
+
},
|
|
4945
|
+
vmPending: {
|
|
4946
|
+
$sum: {
|
|
4947
|
+
$cond: [
|
|
4948
|
+
{ $and: [ { $eq: [ '$type', 'vm' ] }, '$hasPendingIssues' ] },
|
|
4949
|
+
1,
|
|
4950
|
+
0,
|
|
4951
|
+
],
|
|
4952
|
+
},
|
|
4953
|
+
},
|
|
4954
|
+
},
|
|
4955
|
+
},
|
|
4956
|
+
{
|
|
4957
|
+
$group: {
|
|
4958
|
+
_id: 0,
|
|
4959
|
+
layoutPending: {
|
|
4960
|
+
$sum: { $cond: {
|
|
4961
|
+
if: {
|
|
4962
|
+
$gt: [ '$layoutPending', 0 ],
|
|
4963
|
+
},
|
|
4964
|
+
then: 1,
|
|
4965
|
+
else: 0,
|
|
4966
|
+
} },
|
|
4967
|
+
},
|
|
4968
|
+
fixturePending: {
|
|
4969
|
+
$sum: { $cond: {
|
|
4970
|
+
if: {
|
|
4971
|
+
$gt: [ '$fixturePending', 0 ],
|
|
4972
|
+
},
|
|
4973
|
+
then: 1,
|
|
4974
|
+
else: 0,
|
|
4975
|
+
} },
|
|
4976
|
+
},
|
|
4977
|
+
vmPending: {
|
|
4978
|
+
$sum: { $cond: {
|
|
4979
|
+
if: {
|
|
4980
|
+
$gt: [ '$vmPending', 0 ],
|
|
4981
|
+
},
|
|
4982
|
+
then: 1,
|
|
4983
|
+
else: 0,
|
|
4984
|
+
} },
|
|
4985
|
+
},
|
|
4986
|
+
},
|
|
4987
|
+
},
|
|
4988
|
+
{
|
|
4989
|
+
$project: {
|
|
4990
|
+
_id: 0,
|
|
4991
|
+
layoutPending: '$layoutPending',
|
|
4992
|
+
fixturePending: '$fixturePending',
|
|
4993
|
+
vmPending: '$vmPending',
|
|
4994
|
+
},
|
|
4995
|
+
},
|
|
4996
|
+
];
|
|
4997
|
+
|
|
4998
|
+
pendingDetails = await planoTaskComplianceService.aggregate( taskQuery );
|
|
4999
|
+
let result = {
|
|
5000
|
+
data: planoDetails[0].data,
|
|
5001
|
+
count: planoDetails?.[0]?.count?.[0]?.total || 0,
|
|
5002
|
+
pendingDetails: [ { ...pendingDetails?.[0], allStores: planoIdList?.length || 0 } ],
|
|
5003
|
+
};
|
|
5004
|
+
return res.sendSuccess( result );
|
|
4040
5005
|
} catch ( e ) {
|
|
4041
|
-
logger.error( { functionName: '
|
|
5006
|
+
logger.error( { functionName: 'planoList', error: e } );
|
|
4042
5007
|
return res.sendError( e, 500 );
|
|
4043
5008
|
}
|
|
4044
5009
|
}
|
|
4045
5010
|
|
|
4046
|
-
// export async function planoListOld( req, res ) {
|
|
4047
|
-
// try {
|
|
4048
|
-
// let inputData = req.body;
|
|
4049
|
-
|
|
4050
|
-
// let storeDetails = await storeService.find( { clientId: inputData.clientId, status: 'active', ...( inputData?.stores?.length && { storeId: { $in: inputData.stores } } ) }, { storeId: 1 } );
|
|
4051
|
-
// storeDetails = storeDetails.map( ( ele ) => ele.storeId );
|
|
4052
|
-
|
|
4053
|
-
// let getPlanoDetails = await planoService.find( { storeId: { $in: storeDetails } } );
|
|
4054
|
-
// if ( !getPlanoDetails.length ) {
|
|
4055
|
-
// return res.sendError( 'No data found', 204 );
|
|
4056
|
-
// }
|
|
4057
|
-
|
|
4058
|
-
// let getPlanoFloorDetails = await storeBuilderService.find( { _id: getPlanoDetails.map( ( ele ) => ele._id ) } );
|
|
4059
|
-
|
|
4060
|
-
// let planoFloorDetails = getPlanoFloorDetails.map( ( ele ) => {
|
|
4061
|
-
// return { planoId: ele.planoId, floorId: ele.floorId };
|
|
4062
|
-
// } );
|
|
4063
|
-
|
|
4064
|
-
// Promise.all( planoFloorDetails.map( async ( ele ) => {
|
|
4065
|
-
// let fixtureQuery = [
|
|
4066
|
-
// {
|
|
4067
|
-
// $match: {
|
|
4068
|
-
// planoId: ele.planoId,
|
|
4069
|
-
// floorId: ele.floorId,
|
|
4070
|
-
// },
|
|
4071
|
-
// },
|
|
4072
|
-
// {
|
|
4073
|
-
// $group: {
|
|
4074
|
-
// _id: '',
|
|
4075
|
-
// fixtureCount: { $sum: 1 },
|
|
4076
|
-
// vmCount: { $sum: { $size: '$vmConfig' } },
|
|
4077
|
-
// fixtureCapacity: { $sum: '$fixtureCapacity' },
|
|
4078
|
-
// },
|
|
4079
|
-
// },
|
|
4080
|
-
// ];
|
|
4081
|
-
|
|
4082
|
-
// let fixtureDetails = await storeFixtureService.aggregate( fixtureQuery );
|
|
4083
|
-
|
|
4084
|
-
// let taskQuery = [
|
|
4085
|
-
// {
|
|
4086
|
-
// $match: {
|
|
4087
|
-
// $expr: {
|
|
4088
|
-
// $and: [
|
|
4089
|
-
// { $eq: [ '$planoId', ele.planoId ] },
|
|
4090
|
-
// { $eq: [ '$floorId', ele.floorId ] },
|
|
4091
|
-
// { $eq: [ '$isPlano', true ] },
|
|
4092
|
-
// {
|
|
4093
|
-
// $lte: [ '$date_iso', new Date( dayjs().format( 'YYYY-MM-DD' ) ) ],
|
|
4094
|
-
// },
|
|
4095
|
-
// { $in: [ '$planoType', [ 'layout', 'fixture', 'vm' ] ] },
|
|
4096
|
-
// ],
|
|
4097
|
-
// },
|
|
4098
|
-
// },
|
|
4099
|
-
// },
|
|
4100
|
-
// {
|
|
4101
|
-
// $group: {
|
|
4102
|
-
// _id: { type: '$planoType', floorId: '$floorId' },
|
|
4103
|
-
// dateString: { $last: '$date_string' },
|
|
4104
|
-
// checklistStatus: { $last: '$checklistStatus' },
|
|
4105
|
-
// taskId: { $last: '$_id' },
|
|
4106
|
-
// scheduleEndTime_iso: { $last: '$scheduleEndTime_iso' },
|
|
4107
|
-
// },
|
|
4108
|
-
// },
|
|
4109
|
-
// {
|
|
4110
|
-
// $group: {
|
|
4111
|
-
// _id: null,
|
|
4112
|
-
// taskStatus: {
|
|
4113
|
-
// $push: {
|
|
4114
|
-
// type: '$_id.type',
|
|
4115
|
-
// status: '$checklistStatus',
|
|
4116
|
-
// date: '$dateString',
|
|
4117
|
-
// floorId: '$_id.floorId',
|
|
4118
|
-
// endTime: '$scheduleEndTime_iso',
|
|
4119
|
-
// breach: {
|
|
4120
|
-
// $cond: {
|
|
4121
|
-
// if: {
|
|
4122
|
-
// $gte: [ '$scheduleEndTime_iso', new Date() ],
|
|
4123
|
-
// },
|
|
4124
|
-
// then: false,
|
|
4125
|
-
// else: true,
|
|
4126
|
-
// },
|
|
4127
|
-
// },
|
|
4128
|
-
// },
|
|
4129
|
-
// },
|
|
4130
|
-
// taskIds: { $push: '$taskId' },
|
|
4131
|
-
// },
|
|
4132
|
-
// },
|
|
4133
|
-
// ];
|
|
4134
|
-
|
|
4135
|
-
// let taskDetails = await planotaskService.aggregate( taskQuery );
|
|
4136
|
-
|
|
4137
|
-
// let complianceQuery = [
|
|
4138
|
-
// [
|
|
4139
|
-
// {
|
|
4140
|
-
// $match: {
|
|
4141
|
-
// $expr: {
|
|
4142
|
-
// $and: [
|
|
4143
|
-
// { $eq: [ '$floorId', '$$floor' ] },
|
|
4144
|
-
// { $in: [ '$type', [ 'layout', 'fixture', 'vm' ] ] },
|
|
4145
|
-
// ],
|
|
4146
|
-
// },
|
|
4147
|
-
// },
|
|
4148
|
-
// },
|
|
4149
|
-
// { $sort: { _id: -1 } },
|
|
4150
|
-
// {
|
|
4151
|
-
// $set: {
|
|
4152
|
-
// hasCompletedAnswers: {
|
|
4153
|
-
// $anyElementTrue: {
|
|
4154
|
-
// $map: {
|
|
4155
|
-
// input: '$answers',
|
|
4156
|
-
// as: 'ans',
|
|
4157
|
-
// in: { $eq: [ { $ifNull: [ '$$ans.status', null ] }, null ] },
|
|
4158
|
-
// },
|
|
4159
|
-
// },
|
|
4160
|
-
// },
|
|
4161
|
-
// hasPendingIssues: {
|
|
4162
|
-
// $anyElementTrue: {
|
|
4163
|
-
// $map: {
|
|
4164
|
-
// input: {
|
|
4165
|
-
// $reduce: {
|
|
4166
|
-
// input: '$answers',
|
|
4167
|
-
// initialValue: [],
|
|
4168
|
-
// in: {
|
|
4169
|
-
// $concatArrays: [
|
|
4170
|
-
// '$$value',
|
|
4171
|
-
// {
|
|
4172
|
-
// $reduce: {
|
|
4173
|
-
// input: { $ifNull: [ '$$this.issues', [] ] },
|
|
4174
|
-
// initialValue: [],
|
|
4175
|
-
// in: {
|
|
4176
|
-
// $concatArrays: [
|
|
4177
|
-
// '$$value',
|
|
4178
|
-
// { $ifNull: [ '$$this.Details', [] ] },
|
|
4179
|
-
// ],
|
|
4180
|
-
// },
|
|
4181
|
-
// },
|
|
4182
|
-
// },
|
|
4183
|
-
// ],
|
|
4184
|
-
// },
|
|
4185
|
-
// },
|
|
4186
|
-
// },
|
|
4187
|
-
// as: 'detail',
|
|
4188
|
-
// in: {
|
|
4189
|
-
// $or: [
|
|
4190
|
-
// { $eq: [ '$$detail.status', 'pending' ] },
|
|
4191
|
-
// ],
|
|
4192
|
-
// },
|
|
4193
|
-
// },
|
|
4194
|
-
// },
|
|
4195
|
-
// },
|
|
4196
|
-
// hasDisagreeIssues: {
|
|
4197
|
-
// $anyElementTrue: {
|
|
4198
|
-
// $map: {
|
|
4199
|
-
// input: {
|
|
4200
|
-
// $concatArrays: [
|
|
4201
|
-
// '$answers',
|
|
4202
|
-
// {
|
|
4203
|
-
// $reduce: {
|
|
4204
|
-
// input: '$answers',
|
|
4205
|
-
// initialValue: [],
|
|
4206
|
-
// in: {
|
|
4207
|
-
// $concatArrays: [
|
|
4208
|
-
// '$$value',
|
|
4209
|
-
// {
|
|
4210
|
-
// $reduce: {
|
|
4211
|
-
// input: { $ifNull: [ '$$this.issues', [] ] },
|
|
4212
|
-
// initialValue: [],
|
|
4213
|
-
// in: {
|
|
4214
|
-
// $concatArrays: [
|
|
4215
|
-
// '$$value',
|
|
4216
|
-
// { $ifNull: [ '$$this.Details', [] ] },
|
|
4217
|
-
// ],
|
|
4218
|
-
// },
|
|
4219
|
-
// },
|
|
4220
|
-
// },
|
|
4221
|
-
// ],
|
|
4222
|
-
// },
|
|
4223
|
-
// },
|
|
4224
|
-
// },
|
|
4225
|
-
// ],
|
|
4226
|
-
// },
|
|
4227
|
-
// as: 'detail',
|
|
4228
|
-
// in: {
|
|
4229
|
-
// $or: [ { $eq: [ '$$detail.status', 'disagree' ] } ],
|
|
4230
|
-
// },
|
|
4231
|
-
// },
|
|
4232
|
-
// },
|
|
4233
|
-
// },
|
|
4234
|
-
// },
|
|
4235
|
-
// },
|
|
4236
|
-
// {
|
|
4237
|
-
// $group: {
|
|
4238
|
-
// _id: '$floorId',
|
|
4239
|
-
// layoutCount: {
|
|
4240
|
-
// $sum: { $cond: [ { $eq: [ '$type', 'layout' ] }, 1, 0 ] },
|
|
4241
|
-
// },
|
|
4242
|
-
// fixtureCount: {
|
|
4243
|
-
// $sum: { $cond: [ { $eq: [ '$type', 'fixture' ] }, 1, 0 ] },
|
|
4244
|
-
// },
|
|
4245
|
-
// vmCount: {
|
|
4246
|
-
// $sum: { $cond: [ { $eq: [ '$type', 'vm' ] }, 1, 0 ] },
|
|
4247
|
-
// },
|
|
4248
|
-
// layoutPending: {
|
|
4249
|
-
// $sum: {
|
|
4250
|
-
// $cond: [
|
|
4251
|
-
// { $and: [ { $eq: [ '$type', 'layout' ] }, '$hasPendingIssues' ] },
|
|
4252
|
-
// 1,
|
|
4253
|
-
// 0,
|
|
4254
|
-
// ],
|
|
4255
|
-
// },
|
|
4256
|
-
// },
|
|
4257
|
-
// fixturePending: {
|
|
4258
|
-
// $sum: {
|
|
4259
|
-
// $cond: [
|
|
4260
|
-
// { $and: [ { $eq: [ '$type', 'fixture' ] }, { $or: [ '$hasPendingIssues', '$hasCompletedAnswers' ] } ] },
|
|
4261
|
-
// 1,
|
|
4262
|
-
// 0,
|
|
4263
|
-
// ],
|
|
4264
|
-
// },
|
|
4265
|
-
// },
|
|
4266
|
-
// fixtureApproved: {
|
|
4267
|
-
// $push: {
|
|
4268
|
-
// $cond: [
|
|
4269
|
-
// {
|
|
4270
|
-
// $and: [
|
|
4271
|
-
// { $eq: [ '$type', 'fixture' ] },
|
|
4272
|
-
// { $eq: [ '$approvalStatus', 'approved' ] },
|
|
4273
|
-
// ],
|
|
4274
|
-
// },
|
|
4275
|
-
// '$approvalStatus',
|
|
4276
|
-
// '$$REMOVE',
|
|
4277
|
-
// ],
|
|
4278
|
-
// },
|
|
4279
|
-
// },
|
|
4280
|
-
// vmPending: {
|
|
4281
|
-
// $sum: {
|
|
4282
|
-
// $cond: [
|
|
4283
|
-
// { $and: [ { $eq: [ '$type', 'vm' ] }, '$hasPendingIssues' ] },
|
|
4284
|
-
// 1,
|
|
4285
|
-
// 0,
|
|
4286
|
-
// ],
|
|
4287
|
-
// },
|
|
4288
|
-
// },
|
|
4289
|
-
// layoutDisagree: {
|
|
4290
|
-
// $sum: {
|
|
4291
|
-
// $cond: [
|
|
4292
|
-
// { $and: [ { $eq: [ '$type', 'layout' ] }, '$hasDisagreeIssues' ] },
|
|
4293
|
-
// 1,
|
|
4294
|
-
// 0,
|
|
4295
|
-
// ],
|
|
4296
|
-
// },
|
|
4297
|
-
// },
|
|
4298
|
-
// fixtureDisagree: {
|
|
4299
|
-
// $sum: {
|
|
4300
|
-
// $cond: [
|
|
4301
|
-
// { $and: [ { $eq: [ '$type', 'fixture' ] }, '$hasDisagreeIssues' ] },
|
|
4302
|
-
// 1,
|
|
4303
|
-
// 0,
|
|
4304
|
-
// ],
|
|
4305
|
-
// },
|
|
4306
|
-
// },
|
|
4307
|
-
// vmDisagree: {
|
|
4308
|
-
// $sum: {
|
|
4309
|
-
// $cond: [
|
|
4310
|
-
// { $and: [ { $eq: [ '$type', 'vm' ] }, '$hasDisagreeIssues' ] },
|
|
4311
|
-
// 1,
|
|
4312
|
-
// 0,
|
|
4313
|
-
// ],
|
|
4314
|
-
// },
|
|
4315
|
-
// },
|
|
4316
|
-
// },
|
|
4317
|
-
// },
|
|
4318
|
-
// {
|
|
4319
|
-
// $project: {
|
|
4320
|
-
// _id: 0,
|
|
4321
|
-
// layoutStatus: {
|
|
4322
|
-
// $cond: {
|
|
4323
|
-
// if: {
|
|
4324
|
-
// $and: [
|
|
4325
|
-
// { $gt: [ '$layoutCount', 0 ] },
|
|
4326
|
-
// { $eq: [ '$layoutPending', 0 ] },
|
|
4327
|
-
// { $eq: [ '$layoutDisagree', 0 ] },
|
|
4328
|
-
// ],
|
|
4329
|
-
// },
|
|
4330
|
-
// then: 'complete',
|
|
4331
|
-
// else: {
|
|
4332
|
-
// $cond: {
|
|
4333
|
-
// if: {
|
|
4334
|
-
// $and: [
|
|
4335
|
-
// {
|
|
4336
|
-
// $gt: [ '$layoutCount', 0 ],
|
|
4337
|
-
// },
|
|
4338
|
-
// {
|
|
4339
|
-
// $gt: [
|
|
4340
|
-
// '$layoutPending',
|
|
4341
|
-
// 0,
|
|
4342
|
-
// ],
|
|
4343
|
-
// },
|
|
4344
|
-
// ],
|
|
4345
|
-
// },
|
|
4346
|
-
// then: 'pending',
|
|
4347
|
-
// else: {
|
|
4348
|
-
// $cond: {
|
|
4349
|
-
// if: {
|
|
4350
|
-
// $and: [
|
|
4351
|
-
// {
|
|
4352
|
-
// $gt: [ '$layoutCount', 0 ],
|
|
4353
|
-
// },
|
|
4354
|
-
// {
|
|
4355
|
-
// $gt: [
|
|
4356
|
-
// '$layoutDisagree',
|
|
4357
|
-
// 0,
|
|
4358
|
-
// ],
|
|
4359
|
-
// },
|
|
4360
|
-
// ],
|
|
4361
|
-
// },
|
|
4362
|
-
// then: 'disagree',
|
|
4363
|
-
// else: '',
|
|
4364
|
-
// },
|
|
4365
|
-
// },
|
|
4366
|
-
// },
|
|
4367
|
-
// },
|
|
4368
|
-
// },
|
|
4369
|
-
// },
|
|
4370
|
-
// fixtureStatus: {
|
|
4371
|
-
// $cond: {
|
|
4372
|
-
// if: {
|
|
4373
|
-
// $and: [
|
|
4374
|
-
// { $gt: [ '$fixtureCount', 0 ] },
|
|
4375
|
-
// {
|
|
4376
|
-
// $eq: [ '$fixturePending', 0 ],
|
|
4377
|
-
// },
|
|
4378
|
-
// {
|
|
4379
|
-
// $eq: [ '$fixtureDisagree', 0 ],
|
|
4380
|
-
// },
|
|
4381
|
-
// {
|
|
4382
|
-
// $eq: [ { $size: '$fixtureApproved' }, '$fixtureCount' ],
|
|
4383
|
-
// },
|
|
4384
|
-
// ],
|
|
4385
|
-
// },
|
|
4386
|
-
// then: 'complete',
|
|
4387
|
-
// else: {
|
|
4388
|
-
// $cond: {
|
|
4389
|
-
// if: {
|
|
4390
|
-
// $and: [
|
|
4391
|
-
// {
|
|
4392
|
-
// $gt: [
|
|
4393
|
-
// '$fixtureCount',
|
|
4394
|
-
// 0,
|
|
4395
|
-
// ],
|
|
4396
|
-
// },
|
|
4397
|
-
// {
|
|
4398
|
-
// $gt: [
|
|
4399
|
-
// '$fixturePending',
|
|
4400
|
-
// 0,
|
|
4401
|
-
// ],
|
|
4402
|
-
// },
|
|
4403
|
-
// ],
|
|
4404
|
-
// },
|
|
4405
|
-
// then: 'pending',
|
|
4406
|
-
// else: {
|
|
4407
|
-
// $cond: {
|
|
4408
|
-
// if: {
|
|
4409
|
-
// $and: [
|
|
4410
|
-
// {
|
|
4411
|
-
// $gt: [ '$fixtureCount', 0 ],
|
|
4412
|
-
// },
|
|
4413
|
-
// {
|
|
4414
|
-
// $gt: [
|
|
4415
|
-
// '$fixtureDisagree',
|
|
4416
|
-
// 0,
|
|
4417
|
-
// ],
|
|
4418
|
-
// },
|
|
4419
|
-
// ],
|
|
4420
|
-
// },
|
|
4421
|
-
// then: 'disagree',
|
|
4422
|
-
// else: '',
|
|
4423
|
-
// },
|
|
4424
|
-
// },
|
|
4425
|
-
// },
|
|
4426
|
-
// },
|
|
4427
|
-
// },
|
|
4428
|
-
// },
|
|
4429
|
-
// vmStatus: {
|
|
4430
|
-
// $cond: {
|
|
4431
|
-
// if: {
|
|
4432
|
-
// $and: [
|
|
4433
|
-
// { $gt: [ '$vmCount', 0 ] },
|
|
4434
|
-
// { $eq: [ '$vmPending', 0 ] },
|
|
4435
|
-
// { $eq: [ '$vmDisagree', 0 ] },
|
|
4436
|
-
// ],
|
|
4437
|
-
// },
|
|
4438
|
-
// then: 'complete',
|
|
4439
|
-
// else: {
|
|
4440
|
-
// $cond: {
|
|
4441
|
-
// if: {
|
|
4442
|
-
// $and: [
|
|
4443
|
-
// { $gt: [ '$vmCount', 0 ] },
|
|
4444
|
-
// { $gt: [ '$vmPending', 0 ] },
|
|
4445
|
-
// ],
|
|
4446
|
-
// },
|
|
4447
|
-
// then: 'pending',
|
|
4448
|
-
// else: {
|
|
4449
|
-
// $cond: {
|
|
4450
|
-
// if: {
|
|
4451
|
-
// $and: [
|
|
4452
|
-
// {
|
|
4453
|
-
// $gt: [ '$vmCount', 0 ],
|
|
4454
|
-
// },
|
|
4455
|
-
// {
|
|
4456
|
-
// $gt: [
|
|
4457
|
-
// '$vmDisagree',
|
|
4458
|
-
// 0,
|
|
4459
|
-
// ],
|
|
4460
|
-
// },
|
|
4461
|
-
// ],
|
|
4462
|
-
// },
|
|
4463
|
-
// then: 'disagree',
|
|
4464
|
-
// else: '',
|
|
4465
|
-
// },
|
|
4466
|
-
// },
|
|
4467
|
-
// },
|
|
4468
|
-
// },
|
|
4469
|
-
// },
|
|
4470
|
-
// },
|
|
4471
|
-
// layoutPending: 1,
|
|
4472
|
-
// fixturePending: 1,
|
|
4473
|
-
// vmPending: 1,
|
|
4474
|
-
// layoutCount: 1,
|
|
4475
|
-
// fixtureCount: 1,
|
|
4476
|
-
// vmCount: 1,
|
|
4477
|
-
// // completeLayout: 1,
|
|
4478
|
-
// layoutDisagree: 1,
|
|
4479
|
-
// fixtureDisagree: 1,
|
|
4480
|
-
// vmDisagree: 1,
|
|
4481
|
-
// },
|
|
4482
|
-
// },
|
|
4483
|
-
// ],
|
|
4484
|
-
// ];
|
|
4485
|
-
// } ) );
|
|
4486
|
-
|
|
4487
|
-
// return res.sendSuccess( result );
|
|
4488
|
-
// } catch ( e ) {
|
|
4489
|
-
// logger.error( { functionName: 'planoList', error: e } );
|
|
4490
|
-
// return res.sendError( e, 500 );
|
|
4491
|
-
// }
|
|
4492
|
-
// }
|
|
4493
|
-
|
|
4494
|
-
// export async function getCardDetails( req, res ) {
|
|
4495
|
-
// try {
|
|
4496
|
-
// let storeDetails = await storeService.find( { clientId: inputData.clientId, status: 'active', ...( inputData?.stores?.length && { storeId: { $in: inputData.stores } } ) }, { storeId: 1 } );
|
|
4497
|
-
// storeDetails = storeDetails.map( ( ele ) => ele.storeId );
|
|
4498
|
-
|
|
4499
|
-
// let planoDetails = planoService.find( { storeId: { $in: storeDetails } }, { _id: 1 } );
|
|
4500
|
-
// if ( !planoDetails.length ) {
|
|
4501
|
-
// return res.sendError( 'No data found', 204 );
|
|
4502
|
-
// }
|
|
4503
|
-
// let planoIdList = planoDetails.map( ( ele ) => ele._id );
|
|
4504
|
-
// let taskQuery = [
|
|
4505
|
-
// {
|
|
4506
|
-
// $match: {
|
|
4507
|
-
// planoId: { $in: planoIdList },
|
|
4508
|
-
// isPlano: true,
|
|
4509
|
-
// date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
|
|
4510
|
-
// planoType: { $in: [ 'layout', 'fixture', 'vm' ] },
|
|
4511
|
-
// },
|
|
4512
|
-
// },
|
|
4513
|
-
// {
|
|
4514
|
-
// $group: {
|
|
4515
|
-
// _id: { store: '$storeName', floorId: '$floorId', type: '$planoType' },
|
|
4516
|
-
// planoId: { $last: '$planoId' },
|
|
4517
|
-
// checklistStatus: { $last: '$checklistStatus' },
|
|
4518
|
-
// taskId: { $last: '$_id' },
|
|
4519
|
-
// },
|
|
4520
|
-
// },
|
|
4521
|
-
// {
|
|
4522
|
-
// $match: {
|
|
4523
|
-
// checklistStatus: 'submit',
|
|
4524
|
-
// },
|
|
4525
|
-
// },
|
|
4526
|
-
// {
|
|
4527
|
-
// $project: {
|
|
4528
|
-
// _id: 0,
|
|
4529
|
-
// type: '$_id.type',
|
|
4530
|
-
// planoId: 1,
|
|
4531
|
-
// checklistStatus: 1,
|
|
4532
|
-
// taskId: 1,
|
|
4533
|
-
// floorId: '$_id.floorId',
|
|
4534
|
-
// },
|
|
4535
|
-
// },
|
|
4536
|
-
// ];
|
|
4537
|
-
|
|
4538
|
-
// let pendingDetails = await planotaskService.aggregate( taskQuery );
|
|
4539
|
-
// taskQuery = [
|
|
4540
|
-
// {
|
|
4541
|
-
// $match: {
|
|
4542
|
-
// taskId: { $in: pendingDetails.map( ( ele ) => ele.taskId ) },
|
|
4543
|
-
// // taskType: 'initial',
|
|
4544
|
-
// },
|
|
4545
|
-
// },
|
|
4546
|
-
// {
|
|
4547
|
-
// $set: {
|
|
4548
|
-
// hasCompletedAnswers: {
|
|
4549
|
-
// $anyElementTrue: {
|
|
4550
|
-
// $map: {
|
|
4551
|
-
// input: '$answers',
|
|
4552
|
-
// as: 'ans',
|
|
4553
|
-
// in: { $eq: [ { $ifNull: [ '$$ans.status', null ] }, null ] },
|
|
4554
|
-
// },
|
|
4555
|
-
// },
|
|
4556
|
-
// },
|
|
4557
|
-
// hasPendingIssues: {
|
|
4558
|
-
// $anyElementTrue: {
|
|
4559
|
-
// $map: {
|
|
4560
|
-
// input: {
|
|
4561
|
-
// $reduce: {
|
|
4562
|
-
// input: '$answers',
|
|
4563
|
-
// initialValue: [],
|
|
4564
|
-
// in: {
|
|
4565
|
-
// $concatArrays: [
|
|
4566
|
-
// '$$value',
|
|
4567
|
-
// {
|
|
4568
|
-
// $reduce: {
|
|
4569
|
-
// input: { $ifNull: [ '$$this.issues', [] ] },
|
|
4570
|
-
// initialValue: [],
|
|
4571
|
-
// in: {
|
|
4572
|
-
// $concatArrays: [
|
|
4573
|
-
// '$$value',
|
|
4574
|
-
// { $ifNull: [ '$$this.Details', [] ] },
|
|
4575
|
-
// ],
|
|
4576
|
-
// },
|
|
4577
|
-
// },
|
|
4578
|
-
// },
|
|
4579
|
-
// ],
|
|
4580
|
-
// },
|
|
4581
|
-
// },
|
|
4582
|
-
// },
|
|
4583
|
-
// as: 'detail',
|
|
4584
|
-
// in: {
|
|
4585
|
-
// $or: [
|
|
4586
|
-
// { $eq: [ '$$detail.status', 'pending' ] },
|
|
4587
|
-
// ],
|
|
4588
|
-
// },
|
|
4589
|
-
// },
|
|
4590
|
-
// },
|
|
4591
|
-
// },
|
|
4592
|
-
// },
|
|
4593
|
-
// },
|
|
4594
|
-
// {
|
|
4595
|
-
// $group: {
|
|
4596
|
-
// _id: { type: '$type', planoId: '$planoId' },
|
|
4597
|
-
// layoutPending: {
|
|
4598
|
-
// $sum: {
|
|
4599
|
-
// $cond: [
|
|
4600
|
-
// { $and: [ { $eq: [ '$type', 'layout' ] }, '$hasPendingIssues' ] },
|
|
4601
|
-
// 1,
|
|
4602
|
-
// 0,
|
|
4603
|
-
// ],
|
|
4604
|
-
// },
|
|
4605
|
-
// },
|
|
4606
|
-
// fixturePending: {
|
|
4607
|
-
// $sum: {
|
|
4608
|
-
// $cond: [
|
|
4609
|
-
// { $and: [ { $eq: [ '$type', 'fixture' ] }, { $or: [ '$hasPendingIssues', '$hasCompletedAnswers' ] } ] },
|
|
4610
|
-
// 1,
|
|
4611
|
-
// 0,
|
|
4612
|
-
// ],
|
|
4613
|
-
// },
|
|
4614
|
-
// },
|
|
4615
|
-
// vmPending: {
|
|
4616
|
-
// $sum: {
|
|
4617
|
-
// $cond: [
|
|
4618
|
-
// { $and: [ { $eq: [ '$type', 'vm' ] }, '$hasPendingIssues' ] },
|
|
4619
|
-
// 1,
|
|
4620
|
-
// 0,
|
|
4621
|
-
// ],
|
|
4622
|
-
// },
|
|
4623
|
-
// },
|
|
4624
|
-
// },
|
|
4625
|
-
// },
|
|
4626
|
-
// {
|
|
4627
|
-
// $group: {
|
|
4628
|
-
// _id: 0,
|
|
4629
|
-
// layoutPending: {
|
|
4630
|
-
// $sum: { $cond: {
|
|
4631
|
-
// if: {
|
|
4632
|
-
// $gt: [ '$layoutPending', 0 ],
|
|
4633
|
-
// },
|
|
4634
|
-
// then: 1,
|
|
4635
|
-
// else: 0,
|
|
4636
|
-
// } },
|
|
4637
|
-
// },
|
|
4638
|
-
// fixturePending: {
|
|
4639
|
-
// $sum: { $cond: {
|
|
4640
|
-
// if: {
|
|
4641
|
-
// $gt: [ '$fixturePending', 0 ],
|
|
4642
|
-
// },
|
|
4643
|
-
// then: 1,
|
|
4644
|
-
// else: 0,
|
|
4645
|
-
// } },
|
|
4646
|
-
// },
|
|
4647
|
-
// vmPending: {
|
|
4648
|
-
// $sum: { $cond: {
|
|
4649
|
-
// if: {
|
|
4650
|
-
// $gt: [ '$vmPending', 0 ],
|
|
4651
|
-
// },
|
|
4652
|
-
// then: 1,
|
|
4653
|
-
// else: 0,
|
|
4654
|
-
// } },
|
|
4655
|
-
// },
|
|
4656
|
-
// },
|
|
4657
|
-
// },
|
|
4658
|
-
// {
|
|
4659
|
-
// $project: {
|
|
4660
|
-
// _id: 0,
|
|
4661
|
-
// layoutPending: '$layoutPending',
|
|
4662
|
-
// fixturePending: '$fixturePending',
|
|
4663
|
-
// vmPending: '$vmPending',
|
|
4664
|
-
// },
|
|
4665
|
-
// },
|
|
4666
|
-
// ];
|
|
4667
|
-
|
|
4668
|
-
// pendingDetails = await planoTaskComplianceService.aggregate( taskQuery );
|
|
4669
|
-
// return res.sendSuccess( { ...pendingDetails?.[0], allStores: planoDetails?.length || 0 } );
|
|
4670
|
-
// } catch ( e ) {
|
|
4671
|
-
// logger.error( { functioName: 'getCardDetails', error: e } );
|
|
4672
|
-
// return res.sendError( e, 500 );
|
|
4673
|
-
// }
|
|
4674
|
-
// }
|
|
4675
|
-
|
|
4676
5011
|
export async function planoList( req, res ) {
|
|
4677
5012
|
try {
|
|
4678
5013
|
let inputData = req.body;
|
|
@@ -7139,6 +7474,75 @@ export async function calculateCompliance( req, res ) {
|
|
|
7139
7474
|
_id: 0,
|
|
7140
7475
|
date: '$_id',
|
|
7141
7476
|
count: 1,
|
|
7477
|
+
time: {
|
|
7478
|
+
$let: {
|
|
7479
|
+
vars: {
|
|
7480
|
+
h: {
|
|
7481
|
+
$hour: {
|
|
7482
|
+
date: '$_id',
|
|
7483
|
+
timezone: 'Asia/Kolkata',
|
|
7484
|
+
},
|
|
7485
|
+
},
|
|
7486
|
+
m: {
|
|
7487
|
+
$minute: {
|
|
7488
|
+
date: '$_id',
|
|
7489
|
+
timezone: 'Asia/Kolkata',
|
|
7490
|
+
},
|
|
7491
|
+
},
|
|
7492
|
+
},
|
|
7493
|
+
in: {
|
|
7494
|
+
$concat: [
|
|
7495
|
+
{
|
|
7496
|
+
$toString: {
|
|
7497
|
+
$cond: [
|
|
7498
|
+
{ $eq: [ '$$h', 0 ] }, 12,
|
|
7499
|
+
{
|
|
7500
|
+
$cond: [
|
|
7501
|
+
{ $gt: [ '$$h', 12 ] },
|
|
7502
|
+
{ $subtract: [ '$$h', 12 ] },
|
|
7503
|
+
'$$h',
|
|
7504
|
+
],
|
|
7505
|
+
},
|
|
7506
|
+
],
|
|
7507
|
+
},
|
|
7508
|
+
},
|
|
7509
|
+
':',
|
|
7510
|
+
{
|
|
7511
|
+
$cond: [
|
|
7512
|
+
{ $lt: [ '$$m', 10 ] },
|
|
7513
|
+
{ $concat: [ '0', { $toString: '$$m' } ] },
|
|
7514
|
+
{ $toString: '$$m' },
|
|
7515
|
+
],
|
|
7516
|
+
},
|
|
7517
|
+
' ',
|
|
7518
|
+
{
|
|
7519
|
+
$cond: [
|
|
7520
|
+
{ $lt: [ '$$h', 12 ] },
|
|
7521
|
+
'AM',
|
|
7522
|
+
'PM',
|
|
7523
|
+
],
|
|
7524
|
+
},
|
|
7525
|
+
],
|
|
7526
|
+
},
|
|
7527
|
+
},
|
|
7528
|
+
},
|
|
7529
|
+
amPm: {
|
|
7530
|
+
$cond: [
|
|
7531
|
+
{
|
|
7532
|
+
$lt: [
|
|
7533
|
+
{
|
|
7534
|
+
$hour: {
|
|
7535
|
+
date: '$_id',
|
|
7536
|
+
timezone: 'Asia/Kolkata',
|
|
7537
|
+
},
|
|
7538
|
+
},
|
|
7539
|
+
12,
|
|
7540
|
+
],
|
|
7541
|
+
},
|
|
7542
|
+
'AM',
|
|
7543
|
+
'PM',
|
|
7544
|
+
],
|
|
7545
|
+
},
|
|
7142
7546
|
},
|
|
7143
7547
|
},
|
|
7144
7548
|
{
|
|
@@ -7149,6 +7553,7 @@ export async function calculateCompliance( req, res ) {
|
|
|
7149
7553
|
},
|
|
7150
7554
|
];
|
|
7151
7555
|
let getCompliance = await planoComplianceService.aggregate( query );
|
|
7556
|
+
|
|
7152
7557
|
let result = {
|
|
7153
7558
|
merchCompliance: 0,
|
|
7154
7559
|
previousMerchCompliance: 0,
|
|
@@ -7177,21 +7582,28 @@ export async function calculateCompliance( req, res ) {
|
|
|
7177
7582
|
},
|
|
7178
7583
|
];
|
|
7179
7584
|
let totalProducts = await storeFixtureService.aggregate( productCountQuery );
|
|
7585
|
+
function formatPercentage( value ) {
|
|
7586
|
+
if ( value >= 100 ) return 100;
|
|
7587
|
+
|
|
7588
|
+
const truncated = Math.floor( value * 10 ) / 10;
|
|
7589
|
+
|
|
7590
|
+
return Number.isInteger( truncated ) ? Math.trunc( truncated ) : truncated;
|
|
7591
|
+
}
|
|
7180
7592
|
if ( totalProducts.length ) {
|
|
7181
|
-
result.merchCompliance =
|
|
7182
|
-
let previousMerchCompliance = getCompliance?.[1]?.count ?
|
|
7183
|
-
if (
|
|
7593
|
+
result.merchCompliance =formatPercentage( ( getCompliance?.[0]?.count / totalProducts?.[0]?.productCount ) * 100 );
|
|
7594
|
+
let previousMerchCompliance = getCompliance?.[1]?.count ? formatPercentage( ( getCompliance?.[1]?.count / totalProducts?.[0]?.productCount ) * 100 ) : 0;
|
|
7595
|
+
if ( getCompliance.length > 1 && result.merchCompliance != previousMerchCompliance ) {
|
|
7184
7596
|
if ( result.merchCompliance > previousMerchCompliance ) {
|
|
7185
7597
|
let diff = result.merchCompliance - previousMerchCompliance;
|
|
7186
|
-
result.previousMerchCompliance = diff;
|
|
7598
|
+
result.previousMerchCompliance = formatPercentage( diff );
|
|
7187
7599
|
result.rateIncrease = true;
|
|
7188
7600
|
} else {
|
|
7189
7601
|
let diff = previousMerchCompliance - result.merchCompliance;
|
|
7190
|
-
result.previousMerchCompliance = diff;
|
|
7602
|
+
result.previousMerchCompliance = formatPercentage( diff );
|
|
7191
7603
|
result.rateIncrease = false;
|
|
7192
7604
|
}
|
|
7193
7605
|
}
|
|
7194
|
-
result.lastCheck =
|
|
7606
|
+
result.lastCheck = `${getCompliance?.[0]?.time}`;
|
|
7195
7607
|
}
|
|
7196
7608
|
}
|
|
7197
7609
|
return res.sendSuccess( result );
|
|
@@ -7200,6 +7612,7 @@ export async function calculateCompliance( req, res ) {
|
|
|
7200
7612
|
return res.sendError( e, 500 );
|
|
7201
7613
|
}
|
|
7202
7614
|
}
|
|
7615
|
+
|
|
7203
7616
|
export async function getPlanogramList( req, res ) {
|
|
7204
7617
|
try {
|
|
7205
7618
|
const {
|
|
@@ -7209,13 +7622,40 @@ export async function getPlanogramList( req, res ) {
|
|
|
7209
7622
|
searchValue = '',
|
|
7210
7623
|
sortColumnName = '',
|
|
7211
7624
|
sortBy = '',
|
|
7625
|
+
filter = {},
|
|
7212
7626
|
} = req.body;
|
|
7213
7627
|
|
|
7214
7628
|
const page = Math.max( offset - 1, 0 );
|
|
7215
7629
|
const skip = page * limit;
|
|
7216
7630
|
|
|
7631
|
+
const today = new Date( dayjs().format( 'YYYY-MM-DD' ) );
|
|
7632
|
+
|
|
7633
|
+
const storeQuery = { clientId };
|
|
7634
|
+
|
|
7635
|
+
if ( filter?.country?.length ) {
|
|
7636
|
+
storeQuery['storeProfile.country'] = { $in: filter.country };
|
|
7637
|
+
}
|
|
7638
|
+
|
|
7639
|
+
if ( filter?.city?.length ) {
|
|
7640
|
+
storeQuery['storeProfile.city'] = { $in: filter.city };
|
|
7641
|
+
}
|
|
7642
|
+
|
|
7643
|
+
const storeDocs = await storeService.find( storeQuery );
|
|
7644
|
+
|
|
7645
|
+
if ( !storeDocs.length ) {
|
|
7646
|
+
return res.sendSuccess( { data: [], count: 0 } );
|
|
7647
|
+
}
|
|
7648
|
+
|
|
7649
|
+
const allowedStoreIds = storeDocs.map( ( s ) => s.storeId );
|
|
7650
|
+
|
|
7217
7651
|
const pipeline = [
|
|
7218
|
-
{
|
|
7652
|
+
{
|
|
7653
|
+
$match: {
|
|
7654
|
+
clientId,
|
|
7655
|
+
storeId: { $in: allowedStoreIds },
|
|
7656
|
+
},
|
|
7657
|
+
},
|
|
7658
|
+
|
|
7219
7659
|
{
|
|
7220
7660
|
$lookup: {
|
|
7221
7661
|
from: 'storefixtures',
|
|
@@ -7225,15 +7665,8 @@ export async function getPlanogramList( req, res ) {
|
|
|
7225
7665
|
$match: {
|
|
7226
7666
|
$expr: {
|
|
7227
7667
|
$and: [
|
|
7228
|
-
{ $eq: [
|
|
7229
|
-
|
|
7230
|
-
],
|
|
7231
|
-
},
|
|
7232
|
-
{
|
|
7233
|
-
$eq: [
|
|
7234
|
-
'$floorId', '$$floor',
|
|
7235
|
-
],
|
|
7236
|
-
},
|
|
7668
|
+
{ $eq: [ '$planoId', '$$plano' ] },
|
|
7669
|
+
{ $eq: [ '$floorId', '$$floor' ] },
|
|
7237
7670
|
],
|
|
7238
7671
|
},
|
|
7239
7672
|
},
|
|
@@ -7248,6 +7681,7 @@ export async function getPlanogramList( req, res ) {
|
|
|
7248
7681
|
as: 'fixtureDetails',
|
|
7249
7682
|
},
|
|
7250
7683
|
},
|
|
7684
|
+
|
|
7251
7685
|
{
|
|
7252
7686
|
$lookup: {
|
|
7253
7687
|
from: 'planocompliances',
|
|
@@ -7257,42 +7691,23 @@ export async function getPlanogramList( req, res ) {
|
|
|
7257
7691
|
$match: {
|
|
7258
7692
|
$expr: {
|
|
7259
7693
|
$and: [
|
|
7260
|
-
{
|
|
7261
|
-
|
|
7262
|
-
},
|
|
7263
|
-
{
|
|
7264
|
-
$eq: [ '$floorId', '$$floor' ],
|
|
7265
|
-
},
|
|
7266
|
-
{
|
|
7267
|
-
$eq: [ '$date', new Date( dayjs().format( 'YYYY-MM-DD' ) ) ],
|
|
7268
|
-
},
|
|
7694
|
+
{ $eq: [ '$planoId', '$$plano' ] },
|
|
7695
|
+
{ $eq: [ '$floorId', '$$floor' ] },
|
|
7696
|
+
{ $eq: [ '$date', today ] },
|
|
7697
|
+
{ $eq: [ '$compliance', 'proper' ] },
|
|
7269
7698
|
],
|
|
7270
7699
|
},
|
|
7271
7700
|
},
|
|
7272
7701
|
},
|
|
7273
|
-
{
|
|
7274
|
-
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
},
|
|
7278
|
-
},
|
|
7279
|
-
{
|
|
7280
|
-
$project: {
|
|
7281
|
-
_id: 0,
|
|
7282
|
-
date: '$_id',
|
|
7283
|
-
count: 1,
|
|
7284
|
-
},
|
|
7285
|
-
},
|
|
7286
|
-
{
|
|
7287
|
-
$sort: { date: -1 },
|
|
7288
|
-
},
|
|
7289
|
-
{
|
|
7290
|
-
$limit: 1,
|
|
7291
|
-
},
|
|
7702
|
+
{ $group: { _id: '$createdAt', count: { $sum: 1 } } },
|
|
7703
|
+
{ $project: { _id: 0, date: '$_id', count: 1 } },
|
|
7704
|
+
{ $sort: { date: -1 } },
|
|
7705
|
+
{ $limit: 1 },
|
|
7292
7706
|
],
|
|
7293
7707
|
as: 'complianceCount',
|
|
7294
7708
|
},
|
|
7295
7709
|
},
|
|
7710
|
+
|
|
7296
7711
|
{
|
|
7297
7712
|
$project: {
|
|
7298
7713
|
_id: 1,
|
|
@@ -7309,22 +7724,34 @@ export async function getPlanogramList( req, res ) {
|
|
|
7309
7724
|
fixtureDetails: 1,
|
|
7310
7725
|
complianceCount: 1,
|
|
7311
7726
|
merchCompliance: {
|
|
7312
|
-
$
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7727
|
+
$round: [
|
|
7728
|
+
{
|
|
7729
|
+
$multiply: [
|
|
7730
|
+
{
|
|
7731
|
+
$divide: [
|
|
7732
|
+
{ $ifNull: [ { $arrayElemAt: [ '$complianceCount.count', 0 ] }, 0 ] },
|
|
7733
|
+
{ $ifNull: [ { $arrayElemAt: [ '$fixtureDetails.productCount', 0 ] }, 1 ] },
|
|
7734
|
+
],
|
|
7735
|
+
},
|
|
7736
|
+
100,
|
|
7737
|
+
],
|
|
7738
|
+
},
|
|
7739
|
+
1,
|
|
7740
|
+
],
|
|
7323
7741
|
},
|
|
7324
7742
|
},
|
|
7325
7743
|
},
|
|
7326
7744
|
];
|
|
7327
7745
|
|
|
7746
|
+
if ( filter?.compliance?.length === 2 ) {
|
|
7747
|
+
const [ minC, maxC ] = filter.compliance.map( Number );
|
|
7748
|
+
pipeline.push( {
|
|
7749
|
+
$match: {
|
|
7750
|
+
merchCompliance: { $gte: minC, $lte: maxC },
|
|
7751
|
+
},
|
|
7752
|
+
} );
|
|
7753
|
+
}
|
|
7754
|
+
|
|
7328
7755
|
if ( searchValue?.trim() ) {
|
|
7329
7756
|
const values = searchValue.split( ',' ).map( ( s ) => s.trim().toLowerCase() );
|
|
7330
7757
|
|
|
@@ -7348,26 +7775,39 @@ export async function getPlanogramList( req, res ) {
|
|
|
7348
7775
|
|
|
7349
7776
|
pipeline.push( {
|
|
7350
7777
|
$facet: {
|
|
7351
|
-
data: [
|
|
7352
|
-
{ $skip: skip },
|
|
7353
|
-
{ $limit: limit },
|
|
7354
|
-
],
|
|
7778
|
+
data: [ { $skip: skip }, { $limit: limit } ],
|
|
7355
7779
|
count: [ { $count: 'total' } ],
|
|
7356
7780
|
},
|
|
7357
7781
|
} );
|
|
7358
7782
|
|
|
7359
7783
|
const result = await layoutService.aggregate( pipeline );
|
|
7360
7784
|
|
|
7361
|
-
|
|
7785
|
+
let data = result?.[0]?.data || [];
|
|
7362
7786
|
const total = result?.[0]?.count?.[0]?.total || 0;
|
|
7363
7787
|
|
|
7364
|
-
if ( data.length
|
|
7788
|
+
if ( !data.length ) {
|
|
7365
7789
|
return res.sendError( 'No data found', 204 );
|
|
7366
7790
|
}
|
|
7367
7791
|
|
|
7368
|
-
|
|
7792
|
+
const storeMap = {};
|
|
7793
|
+
storeDocs.forEach( ( st ) => {
|
|
7794
|
+
storeMap[st.storeId] = st;
|
|
7795
|
+
} );
|
|
7796
|
+
|
|
7797
|
+
data = data.map( ( d ) => {
|
|
7798
|
+
const st = storeMap[d.storeId];
|
|
7799
|
+
d.storeInfo = st ?
|
|
7800
|
+
{
|
|
7801
|
+
country: st.storeProfile?.country,
|
|
7802
|
+
state: st.storeProfile?.state,
|
|
7803
|
+
city: st.storeProfile?.city,
|
|
7804
|
+
} :
|
|
7805
|
+
null;
|
|
7806
|
+
|
|
7369
7807
|
d.createdAt = dayjs.utc( d.createdAt ).format( 'DD MMM, YYYY' );
|
|
7370
7808
|
d.updatedAt = dayjs.utc( d.updatedAt ).format( 'DD MMM, YYYY' );
|
|
7809
|
+
|
|
7810
|
+
return d;
|
|
7371
7811
|
} );
|
|
7372
7812
|
|
|
7373
7813
|
return res.sendSuccess( { data, count: total } );
|
|
@@ -7376,3 +7816,12 @@ export async function getPlanogramList( req, res ) {
|
|
|
7376
7816
|
return res.sendError( err, 500 );
|
|
7377
7817
|
}
|
|
7378
7818
|
}
|
|
7819
|
+
|
|
7820
|
+
export async function updatePlanoRevison( req, res ) {
|
|
7821
|
+
try {
|
|
7822
|
+
|
|
7823
|
+
} catch ( e ) {
|
|
7824
|
+
logger.error( { functionName: 'updatePlanoRevison', error: e } );
|
|
7825
|
+
return res.sendError( e, 500 );
|
|
7826
|
+
}
|
|
7827
|
+
}
|