tango-app-api-task 3.2.1-beta-8 → 3.2.1-beta-10
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 +3 -3
- package/src/controllers/task.controller.js +29 -9
- package/src/dtos/task.dto.js +19 -0
- package/src/routes/task.routes.js +3 -3
- package/app.js +0 -46
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-task",
|
|
3
|
-
"version": "3.2.1-beta-
|
|
3
|
+
"version": "3.2.1-beta-10",
|
|
4
4
|
"description": "Task",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . && node
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node index.js\""
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=18.10.0"
|
|
@@ -2325,7 +2325,8 @@ export async function createAiTask( req, res ) {
|
|
|
2325
2325
|
return res.sendError( 'No user Found For this store', 500 );
|
|
2326
2326
|
}
|
|
2327
2327
|
userId = finduser.userId;
|
|
2328
|
-
|
|
2328
|
+
inputBody.userName = finduser.userName;
|
|
2329
|
+
inputBody.userEmail = finduser.userEmail;
|
|
2329
2330
|
|
|
2330
2331
|
// let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
|
|
2331
2332
|
let time = inputBody?.scheduleEndTime || '11:59 PM';
|
|
@@ -2336,14 +2337,29 @@ export async function createAiTask( req, res ) {
|
|
|
2336
2337
|
// await sendPushNotification( title, description, fcmToken );
|
|
2337
2338
|
// }
|
|
2338
2339
|
|
|
2339
|
-
let userAdmin = await userService.findOne( { clientId: inputBody.clientId, role: 'superadmin', isActive: true } );
|
|
2340
2340
|
|
|
2341
|
+
let approverList = inputBody?.approver.split( ',' );
|
|
2342
|
+
console.log( approverList );
|
|
2343
|
+
|
|
2344
|
+
let userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: approverList }, isActive: true }, { name: '$userName', email: 1 } );
|
|
2345
|
+
console.log( userAdmin );
|
|
2346
|
+
if ( userAdmin&&userAdmin.length===0 ) {
|
|
2347
|
+
return res.sendError( 'Atlease one active approver is required', 500 );
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
let creator = await userService.find( { clientId: inputBody.clientId, email: { $in: inputBody.creator }, isActive: true } );
|
|
2351
|
+
if ( creator&&creator.length===0 ) {
|
|
2352
|
+
return res.sendError( 'Atlease one active creator is required', 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
|
+
}
|
|
2341
2357
|
|
|
2342
2358
|
let data = {
|
|
2343
2359
|
checkListName: `${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`,
|
|
2344
2360
|
checkListDescription: inputBody.taskDescription,
|
|
2345
|
-
createdBy:
|
|
2346
|
-
createdByName:
|
|
2361
|
+
createdBy: creator[0]._id,
|
|
2362
|
+
createdByName: creator[0].userName,
|
|
2347
2363
|
publish: true,
|
|
2348
2364
|
questionCount: 1,
|
|
2349
2365
|
storeCount: 1,
|
|
@@ -2359,7 +2375,8 @@ export async function createAiTask( req, res ) {
|
|
|
2359
2375
|
};
|
|
2360
2376
|
|
|
2361
2377
|
|
|
2362
|
-
data['approver'] =
|
|
2378
|
+
data['approver'] = userAdmin;
|
|
2379
|
+
console.log( data );
|
|
2363
2380
|
|
|
2364
2381
|
let answer = await findAnswer( inputBody?.answerType );
|
|
2365
2382
|
if ( answer.length==0 ) {
|
|
@@ -2396,17 +2413,19 @@ export async function createAiTask( req, res ) {
|
|
|
2396
2413
|
|
|
2397
2414
|
let response = await taskService.create( data );
|
|
2398
2415
|
if ( response?.approver.length ) {
|
|
2399
|
-
let
|
|
2416
|
+
let inputData = [];
|
|
2400
2417
|
response?.approver.forEach( ( ele ) => {
|
|
2401
|
-
|
|
2402
|
-
|
|
2418
|
+
console.log( data );
|
|
2419
|
+
inputData.push( {
|
|
2420
|
+
userEmail: ele.email,
|
|
2403
2421
|
checkListId: response._id,
|
|
2404
2422
|
type: 'task',
|
|
2405
2423
|
client_id: inputBody.clientId,
|
|
2406
2424
|
checkListName: data?.checkListName || '',
|
|
2407
2425
|
} );
|
|
2408
2426
|
} );
|
|
2409
|
-
|
|
2427
|
+
console.log( inputData );
|
|
2428
|
+
await traxApprover.insertMany( inputData );
|
|
2410
2429
|
}
|
|
2411
2430
|
|
|
2412
2431
|
if ( response?._id ) {
|
|
@@ -2466,6 +2485,7 @@ export async function createAiTask( req, res ) {
|
|
|
2466
2485
|
client_id: inputBody.clientId,
|
|
2467
2486
|
userId: userId,
|
|
2468
2487
|
};
|
|
2488
|
+
console.log( userDetails );
|
|
2469
2489
|
await taskAssignService.create( userDetails );
|
|
2470
2490
|
await insertSingleProcessData( response?._id );
|
|
2471
2491
|
return res.sendSuccess( 'Task created successfully' );
|
|
@@ -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
|
|
package/app.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import express from 'express';
|
|
2
|
-
import { taskRouter, taskDashboardRouter, taskActionCenterRouter } from './index.js';
|
|
3
|
-
|
|
4
|
-
import dotenv from 'dotenv';
|
|
5
|
-
import pkg from 'body-parser';
|
|
6
|
-
const { json, urlencoded } = pkg;
|
|
7
|
-
import fileupload from 'express-fileupload';
|
|
8
|
-
import { logger } from 'tango-app-api-middleware';
|
|
9
|
-
import { connectdb } from './config/database/database.js';
|
|
10
|
-
import responseMiddleware from './config/response/response.js';
|
|
11
|
-
import errorMiddleware from './config/response/error.js';
|
|
12
|
-
import cors from 'cors';
|
|
13
|
-
|
|
14
|
-
const env=dotenv.config();
|
|
15
|
-
|
|
16
|
-
const app = express();
|
|
17
|
-
const PORT = process.env.PORT || 3000;
|
|
18
|
-
app.use( cors() );
|
|
19
|
-
|
|
20
|
-
app.use( fileupload() );
|
|
21
|
-
|
|
22
|
-
if ( env.error ) {
|
|
23
|
-
logger.error( '.env not found' );
|
|
24
|
-
process.exit( 1 );
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
app.use( json( { limit: '500mb' } ) );
|
|
28
|
-
app.use(
|
|
29
|
-
urlencoded( {
|
|
30
|
-
extended: true,
|
|
31
|
-
} ),
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
app.use( responseMiddleware );
|
|
35
|
-
app.use( errorMiddleware );
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
app.use( '/task', taskRouter );
|
|
39
|
-
app.use( '/task/dashboard', taskDashboardRouter );
|
|
40
|
-
app.use( '/task/actionCenter', taskActionCenterRouter );
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
app.listen( PORT, () => {
|
|
44
|
-
console.log( `server is running on port= ${PORT} ` );
|
|
45
|
-
connectdb();
|
|
46
|
-
} );
|