tango-app-api-task 3.2.1-beta-9 → 3.2.1-beta-11
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
|
@@ -2337,14 +2337,29 @@ export async function createAiTask( req, res ) {
|
|
|
2337
2337
|
// await sendPushNotification( title, description, fcmToken );
|
|
2338
2338
|
// }
|
|
2339
2339
|
|
|
2340
|
-
let userAdmin = await userService.findOne( { clientId: inputBody.clientId, role: 'superadmin', isActive: true } );
|
|
2341
2340
|
|
|
2341
|
+
let approverList = inputBody?.approver.split( ',' );
|
|
2342
|
+
console.log( approverList );
|
|
2343
|
+
|
|
2344
|
+
let userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: approverList }, userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
|
|
2345
|
+
console.log( userAdmin );
|
|
2346
|
+
if ( userAdmin&&userAdmin.length===0 ) {
|
|
2347
|
+
return res.sendError( 'Invalid Approver Details', 500 );
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
let creator = await userService.find( { clientId: inputBody.clientId, email: { $in: inputBody.creator }, userType: 'client', isActive: true } );
|
|
2351
|
+
if ( creator&&creator.length===0 ) {
|
|
2352
|
+
return res.sendError( 'Invalid Creator Details', 500 );
|
|
2353
|
+
}
|
|
2354
|
+
if ( req.files&&req.files.referenceImage&& req.files.referenceImage.length>3 ) {
|
|
2355
|
+
return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
|
|
2356
|
+
}
|
|
2342
2357
|
|
|
2343
2358
|
let data = {
|
|
2344
2359
|
checkListName: `${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`,
|
|
2345
2360
|
checkListDescription: inputBody.taskDescription,
|
|
2346
|
-
createdBy:
|
|
2347
|
-
createdByName:
|
|
2361
|
+
createdBy: creator[0]._id,
|
|
2362
|
+
createdByName: creator[0].userName,
|
|
2348
2363
|
publish: true,
|
|
2349
2364
|
questionCount: 1,
|
|
2350
2365
|
storeCount: 1,
|
|
@@ -2360,7 +2375,8 @@ export async function createAiTask( req, res ) {
|
|
|
2360
2375
|
};
|
|
2361
2376
|
|
|
2362
2377
|
|
|
2363
|
-
data['approver'] =
|
|
2378
|
+
data['approver'] = userAdmin;
|
|
2379
|
+
console.log( data );
|
|
2364
2380
|
|
|
2365
2381
|
let answer = await findAnswer( inputBody?.answerType );
|
|
2366
2382
|
if ( answer.length==0 ) {
|
|
@@ -2397,17 +2413,19 @@ export async function createAiTask( req, res ) {
|
|
|
2397
2413
|
|
|
2398
2414
|
let response = await taskService.create( data );
|
|
2399
2415
|
if ( response?.approver.length ) {
|
|
2400
|
-
let
|
|
2416
|
+
let inputData = [];
|
|
2401
2417
|
response?.approver.forEach( ( ele ) => {
|
|
2402
|
-
|
|
2403
|
-
|
|
2418
|
+
console.log( data );
|
|
2419
|
+
inputData.push( {
|
|
2420
|
+
userEmail: ele.email,
|
|
2404
2421
|
checkListId: response._id,
|
|
2405
2422
|
type: 'task',
|
|
2406
2423
|
client_id: inputBody.clientId,
|
|
2407
2424
|
checkListName: data?.checkListName || '',
|
|
2408
2425
|
} );
|
|
2409
2426
|
} );
|
|
2410
|
-
|
|
2427
|
+
console.log( inputData );
|
|
2428
|
+
await traxApprover.insertMany( inputData );
|
|
2411
2429
|
}
|
|
2412
2430
|
|
|
2413
2431
|
if ( response?._id ) {
|
|
@@ -2429,6 +2447,8 @@ export async function createAiTask( req, res ) {
|
|
|
2429
2447
|
|
|
2430
2448
|
if ( req.files&& req.files.referenceImage&&req.files.referenceImage.length ) {
|
|
2431
2449
|
let images = [];
|
|
2450
|
+
console.log( req.files.referenceImage.length );
|
|
2451
|
+
|
|
2432
2452
|
|
|
2433
2453
|
for ( let image of req.files.referenceImage ) {
|
|
2434
2454
|
let uplaodedImage =await uploadmultiImage( image );
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const aitaskvalidationSchema = Joi.object().keys( {
|
|
5
|
+
storeName: Joi.string().required(),
|
|
6
|
+
taskName: Joi.string().required(),
|
|
7
|
+
question: Joi.string().required(),
|
|
8
|
+
answerType: Joi.string().required(),
|
|
9
|
+
approver: Joi.string().required(),
|
|
10
|
+
options: Joi.string().optional(),
|
|
11
|
+
scheduleDate: Joi.string().optional(),
|
|
12
|
+
time: Joi.string().optional(),
|
|
13
|
+
creator: Joi.string().optional(),
|
|
14
|
+
|
|
15
|
+
} );
|
|
16
|
+
|
|
17
|
+
export const aitaskvalidation = {
|
|
18
|
+
body: aitaskvalidationSchema,
|
|
19
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
import * as taskController from '../controllers/task.controller.js';
|
|
3
|
-
import { isAllowedSessionHandler, accessVerification, isAllowedClient, isAllowedInternalAPIHandler } from 'tango-app-api-middleware';
|
|
3
|
+
import { isAllowedSessionHandler, validate, accessVerification, isAllowedClient, isAllowedInternalAPIHandler } from 'tango-app-api-middleware';
|
|
4
4
|
import express from 'express';
|
|
5
|
-
|
|
5
|
+
import { aitaskvalidation } from '../dtos/task.dto.js';
|
|
6
6
|
export const taskRouter = express.Router();
|
|
7
7
|
|
|
8
8
|
taskRouter
|
|
@@ -27,7 +27,7 @@ taskRouter
|
|
|
27
27
|
.get( '/duplicateTask/:checklistId', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.duplicateChecklist )
|
|
28
28
|
.get( '/teamMigrations', taskController.teamMigrations )
|
|
29
29
|
.post( '/createaiChecklist', isAllowedInternalAPIHandler, taskController.createAiChecklist )
|
|
30
|
-
.post( '/createaiTask', isAllowedInternalAPIHandler, taskController.createAiTask )
|
|
30
|
+
.post( '/createaiTask', isAllowedInternalAPIHandler, validate( aitaskvalidation ), taskController.createAiTask )
|
|
31
31
|
.get( '/getcoustemer', taskController.customertrial );
|
|
32
32
|
|
|
33
33
|
|