tango-app-api-task 3.2.1-beta-36 → 3.2.1-beta-38

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-36",
3
+ "version": "3.2.1-beta-38",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -594,12 +594,14 @@ export const validateUserv1 = async ( req, res ) => {
594
594
  assignDetails.forEach( ( item ) => {
595
595
  let getStoreDetails = storeDetails.find( ( store ) => store.storeName.toLowerCase() == item.storeName.toLowerCase() );
596
596
  if ( getStoreDetails ) {
597
- let storeUserDetails = userDetails.find( ( ele ) => ele.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
597
+ // let storeUserDetails = userDetails.find( ( ele ) => ele.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
598
598
  item._id = getStoreDetails._id;
599
599
  item.storeId = getStoreDetails.storeId;
600
- item.userName = storeUserDetails ? storeUserDetails?.userName : item?.userName;
600
+ item.userName = getStoreDetails?.spocDetails?.[0]?.name || item.userName;
601
+ // item.userName = storeUserDetails ? storeUserDetails?.userName : item?.userName;
601
602
  item.storeName = getStoreDetails.storeName;
602
- item.userEmail = storeUserDetails ? storeUserDetails?.email : item.userEmail;
603
+ item.userEmail = getStoreDetails?.spocDetails?.[0]?.email || item.userEmail;
604
+ // item.userEmail = storeUserDetails ? storeUserDetails?.email : item.userEmail;
603
605
  }
604
606
  } );
605
607
  } else {
@@ -1927,15 +1929,19 @@ export async function getAnswerCount( req, res ) {
1927
1929
  export const taskDropdown = async ( req, res ) => {
1928
1930
  try {
1929
1931
  let requestData = req.body;
1930
-
1932
+ let fromDate = new Date( requestData.fromDate );
1933
+ let toDate = new Date( requestData.toDate );
1934
+ let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
1935
+ toDate = new Date( toDate.getTime() - userTimezoneOffset );
1936
+ toDate.setUTCHours( 23, 59, 59, 59 );
1931
1937
  let result = {};
1932
1938
 
1933
1939
  let findQuery = [];
1934
1940
  let findAndQuery = [];
1935
1941
  findAndQuery.push(
1936
1942
  { client_id: requestData.clientId },
1937
- // { date_iso: { $gte: fromDate } },
1938
- // { date_iso: { $lte: toDate } },
1943
+ { date_iso: { $gte: fromDate } },
1944
+ { date_iso: { $lte: toDate } },
1939
1945
  { checkListType: { $in: [ 'task', 'checklistTask', 'cctv' ] } },
1940
1946
  );
1941
1947
 
@@ -2854,6 +2860,212 @@ export async function StoreHygienetask( req, res ) {
2854
2860
  return res.sendError( e, 500 );
2855
2861
  }
2856
2862
  }
2863
+ export async function commonAiTask( req, res ) {
2864
+ try {
2865
+ let inputBody = req.body;
2866
+
2867
+ inputBody.clientId = 11;
2868
+ inputBody.taskDescription = '';
2869
+ let userId;
2870
+ let storeDetails = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
2871
+ if ( !storeDetails ) {
2872
+ return res.sendError( 'Store Not Found', 500 );
2873
+ }
2874
+
2875
+ let url = JSON.parse( process.env.LAMBDAURL );
2876
+ let checklistId = url.dailystoreChecklistId;
2877
+ let finduser = await checklistassignconfigModel.findOne( { checkListId: new mongoose.Types.ObjectId( checklistId ), store_id: storeDetails.storeId } );
2878
+
2879
+ if ( !finduser ) {
2880
+ return res.sendError( 'No user Found For this store', 500 );
2881
+ }
2882
+
2883
+ userId = finduser.userId;
2884
+ inputBody.userName = finduser.userName;
2885
+ inputBody.userEmail = finduser.userEmail;
2886
+
2887
+
2888
+ let teamList = await findteams( { users: { $elemMatch: { email: finduser.userEmail } } } );
2889
+
2890
+ inputBody.approver = '';
2891
+ for ( let team of teamList ) {
2892
+ for ( let user of team.Teamlead ) {
2893
+ inputBody.approver = user.email + ',' + inputBody.approver;
2894
+ }
2895
+ }
2896
+ inputBody.approver = inputBody.approver.replace( /,$/, '' );
2897
+
2898
+
2899
+ let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
2900
+ let time = inputBody?.scheduleEndTime || '11:59 PM';
2901
+ let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
2902
+ let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
2903
+ if ( userDetails&&userDetails.fcmToken ) {
2904
+ const fcmToken = userDetails.fcmToken;
2905
+ await sendPushNotification( title, description, fcmToken );
2906
+ }
2907
+ const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
2908
+ const currentTime = dayjs.utc();
2909
+ if ( inputDateTime.isBefore( currentTime ) ) {
2910
+ return res.sendError( 'The input date-time is before the current time.', 500 );
2911
+ }
2912
+
2913
+ let approverList = inputBody?.approver.split( ',' );
2914
+
2915
+
2916
+ let userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: approverList }, userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
2917
+
2918
+ if ( userAdmin && userAdmin.length === 0 ) {
2919
+ userAdmin = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
2920
+ }
2921
+
2922
+ let creator = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true } );
2923
+ if ( creator && creator.length === 0 ) {
2924
+ return res.sendError( 'Invalid Creator Details', 500 );
2925
+ }
2926
+
2927
+ if ( req.body && req.body.referenceImage && req.body.referenceImage.length > 3 ) {
2928
+ return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
2929
+ }
2930
+ let data = {
2931
+ checkListName: `${inputBody.taskName}(${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )})`,
2932
+ checkListDescription: inputBody.taskDescription,
2933
+ createdBy: creator[0]._id,
2934
+ createdByName: creator[0].userName,
2935
+ publish: true,
2936
+ questionCount: 1,
2937
+ storeCount: 1,
2938
+ scheduleDate: date,
2939
+ scheduleEndTime: time,
2940
+ scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
2941
+ priorityType: 'high',
2942
+ client_id: inputBody.clientId,
2943
+ checkListType: 'task',
2944
+ publishDate: new Date(),
2945
+ locationCount: 1,
2946
+ ...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
2947
+ };
2948
+ data['approver'] = userAdmin;
2949
+ let answer = await findAnswer( inputBody?.answerType );
2950
+ if ( answer.length == 0 ) {
2951
+ return res.sendError( 'please enter Valid AnswerType', 500 );
2952
+ }
2953
+ if ( inputBody?.answerType === 'multiplechoicesingle' || inputBody?.answerType === 'multiplechoicemultiple' ) {
2954
+ if ( inputBody?.options && inputBody?.options.length > 0 ) {
2955
+ let optionsResult = [];
2956
+ let optionList = inputBody?.options.split( ',' );
2957
+ for ( let option of optionList ) {
2958
+ let optiondata = {
2959
+ 'answer': '',
2960
+ 'sopFlag': false,
2961
+ 'validation': false,
2962
+ 'validationType': '',
2963
+ 'referenceImage': [],
2964
+ 'runAI': false,
2965
+ 'allowUploadfromGallery': false,
2966
+ 'descriptivetype': '',
2967
+ 'showLinked': false,
2968
+ 'linkedQuestion': 0,
2969
+ 'nestedQuestion': [],
2970
+ };
2971
+ optiondata.answer = option;
2972
+ optionsResult.push( optiondata );
2973
+ }
2974
+ answer = optionsResult;
2975
+ } else {
2976
+ return res.sendError( 'please enter Valid Options', 500 );
2977
+ }
2978
+ }
2979
+ let response = await taskService.create( data );
2980
+ if ( response?.approver.length ) {
2981
+ let inputData = [];
2982
+ response?.approver.forEach( ( ele ) => {
2983
+ inputData.push( {
2984
+ userEmail: ele.email,
2985
+ checkListId: response._id,
2986
+ type: 'task',
2987
+ client_id: inputBody.clientId,
2988
+ checkListName: data?.checkListName || '',
2989
+ } );
2990
+ } );
2991
+ await traxApprover.insertMany( inputData );
2992
+ }
2993
+ if ( response?._id ) {
2994
+ let question = [
2995
+ {
2996
+ 'qno': 1,
2997
+ 'qname': inputBody.question,
2998
+ 'answerType': inputBody?.answerType || 'yes/no',
2999
+ 'runAI': false,
3000
+ 'runAIDescription': '',
3001
+ 'allowUploadfromGallery': false,
3002
+ 'linkType': false,
3003
+ 'questionReferenceImage': [],
3004
+ 'answers': answer,
3005
+ 'descriptivetype': 'text',
3006
+ },
3007
+ ];
3008
+ let images = [];
3009
+ for ( let imgpath of req.body.referenceImage ) {
3010
+ let configURL = JSON.parse( process.env.BUCKET );
3011
+ let inputData = {
3012
+ Bucket: configURL.commonAiTaskBucket,
3013
+ Key: imgpath,
3014
+ };
3015
+ let output = await getObject( inputData );
3016
+ console.log( output );
3017
+
3018
+ let image = {
3019
+ data: output.Body,
3020
+ name: imgpath,
3021
+ mimetype: output.ContentType,
3022
+ };
3023
+ let uplaodedImage = await uploadmultiImage( image );
3024
+
3025
+ let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
3026
+ let url = imgUrl.split( '/' );
3027
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
3028
+ url.splice( 0, 3 );
3029
+ }
3030
+ images.push( url.join( '/' ) );
3031
+ }
3032
+ question[0].questionReferenceImage = images;
3033
+
3034
+ if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
3035
+ answer[0].referenceImage = question[0].questionReferenceImage;
3036
+ }
3037
+
3038
+
3039
+ question = {
3040
+ checkListId: response?._id,
3041
+ question: question,
3042
+ section: 'Section 1',
3043
+ checkList: data.checkListName,
3044
+ client_id: inputBody.clientId,
3045
+ };
3046
+ await taskQuestionService.create( question );
3047
+
3048
+ let userDetails = {
3049
+ userName: inputBody.userName,
3050
+ userEmail: inputBody.userEmail,
3051
+ store_id: storeDetails.storeId,
3052
+ storeName: storeDetails.storeName,
3053
+ city: storeDetails?.storeProfile?.city,
3054
+ checkFlag: true,
3055
+ checkListId: response?._id,
3056
+ checkListName: data.checkListName,
3057
+ client_id: inputBody.clientId,
3058
+ userId: userId,
3059
+ };
3060
+ await taskAssignService.create( userDetails );
3061
+ await insertSingleProcessData( response?._id );
3062
+ return res.sendSuccess( 'Task created successfully' );
3063
+ }
3064
+ } catch ( e ) {
3065
+ logger.error( { function: 'commonAiTask', error: e } );
3066
+ return res.sendError( e, 500 );
3067
+ }
3068
+ }
2857
3069
  export async function eyeTesttask( req, res ) {
2858
3070
  try {
2859
3071
  let inputBody = req.body;
@@ -3101,14 +3313,14 @@ export async function createAiTask( req, res ) {
3101
3313
  inputBody.userEmail = finduser.userEmail;
3102
3314
 
3103
3315
 
3104
- // let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
3316
+ let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
3105
3317
  let time = inputBody?.scheduleEndTime || '11:59 PM';
3106
3318
  let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
3107
- // let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
3108
- // if ( userDetails&&userDetails.fcmToken ) {
3109
- // const fcmToken = userDetails.fcmToken;
3110
- // await sendPushNotification( title, description, fcmToken );
3111
- // }
3319
+ let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
3320
+ if ( userDetails&&userDetails.fcmToken ) {
3321
+ const fcmToken = userDetails.fcmToken;
3322
+ await sendPushNotification( title, description, fcmToken );
3323
+ }
3112
3324
  const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
3113
3325
  const currentTime = dayjs.utc();
3114
3326
  if ( inputDateTime.isBefore( currentTime ) ) {
@@ -265,7 +265,7 @@ export const taskInfoTableV1 = async ( req, res ) => {
265
265
  findQuery.push( { $addFields: { store: { $toLower: '$storeName' } } } );
266
266
  query = { store: { $in: storeList } };
267
267
  } else {
268
- query = { storeName: { $regex: requestData.searchValue.trim(), $options: 'i' } };
268
+ query = { $or: [ { storeName: { $regex: requestData.searchValue.trim(), $options: 'i' } }, { userName: { $regex: requestData.searchValue.trim(), $options: 'i' } }, { userEmail: { $regex: requestData.searchValue.trim(), $options: 'i' } } ] };
269
269
  }
270
270
  findQuery.push( { $match: { $or: [ query ] } } );
271
271
  }
@@ -405,6 +405,21 @@ export const taskInfoTableV1 = async ( req, res ) => {
405
405
  taskInfoData[0].data[i].scheduleEndTime_iso = dayjs.utc( taskInfoData[0].data[i].scheduleEndTime_iso ).format( 'DD MMM YYYY' );
406
406
  }
407
407
  result.taskInfo = taskInfoData[0].data;
408
+ if ( req.body.export ) {
409
+ const exportResult = [];
410
+ for ( let task of result.taskInfo ) {
411
+ exportResult.push( {
412
+ 'Store': task?.storeName ||'--',
413
+ 'Store SPOC': task?.userEmail ||'--',
414
+ 'Due On': dayjs.utc( task?.scheduleEndTime_iso ).format( 'DD MMM, YYYY' ) || '--',
415
+ 'Submitted On': task?.submitTime_string || '--',
416
+ 'Assigned To': task?.storeCount ||'--',
417
+ 'status': task?.checklistStatus ||'--',
418
+ } );
419
+ }
420
+ await download( exportResult, res );
421
+ return;
422
+ }
408
423
  return res.sendSuccess( result );
409
424
  } catch ( error ) {
410
425
  console.log( 'error =>', error );
@@ -747,8 +762,9 @@ export const taskDropdownListV1 = async ( req, res ) => {
747
762
  checkListName: { $first: '$checkListName' },
748
763
  checkListType: { $first: '$checkListType' },
749
764
  createdByName: { $first: '$createdByName' },
750
- storeCount: { $first: '$storeCount' },
765
+ storeCount: { $sum: 1 },
751
766
  scheduleEndTimeISO: { $first: '$scheduleEndTimeISO' },
767
+ coverage: { $first: '$coverage' },
752
768
  // submitTime_string: { $first: '$submitTime_string' },
753
769
  },
754
770
  },
@@ -763,6 +779,7 @@ export const taskDropdownListV1 = async ( req, res ) => {
763
779
  createdByName: 1,
764
780
  storeCount: 1,
765
781
  scheduleEndTimeISO: 1,
782
+ coverage: 1,
766
783
  // submitTime_string: 1,
767
784
  },
768
785
  } );
@@ -1029,6 +1046,7 @@ export async function taskDetails( req, res ) {
1029
1046
  },
1030
1047
  'publishDate': { $first: '$publishDate' },
1031
1048
  'priorityType': { $first: '$priorityType' },
1049
+ 'createdByName': { $first: '$createdByName' },
1032
1050
  // storeCount: { $first: '$storeCount' },
1033
1051
  'storeCount': { $sum: 1 },
1034
1052
  'submitCount': { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] } },
@@ -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
  .post( '/updateAssign', isAllowedSessionHandler, taskController.updateAssign );
39
40