tango-app-api-task 3.7.33 → 3.7.35
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 +1 -1
- package/src/controllers/task.controller.js +282 -281
package/package.json
CHANGED
|
@@ -7223,7 +7223,7 @@ export async function AITaskCreation( req, res ) {
|
|
|
7223
7223
|
}
|
|
7224
7224
|
stores = Array.from( storeIds );
|
|
7225
7225
|
}
|
|
7226
|
-
if ( stores.includes( storeData.storeId ) ) {
|
|
7226
|
+
if ( stores.includes( storeData.storeId ) || userDetails.role === 'superadmin' ) {
|
|
7227
7227
|
finduser.push( user );
|
|
7228
7228
|
}
|
|
7229
7229
|
}
|
|
@@ -7339,160 +7339,161 @@ export async function AITaskCreation( req, res ) {
|
|
|
7339
7339
|
}
|
|
7340
7340
|
|
|
7341
7341
|
// Check this Task Already Exist////
|
|
7342
|
+
let checkTask = await taskService.findOne( { checkListName: inputBody.taskName } );
|
|
7343
|
+
if ( checkTask ) {
|
|
7344
|
+
let singleInsert = await insertAItaskProcessedTaskCreation( checkTask, inputBody, date, time, storeData, finduser, answer, userAdmin );
|
|
7345
|
+
if ( singleInsert ) {
|
|
7346
|
+
return res.sendSuccess( 'Task created successfully' );
|
|
7347
|
+
} else {
|
|
7348
|
+
return res.sendError( 'something went wrong, please try again', 500 );
|
|
7349
|
+
}
|
|
7350
|
+
} else {
|
|
7351
|
+
let data = {
|
|
7352
|
+
// checkListName: `${inputBody.taskName}(${storeData.storeName}-${dayjs().format( 'YYYY-MM-DD' )}-${inputBody.zoneName ? inputBody.zoneName : ''})`,
|
|
7353
|
+
checkListName: inputBody.taskName,
|
|
7354
|
+
checkListDescription: inputBody.taskDescription,
|
|
7355
|
+
createdBy: creator[0]._id,
|
|
7356
|
+
createdByName: creator[0].userName,
|
|
7357
|
+
publish: true,
|
|
7358
|
+
questionCount: 1,
|
|
7359
|
+
storeCount: 1,
|
|
7360
|
+
scheduleDate: date,
|
|
7361
|
+
scheduleEndTime: time,
|
|
7362
|
+
scheduleEndTimeISO: scheduleEndData,
|
|
7363
|
+
priorityType: 'high',
|
|
7364
|
+
client_id: inputBody.clientId,
|
|
7365
|
+
checkListType: 'task',
|
|
7366
|
+
publishDate: new Date(),
|
|
7367
|
+
locationCount: 1,
|
|
7368
|
+
...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
|
|
7369
|
+
coverage: 'store',
|
|
7370
|
+
checkListFrom: 'api',
|
|
7371
|
+
zoneName: inputBody.zoneName || '',
|
|
7372
|
+
checkListType: 'task',
|
|
7373
|
+
};
|
|
7374
|
+
data['approver'] = userAdmin;
|
|
7342
7375
|
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
if ( [ 'multiplechoicesingle', 'multiplechoicemultiple', 'dropdown' ].includes( inputBody?.answerType ) ) {
|
|
7371
|
-
if ( inputBody?.options && inputBody?.options.length > 0 ) {
|
|
7372
|
-
let optionsResult = [];
|
|
7373
|
-
let optionList = inputBody?.options.split( ',' );
|
|
7374
|
-
for ( let option of optionList ) {
|
|
7375
|
-
let optiondata = {
|
|
7376
|
-
'answer': '',
|
|
7377
|
-
'sopFlag': false,
|
|
7378
|
-
'validation': false,
|
|
7379
|
-
'validationType': '',
|
|
7380
|
-
'referenceImage': [],
|
|
7381
|
-
'runAI': false,
|
|
7382
|
-
'allowUploadfromGallery': false,
|
|
7383
|
-
'descriptivetype': '',
|
|
7384
|
-
'showLinked': false,
|
|
7385
|
-
'linkedQuestion': 0,
|
|
7386
|
-
'nestedQuestion': [],
|
|
7387
|
-
'reason': inputBody.reason,
|
|
7388
|
-
'detectionTime': inputBody.detectionTime,
|
|
7389
|
-
};
|
|
7390
|
-
optiondata.answer = option;
|
|
7391
|
-
optionsResult.push( optiondata );
|
|
7376
|
+
if ( [ 'multiplechoicesingle', 'multiplechoicemultiple', 'dropdown' ].includes( inputBody?.answerType ) ) {
|
|
7377
|
+
if ( inputBody?.options && inputBody?.options.length > 0 ) {
|
|
7378
|
+
let optionsResult = [];
|
|
7379
|
+
let optionList = inputBody?.options.split( ',' );
|
|
7380
|
+
for ( let option of optionList ) {
|
|
7381
|
+
let optiondata = {
|
|
7382
|
+
'answer': '',
|
|
7383
|
+
'sopFlag': false,
|
|
7384
|
+
'validation': false,
|
|
7385
|
+
'validationType': '',
|
|
7386
|
+
'referenceImage': [],
|
|
7387
|
+
'runAI': false,
|
|
7388
|
+
'allowUploadfromGallery': false,
|
|
7389
|
+
'descriptivetype': '',
|
|
7390
|
+
'showLinked': false,
|
|
7391
|
+
'linkedQuestion': 0,
|
|
7392
|
+
'nestedQuestion': [],
|
|
7393
|
+
'reason': inputBody.reason,
|
|
7394
|
+
'detectionTime': inputBody.detectionTime,
|
|
7395
|
+
};
|
|
7396
|
+
optiondata.answer = option;
|
|
7397
|
+
optionsResult.push( optiondata );
|
|
7398
|
+
}
|
|
7399
|
+
answer = optionsResult;
|
|
7400
|
+
} else {
|
|
7401
|
+
return res.sendError( 'please enter Valid Options', 500 );
|
|
7392
7402
|
}
|
|
7393
|
-
answer = optionsResult;
|
|
7394
|
-
} else {
|
|
7395
|
-
return res.sendError( 'please enter Valid Options', 500 );
|
|
7396
7403
|
}
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
|
|
7404
|
+
let clientDetails = await clientService.findOne( { clientId: inputBody?.clientId }, { traxVideoUploadTimeLimit: 1 } );
|
|
7405
|
+
data['videoUploadTimeLimit'] = clientDetails?.traxVideoUploadTimeLimit || 0;
|
|
7406
|
+
let response = await taskService.create( data );
|
|
7407
|
+
if ( response?.approver.length ) {
|
|
7408
|
+
let inputData = [];
|
|
7409
|
+
response?.approver.forEach( ( ele ) => {
|
|
7410
|
+
inputData.push( {
|
|
7411
|
+
userEmail: ele.email,
|
|
7412
|
+
checkListId: response._id,
|
|
7413
|
+
type: 'task',
|
|
7414
|
+
client_id: inputBody.clientId,
|
|
7415
|
+
checkListName: data?.checkListName || '',
|
|
7416
|
+
} );
|
|
7410
7417
|
} );
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
}
|
|
7418
|
+
await traxApprover.insertMany( inputData );
|
|
7419
|
+
}
|
|
7414
7420
|
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7421
|
+
if ( response?._id ) {
|
|
7422
|
+
let question = [
|
|
7423
|
+
{
|
|
7424
|
+
'qno': 1,
|
|
7425
|
+
'qname': inputBody.question,
|
|
7426
|
+
'answerType': inputBody?.answerType || 'yes/no',
|
|
7427
|
+
'runAI': false,
|
|
7428
|
+
'runAIDescription': '',
|
|
7429
|
+
'allowUploadfromGallery': false,
|
|
7430
|
+
'linkType': false,
|
|
7431
|
+
'questionReferenceImage': [],
|
|
7432
|
+
'answers': answer,
|
|
7433
|
+
'descriptivetype': 'text',
|
|
7434
|
+
'allowMultiple': inputBody.multi,
|
|
7435
|
+
},
|
|
7436
|
+
];
|
|
7431
7437
|
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7439
|
-
|
|
7440
|
-
|
|
7441
|
-
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7438
|
+
let images = [];
|
|
7439
|
+
for ( let imgpath of req.body.referenceImage ) {
|
|
7440
|
+
let configURL = JSON.parse( process.env.BUCKET );
|
|
7441
|
+
let inputData = {
|
|
7442
|
+
Bucket: configURL.aiTraxoutput,
|
|
7443
|
+
Key: imgpath,
|
|
7444
|
+
};
|
|
7445
|
+
let output = await getObject( inputData );
|
|
7446
|
+
// / Check Bucket
|
|
7447
|
+
let image = {
|
|
7448
|
+
data: output.Body,
|
|
7449
|
+
name: imgpath,
|
|
7450
|
+
mimetype: output.ContentType,
|
|
7451
|
+
};
|
|
7452
|
+
let uplaodedImage = await uploadmultiImage( image );
|
|
7453
|
+
let imgUrl = decodeURIComponent( uplaodedImage?.imgUrl.split( '?' )[0] );
|
|
7454
|
+
let url = imgUrl.split( '/' );
|
|
7455
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
7456
|
+
url.splice( 0, 3 );
|
|
7457
|
+
}
|
|
7458
|
+
images.push( url.join( '/' ) );
|
|
7451
7459
|
}
|
|
7452
|
-
|
|
7453
|
-
}
|
|
7454
|
-
question[0].questionReferenceImage = images;
|
|
7455
|
-
|
|
7456
|
-
if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
|
|
7457
|
-
answer[0].referenceImage = question[0].questionReferenceImage;
|
|
7458
|
-
}
|
|
7460
|
+
question[0].questionReferenceImage = images;
|
|
7459
7461
|
|
|
7460
|
-
|
|
7461
|
-
|
|
7462
|
-
|
|
7463
|
-
section: 'Section 1',
|
|
7464
|
-
checkList: data.checkListName,
|
|
7465
|
-
client_id: inputBody.clientId,
|
|
7466
|
-
};
|
|
7462
|
+
if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
|
|
7463
|
+
answer[0].referenceImage = question[0].questionReferenceImage;
|
|
7464
|
+
}
|
|
7467
7465
|
|
|
7468
|
-
|
|
7469
|
-
|
|
7470
|
-
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
finduser.forEach( ( ele ) => {
|
|
7474
|
-
userDetails = {
|
|
7475
|
-
userName: ele.userName,
|
|
7476
|
-
userEmail: ele.userEmail,
|
|
7477
|
-
store_id: storeData.storeId,
|
|
7478
|
-
storeName: storeData.storeName,
|
|
7479
|
-
city: storeData?.storeProfile?.city,
|
|
7480
|
-
checkFlag: true,
|
|
7481
|
-
checkListId: response?.upsertedId ?? taskDetails._id,
|
|
7482
|
-
checkListName: data.checkListName,
|
|
7466
|
+
question = {
|
|
7467
|
+
checkListId: response?._id,
|
|
7468
|
+
question: question,
|
|
7469
|
+
section: 'Section 1',
|
|
7470
|
+
checkList: data.checkListName,
|
|
7483
7471
|
client_id: inputBody.clientId,
|
|
7484
|
-
userId: ele.userId,
|
|
7485
|
-
assignId: storeData?._id,
|
|
7486
|
-
country: storeData?.storeProfile?.country,
|
|
7487
|
-
state: storeData?.storeProfile?.state,
|
|
7488
7472
|
};
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7473
|
+
await taskQuestionService.create( question );
|
|
7474
|
+
let userDetails = [];
|
|
7475
|
+
finduser.forEach( ( ele ) => {
|
|
7476
|
+
userDetails = {
|
|
7477
|
+
userName: ele.userName,
|
|
7478
|
+
userEmail: ele.userEmail,
|
|
7479
|
+
store_id: storeData.storeId,
|
|
7480
|
+
storeName: storeData.storeName,
|
|
7481
|
+
city: storeData?.storeProfile?.city,
|
|
7482
|
+
checkFlag: true,
|
|
7483
|
+
checkListId: response?._id,
|
|
7484
|
+
checkListName: data.checkListName,
|
|
7485
|
+
client_id: inputBody.clientId,
|
|
7486
|
+
userId: ele.userId,
|
|
7487
|
+
assignId: storeData?._id,
|
|
7488
|
+
country: storeData?.storeProfile?.country,
|
|
7489
|
+
state: storeData?.storeProfile?.state,
|
|
7490
|
+
};
|
|
7491
|
+
} );
|
|
7492
|
+
|
|
7493
|
+
await taskAssignService.insertMany( userDetails );
|
|
7494
|
+
await insertSingleProcessData( response?._id, false, { aiTask: true, aiType: inputBody.aiType } );
|
|
7495
|
+
return res.sendSuccess( 'Task created successfully' );
|
|
7492
7496
|
}
|
|
7493
|
-
await taskAssignService.insertMany( userDetails );
|
|
7494
|
-
await insertSingleProcessData( response?.upsertedId ?? taskDetails._id, false, { aiTask: true, aiType: inputBody.aiType } );
|
|
7495
|
-
return res.sendSuccess( 'Task created successfully' );
|
|
7496
7497
|
}
|
|
7497
7498
|
} catch ( e ) {
|
|
7498
7499
|
console.log( 'e =>', e );
|
|
@@ -7501,144 +7502,144 @@ export async function AITaskCreation( req, res ) {
|
|
|
7501
7502
|
}
|
|
7502
7503
|
}
|
|
7503
7504
|
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
//
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
|
|
7557
|
-
|
|
7558
|
-
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
|
-
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
|
|
7573
|
-
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
|
|
7601
|
-
|
|
7602
|
-
|
|
7603
|
-
|
|
7604
|
-
|
|
7605
|
-
|
|
7606
|
-
|
|
7607
|
-
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
-
//
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7632
|
-
|
|
7633
|
-
|
|
7634
|
-
|
|
7635
|
-
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
|
|
7639
|
-
|
|
7640
|
-
|
|
7641
|
-
|
|
7505
|
+
async function insertAItaskProcessedTaskCreation( checkTask, inputBody, date, time, storeDetails, finduser, answer, userAdmin ) {
|
|
7506
|
+
try {
|
|
7507
|
+
let getquestion = await taskQuestionService.findOne( { checkListId: checkTask._id } );
|
|
7508
|
+
let getolddata = await taskProcessedService.findOne( { sourceCheckList_id: checkTask._id } );
|
|
7509
|
+
let getoldConfigdata = await taskService.findOne( { _id: checkTask._id } );
|
|
7510
|
+
|
|
7511
|
+
const uniqueUsers = mergeUnique( getoldConfigdata.approver, userAdmin, '_id' );
|
|
7512
|
+
|
|
7513
|
+
// Question Patten Making
|
|
7514
|
+
let question = [
|
|
7515
|
+
{
|
|
7516
|
+
'qno': 1,
|
|
7517
|
+
'qname': inputBody.question,
|
|
7518
|
+
'answerType': inputBody?.answerType || 'yes/no',
|
|
7519
|
+
'runAI': false,
|
|
7520
|
+
'runAIDescription': '',
|
|
7521
|
+
'allowUploadfromGallery': false,
|
|
7522
|
+
'linkType': false,
|
|
7523
|
+
'questionReferenceImage': [],
|
|
7524
|
+
'answers': answer,
|
|
7525
|
+
'descriptivetype': 'text',
|
|
7526
|
+
'allowMultiple': inputBody.multi,
|
|
7527
|
+
},
|
|
7528
|
+
];
|
|
7529
|
+
|
|
7530
|
+
let images = [];
|
|
7531
|
+
for ( let imgpath of inputBody.referenceImage ) {
|
|
7532
|
+
let configURL = JSON.parse( process.env.BUCKET );
|
|
7533
|
+
let inputData = {
|
|
7534
|
+
Bucket: configURL.aiTraxoutput,
|
|
7535
|
+
Key: imgpath,
|
|
7536
|
+
};
|
|
7537
|
+
let output = await getObject( inputData );
|
|
7538
|
+
let image = {
|
|
7539
|
+
data: output.Body,
|
|
7540
|
+
name: imgpath,
|
|
7541
|
+
mimetype: output.ContentType,
|
|
7542
|
+
};
|
|
7543
|
+
let uplaodedImage = await uploadmultiImage( image );
|
|
7544
|
+
let imgUrl = decodeURIComponent( uplaodedImage?.imgUrl.split( '?' )[0] );
|
|
7545
|
+
let url = imgUrl.split( '/' );
|
|
7546
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
7547
|
+
url.splice( 0, 3 );
|
|
7548
|
+
}
|
|
7549
|
+
images.push( url.join( '/' ) );
|
|
7550
|
+
}
|
|
7551
|
+
question[0].questionReferenceImage = images;
|
|
7552
|
+
|
|
7553
|
+
if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
|
|
7554
|
+
answer[0].referenceImage = question[0].questionReferenceImage;
|
|
7555
|
+
}
|
|
7556
|
+
|
|
7557
|
+
let questions = {
|
|
7558
|
+
questions: question,
|
|
7559
|
+
sectionName: getquestion.section,
|
|
7560
|
+
section_id: getquestion._id,
|
|
7561
|
+
};
|
|
7562
|
+
|
|
7563
|
+
let oldData = getolddata.toObject();
|
|
7564
|
+
delete oldData._id;
|
|
7565
|
+
delete oldData.submitTime_string;
|
|
7566
|
+
delete oldData.startTime_string;
|
|
7567
|
+
delete oldData.submitTime;
|
|
7568
|
+
delete oldData.startTime;
|
|
7569
|
+
delete oldData.submitMobileTime;
|
|
7570
|
+
delete oldData.startMobileTime;
|
|
7571
|
+
oldData.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
|
|
7572
|
+
oldData.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
|
|
7573
|
+
oldData.scheduleStartTime_iso = date;
|
|
7574
|
+
oldData.scheduleEndTime_iso = dayjs.utc( inputBody.scheduleEndData, 'YYYY-MM-DD hh:mm A' ).format();
|
|
7575
|
+
oldData.scheduleEndTime = dayjs.utc( inputBody.scheduleEndData, 'YYYY-MM-DD hh:mm A' ).format( 'hh:mm A' );
|
|
7576
|
+
oldData.scheduleStartTime = dayjs.utc().format( 'hh:mm A' );
|
|
7577
|
+
oldData.store_id = storeDetails.storeId;
|
|
7578
|
+
oldData.storeName = storeDetails.storeName;
|
|
7579
|
+
oldData.country = storeDetails.storeProfile.country;
|
|
7580
|
+
oldData.checklistStatus = 'open';
|
|
7581
|
+
oldData.timeFlagStatus = true;
|
|
7582
|
+
oldData.checkListFrom = 'api';
|
|
7583
|
+
oldData.createdAt = new Date();
|
|
7584
|
+
oldData.updatedAt = new Date();
|
|
7585
|
+
oldData.approvalStatus = false;
|
|
7586
|
+
oldData.approvalEnable = true;
|
|
7587
|
+
oldData.approvalTime = '';
|
|
7588
|
+
oldData.approvalTime_string = '';
|
|
7589
|
+
oldData.redoStatus = false;
|
|
7590
|
+
oldData.approvalByName = '';
|
|
7591
|
+
oldData.approvalByEmail = '';
|
|
7592
|
+
oldData.questionAnswers = [ questions ];
|
|
7593
|
+
oldData.zoneName = inputBody.zoneName || '';
|
|
7594
|
+
oldData.checkListType = 'task' || '';
|
|
7595
|
+
if ( inputBody.aiType ) {
|
|
7596
|
+
oldData.aiType = inputBody.aiType;
|
|
7597
|
+
}
|
|
7598
|
+
let configDetails = await taskProcessedConfigService.insert( oldData );
|
|
7599
|
+
let insertData = [];
|
|
7600
|
+
finduser.forEach( ( user ) => {
|
|
7601
|
+
let newData = { ...oldData };
|
|
7602
|
+
newData.userId = user.userId;
|
|
7603
|
+
newData.userName = user.userName;
|
|
7604
|
+
newData.userEmail = user.userEmail;
|
|
7605
|
+
newData.checkListId = configDetails._id;
|
|
7606
|
+
insertData.push( { ...newData } );
|
|
7607
|
+
} );
|
|
7608
|
+
let insertprocessdata = await taskProcessedService.insertMany( insertData );
|
|
7609
|
+
if ( insertprocessdata ) {
|
|
7610
|
+
if ( uniqueUsers && uniqueUsers.length>0 ) {
|
|
7611
|
+
// updated Task Approver//
|
|
7612
|
+
await taskService.updateOne( { _id: oldData.sourceCheckList_id }, { approver: uniqueUsers } );
|
|
7613
|
+
for ( let k = 0; k < uniqueUsers.length; k++ ) {
|
|
7614
|
+
let checkapprover = {
|
|
7615
|
+
userEmail: uniqueUsers[k].email,
|
|
7616
|
+
checkListId: oldData.sourceCheckList_id,
|
|
7617
|
+
type: 'task',
|
|
7618
|
+
client_id: oldData.client_id,
|
|
7619
|
+
isDeleted: false,
|
|
7620
|
+
};
|
|
7621
|
+
let getapproverData = await traxApprover.findOne( checkapprover );
|
|
7622
|
+
if ( !getapproverData ) {
|
|
7623
|
+
let inserApproverData = {
|
|
7624
|
+
userEmail: uniqueUsers[k].email,
|
|
7625
|
+
checkListId: oldData.sourceCheckList_id,
|
|
7626
|
+
type: 'task',
|
|
7627
|
+
client_id: oldData.client_id,
|
|
7628
|
+
isDeleted: false,
|
|
7629
|
+
};
|
|
7630
|
+
await traxApprover.create( inserApproverData );
|
|
7631
|
+
}
|
|
7632
|
+
}
|
|
7633
|
+
}
|
|
7634
|
+
return true;
|
|
7635
|
+
} else {
|
|
7636
|
+
return false;
|
|
7637
|
+
}
|
|
7638
|
+
} catch ( error ) {
|
|
7639
|
+
logger.error( { error: error, function: 'insertSingleProcessedTask' } );
|
|
7640
|
+
return false;
|
|
7641
|
+
}
|
|
7642
|
+
}
|
|
7642
7643
|
|
|
7643
7644
|
function mergeUnique( arr1 = [], arr2 = [], key = '_id' ) {
|
|
7644
7645
|
const merged = [ ...arr1, ...arr2 ];
|