tango-app-api-task 3.2.1-beta-27 → 3.2.1-beta-29

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.2.1-beta-27",
3
+ "version": "3.2.1-beta-29",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2649,6 +2649,212 @@ export async function StoreHygienetask( req, res ) {
2649
2649
  return res.sendError( e, 500 );
2650
2650
  }
2651
2651
  }
2652
+ export async function commonAiTask( req, res ) {
2653
+ try {
2654
+ let inputBody = req.body;
2655
+
2656
+ inputBody.clientId = 11;
2657
+ inputBody.taskDescription = '';
2658
+ let userId;
2659
+ let storeDetails = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
2660
+ if ( !storeDetails ) {
2661
+ return res.sendError( 'Store Not Found', 500 );
2662
+ }
2663
+
2664
+ let url = JSON.parse( process.env.LAMBDAURL );
2665
+ let checklistId = url.dailystoreChecklistId;
2666
+ let finduser = await checklistassignconfigModel.findOne( { checkListId: new mongoose.Types.ObjectId( checklistId ), store_id: storeDetails.storeId } );
2667
+
2668
+ if ( !finduser ) {
2669
+ return res.sendError( 'No user Found For this store', 500 );
2670
+ }
2671
+
2672
+ userId = finduser.userId;
2673
+ inputBody.userName = finduser.userName;
2674
+ inputBody.userEmail = finduser.userEmail;
2675
+
2676
+
2677
+ let teamList = await findteams( { users: { $elemMatch: { email: finduser.userEmail } } } );
2678
+
2679
+ inputBody.approver = '';
2680
+ for ( let team of teamList ) {
2681
+ for ( let user of team.Teamlead ) {
2682
+ inputBody.approver = user.email + ',' + inputBody.approver;
2683
+ }
2684
+ }
2685
+ inputBody.approver = inputBody.approver.replace( /,$/, '' );
2686
+
2687
+
2688
+ // let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
2689
+ let time = inputBody?.scheduleEndTime || '11:59 PM';
2690
+ let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
2691
+ // let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
2692
+ // if ( userDetails&&userDetails.fcmToken ) {
2693
+ // const fcmToken = userDetails.fcmToken;
2694
+ // await sendPushNotification( title, description, fcmToken );
2695
+ // }
2696
+ const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
2697
+ const currentTime = dayjs.utc();
2698
+ if ( inputDateTime.isBefore( currentTime ) ) {
2699
+ return res.sendError( 'The input date-time is before the current time.', 500 );
2700
+ }
2701
+
2702
+ let approverList = inputBody?.approver.split( ',' );
2703
+
2704
+
2705
+ let userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: approverList }, userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
2706
+
2707
+ if ( userAdmin && userAdmin.length === 0 ) {
2708
+ userAdmin = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
2709
+ }
2710
+
2711
+ let creator = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true } );
2712
+ if ( creator && creator.length === 0 ) {
2713
+ return res.sendError( 'Invalid Creator Details', 500 );
2714
+ }
2715
+
2716
+ if ( req.body && req.body.referenceImage && req.body.referenceImage.length > 3 ) {
2717
+ return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
2718
+ }
2719
+ let data = {
2720
+ checkListName: `${inputBody.taskName}(${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}-${inputBody.count})`,
2721
+ checkListDescription: inputBody.taskDescription,
2722
+ createdBy: creator[0]._id,
2723
+ createdByName: creator[0].userName,
2724
+ publish: true,
2725
+ questionCount: 1,
2726
+ storeCount: 1,
2727
+ scheduleDate: date,
2728
+ scheduleEndTime: time,
2729
+ scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
2730
+ priorityType: 'high',
2731
+ client_id: inputBody.clientId,
2732
+ checkListType: 'task',
2733
+ publishDate: new Date(),
2734
+ locationCount: 1,
2735
+ ...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
2736
+ };
2737
+ data['approver'] = userAdmin;
2738
+ let answer = await findAnswer( inputBody?.answerType );
2739
+ if ( answer.length == 0 ) {
2740
+ return res.sendError( 'please enter Valid AnswerType', 500 );
2741
+ }
2742
+ if ( inputBody?.answerType === 'multiplechoicesingle' || inputBody?.answerType === 'multiplechoicemultiple' ) {
2743
+ if ( inputBody?.options && inputBody?.options.length > 0 ) {
2744
+ let optionsResult = [];
2745
+ let optionList = inputBody?.options.split( ',' );
2746
+ for ( let option of optionList ) {
2747
+ let optiondata = {
2748
+ 'answer': '',
2749
+ 'sopFlag': false,
2750
+ 'validation': false,
2751
+ 'validationType': '',
2752
+ 'referenceImage': [],
2753
+ 'runAI': false,
2754
+ 'allowUploadfromGallery': false,
2755
+ 'descriptivetype': '',
2756
+ 'showLinked': false,
2757
+ 'linkedQuestion': 0,
2758
+ 'nestedQuestion': [],
2759
+ };
2760
+ optiondata.answer = option;
2761
+ optionsResult.push( optiondata );
2762
+ }
2763
+ answer = optionsResult;
2764
+ } else {
2765
+ return res.sendError( 'please enter Valid Options', 500 );
2766
+ }
2767
+ }
2768
+ let response = await taskService.create( data );
2769
+ if ( response?.approver.length ) {
2770
+ let inputData = [];
2771
+ response?.approver.forEach( ( ele ) => {
2772
+ inputData.push( {
2773
+ userEmail: ele.email,
2774
+ checkListId: response._id,
2775
+ type: 'task',
2776
+ client_id: inputBody.clientId,
2777
+ checkListName: data?.checkListName || '',
2778
+ } );
2779
+ } );
2780
+ await traxApprover.insertMany( inputData );
2781
+ }
2782
+ if ( response?._id ) {
2783
+ let question = [
2784
+ {
2785
+ 'qno': 1,
2786
+ 'qname': inputBody.question,
2787
+ 'answerType': inputBody?.answerType || 'yes/no',
2788
+ 'runAI': false,
2789
+ 'runAIDescription': '',
2790
+ 'allowUploadfromGallery': false,
2791
+ 'linkType': false,
2792
+ 'questionReferenceImage': [],
2793
+ 'answers': answer,
2794
+ 'descriptivetype': 'text',
2795
+ },
2796
+ ];
2797
+ let images = [];
2798
+ for ( let imgpath of req.body.referenceImage ) {
2799
+ let configURL = JSON.parse( process.env.BUCKET );
2800
+ let inputData = {
2801
+ Bucket: configURL.commonAiTaskBucket,
2802
+ Key: imgpath,
2803
+ };
2804
+ let output = await getObject( inputData );
2805
+ console.log( output );
2806
+
2807
+ let image = {
2808
+ data: output.Body,
2809
+ name: imgpath,
2810
+ mimetype: output.ContentType,
2811
+ };
2812
+ let uplaodedImage = await uploadmultiImage( image );
2813
+
2814
+ let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
2815
+ let url = imgUrl.split( '/' );
2816
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
2817
+ url.splice( 0, 3 );
2818
+ }
2819
+ images.push( url.join( '/' ) );
2820
+ }
2821
+ question[0].questionReferenceImage = images;
2822
+
2823
+ if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
2824
+ answer[0].referenceImage = question[0].questionReferenceImage;
2825
+ }
2826
+
2827
+
2828
+ question = {
2829
+ checkListId: response?._id,
2830
+ question: question,
2831
+ section: 'Section 1',
2832
+ checkList: data.checkListName,
2833
+ client_id: inputBody.clientId,
2834
+ };
2835
+ await taskQuestionService.create( question );
2836
+
2837
+ let userDetails = {
2838
+ userName: inputBody.userName,
2839
+ userEmail: inputBody.userEmail,
2840
+ store_id: storeDetails.storeId,
2841
+ storeName: storeDetails.storeName,
2842
+ city: storeDetails?.storeProfile?.city,
2843
+ checkFlag: true,
2844
+ checkListId: response?._id,
2845
+ checkListName: data.checkListName,
2846
+ client_id: inputBody.clientId,
2847
+ userId: userId,
2848
+ };
2849
+ await taskAssignService.create( userDetails );
2850
+ await insertSingleProcessData( response?._id );
2851
+ return res.sendSuccess( 'Task created successfully' );
2852
+ }
2853
+ } catch ( e ) {
2854
+ logger.error( { function: 'commonAiTask', error: e } );
2855
+ return res.sendError( e, 500 );
2856
+ }
2857
+ }
2652
2858
  export async function eyeTesttask( req, res ) {
2653
2859
  try {
2654
2860
  let inputBody = req.body;
@@ -3421,7 +3627,7 @@ async function assignUsers( data ) {
3421
3627
  {
3422
3628
  $match: {
3423
3629
  clientId: data.clientId,
3424
- ...( !data?.clusterName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
3630
+ ...( data?.id ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
3425
3631
  },
3426
3632
  },
3427
3633
  {
@@ -3486,7 +3692,7 @@ async function assignUsers( data ) {
3486
3692
  {
3487
3693
  $match: {
3488
3694
  clientId: data.clientId,
3489
- ...( !data.storeName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
3695
+ ...( data?.id ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
3490
3696
  },
3491
3697
  },
3492
3698
  ];
@@ -3533,7 +3739,7 @@ async function assignUsers( data ) {
3533
3739
  {
3534
3740
  $match: {
3535
3741
  clientId: data.clientId,
3536
- ...( !data?.teamName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
3742
+ ...( data?.id ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
3537
3743
  },
3538
3744
  },
3539
3745
  ];
@@ -3580,7 +3786,7 @@ async function assignUsers( data ) {
3580
3786
  {
3581
3787
  $match: {
3582
3788
  clientId: data.clientId,
3583
- ...( !data?.userEmail ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
3789
+ ...( data?.id ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
3584
3790
  },
3585
3791
  },
3586
3792
  ];
@@ -3614,7 +3820,7 @@ async function assignUsers( data ) {
3614
3820
  }
3615
3821
 
3616
3822
  // console.log( assignedData, 'test', data );
3617
- if ( assignedData && !data.upload && data.insert ) {
3823
+ if ( assignedData && data?.insert ) {
3618
3824
  await taskAssignService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
3619
3825
  } else {
3620
3826
  return assignedData;
@@ -159,6 +159,7 @@ export const approvalTableV1 = async ( req, res ) => {
159
159
  ],
160
160
  },
161
161
  },
162
+ coverage: { $first: '$coverage' },
162
163
  },
163
164
  },
164
165
  {
@@ -177,6 +178,7 @@ export const approvalTableV1 = async ( req, res ) => {
177
178
  unApproveCount: 1,
178
179
  storeName: 1,
179
180
  redo: '$_id.redoType',
181
+ coverage: 1,
180
182
  },
181
183
  },
182
184
  {
@@ -23,6 +23,16 @@ export const StoreHygienetaskSchema = Joi.object().keys( {
23
23
  referenceImage: Joi.array().required(),
24
24
  count: Joi.number().required(),
25
25
  } );
26
+ export const commonAiTaskSchema = Joi.object().keys( {
27
+ storeName: Joi.string().required(),
28
+ taskName: Joi.string().required(),
29
+ question: Joi.string().required(),
30
+ answerType: Joi.string().required(),
31
+ options: Joi.string().optional(),
32
+ scheduleDate: Joi.string().optional(),
33
+ scheduleEndTime: Joi.string().optional(),
34
+ referenceImage: Joi.array().required(),
35
+ } );
26
36
 
27
37
 
28
38
  export const eyeTesttaskSchema = Joi.object().keys( {
@@ -41,6 +51,9 @@ export const aitaskvalidation = {
41
51
  export const StoreHygienetaskvalidation = {
42
52
  body: StoreHygienetaskSchema,
43
53
  };
54
+ export const commonAiTaskvalidation = {
55
+ body: commonAiTaskSchema,
56
+ };
44
57
  export const eyeTesttaskvalidation = {
45
58
  body: eyeTesttaskSchema,
46
59
  };
@@ -2,7 +2,7 @@
2
2
  import * as taskController from '../controllers/task.controller.js';
3
3
  import { isAllowedSessionHandler, validate, accessVerification, isAllowedClient, isAllowedInternalAPIHandler } from 'tango-app-api-middleware';
4
4
  import express from 'express';
5
- import { aitaskvalidation, StoreHygienetaskvalidation, eyeTesttaskvalidation } from '../dtos/task.dto.js';
5
+ import { aitaskvalidation, StoreHygienetaskvalidation, eyeTesttaskvalidation, commonAiTaskvalidation } from '../dtos/task.dto.js';
6
6
  export const taskRouter = express.Router();
7
7
 
8
8
  taskRouter
@@ -34,6 +34,7 @@ taskRouter
34
34
  .post( '/createaiTask', isAllowedInternalAPIHandler, validate( aitaskvalidation ), taskController.createAiTask )
35
35
  .post( '/StoreHygienetask', isAllowedInternalAPIHandler, validate( StoreHygienetaskvalidation ), taskController.StoreHygienetask )
36
36
  .post( '/eyeTesttask', isAllowedInternalAPIHandler, validate( eyeTesttaskvalidation ), taskController.eyeTesttask )
37
+ .post( '/commonAiTask', isAllowedInternalAPIHandler, validate( commonAiTaskvalidation ), taskController.commonAiTask )
37
38
  .get( '/getcoustemer', taskController.customertrial );
38
39
 
39
40