tango-app-api-task 3.7.33 → 3.7.34

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-task",
3
- "version": "3.7.33",
3
+ "version": "3.7.34",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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
- let taskDetails = await taskService.findOne( { checkListName: inputBody.taskName, client_id: req.body.clientId } );
7344
-
7345
- let data = {
7346
- // checkListName: `${inputBody.taskName}(${storeData.storeName}-${dayjs().format( 'YYYY-MM-DD' )}-${inputBody.zoneName ? inputBody.zoneName : ''})`,
7347
- checkListName: inputBody.taskName,
7348
- checkListDescription: inputBody.taskDescription,
7349
- createdBy: creator[0]._id,
7350
- createdByName: creator[0].userName,
7351
- publish: true,
7352
- questionCount: 1,
7353
- storeCount: 1,
7354
- scheduleDate: date,
7355
- scheduleEndTime: time,
7356
- scheduleEndTimeISO: inputBody['scheduleEndData'],
7357
- priorityType: 'high',
7358
- client_id: inputBody.clientId,
7359
- checkListType: 'task',
7360
- publishDate: new Date(),
7361
- locationCount: 1,
7362
- ...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
7363
- coverage: 'store',
7364
- checkListFrom: 'api',
7365
- zoneName: inputBody.zoneName || '',
7366
- checkListType: 'task',
7367
- };
7368
- data['approver'] = userAdmin;
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
- let clientDetails = await clientService.findOne( { clientId: inputBody?.clientId }, { traxVideoUploadTimeLimit: 1 } );
7399
- data['videoUploadTimeLimit'] = clientDetails?.traxVideoUploadTimeLimit || 0;
7400
- let response = await taskService.updateOne( { checkListName: inputBody.taskName, client_id: req.body.clientId }, data );
7401
- if ( inputBody.approver.length ) {
7402
- let inputData = [];
7403
- inputBody.approver.forEach( ( ele ) => {
7404
- inputData.push( {
7405
- userEmail: ele.email,
7406
- checkListId: response?.upsertedId ?? taskDetails._id,
7407
- type: 'task',
7408
- client_id: inputBody.clientId,
7409
- checkListName: data?.checkListName || '',
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
- await traxApprover.insertMany( inputData );
7413
- }
7418
+ await traxApprover.insertMany( inputData );
7419
+ }
7414
7420
 
7415
- if ( response?.upsertedId ?? taskDetails._id ) {
7416
- let question = [
7417
- {
7418
- 'qno': 1,
7419
- 'qname': inputBody.question,
7420
- 'answerType': inputBody?.answerType || 'yes/no',
7421
- 'runAI': false,
7422
- 'runAIDescription': '',
7423
- 'allowUploadfromGallery': false,
7424
- 'linkType': false,
7425
- 'questionReferenceImage': [],
7426
- 'answers': answer,
7427
- 'descriptivetype': 'text',
7428
- 'allowMultiple': inputBody.multi,
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
- let images = [];
7433
- for ( let imgpath of req.body.referenceImage ) {
7434
- let configURL = JSON.parse( process.env.BUCKET );
7435
- let inputData = {
7436
- Bucket: configURL.aiTraxoutput,
7437
- Key: imgpath,
7438
- };
7439
- let output = await getObject( inputData );
7440
- // / Check Bucket
7441
- let image = {
7442
- data: output.Body,
7443
- name: imgpath,
7444
- mimetype: output.ContentType,
7445
- };
7446
- let uplaodedImage = await uploadmultiImage( image );
7447
- let imgUrl = decodeURIComponent( uplaodedImage?.imgUrl.split( '?' )[0] );
7448
- let url = imgUrl.split( '/' );
7449
- if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
7450
- url.splice( 0, 3 );
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
- images.push( url.join( '/' ) );
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
- question = {
7461
- checkListId: response?.upsertedId ?? taskDetails._id,
7462
- question: question,
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
- if ( taskDetails ) {
7469
- await taskQuestionService.deleteMany( { checkListId: taskDetails._id } );
7470
- }
7471
- await taskQuestionService.create( question );
7472
- let userDetails = [];
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
- if ( taskDetails ) {
7491
- await taskAssignService.deleteMany( { checkListId: taskDetails._id } );
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
- // async function insertAItaskProcessedTaskCreation( checkTask, inputBody, date, time, storeDetails, finduser, answer, userAdmin ) {
7505
- // try {
7506
- // let getquestion = await taskQuestionService.findOne( { checkListId: checkTask._id } );
7507
- // let getolddata = await taskProcessedService.findOne( { sourceCheckList_id: checkTask._id } );
7508
- // let getoldConfigdata = await taskService.findOne( { _id: checkTask._id } );
7509
-
7510
- // const uniqueUsers = mergeUnique( getoldConfigdata.approver, userAdmin, '_id' );
7511
- // // Question Patten Making
7512
- // let question = [
7513
- // {
7514
- // 'qno': 1,
7515
- // 'qname': inputBody.question,
7516
- // 'answerType': inputBody?.answerType || 'yes/no',
7517
- // 'runAI': false,
7518
- // 'runAIDescription': '',
7519
- // 'allowUploadfromGallery': false,
7520
- // 'linkType': false,
7521
- // 'questionReferenceImage': [],
7522
- // 'answers': answer,
7523
- // 'descriptivetype': 'text',
7524
- // 'allowMultiple': inputBody.multi,
7525
- // },
7526
- // ];
7527
-
7528
- // let images = [];
7529
- // for ( let imgpath of inputBody.referenceImage ) {
7530
- // let configURL = JSON.parse( process.env.BUCKET );
7531
- // let inputData = {
7532
- // Bucket: configURL.aiTraxoutput,
7533
- // Key: imgpath,
7534
- // };
7535
- // let output = await getObject( inputData );
7536
- // let image = {
7537
- // data: output.Body,
7538
- // name: imgpath,
7539
- // mimetype: output.ContentType,
7540
- // };
7541
- // let uplaodedImage = await uploadmultiImage( image );
7542
- // let imgUrl = decodeURIComponent( uplaodedImage?.imgUrl.split( '?' )[0] );
7543
- // let url = imgUrl.split( '/' );
7544
- // if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
7545
- // url.splice( 0, 3 );
7546
- // }
7547
- // images.push( url.join( '/' ) );
7548
- // }
7549
- // question[0].questionReferenceImage = images;
7550
-
7551
- // if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
7552
- // answer[0].referenceImage = question[0].questionReferenceImage;
7553
- // }
7554
-
7555
- // let questions = {
7556
- // questions: question,
7557
- // sectionName: getquestion.section,
7558
- // section_id: getquestion._id,
7559
- // };
7560
-
7561
- // let oldData = getolddata.toObject();
7562
- // delete oldData._id;
7563
- // delete oldData.submitTime_string;
7564
- // delete oldData.startTime_string;
7565
- // delete oldData.submitTime;
7566
- // delete oldData.startTime;
7567
- // delete oldData.submitMobileTime;
7568
- // delete oldData.startMobileTime;
7569
- // oldData.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
7570
- // oldData.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
7571
- // oldData.scheduleStartTime_iso = date;
7572
- // oldData.scheduleEndTime_iso = dayjs.utc( inputBody.scheduleEndData, 'YYYY-MM-DD hh:mm A' ).format();
7573
- // oldData.scheduleEndTime = dayjs.utc( inputBody.scheduleEndData, 'YYYY-MM-DD hh:mm A' ).format( 'hh:mm A' );
7574
- // oldData.scheduleStartTime = dayjs.utc().format( 'hh:mm A' );
7575
- // oldData.store_id = storeDetails.storeId;
7576
- // oldData.storeName = storeDetails.storeName;
7577
- // oldData.country = storeDetails.storeProfile.country;
7578
- // oldData.checklistStatus = 'open';
7579
- // oldData.timeFlagStatus = true;
7580
- // oldData.checkListFrom = 'api';
7581
- // oldData.createdAt = new Date();
7582
- // oldData.updatedAt = new Date();
7583
- // oldData.approvalStatus = false;
7584
- // oldData.approvalEnable = true;
7585
- // oldData.approvalTime = '';
7586
- // oldData.approvalTime_string = '';
7587
- // oldData.redoStatus = false;
7588
- // oldData.approvalByName = '';
7589
- // oldData.approvalByEmail = '';
7590
- // oldData.questionAnswers = [ questions ];
7591
- // oldData.zoneName = inputBody.zoneName || '';
7592
- // oldData.checkListType = 'task' || '';
7593
- // if ( inputBody.aiType ) {
7594
- // oldData.aiType = inputBody.aiType;
7595
- // }
7596
- // let configDetails = await taskProcessedConfigService.insert( oldData );
7597
- // let insertData = [];
7598
- // finduser.forEach( ( user ) => {
7599
- // let newData = { ...oldData };
7600
- // newData.userId = user.userId;
7601
- // newData.userName = user.userName;
7602
- // newData.userEmail = user.userEmail;
7603
- // newData.checkListId = configDetails._id;
7604
- // insertData.push( { ...newData } );
7605
- // } );
7606
- // let insertprocessdata = await taskProcessedService.insertMany( insertData );
7607
- // console.log( '🚀 ~ insertAItaskSingleProcessedTask ~ insertprocessdata:', insertprocessdata );
7608
- // if ( insertprocessdata ) {
7609
- // if ( uniqueUsers && uniqueUsers.length>0 ) {
7610
- // // updated Task Approver//
7611
- // await taskService.updateOne( { _id: oldData.sourceCheckList_id }, { approver: uniqueUsers } );
7612
- // for ( let k = 0; k < uniqueUsers.length; k++ ) {
7613
- // let checkapprover = {
7614
- // userEmail: uniqueUsers[k].email,
7615
- // checkListId: oldData.sourceCheckList_id,
7616
- // type: 'task',
7617
- // client_id: oldData.client_id,
7618
- // isDeleted: false,
7619
- // };
7620
- // let getapproverData = await traxApprover.findOne( checkapprover );
7621
- // if ( !getapproverData ) {
7622
- // let inserApproverData = {
7623
- // userEmail: uniqueUsers[k].email,
7624
- // checkListId: oldData.sourceCheckList_id,
7625
- // type: 'task',
7626
- // client_id: oldData.client_id,
7627
- // isDeleted: false,
7628
- // };
7629
- // await traxApprover.create( inserApproverData );
7630
- // }
7631
- // }
7632
- // }
7633
- // return true;
7634
- // } else {
7635
- // return false;
7636
- // }
7637
- // } catch ( error ) {
7638
- // logger.error( { error: error, function: 'insertSingleProcessedTask' } );
7639
- // return false;
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 ];