tango-app-api-task 3.2.1-beta-1 → 3.2.1-beta-2
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
|
@@ -15457,3 +15457,156 @@ export async function teamMigrations( req, res ) {
|
|
|
15457
15457
|
return res.sendError( error, 500 );
|
|
15458
15458
|
}
|
|
15459
15459
|
}
|
|
15460
|
+
|
|
15461
|
+
export async function createAiChecklist( req, res ) {
|
|
15462
|
+
try {
|
|
15463
|
+
let inputBody = req.body;
|
|
15464
|
+
let userId;
|
|
15465
|
+
let storeDetails = await storeService.findOne( { storeId: inputBody.storeId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
|
|
15466
|
+
let userDetails = await userService.findOne( { email: inputBody.userEmail } );
|
|
15467
|
+
if ( !userDetails ) {
|
|
15468
|
+
let userData = {
|
|
15469
|
+
userName: inputBody.name,
|
|
15470
|
+
email: inputBody.userEmail,
|
|
15471
|
+
mobileNumber: '',
|
|
15472
|
+
clientId: inputBody.clientId,
|
|
15473
|
+
};
|
|
15474
|
+
userId = await createUser( userData );
|
|
15475
|
+
} else {
|
|
15476
|
+
userId = userDetails._id;
|
|
15477
|
+
}
|
|
15478
|
+
|
|
15479
|
+
let title = `New Task Alert ${inputBody.taskName}`;
|
|
15480
|
+
let time = inputBody?.scheduleEndTime || '11:59 PM';
|
|
15481
|
+
let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
|
|
15482
|
+
let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
|
|
15483
|
+
if ( userDetails.fcmToken ) {
|
|
15484
|
+
const fcmToken = userDetails.fcmToken;
|
|
15485
|
+
await sendPushNotification( title, description, fcmToken );
|
|
15486
|
+
}
|
|
15487
|
+
|
|
15488
|
+
let userAdmin = await userService.findOne( { clientId: inputBody.clientId, role: 'superadmin', isActive: true } );
|
|
15489
|
+
console.log( userAdmin );
|
|
15490
|
+
|
|
15491
|
+
let data = {
|
|
15492
|
+
checkListName: inputBody.taskName,
|
|
15493
|
+
checkListDescription: inputBody.checkListDescription,
|
|
15494
|
+
createdBy: userAdmin._id,
|
|
15495
|
+
createdByName: userAdmin.userName,
|
|
15496
|
+
publish: true,
|
|
15497
|
+
questionCount: 1,
|
|
15498
|
+
storeCount: 1,
|
|
15499
|
+
scheduleDate: date,
|
|
15500
|
+
scheduleEndTime: time,
|
|
15501
|
+
scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
|
|
15502
|
+
priorityType: 'high',
|
|
15503
|
+
client_id: inputBody.clientId,
|
|
15504
|
+
checkListType: 'task',
|
|
15505
|
+
publishDate: new Date(),
|
|
15506
|
+
locationCount: 1,
|
|
15507
|
+
...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
|
|
15508
|
+
};
|
|
15509
|
+
|
|
15510
|
+
|
|
15511
|
+
data['approver'] = { name: userAdmin.userName, value: userAdmin.email };
|
|
15512
|
+
|
|
15513
|
+
|
|
15514
|
+
let response = await taskService.create( data );
|
|
15515
|
+
if ( response?.approver.length ) {
|
|
15516
|
+
let data = [];
|
|
15517
|
+
response?.approver.forEach( ( ele ) => {
|
|
15518
|
+
data.push( {
|
|
15519
|
+
userEmail: ele.value,
|
|
15520
|
+
checkListId: response._id,
|
|
15521
|
+
type: 'task',
|
|
15522
|
+
client_id: inputBody.clientId,
|
|
15523
|
+
checkListName: inputBody?.taskName || '',
|
|
15524
|
+
} );
|
|
15525
|
+
} );
|
|
15526
|
+
await traxApprover.insertMany( data );
|
|
15527
|
+
}
|
|
15528
|
+
|
|
15529
|
+
if ( response?._id ) {
|
|
15530
|
+
let question = [
|
|
15531
|
+
{
|
|
15532
|
+
'qno': 1,
|
|
15533
|
+
'qname': inputBody.question,
|
|
15534
|
+
'answerType': inputBody?.answerType || 'yes/no',
|
|
15535
|
+
'runAI': false,
|
|
15536
|
+
'runAIDescription': '',
|
|
15537
|
+
'allowUploadfromGallery': false,
|
|
15538
|
+
'linkType': false,
|
|
15539
|
+
'questionReferenceImage': [],
|
|
15540
|
+
'answers': [
|
|
15541
|
+
{
|
|
15542
|
+
'answer': 'Yes',
|
|
15543
|
+
'answeroptionNumber': 1,
|
|
15544
|
+
'sopFlag': false,
|
|
15545
|
+
'validation': false,
|
|
15546
|
+
'validationType': '',
|
|
15547
|
+
'linkedQuestion': 0,
|
|
15548
|
+
'showLinked': false,
|
|
15549
|
+
'referenceImage': '',
|
|
15550
|
+
'runAI': false,
|
|
15551
|
+
'allowUploadfromGallery': false,
|
|
15552
|
+
'descriptivetype': '',
|
|
15553
|
+
},
|
|
15554
|
+
{
|
|
15555
|
+
'answer': 'No',
|
|
15556
|
+
'answeroptionNumber': 2,
|
|
15557
|
+
'sopFlag': false,
|
|
15558
|
+
'validation': false,
|
|
15559
|
+
'validationType': '',
|
|
15560
|
+
'linkedQuestion': 0,
|
|
15561
|
+
'showLinked': false,
|
|
15562
|
+
'referenceImage': '',
|
|
15563
|
+
'runAI': false,
|
|
15564
|
+
'allowUploadfromGallery': false,
|
|
15565
|
+
'descriptivetype': '',
|
|
15566
|
+
},
|
|
15567
|
+
],
|
|
15568
|
+
'descriptivetype': 'text',
|
|
15569
|
+
},
|
|
15570
|
+
];
|
|
15571
|
+
if ( inputBody.referenceImage.length ) {
|
|
15572
|
+
let images = [];
|
|
15573
|
+
question[0].questionReferenceImage.forEach( ( ele ) => {
|
|
15574
|
+
let imgUrl = decodeURIComponent( ele.split( '?' )[0] );
|
|
15575
|
+
let url = imgUrl.split( '/' );
|
|
15576
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
15577
|
+
url.splice( 0, 3 );
|
|
15578
|
+
}
|
|
15579
|
+
images.push( url.join( '/' ) );
|
|
15580
|
+
} );
|
|
15581
|
+
question[0].questionReferenceImage = images;
|
|
15582
|
+
}
|
|
15583
|
+
question = {
|
|
15584
|
+
checkListId: response?._id,
|
|
15585
|
+
question: question,
|
|
15586
|
+
section: 'Section 1',
|
|
15587
|
+
checkList: data.checkListName,
|
|
15588
|
+
client_id: inputBody.clientId,
|
|
15589
|
+
};
|
|
15590
|
+
await taskQuestionService.create( question );
|
|
15591
|
+
|
|
15592
|
+
let userDetails = {
|
|
15593
|
+
userName: inputBody.userName,
|
|
15594
|
+
userEmail: inputBody.userEmail,
|
|
15595
|
+
store_id: storeDetails.storeId,
|
|
15596
|
+
storeName: storeDetails.storeName,
|
|
15597
|
+
city: storeDetails?.storeProfile?.city,
|
|
15598
|
+
checkFlag: true,
|
|
15599
|
+
checkListId: response?._id,
|
|
15600
|
+
checkListName: data.checkListName,
|
|
15601
|
+
client_id: inputBody.clientId,
|
|
15602
|
+
userId: userId,
|
|
15603
|
+
};
|
|
15604
|
+
await taskAssignService.create( userDetails );
|
|
15605
|
+
await insertSingleProcessData( response?._id );
|
|
15606
|
+
return res.sendSuccess( 'Task created successfully' );
|
|
15607
|
+
}
|
|
15608
|
+
} catch ( e ) {
|
|
15609
|
+
logger.error( { function: createAiChecklist, error: e } );
|
|
15610
|
+
return res.sendError( e, 500 );
|
|
15611
|
+
}
|
|
15612
|
+
}
|
|
@@ -990,7 +990,7 @@ export async function taskDetails( req, res ) {
|
|
|
990
990
|
$match: {
|
|
991
991
|
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
992
992
|
client_id: req.body.clientId,
|
|
993
|
-
|
|
993
|
+
store_id: { $in: req.body.storeId },
|
|
994
994
|
...( idList.length ) ? { sourceCheckList_id: { $in: idList } } : {},
|
|
995
995
|
},
|
|
996
996
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import * as taskController from '../controllers/task.controller.js';
|
|
3
|
-
import { isAllowedSessionHandler, accessVerification, isAllowedClient } from 'tango-app-api-middleware';
|
|
3
|
+
import { isAllowedSessionHandler, accessVerification, isAllowedClient, isAllowedInternalAPIHandler } from 'tango-app-api-middleware';
|
|
4
4
|
import express from 'express';
|
|
5
5
|
|
|
6
6
|
export const taskRouter = express.Router();
|
|
@@ -25,6 +25,7 @@ taskRouter
|
|
|
25
25
|
.get( '/task-list', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ ] } ] } ), taskController.taskList )
|
|
26
26
|
.put( '/publish', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.updatePublish )
|
|
27
27
|
.get( '/duplicateTask/:checklistId', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.duplicateChecklist )
|
|
28
|
-
.get( '/teamMigrations', taskController.teamMigrations )
|
|
28
|
+
.get( '/teamMigrations', taskController.teamMigrations )
|
|
29
|
+
.post( '/createaiChecklist', isAllowedInternalAPIHandler, taskController.createAiChecklist );
|
|
29
30
|
|
|
30
31
|
|