tango-app-api-store-builder 1.0.0-beta-123 → 1.0.0-beta-125
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/managePlano.controller.js +55 -5
- package/src/controllers/planoLibrary.controller.js +9 -8
- package/src/controllers/script.controller.js +35 -0
- package/src/controllers/storeBuilder.controller.js +240 -204
- package/src/controllers/task.controller.js +187 -141
- package/src/routes/managePlano.routes.js +1 -1
- package/src/service/assignService.service.js +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-store-builder",
|
|
3
|
-
"version": "1.0.0-beta-
|
|
3
|
+
"version": "1.0.0-beta-125",
|
|
4
4
|
"description": "storeBuilder",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"path": "^0.12.7",
|
|
33
33
|
"selenium-webdriver": "^4.31.0",
|
|
34
34
|
"sharp": "^0.34.1",
|
|
35
|
-
"tango-api-schema": "2.2.
|
|
35
|
+
"tango-api-schema": "2.2.162",
|
|
36
36
|
"tango-app-api-middleware": "3.1.48",
|
|
37
37
|
"url": "^0.11.4",
|
|
38
38
|
"winston": "^3.17.0",
|
|
@@ -53,6 +53,7 @@ export async function getplanoFeedback( req, res ) {
|
|
|
53
53
|
},
|
|
54
54
|
|
|
55
55
|
}, { $unwind: { path: '$taskData', preserveNullAndEmptyArrays: true } },
|
|
56
|
+
{ $sort: { _id: -1 } },
|
|
56
57
|
);
|
|
57
58
|
|
|
58
59
|
|
|
@@ -474,9 +475,9 @@ export async function updateFixtureStatus( req, res ) {
|
|
|
474
475
|
console.log( updateResponse.answers[0] );
|
|
475
476
|
let findissuse= updateResponse.answers[0].issues.filter( ( data ) => data._id==req.body.issueId );
|
|
476
477
|
console.log( findissuse );
|
|
477
|
-
let findDetails = findissuse[0].Details.filter( ( det ) => det.status==='
|
|
478
|
+
let findDetails = findissuse[0].Details.filter( ( det ) => det.status==='agree' );
|
|
478
479
|
console.log( '======', findDetails.length );
|
|
479
|
-
if ( findDetails.length
|
|
480
|
+
if ( findissuse[0].Details.length=== findDetails.length ) {
|
|
480
481
|
await planoTaskService.updateOnefilters(
|
|
481
482
|
{ _id: new mongoose.Types.ObjectId( req.body._id ) },
|
|
482
483
|
{
|
|
@@ -485,10 +486,22 @@ export async function updateFixtureStatus( req, res ) {
|
|
|
485
486
|
[
|
|
486
487
|
{ 'ans._id': new mongoose.Types.ObjectId( req.body.answerId ) },
|
|
487
488
|
{ 'iss._id': new mongoose.Types.ObjectId( req.body.issueId ) },
|
|
488
|
-
|
|
489
|
-
|
|
490
489
|
] );
|
|
491
490
|
}
|
|
491
|
+
let findoneplanoData = await planoTaskService.findOne( { _id: new mongoose.Types.ObjectId( req.body._id ) } );
|
|
492
|
+
console.log( '************', findoneplanoData.answers[0].issues );
|
|
493
|
+
let totalApproved= findoneplanoData.answers[0].issues.filter( ( data ) => data.status==='pending' );
|
|
494
|
+
console.log( '---------->', totalApproved.length );
|
|
495
|
+
if ( totalApproved.length===0 ) {
|
|
496
|
+
await planoTaskService.updateOne(
|
|
497
|
+
{
|
|
498
|
+
_id: new mongoose.Types.ObjectId( req.body._id ),
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
'status': 'complete',
|
|
502
|
+
},
|
|
503
|
+
);
|
|
504
|
+
}
|
|
492
505
|
}
|
|
493
506
|
|
|
494
507
|
if ( req.body.taskType==='layout' ) {
|
|
@@ -556,7 +569,7 @@ export async function updateStoreFixture( req, res ) {
|
|
|
556
569
|
currentFixtureDoc = {
|
|
557
570
|
...currentFixtureDoc,
|
|
558
571
|
...newTemplate.toObject(),
|
|
559
|
-
|
|
572
|
+
fixtureConfigId: newTemplate.toObject()._id,
|
|
560
573
|
productBrandName: [ ...productBrandName ],
|
|
561
574
|
productCategory: [ ...productCategory ],
|
|
562
575
|
productSubCategory: [ ...productSubCategory ],
|
|
@@ -602,3 +615,40 @@ export async function updateStoreFixture( req, res ) {
|
|
|
602
615
|
}
|
|
603
616
|
}
|
|
604
617
|
|
|
618
|
+
export async function updateredostatus( req, res ) {
|
|
619
|
+
try {
|
|
620
|
+
console.log( '------->', req.body );
|
|
621
|
+
if ( req.body.type==='layout' ) {
|
|
622
|
+
await planoTaskService.updateOne(
|
|
623
|
+
{
|
|
624
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
625
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
626
|
+
type: req.body.type,
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
'answers.$[].issues.$[].status': 'completed',
|
|
630
|
+
'answers.$[].issues.$[].Details.$[].status': 'agree',
|
|
631
|
+
'status': 'complete',
|
|
632
|
+
},
|
|
633
|
+
);
|
|
634
|
+
} else {
|
|
635
|
+
await planoTaskService.updateOne(
|
|
636
|
+
{
|
|
637
|
+
planoId: new mongoose.Types.ObjectId( req.body.planoId ),
|
|
638
|
+
floorId: new mongoose.Types.ObjectId( req.body.floorId ),
|
|
639
|
+
fixtureId: new mongoose.Types.ObjectId( req.body.fixtureId ),
|
|
640
|
+
type: req.body.type,
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
'answers.$[].issues.$[].status': 'completed',
|
|
644
|
+
'answers.$[].issues.$[].Details.$[].status': 'agree',
|
|
645
|
+
'status': 'complete',
|
|
646
|
+
},
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
res.sendSuccess( 'updated successfully' );
|
|
650
|
+
} catch ( e ) {
|
|
651
|
+
logger.error( { functionName: 'updateredostatus', error: e } );
|
|
652
|
+
return res.sendError( e, 500 );
|
|
653
|
+
}
|
|
654
|
+
}
|
|
@@ -1327,18 +1327,19 @@ export async function getVmDetails( req, res ) {
|
|
|
1327
1327
|
return res.sendError( 'No data found', 204 );
|
|
1328
1328
|
}
|
|
1329
1329
|
getVmDetails = getVmDetails.toObject();
|
|
1330
|
+
getVmDetails.templateCount = 0;
|
|
1330
1331
|
let templateDetails = await fixtureTemplateService.find( { 'vmConfig.vmId': { $in: req.query.vmId } } );
|
|
1331
1332
|
if ( templateDetails.length && getVmDetails.status != 'draft' ) {
|
|
1332
1333
|
getVmDetails.templateCount = templateDetails.length;
|
|
1333
1334
|
getVmDetails.status = 'inactive';
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1335
|
+
let fixtureDetails = await storeFixtureService.find( { 'vmConfig.vmId': { $in: req.query.vmId } }, { planoId: 1 } );
|
|
1336
|
+
if ( fixtureDetails.length ) {
|
|
1337
|
+
let planoList = fixtureDetails.map( ( ele ) => ele.planoId );
|
|
1338
|
+
let planoDetails = await planoService.find( { _id: { $in: planoList } }, { status: 1 } );
|
|
1339
|
+
planoDetails = planoDetails.map( ( ele ) => ele.status );
|
|
1340
|
+
if ( planoDetails.includes( 'completed' ) ) {
|
|
1341
|
+
getVmDetails.status = 'active';
|
|
1342
|
+
}
|
|
1342
1343
|
}
|
|
1343
1344
|
}
|
|
1344
1345
|
return res.sendSuccess( getVmDetails );
|
|
@@ -8619,3 +8619,38 @@ export async function migrateCrestv1( req, res ) {
|
|
|
8619
8619
|
// exportFixtureJsonToExcel( fixtures, 'output.xlsx' );
|
|
8620
8620
|
|
|
8621
8621
|
|
|
8622
|
+
// import { readFile, writeFile } from 'fs/promises';
|
|
8623
|
+
|
|
8624
|
+
|
|
8625
|
+
// try {
|
|
8626
|
+
// const raw = await readFile('response.json', 'utf-8');
|
|
8627
|
+
// const json = JSON.parse(raw);
|
|
8628
|
+
|
|
8629
|
+
// const resultArray = json;
|
|
8630
|
+
// const uniqueTypes = new Set();
|
|
8631
|
+
|
|
8632
|
+
// for (const obj of resultArray) {
|
|
8633
|
+
// for (const item of obj.data?.result) {
|
|
8634
|
+
// if (Array.isArray(item.fixtures)) {
|
|
8635
|
+
// for (const fixture of item.fixtures) {
|
|
8636
|
+
// console.log(fixture)
|
|
8637
|
+
// const { fixtureName } = fixture;
|
|
8638
|
+
// if (fixtureName) {
|
|
8639
|
+
// const parts = fixtureName.split(' - ');
|
|
8640
|
+
// if (parts.length >= 3) {
|
|
8641
|
+
// const type = parts.slice(2).join(' - ');
|
|
8642
|
+
// uniqueTypes.add(type);
|
|
8643
|
+
// }
|
|
8644
|
+
// }
|
|
8645
|
+
// }
|
|
8646
|
+
// }
|
|
8647
|
+
// }
|
|
8648
|
+
|
|
8649
|
+
|
|
8650
|
+
// }
|
|
8651
|
+
|
|
8652
|
+
// await writeFile('unique.json', JSON.stringify([...uniqueTypes], null, 2), 'utf-8');
|
|
8653
|
+
|
|
8654
|
+
// } catch (err) {
|
|
8655
|
+
// console.error('Error processing file:', err);
|
|
8656
|
+
// }
|
|
@@ -2983,6 +2983,7 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
2983
2983
|
let productCapacity = 0;
|
|
2984
2984
|
let fixtureCount = 0;
|
|
2985
2985
|
let totalVmCount = 0;
|
|
2986
|
+
let redoCount = 0;
|
|
2986
2987
|
const layoutPolygonWithFixtures = await Promise.all(
|
|
2987
2988
|
floor.layoutPolygon.map( async ( element ) => {
|
|
2988
2989
|
const fixtures = await storeFixtureService.findAndSort( {
|
|
@@ -3012,7 +3013,6 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
3012
3013
|
const compliance = await planoTaskComplianceService.findOne( {
|
|
3013
3014
|
fixtureId: fixture._id,
|
|
3014
3015
|
type: req.body?.type ? req.body.type : 'fixture',
|
|
3015
|
-
date_string: req.body?.date,
|
|
3016
3016
|
}, { status: 1, answers: 1 } );
|
|
3017
3017
|
|
|
3018
3018
|
const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { }, { shelfNumber: 1 } );
|
|
@@ -3043,8 +3043,14 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
3043
3043
|
|
|
3044
3044
|
let disabled = true;
|
|
3045
3045
|
if ( compliance?.status && compliance.status == 'incomplete' ) {
|
|
3046
|
-
|
|
3047
|
-
|
|
3046
|
+
const hasDisagree = compliance?.answers?.some( ( answer ) =>
|
|
3047
|
+
answer?.issues?.some( ( issue ) =>
|
|
3048
|
+
issue?.Details?.some( ( detail ) => detail.status === 'disagree' ),
|
|
3049
|
+
),
|
|
3050
|
+
);
|
|
3051
|
+
|
|
3052
|
+
if ( hasDisagree ) {
|
|
3053
|
+
redoCount++;
|
|
3048
3054
|
disabled = false;
|
|
3049
3055
|
}
|
|
3050
3056
|
}
|
|
@@ -3102,7 +3108,6 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
3102
3108
|
const compliance = await planoTaskComplianceService.findOne( {
|
|
3103
3109
|
fixtureId: fixture._id,
|
|
3104
3110
|
type: req.body?.type ? req.body.type : 'fixture',
|
|
3105
|
-
date_string: req.body?.date,
|
|
3106
3111
|
}, { status: 1 } );
|
|
3107
3112
|
|
|
3108
3113
|
const shelves = await fixtureShelfService.findAndSort( { fixtureId: fixture._id }, { }, { shelfNumber: 1 } );
|
|
@@ -3124,7 +3129,6 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
3124
3129
|
const vmDetails = await Promise.all( fixture.toObject()?.vmConfig?.map( async ( vm ) => {
|
|
3125
3130
|
totalVmCount += 1;
|
|
3126
3131
|
const vmInfo = await planoVmService.findOne( { _id: vm.vmId } );
|
|
3127
|
-
console.log( vmInfo?.toObject() );
|
|
3128
3132
|
return {
|
|
3129
3133
|
...vm,
|
|
3130
3134
|
...vmInfo?.toObject(),
|
|
@@ -3133,8 +3137,14 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
3133
3137
|
|
|
3134
3138
|
let disabled = true;
|
|
3135
3139
|
if ( compliance?.status && compliance.status == 'incomplete' ) {
|
|
3136
|
-
|
|
3137
|
-
|
|
3140
|
+
const hasDisagree = compliance?.answers?.some( ( answer ) =>
|
|
3141
|
+
answer?.issues?.some( ( issue ) =>
|
|
3142
|
+
issue?.Details?.some( ( detail ) => detail.status === 'disagree' ),
|
|
3143
|
+
),
|
|
3144
|
+
);
|
|
3145
|
+
|
|
3146
|
+
if ( hasDisagree ) {
|
|
3147
|
+
redoCount++;
|
|
3138
3148
|
disabled = false;
|
|
3139
3149
|
}
|
|
3140
3150
|
}
|
|
@@ -3164,6 +3174,7 @@ export async function storeFixturesTaskv2( req, res ) {
|
|
|
3164
3174
|
return {
|
|
3165
3175
|
...floor.toObject(),
|
|
3166
3176
|
fixtureCount: fixtureCount,
|
|
3177
|
+
redoCount: redoCount,
|
|
3167
3178
|
vmCount: totalVmCount,
|
|
3168
3179
|
layoutPolygon: layoutPolygonWithFixtures,
|
|
3169
3180
|
centerFixture: centerFixturesWithStatus,
|
|
@@ -3258,7 +3269,10 @@ export async function planoList( req, res ) {
|
|
|
3258
3269
|
$expr: {
|
|
3259
3270
|
$and: [
|
|
3260
3271
|
{ $eq: [ '$planoId', '$$plano' ] },
|
|
3261
|
-
{
|
|
3272
|
+
{ $eq: [ '$isPlano', true ] },
|
|
3273
|
+
{
|
|
3274
|
+
$lte: [ '$date_iso', new Date( dayjs().format( 'YYYY-MM-DD' ) ) ],
|
|
3275
|
+
},
|
|
3262
3276
|
],
|
|
3263
3277
|
},
|
|
3264
3278
|
},
|
|
@@ -3268,28 +3282,51 @@ export async function planoList( req, res ) {
|
|
|
3268
3282
|
_id: '$planoType',
|
|
3269
3283
|
dateString: { $last: '$date_string' },
|
|
3270
3284
|
checklistStatus: { $last: '$checklistStatus' },
|
|
3285
|
+
taskId: { $last: '$_id' },
|
|
3286
|
+
},
|
|
3287
|
+
},
|
|
3288
|
+
{
|
|
3289
|
+
$group: {
|
|
3290
|
+
_id: null,
|
|
3291
|
+
taskStatus: {
|
|
3292
|
+
$push: {
|
|
3293
|
+
type: '$_id',
|
|
3294
|
+
status: '$checklistStatus',
|
|
3295
|
+
date: '$dateString',
|
|
3296
|
+
},
|
|
3297
|
+
},
|
|
3298
|
+
taskIds: { $push: '$taskId' },
|
|
3271
3299
|
},
|
|
3272
3300
|
},
|
|
3273
3301
|
],
|
|
3274
3302
|
as: 'planoTask',
|
|
3275
3303
|
},
|
|
3276
3304
|
},
|
|
3305
|
+
{
|
|
3306
|
+
$addFields: {
|
|
3307
|
+
taskIds: { $ifNull: [ { $arrayElemAt: [ '$planoTask.taskIds', 0 ] }, [] ] },
|
|
3308
|
+
taskStatus: { $ifNull: [ { $arrayElemAt: [ '$planoTask.taskStatus', 0 ] }, [] ] },
|
|
3309
|
+
},
|
|
3310
|
+
},
|
|
3277
3311
|
{
|
|
3278
3312
|
$lookup: {
|
|
3279
3313
|
from: 'planotaskcompliances',
|
|
3280
|
-
let: { plano: '$_id' },
|
|
3314
|
+
let: { plano: '$_id', taskId: '$taskIds' },
|
|
3281
3315
|
pipeline: [
|
|
3282
3316
|
{
|
|
3283
3317
|
$match: {
|
|
3284
3318
|
$expr: {
|
|
3285
|
-
$
|
|
3319
|
+
$and: [
|
|
3320
|
+
{ $eq: [ '$planoId', '$$plano' ] },
|
|
3321
|
+
{ $in: [ '$taskId', '$$taskId' ] },
|
|
3322
|
+
],
|
|
3286
3323
|
},
|
|
3287
3324
|
},
|
|
3288
3325
|
},
|
|
3289
3326
|
{ $sort: { _id: -1 } },
|
|
3290
3327
|
{
|
|
3291
3328
|
$group: {
|
|
3292
|
-
_id: {
|
|
3329
|
+
_id: { type: '$type', planoId: '$planoId' },
|
|
3293
3330
|
layoutCount: {
|
|
3294
3331
|
$sum: {
|
|
3295
3332
|
$cond: {
|
|
@@ -3573,6 +3610,7 @@ export async function planoList( req, res ) {
|
|
|
3573
3610
|
},
|
|
3574
3611
|
{
|
|
3575
3612
|
$project: {
|
|
3613
|
+
storeId: 1,
|
|
3576
3614
|
storeName: 1,
|
|
3577
3615
|
layoutName: 1,
|
|
3578
3616
|
layoutDetails: '$layout.layoutDetails',
|
|
@@ -3599,12 +3637,34 @@ export async function planoList( req, res ) {
|
|
|
3599
3637
|
},
|
|
3600
3638
|
} );
|
|
3601
3639
|
}
|
|
3602
|
-
if ( inputData?.filter?.taskPending?.length ) {
|
|
3640
|
+
if ( inputData?.filter?.taskPending?.length && inputData?.filter?.taskPending != 'all' ) {
|
|
3641
|
+
let andQuery = [];
|
|
3642
|
+
|
|
3643
|
+
if ( inputData.filter.taskPending == 'layout' ) {
|
|
3644
|
+
andQuery.push(
|
|
3645
|
+
{ 'planoTask.taskStatus.type': 'layout' },
|
|
3646
|
+
{ 'planoTask.taskStatus.status': 'submit' },
|
|
3647
|
+
{ 'taskDetails.layoutStatus': 'pending' },
|
|
3648
|
+
);
|
|
3649
|
+
}
|
|
3650
|
+
if ( inputData.filter.taskPending == 'fixture' ) {
|
|
3651
|
+
andQuery.push(
|
|
3652
|
+
{ 'planoTask.taskStatus.type': 'fixture' },
|
|
3653
|
+
{ 'planoTask.taskStatus.status': 'submit' },
|
|
3654
|
+
{ 'taskDetails.fixtureStatus': 'pending' },
|
|
3655
|
+
);
|
|
3656
|
+
}
|
|
3657
|
+
if ( inputData.filter.taskPending == 'vm' ) {
|
|
3658
|
+
andQuery.push(
|
|
3659
|
+
{ 'planoTask.taskStatus.type': 'vm' },
|
|
3660
|
+
{ 'taskDetails.vmStatus': 'pending' },
|
|
3661
|
+
{ 'planoTask.taskStatus.status': 'submit' },
|
|
3662
|
+
);
|
|
3663
|
+
}
|
|
3664
|
+
|
|
3603
3665
|
query.push( {
|
|
3604
3666
|
$match: {
|
|
3605
|
-
|
|
3606
|
-
...( inputData.filter.taskPending == 'fixture' ) ? { 'taskDetails.fixtureStatus': 'pending', 'planoTask._id': 'fixture', 'planoTask.checklistStatus': 'submit' } :{},
|
|
3607
|
-
...( inputData.filter.taskPending == 'vm' ) ? { 'taskDetails.vmStatus': 'pending', 'planoTask._id': 'vm', 'planoTask.checklistStatus': 'submit' } :{},
|
|
3667
|
+
$and: andQuery,
|
|
3608
3668
|
},
|
|
3609
3669
|
} );
|
|
3610
3670
|
}
|
|
@@ -3640,14 +3700,6 @@ export async function planoList( req, res ) {
|
|
|
3640
3700
|
|
|
3641
3701
|
query.push( {
|
|
3642
3702
|
$facet: {
|
|
3643
|
-
planoList: [
|
|
3644
|
-
{
|
|
3645
|
-
$group: {
|
|
3646
|
-
_id: '',
|
|
3647
|
-
planoIds: { $addToSet: '$_id' },
|
|
3648
|
-
},
|
|
3649
|
-
},
|
|
3650
|
-
],
|
|
3651
3703
|
data: [
|
|
3652
3704
|
{ $skip: skip },
|
|
3653
3705
|
{ $limit: limit },
|
|
@@ -3658,6 +3710,8 @@ export async function planoList( req, res ) {
|
|
|
3658
3710
|
},
|
|
3659
3711
|
} );
|
|
3660
3712
|
|
|
3713
|
+
console.log( JSON.stringify( query ) );
|
|
3714
|
+
|
|
3661
3715
|
let planoDetails = await planoService.aggregate( query );
|
|
3662
3716
|
|
|
3663
3717
|
if ( !planoDetails[0].data.length ) {
|
|
@@ -3669,243 +3723,225 @@ export async function planoList( req, res ) {
|
|
|
3669
3723
|
let taskQuery = [
|
|
3670
3724
|
{
|
|
3671
3725
|
$match: {
|
|
3672
|
-
client_id: req.body.clientId,
|
|
3673
3726
|
planoId: { $in: idList },
|
|
3727
|
+
isPlano: true,
|
|
3728
|
+
date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
|
|
3674
3729
|
},
|
|
3675
3730
|
},
|
|
3676
3731
|
{
|
|
3677
3732
|
$group: {
|
|
3678
|
-
_id: '$planoType',
|
|
3679
|
-
checklistStatus: { $last: '$checklistStatus' },
|
|
3733
|
+
_id: { store: '$storeName', type: '$planoType' },
|
|
3680
3734
|
planoId: { $last: '$planoId' },
|
|
3735
|
+
checklistStatus: { $last: '$checklistStatus' },
|
|
3736
|
+
taskId: { $last: '$_id' },
|
|
3737
|
+
},
|
|
3738
|
+
},
|
|
3739
|
+
{
|
|
3740
|
+
$match: {
|
|
3741
|
+
checklistStatus: 'submit',
|
|
3681
3742
|
},
|
|
3682
3743
|
},
|
|
3683
3744
|
{
|
|
3684
3745
|
$project: {
|
|
3685
3746
|
_id: 0,
|
|
3686
|
-
|
|
3747
|
+
type: '$_id.type',
|
|
3687
3748
|
planoId: 1,
|
|
3749
|
+
checklistStatus: 1,
|
|
3750
|
+
taskId: 1,
|
|
3688
3751
|
},
|
|
3689
3752
|
},
|
|
3690
3753
|
];
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
console.log( idList, 'list' );
|
|
3695
|
-
taskQuery = [
|
|
3754
|
+
|
|
3755
|
+
let pendingDetails = await planotaskService.aggregate( taskQuery );
|
|
3756
|
+
query = [
|
|
3696
3757
|
{
|
|
3697
3758
|
$match: {
|
|
3698
|
-
|
|
3699
|
-
checklistStatus: 'submit',
|
|
3759
|
+
taskId: { $in: pendingDetails.map( ( ele ) => ele.taskId ) },
|
|
3700
3760
|
},
|
|
3701
3761
|
},
|
|
3702
3762
|
{
|
|
3703
|
-
$
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
$expr: {
|
|
3763
|
+
$group: {
|
|
3764
|
+
_id: { type: '$type', planoId: '$planoId' },
|
|
3765
|
+
layoutPending: {
|
|
3766
|
+
$sum: {
|
|
3767
|
+
$cond: {
|
|
3768
|
+
if: {
|
|
3710
3769
|
$and: [
|
|
3711
|
-
{
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
$anyElementTrue: {
|
|
3730
|
-
$map: {
|
|
3731
|
-
input: {
|
|
3732
|
-
$reduce: {
|
|
3733
|
-
input: '$answers',
|
|
3734
|
-
initialValue: [],
|
|
3735
|
-
in: {
|
|
3736
|
-
$concatArrays: [
|
|
3737
|
-
'$$value',
|
|
3738
|
-
{
|
|
3739
|
-
$ifNull: [
|
|
3740
|
-
'$$this.issues',
|
|
3741
|
-
[],
|
|
3742
|
-
],
|
|
3743
|
-
},
|
|
3744
|
-
],
|
|
3745
|
-
},
|
|
3770
|
+
{
|
|
3771
|
+
$eq: [ '$type', 'layout' ],
|
|
3772
|
+
},
|
|
3773
|
+
{
|
|
3774
|
+
$anyElementTrue: {
|
|
3775
|
+
$map: {
|
|
3776
|
+
input: {
|
|
3777
|
+
$reduce: {
|
|
3778
|
+
input: '$answers',
|
|
3779
|
+
initialValue: [],
|
|
3780
|
+
in: {
|
|
3781
|
+
$concatArrays: [
|
|
3782
|
+
'$$value',
|
|
3783
|
+
{
|
|
3784
|
+
$ifNull: [
|
|
3785
|
+
'$$this.issues',
|
|
3786
|
+
[],
|
|
3787
|
+
],
|
|
3746
3788
|
},
|
|
3747
|
-
|
|
3748
|
-
as: 'issue',
|
|
3749
|
-
in: {
|
|
3750
|
-
$eq: [
|
|
3751
|
-
'$$issue.status',
|
|
3752
|
-
'pending',
|
|
3753
|
-
],
|
|
3754
|
-
},
|
|
3789
|
+
],
|
|
3755
3790
|
},
|
|
3756
3791
|
},
|
|
3757
3792
|
},
|
|
3758
|
-
|
|
3793
|
+
as: 'issue',
|
|
3794
|
+
in: {
|
|
3795
|
+
$eq: [
|
|
3796
|
+
'$$issue.status',
|
|
3797
|
+
'pending',
|
|
3798
|
+
],
|
|
3799
|
+
},
|
|
3800
|
+
},
|
|
3759
3801
|
},
|
|
3760
|
-
then: 1,
|
|
3761
|
-
else: 0,
|
|
3762
3802
|
},
|
|
3763
|
-
|
|
3803
|
+
],
|
|
3764
3804
|
},
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3805
|
+
then: 1,
|
|
3806
|
+
else: 0,
|
|
3807
|
+
},
|
|
3808
|
+
},
|
|
3809
|
+
},
|
|
3810
|
+
fixturePending: {
|
|
3811
|
+
$sum: {
|
|
3812
|
+
$cond: {
|
|
3813
|
+
if: {
|
|
3814
|
+
$and: [
|
|
3815
|
+
{
|
|
3816
|
+
$eq: [ '$type', 'fixture' ],
|
|
3817
|
+
},
|
|
3818
|
+
{
|
|
3819
|
+
$anyElementTrue: {
|
|
3820
|
+
$map: {
|
|
3821
|
+
input: {
|
|
3822
|
+
$reduce: {
|
|
3823
|
+
input: '$answers',
|
|
3824
|
+
initialValue: [],
|
|
3825
|
+
in: {
|
|
3826
|
+
$concatArrays: [
|
|
3827
|
+
'$$value',
|
|
3828
|
+
{
|
|
3829
|
+
$ifNull: [
|
|
3830
|
+
'$$this.issues',
|
|
3831
|
+
[],
|
|
3832
|
+
],
|
|
3791
3833
|
},
|
|
3792
|
-
|
|
3793
|
-
as: 'issue',
|
|
3794
|
-
in: {
|
|
3795
|
-
$eq: [
|
|
3796
|
-
'$$issue.status',
|
|
3797
|
-
'pending',
|
|
3798
|
-
],
|
|
3799
|
-
},
|
|
3834
|
+
],
|
|
3800
3835
|
},
|
|
3801
3836
|
},
|
|
3802
3837
|
},
|
|
3803
|
-
|
|
3838
|
+
as: 'issue',
|
|
3839
|
+
in: {
|
|
3840
|
+
$eq: [
|
|
3841
|
+
'$$issue.status',
|
|
3842
|
+
'pending',
|
|
3843
|
+
],
|
|
3844
|
+
},
|
|
3845
|
+
},
|
|
3804
3846
|
},
|
|
3805
|
-
then: 1,
|
|
3806
|
-
else: 0,
|
|
3807
3847
|
},
|
|
3808
|
-
|
|
3848
|
+
],
|
|
3809
3849
|
},
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3850
|
+
then: 1,
|
|
3851
|
+
else: 0,
|
|
3852
|
+
},
|
|
3853
|
+
},
|
|
3854
|
+
},
|
|
3855
|
+
vmPending: {
|
|
3856
|
+
$sum: {
|
|
3857
|
+
$cond: {
|
|
3858
|
+
if: {
|
|
3859
|
+
$and: [
|
|
3860
|
+
{
|
|
3861
|
+
$eq: [ '$type', 'vm' ],
|
|
3862
|
+
},
|
|
3863
|
+
{
|
|
3864
|
+
$anyElementTrue: {
|
|
3865
|
+
$map: {
|
|
3866
|
+
input: {
|
|
3867
|
+
$reduce: {
|
|
3868
|
+
input: '$answers',
|
|
3869
|
+
initialValue: [],
|
|
3870
|
+
in: {
|
|
3871
|
+
$concatArrays: [
|
|
3872
|
+
'$$value',
|
|
3873
|
+
{
|
|
3874
|
+
$ifNull: [
|
|
3875
|
+
'$$this.issues',
|
|
3876
|
+
[],
|
|
3877
|
+
],
|
|
3836
3878
|
},
|
|
3837
|
-
|
|
3838
|
-
as: 'issue',
|
|
3839
|
-
in: {
|
|
3840
|
-
$eq: [
|
|
3841
|
-
'$$issue.status',
|
|
3842
|
-
'pending',
|
|
3843
|
-
],
|
|
3844
|
-
},
|
|
3879
|
+
],
|
|
3845
3880
|
},
|
|
3846
3881
|
},
|
|
3847
3882
|
},
|
|
3848
|
-
|
|
3883
|
+
as: 'issue',
|
|
3884
|
+
in: {
|
|
3885
|
+
$eq: [
|
|
3886
|
+
'$$issue.status',
|
|
3887
|
+
'pending',
|
|
3888
|
+
],
|
|
3889
|
+
},
|
|
3890
|
+
},
|
|
3849
3891
|
},
|
|
3850
|
-
then: 1,
|
|
3851
|
-
else: 0,
|
|
3852
3892
|
},
|
|
3853
|
-
|
|
3854
|
-
},
|
|
3855
|
-
},
|
|
3856
|
-
},
|
|
3857
|
-
{
|
|
3858
|
-
$group: {
|
|
3859
|
-
_id: 0,
|
|
3860
|
-
layoutPending: {
|
|
3861
|
-
$sum: { $cond: {
|
|
3862
|
-
if: {
|
|
3863
|
-
$gt: [ '$layoutPending', 0 ],
|
|
3864
|
-
},
|
|
3865
|
-
then: 1,
|
|
3866
|
-
else: 0,
|
|
3867
|
-
} },
|
|
3868
|
-
},
|
|
3869
|
-
fixturePending: {
|
|
3870
|
-
$sum: { $cond: {
|
|
3871
|
-
if: {
|
|
3872
|
-
$gt: [ '$fixturePending', 0 ],
|
|
3873
|
-
},
|
|
3874
|
-
then: 1,
|
|
3875
|
-
else: 0,
|
|
3876
|
-
} },
|
|
3877
|
-
},
|
|
3878
|
-
vmPending: {
|
|
3879
|
-
$sum: { $cond: {
|
|
3880
|
-
if: {
|
|
3881
|
-
$gt: [ '$vmPending', 0 ],
|
|
3882
|
-
},
|
|
3883
|
-
then: 1,
|
|
3884
|
-
else: 0,
|
|
3885
|
-
} },
|
|
3893
|
+
],
|
|
3886
3894
|
},
|
|
3895
|
+
then: 1,
|
|
3896
|
+
else: 0,
|
|
3887
3897
|
},
|
|
3888
3898
|
},
|
|
3889
|
-
|
|
3890
|
-
as: 'taskFeedback',
|
|
3899
|
+
},
|
|
3891
3900
|
},
|
|
3892
3901
|
},
|
|
3893
3902
|
{
|
|
3894
|
-
$
|
|
3903
|
+
$group: {
|
|
3895
3904
|
_id: 0,
|
|
3896
|
-
|
|
3905
|
+
layoutPending: {
|
|
3906
|
+
$sum: { $cond: {
|
|
3907
|
+
if: {
|
|
3908
|
+
$gt: [ '$layoutPending', 0 ],
|
|
3909
|
+
},
|
|
3910
|
+
then: 1,
|
|
3911
|
+
else: 0,
|
|
3912
|
+
} },
|
|
3913
|
+
},
|
|
3914
|
+
fixturePending: {
|
|
3915
|
+
$sum: { $cond: {
|
|
3916
|
+
if: {
|
|
3917
|
+
$gt: [ '$fixturePending', 0 ],
|
|
3918
|
+
},
|
|
3919
|
+
then: 1,
|
|
3920
|
+
else: 0,
|
|
3921
|
+
} },
|
|
3922
|
+
},
|
|
3923
|
+
vmPending: {
|
|
3924
|
+
$sum: { $cond: {
|
|
3925
|
+
if: {
|
|
3926
|
+
$gt: [ '$vmPending', 0 ],
|
|
3927
|
+
},
|
|
3928
|
+
then: 1,
|
|
3929
|
+
else: 0,
|
|
3930
|
+
} },
|
|
3931
|
+
},
|
|
3897
3932
|
},
|
|
3898
3933
|
},
|
|
3899
3934
|
{
|
|
3900
3935
|
$project: {
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3936
|
+
_id: 0,
|
|
3937
|
+
layoutPending: '$layoutPending',
|
|
3938
|
+
fixturePending: '$fixturePending',
|
|
3939
|
+
vmPending: '$vmPending',
|
|
3904
3940
|
},
|
|
3905
3941
|
},
|
|
3906
3942
|
];
|
|
3907
3943
|
|
|
3908
|
-
|
|
3944
|
+
pendingDetails = await planoTaskComplianceService.aggregate( query );
|
|
3909
3945
|
let result = {
|
|
3910
3946
|
data: planoDetails[0].data,
|
|
3911
3947
|
count: planoDetails?.[0]?.count?.[0]?.total || 0,
|
|
@@ -14,6 +14,8 @@ import mongoose from 'mongoose';
|
|
|
14
14
|
// const ObjectId = mongoose.Types.ObjectId;
|
|
15
15
|
import * as floorService from '../service/storeBuilder.service.js';
|
|
16
16
|
import * as planoStaticService from '../service/planoStaticData.service.js';
|
|
17
|
+
import * as assignService from '../service/assignService.service.js';
|
|
18
|
+
|
|
17
19
|
|
|
18
20
|
dayjs.extend( timeZone );
|
|
19
21
|
|
|
@@ -110,157 +112,196 @@ async function createUser( data ) {
|
|
|
110
112
|
|
|
111
113
|
export async function createTask( req, res ) {
|
|
112
114
|
try {
|
|
113
|
-
let taskDetails = await taskService.find( { isPlano: true, client_id: req.body.clientId, ...( req.body.checkListName )? { checkListName: req.body.checkListName } : {} } );
|
|
114
|
-
let storeList = req.body.stores.map( ( ele ) => ele.store.toLowerCase() );
|
|
115
|
-
let userDetails;
|
|
116
|
-
if ( !taskDetails.length ) {
|
|
117
|
-
return res.sendError( 'No data found', 204 );
|
|
118
|
-
}
|
|
119
|
-
let endDate;
|
|
120
115
|
let scheduleEndTime = '11:59 PM';
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
req.body.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
116
|
+
if ( req.body?.redo ) {
|
|
117
|
+
if ( !req.body.taskId ) {
|
|
118
|
+
return res.sendError( 'Task id is required', 400 );
|
|
119
|
+
}
|
|
120
|
+
let taskInfo = await processedService.findOne( { _id: req.body.taskId } );
|
|
121
|
+
if ( !taskInfo ) {
|
|
122
|
+
return res.sendError( 'No data found', 204 );
|
|
123
|
+
}
|
|
124
|
+
await processedService.updateOne( { _id: req.body.taskId }, { checklistStatus: 'open', redoStatus: true, date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ), scheduleStartTime_iso: dayjs.utc( '12:00 AM', 'hh:mm A' ).format(), scheduleEndTime_iso: dayjs.utc( scheduleEndTime, 'hh:mm A' ).format(), date_string: dayjs().format( 'YYYY-MM-DD' ) } );
|
|
125
|
+
return res.sendSuccess( 'Task redo triggered successfully' );
|
|
126
|
+
} else {
|
|
127
|
+
let taskDetails = await taskService.find( { isPlano: true, client_id: req.body.clientId, ...( req.body.checkListName )? { checkListName: req.body.checkListName } : {} } );
|
|
128
|
+
if ( !taskDetails.length ) {
|
|
129
|
+
return res.sendError( 'No data found', 204 );
|
|
130
|
+
}
|
|
131
|
+
let userDetails;
|
|
132
|
+
let storeList;
|
|
133
|
+
let endDate;
|
|
134
|
+
let taskConfig = await planoStaticService.findOne( { clientId: req.body.clientId, type: 'task' } );
|
|
135
|
+
req.body.days = req.body?.days || 7;
|
|
136
|
+
if ( taskConfig && !req.body?.endTime ) {
|
|
137
|
+
scheduleEndTime = taskConfig?.dueTime || '11:59 PM';
|
|
138
|
+
req.body.days = taskConfig?.dueDay || 1;
|
|
139
|
+
req.body.geoFencing = taskConfig?.allowedStoreLocation || false;
|
|
140
|
+
}
|
|
141
|
+
if ( req.body?.endTime ) {
|
|
142
|
+
scheduleEndTime = req.body.endTime;
|
|
143
|
+
}
|
|
144
|
+
endDate = dayjs().add( req.body.days, 'day' ).format( 'YYYY-MM-DD' );
|
|
145
|
+
endDate = `${endDate} ${scheduleEndTime}`;
|
|
146
|
+
if ( !req.body?.stores?.length ) {
|
|
147
|
+
let assignQuery = [
|
|
148
|
+
{
|
|
149
|
+
$addFields: {
|
|
150
|
+
store: { $toLower: '$storeName' },
|
|
151
|
+
},
|
|
137
152
|
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
153
|
+
{
|
|
154
|
+
$match: {
|
|
155
|
+
client_id: req.body.clientId,
|
|
156
|
+
store: req.body.store.toLowerCase(),
|
|
157
|
+
},
|
|
143
158
|
},
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
];
|
|
160
|
+
let getUserDetails = await assignService.aggregate( assignQuery );
|
|
161
|
+
if ( !getUserDetails.length ) {
|
|
162
|
+
return res.sendError( 'Email is required' );
|
|
163
|
+
}
|
|
164
|
+
req.body.stores = [
|
|
165
|
+
{
|
|
166
|
+
store: getUserDetails[0].storeName,
|
|
167
|
+
email: req.body?.email ? req.body.email : getUserDetails[0].userEmail,
|
|
168
|
+
},
|
|
169
|
+
];
|
|
155
170
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
date_string: dayjs().format( 'YYYY-MM-DD' ),
|
|
165
|
-
sourceCheckList_id: task._id,
|
|
166
|
-
checkListName: task.checkListName,
|
|
167
|
-
checkListId: task._id,
|
|
168
|
-
scheduleStartTime: '12:00 AM',
|
|
169
|
-
scheduleEndTime: scheduleEndTime,
|
|
170
|
-
scheduleStartTime_iso: dayjs.utc( '12:00 AM', 'hh:mm A' ).format(),
|
|
171
|
-
scheduleEndTime_iso: dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format(),
|
|
172
|
-
allowedOverTime: false,
|
|
173
|
-
allowedStoreLocation: req.body?.geoFencing || false,
|
|
174
|
-
createdBy: task.createdBy,
|
|
175
|
-
createdByName: task.createdByName,
|
|
176
|
-
questionAnswers: [],
|
|
177
|
-
isdeleted: false,
|
|
178
|
-
questionCount: 0,
|
|
179
|
-
storeCount: 0,
|
|
180
|
-
locationCount: 0,
|
|
181
|
-
checkListType: 'task',
|
|
182
|
-
country: '',
|
|
183
|
-
store_id: '',
|
|
184
|
-
storeName: '',
|
|
185
|
-
userId: '',
|
|
186
|
-
userName: '',
|
|
187
|
-
userEmail: '',
|
|
188
|
-
checklistStatus: 'open',
|
|
189
|
-
timeFlagStatus: true,
|
|
190
|
-
timeFlag: 0,
|
|
191
|
-
questionFlag: 0,
|
|
192
|
-
mobileDetectionFlag: 0,
|
|
193
|
-
storeOpenCloseFlag: 0,
|
|
194
|
-
reinitiateStatus: false,
|
|
195
|
-
markasread: false,
|
|
196
|
-
uniformDetectionFlag: 0,
|
|
197
|
-
scheduleRepeatedType: 'daily',
|
|
198
|
-
approvalStatus: false,
|
|
199
|
-
approvalEnable: false,
|
|
200
|
-
redoStatus: false,
|
|
201
|
-
isPlano: true,
|
|
202
|
-
planoType: splitName.length == 1 ? splitName[0].toLowerCase() : splitName[0].toLowerCase() + splitName[2],
|
|
203
|
-
};
|
|
204
|
-
let query = [
|
|
205
|
-
{
|
|
206
|
-
$addFields: {
|
|
207
|
-
store: { $toLower: '$storeName' },
|
|
171
|
+
storeList = req.body.stores.map( ( ele ) => ele.store.toLowerCase() );
|
|
172
|
+
let userEmailList = [ ...new Set( req.body.stores.map( ( ele ) => ele.email ) ) ];
|
|
173
|
+
for ( let mail of userEmailList ) {
|
|
174
|
+
let query = [
|
|
175
|
+
{
|
|
176
|
+
$addFields: {
|
|
177
|
+
emailLower: { $toLower: '$email' },
|
|
178
|
+
},
|
|
208
179
|
},
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
180
|
+
{
|
|
181
|
+
$match: {
|
|
182
|
+
clientId: req.body.clientId,
|
|
183
|
+
emailLower: mail.toLowerCase(),
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
];
|
|
187
|
+
userDetails = await userService.aggregate( query );
|
|
188
|
+
if ( !userDetails.length ) {
|
|
189
|
+
let userData = {
|
|
212
190
|
clientId: req.body.clientId,
|
|
213
|
-
|
|
191
|
+
mobileNumber: '',
|
|
192
|
+
email: mail,
|
|
193
|
+
userName: mail.split( '@' )[0],
|
|
194
|
+
};
|
|
195
|
+
await createUser( userData );
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
await Promise.all( taskDetails.map( async ( task ) => {
|
|
199
|
+
let splitName = task?.checkListName.split( ' ' );
|
|
200
|
+
splitName.pop();
|
|
201
|
+
let data = {
|
|
202
|
+
client_id: req.body.clientId,
|
|
203
|
+
date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
204
|
+
date_string: dayjs().format( 'YYYY-MM-DD' ),
|
|
205
|
+
sourceCheckList_id: task._id,
|
|
206
|
+
checkListName: task.checkListName,
|
|
207
|
+
checkListId: task._id,
|
|
208
|
+
scheduleStartTime: '12:00 AM',
|
|
209
|
+
scheduleEndTime: scheduleEndTime,
|
|
210
|
+
scheduleStartTime_iso: dayjs.utc( '12:00 AM', 'hh:mm A' ).format(),
|
|
211
|
+
scheduleEndTime_iso: dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format(),
|
|
212
|
+
allowedOverTime: false,
|
|
213
|
+
allowedStoreLocation: req.body?.geoFencing || false,
|
|
214
|
+
createdBy: task.createdBy,
|
|
215
|
+
createdByName: task.createdByName,
|
|
216
|
+
questionAnswers: [],
|
|
217
|
+
isdeleted: false,
|
|
218
|
+
questionCount: 0,
|
|
219
|
+
storeCount: 0,
|
|
220
|
+
locationCount: 0,
|
|
221
|
+
checkListType: 'task',
|
|
222
|
+
country: '',
|
|
223
|
+
store_id: '',
|
|
224
|
+
storeName: '',
|
|
225
|
+
userId: '',
|
|
226
|
+
userName: '',
|
|
227
|
+
userEmail: '',
|
|
228
|
+
checklistStatus: 'open',
|
|
229
|
+
timeFlagStatus: true,
|
|
230
|
+
timeFlag: 0,
|
|
231
|
+
questionFlag: 0,
|
|
232
|
+
mobileDetectionFlag: 0,
|
|
233
|
+
storeOpenCloseFlag: 0,
|
|
234
|
+
reinitiateStatus: false,
|
|
235
|
+
markasread: false,
|
|
236
|
+
uniformDetectionFlag: 0,
|
|
237
|
+
scheduleRepeatedType: 'daily',
|
|
238
|
+
approvalStatus: false,
|
|
239
|
+
approvalEnable: false,
|
|
240
|
+
redoStatus: false,
|
|
241
|
+
isPlano: true,
|
|
242
|
+
planoType: splitName.length == 1 ? splitName[0].toLowerCase() : splitName[0].toLowerCase() + splitName[2],
|
|
243
|
+
};
|
|
244
|
+
let query = [
|
|
245
|
+
{
|
|
246
|
+
$addFields: {
|
|
247
|
+
store: { $toLower: '$storeName' },
|
|
248
|
+
},
|
|
214
249
|
},
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
250
|
+
{
|
|
251
|
+
$match: {
|
|
252
|
+
clientId: req.body.clientId,
|
|
253
|
+
store: { $in: storeList },
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
];
|
|
257
|
+
|
|
258
|
+
let storeDetails = await storeService.aggregate( query );
|
|
259
|
+
await Promise.all( storeDetails.map( async ( store ) => {
|
|
260
|
+
let getUserEmail = req.body.stores.find( ( ele ) => ele.store.toLowerCase() == store.storeName.toLowerCase() );
|
|
261
|
+
let planoDetails = await planoService.findOne( { storeName: store.storeName } );
|
|
262
|
+
if ( planoDetails ) {
|
|
263
|
+
let floorDetails = await floorService.find( { planoId: planoDetails._id }, { _id: 1, floorName: 1 } );
|
|
264
|
+
for ( let i=0; i<floorDetails.length; i++ ) {
|
|
265
|
+
if ( getUserEmail ) {
|
|
266
|
+
let query = [
|
|
267
|
+
{
|
|
268
|
+
$addFields: {
|
|
269
|
+
emailLower: { $toLower: '$email' },
|
|
270
|
+
},
|
|
230
271
|
},
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
272
|
+
{
|
|
273
|
+
$match: {
|
|
274
|
+
clientId: req.body.clientId,
|
|
275
|
+
emailLower: getUserEmail.email.toLowerCase(),
|
|
276
|
+
},
|
|
236
277
|
},
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
278
|
+
];
|
|
279
|
+
userDetails = await userService.aggregate( query );
|
|
280
|
+
userDetails = userDetails[0];
|
|
281
|
+
}
|
|
282
|
+
let taskData = { ...data };
|
|
283
|
+
if ( floorDetails.length > 1 ) {
|
|
284
|
+
taskData.checkListName = taskData.checkListName +' - '+ floorDetails[i].floorName;
|
|
285
|
+
}
|
|
286
|
+
taskData.floorId = floorDetails[i]._id;
|
|
287
|
+
taskData.store_id = store.storeId;
|
|
288
|
+
taskData.storeName = store.storeName;
|
|
289
|
+
taskData.userId = userDetails._id;
|
|
290
|
+
taskData.userName = userDetails.userName;
|
|
291
|
+
taskData.userEmail = userDetails.email;
|
|
292
|
+
taskData.planoId = planoDetails?._id;
|
|
293
|
+
for ( let i=0; i<req.body.days; i++ ) {
|
|
294
|
+
let currDate = dayjs().add( i, 'day' );
|
|
295
|
+
let insertData = { ...taskData, date_string: currDate.format( 'YYYY-MM-DD' ), date_iso: new Date( currDate.format( 'YYYY-MM-DD' ) ), scheduleStartTime_iso: dayjs.utc( `${currDate.format( 'YYYY-MM-DD' )} 12:00 AM`, 'YYYY-MM-DD hh:mm A' ).format() };
|
|
296
|
+
let response = await processedService.updateOne( { date_string: currDate.format( 'YYYY-MM-DD' ), store_id: insertData.store_id, userEmail: insertData.userEmail, planoId: insertData.planoId, sourceCheckList_id: task._id, ...( taskData?.floorId ) ? { floorId: taskData.floorId }:{} }, insertData );
|
|
297
|
+
console.log( response );
|
|
298
|
+
}
|
|
257
299
|
}
|
|
258
300
|
}
|
|
259
|
-
}
|
|
301
|
+
} ) );
|
|
260
302
|
} ) );
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return res.sendSuccess( 'Task created successfully' );
|
|
303
|
+
return res.sendSuccess( 'Task created successfully' );
|
|
304
|
+
}
|
|
264
305
|
} catch ( e ) {
|
|
265
306
|
console.log( e );
|
|
266
307
|
logger.error( { functionName: 'createTask', error: e } );
|
|
@@ -554,11 +595,16 @@ export async function updateAnswersv2( req, res ) {
|
|
|
554
595
|
type: req.body.type,
|
|
555
596
|
date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
556
597
|
taskId: req.body.taskId,
|
|
598
|
+
taskType: req.body.taskType,
|
|
557
599
|
storeName: req.body?.storeName,
|
|
558
600
|
storeId: req.body?.storeId,
|
|
559
601
|
};
|
|
560
|
-
console.log( data );
|
|
561
|
-
|
|
602
|
+
console.log( '111111', data );
|
|
603
|
+
if ( req.body.type==='layout' ) {
|
|
604
|
+
await planoTaskService.updateOne( { planoId: req.body.planoId, taskType: req.body.taskType, floorId: req.body.floorId, fixtureId: req.body.fixtureId, type: req.body.type, date_string: dayjs().format( 'YYYY-MM-DD' ), ...( taskDetails?._id ) ? { taskId: taskDetails?._id } :{} }, data );
|
|
605
|
+
} else {
|
|
606
|
+
await planoTaskService.updateOne( { planoId: req.body.planoId, floorId: req.body.floorId, fixtureId: req.body.fixtureId, type: req.body.type, date_string: dayjs().format( 'YYYY-MM-DD' ), ...( taskDetails?._id ) ? { taskId: taskDetails?._id } :{} }, data );
|
|
607
|
+
}
|
|
562
608
|
|
|
563
609
|
return res.sendSuccess( 'Fixture details updated successfully' );
|
|
564
610
|
} catch ( e ) {
|
|
@@ -15,4 +15,4 @@ managePlanoRouter
|
|
|
15
15
|
.get( '/fixtureVMList', managePlanoController.fixtureVMList )
|
|
16
16
|
.post( '/updateFixtureStatus', isAllowedSessionHandler, managePlanoController.updateFixtureStatus )
|
|
17
17
|
.post( '/updateStoreFixture', managePlanoController.updateStoreFixture )
|
|
18
|
-
.post( '/
|
|
18
|
+
.post( '/updateredostatus', managePlanoController.updateredostatus );
|