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

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-37",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1927,15 +1927,19 @@ export async function getAnswerCount( req, res ) {
1927
1927
  export const taskDropdown = async ( req, res ) => {
1928
1928
  try {
1929
1929
  let requestData = req.body;
1930
-
1930
+ let fromDate = new Date( requestData.fromDate );
1931
+ let toDate = new Date( requestData.toDate );
1932
+ let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
1933
+ toDate = new Date( toDate.getTime() - userTimezoneOffset );
1934
+ toDate.setUTCHours( 23, 59, 59, 59 );
1931
1935
  let result = {};
1932
1936
 
1933
1937
  let findQuery = [];
1934
1938
  let findAndQuery = [];
1935
1939
  findAndQuery.push(
1936
1940
  { client_id: requestData.clientId },
1937
- // { date_iso: { $gte: fromDate } },
1938
- // { date_iso: { $lte: toDate } },
1941
+ { date_iso: { $gte: fromDate } },
1942
+ { date_iso: { $lte: toDate } },
1939
1943
  { checkListType: { $in: [ 'task', 'checklistTask', 'cctv' ] } },
1940
1944
  );
1941
1945
 
@@ -2854,6 +2858,212 @@ export async function StoreHygienetask( req, res ) {
2854
2858
  return res.sendError( e, 500 );
2855
2859
  }
2856
2860
  }
2861
+ export async function commonAiTask( req, res ) {
2862
+ try {
2863
+ let inputBody = req.body;
2864
+
2865
+ inputBody.clientId = 11;
2866
+ inputBody.taskDescription = '';
2867
+ let userId;
2868
+ let storeDetails = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
2869
+ if ( !storeDetails ) {
2870
+ return res.sendError( 'Store Not Found', 500 );
2871
+ }
2872
+
2873
+ let url = JSON.parse( process.env.LAMBDAURL );
2874
+ let checklistId = url.dailystoreChecklistId;
2875
+ let finduser = await checklistassignconfigModel.findOne( { checkListId: new mongoose.Types.ObjectId( checklistId ), store_id: storeDetails.storeId } );
2876
+
2877
+ if ( !finduser ) {
2878
+ return res.sendError( 'No user Found For this store', 500 );
2879
+ }
2880
+
2881
+ userId = finduser.userId;
2882
+ inputBody.userName = finduser.userName;
2883
+ inputBody.userEmail = finduser.userEmail;
2884
+
2885
+
2886
+ let teamList = await findteams( { users: { $elemMatch: { email: finduser.userEmail } } } );
2887
+
2888
+ inputBody.approver = '';
2889
+ for ( let team of teamList ) {
2890
+ for ( let user of team.Teamlead ) {
2891
+ inputBody.approver = user.email + ',' + inputBody.approver;
2892
+ }
2893
+ }
2894
+ inputBody.approver = inputBody.approver.replace( /,$/, '' );
2895
+
2896
+
2897
+ let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
2898
+ let time = inputBody?.scheduleEndTime || '11:59 PM';
2899
+ let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
2900
+ let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
2901
+ if ( userDetails&&userDetails.fcmToken ) {
2902
+ const fcmToken = userDetails.fcmToken;
2903
+ await sendPushNotification( title, description, fcmToken );
2904
+ }
2905
+ const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
2906
+ const currentTime = dayjs.utc();
2907
+ if ( inputDateTime.isBefore( currentTime ) ) {
2908
+ return res.sendError( 'The input date-time is before the current time.', 500 );
2909
+ }
2910
+
2911
+ let approverList = inputBody?.approver.split( ',' );
2912
+
2913
+
2914
+ let userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: approverList }, userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
2915
+
2916
+ if ( userAdmin && userAdmin.length === 0 ) {
2917
+ userAdmin = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
2918
+ }
2919
+
2920
+ let creator = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true } );
2921
+ if ( creator && creator.length === 0 ) {
2922
+ return res.sendError( 'Invalid Creator Details', 500 );
2923
+ }
2924
+
2925
+ if ( req.body && req.body.referenceImage && req.body.referenceImage.length > 3 ) {
2926
+ return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
2927
+ }
2928
+ let data = {
2929
+ checkListName: `${inputBody.taskName}(${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )})`,
2930
+ checkListDescription: inputBody.taskDescription,
2931
+ createdBy: creator[0]._id,
2932
+ createdByName: creator[0].userName,
2933
+ publish: true,
2934
+ questionCount: 1,
2935
+ storeCount: 1,
2936
+ scheduleDate: date,
2937
+ scheduleEndTime: time,
2938
+ scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
2939
+ priorityType: 'high',
2940
+ client_id: inputBody.clientId,
2941
+ checkListType: 'task',
2942
+ publishDate: new Date(),
2943
+ locationCount: 1,
2944
+ ...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
2945
+ };
2946
+ data['approver'] = userAdmin;
2947
+ let answer = await findAnswer( inputBody?.answerType );
2948
+ if ( answer.length == 0 ) {
2949
+ return res.sendError( 'please enter Valid AnswerType', 500 );
2950
+ }
2951
+ if ( inputBody?.answerType === 'multiplechoicesingle' || inputBody?.answerType === 'multiplechoicemultiple' ) {
2952
+ if ( inputBody?.options && inputBody?.options.length > 0 ) {
2953
+ let optionsResult = [];
2954
+ let optionList = inputBody?.options.split( ',' );
2955
+ for ( let option of optionList ) {
2956
+ let optiondata = {
2957
+ 'answer': '',
2958
+ 'sopFlag': false,
2959
+ 'validation': false,
2960
+ 'validationType': '',
2961
+ 'referenceImage': [],
2962
+ 'runAI': false,
2963
+ 'allowUploadfromGallery': false,
2964
+ 'descriptivetype': '',
2965
+ 'showLinked': false,
2966
+ 'linkedQuestion': 0,
2967
+ 'nestedQuestion': [],
2968
+ };
2969
+ optiondata.answer = option;
2970
+ optionsResult.push( optiondata );
2971
+ }
2972
+ answer = optionsResult;
2973
+ } else {
2974
+ return res.sendError( 'please enter Valid Options', 500 );
2975
+ }
2976
+ }
2977
+ let response = await taskService.create( data );
2978
+ if ( response?.approver.length ) {
2979
+ let inputData = [];
2980
+ response?.approver.forEach( ( ele ) => {
2981
+ inputData.push( {
2982
+ userEmail: ele.email,
2983
+ checkListId: response._id,
2984
+ type: 'task',
2985
+ client_id: inputBody.clientId,
2986
+ checkListName: data?.checkListName || '',
2987
+ } );
2988
+ } );
2989
+ await traxApprover.insertMany( inputData );
2990
+ }
2991
+ if ( response?._id ) {
2992
+ let question = [
2993
+ {
2994
+ 'qno': 1,
2995
+ 'qname': inputBody.question,
2996
+ 'answerType': inputBody?.answerType || 'yes/no',
2997
+ 'runAI': false,
2998
+ 'runAIDescription': '',
2999
+ 'allowUploadfromGallery': false,
3000
+ 'linkType': false,
3001
+ 'questionReferenceImage': [],
3002
+ 'answers': answer,
3003
+ 'descriptivetype': 'text',
3004
+ },
3005
+ ];
3006
+ let images = [];
3007
+ for ( let imgpath of req.body.referenceImage ) {
3008
+ let configURL = JSON.parse( process.env.BUCKET );
3009
+ let inputData = {
3010
+ Bucket: configURL.commonAiTaskBucket,
3011
+ Key: imgpath,
3012
+ };
3013
+ let output = await getObject( inputData );
3014
+ console.log( output );
3015
+
3016
+ let image = {
3017
+ data: output.Body,
3018
+ name: imgpath,
3019
+ mimetype: output.ContentType,
3020
+ };
3021
+ let uplaodedImage = await uploadmultiImage( image );
3022
+
3023
+ let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
3024
+ let url = imgUrl.split( '/' );
3025
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
3026
+ url.splice( 0, 3 );
3027
+ }
3028
+ images.push( url.join( '/' ) );
3029
+ }
3030
+ question[0].questionReferenceImage = images;
3031
+
3032
+ if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
3033
+ answer[0].referenceImage = question[0].questionReferenceImage;
3034
+ }
3035
+
3036
+
3037
+ question = {
3038
+ checkListId: response?._id,
3039
+ question: question,
3040
+ section: 'Section 1',
3041
+ checkList: data.checkListName,
3042
+ client_id: inputBody.clientId,
3043
+ };
3044
+ await taskQuestionService.create( question );
3045
+
3046
+ let userDetails = {
3047
+ userName: inputBody.userName,
3048
+ userEmail: inputBody.userEmail,
3049
+ store_id: storeDetails.storeId,
3050
+ storeName: storeDetails.storeName,
3051
+ city: storeDetails?.storeProfile?.city,
3052
+ checkFlag: true,
3053
+ checkListId: response?._id,
3054
+ checkListName: data.checkListName,
3055
+ client_id: inputBody.clientId,
3056
+ userId: userId,
3057
+ };
3058
+ await taskAssignService.create( userDetails );
3059
+ await insertSingleProcessData( response?._id );
3060
+ return res.sendSuccess( 'Task created successfully' );
3061
+ }
3062
+ } catch ( e ) {
3063
+ logger.error( { function: 'commonAiTask', error: e } );
3064
+ return res.sendError( e, 500 );
3065
+ }
3066
+ }
2857
3067
  export async function eyeTesttask( req, res ) {
2858
3068
  try {
2859
3069
  let inputBody = req.body;
@@ -3101,14 +3311,14 @@ export async function createAiTask( req, res ) {
3101
3311
  inputBody.userEmail = finduser.userEmail;
3102
3312
 
3103
3313
 
3104
- // let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
3314
+ let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
3105
3315
  let time = inputBody?.scheduleEndTime || '11:59 PM';
3106
3316
  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
- // }
3317
+ let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
3318
+ if ( userDetails&&userDetails.fcmToken ) {
3319
+ const fcmToken = userDetails.fcmToken;
3320
+ await sendPushNotification( title, description, fcmToken );
3321
+ }
3112
3322
  const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
3113
3323
  const currentTime = dayjs.utc();
3114
3324
  if ( inputDateTime.isBefore( currentTime ) ) {
@@ -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 );
@@ -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