tango-app-api-task 3.2.1-beta-30 → 3.2.1-beta-31
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
|
@@ -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' )})`,
|
|
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;
|
|
@@ -2896,14 +3102,14 @@ export async function createAiTask( req, res ) {
|
|
|
2896
3102
|
inputBody.userEmail = finduser.userEmail;
|
|
2897
3103
|
|
|
2898
3104
|
|
|
2899
|
-
|
|
3105
|
+
let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
|
|
2900
3106
|
let time = inputBody?.scheduleEndTime || '11:59 PM';
|
|
2901
3107
|
let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
3108
|
+
let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
|
|
3109
|
+
if ( userDetails&&userDetails.fcmToken ) {
|
|
3110
|
+
const fcmToken = userDetails.fcmToken;
|
|
3111
|
+
await sendPushNotification( title, description, fcmToken );
|
|
3112
|
+
}
|
|
2907
3113
|
const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
|
|
2908
3114
|
const currentTime = dayjs.utc();
|
|
2909
3115
|
if ( inputDateTime.isBefore( currentTime ) ) {
|
package/src/dtos/task.dto.js
CHANGED
|
@@ -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
|
|