tango-app-api-trax 3.7.2-multireff-12 → 3.7.3-runai-1
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/app.js +56 -0
- package/package.json +3 -3
- package/src/controllers/mobileTrax.controller.js +1 -1
- package/src/controllers/trax.controller.js +161 -1
- package/src/dtos/validation.dtos.js +27 -0
- package/src/routes/trax.routes.js +5 -3
- package/src/services/runAIFeatures.services.js +31 -0
- package/src/services/runAIRequest.services.js +31 -0
package/app.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { traxDashboardRouter, traxFlagRouter, traxRouter, downloadRouter, mobileRouter, locusOrderRouter, internalTraxRouter, traxActivityLogRouter, galleryRouter } from './index.js';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
import pkg from 'body-parser';
|
|
5
|
+
const { json, urlencoded } = pkg;
|
|
6
|
+
import { logger } from 'tango-app-api-middleware';
|
|
7
|
+
import { connectdb } from './config/database/database.js';
|
|
8
|
+
import responseMiddleware from './config/response/response.js';
|
|
9
|
+
import errorMiddleware from './config/response/error.js';
|
|
10
|
+
import cors from 'cors';
|
|
11
|
+
import admin from 'firebase-admin';
|
|
12
|
+
import fileupload from 'express-fileupload';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const serviceAccountPath = JSON.parse( process.env.FIREBASE );
|
|
16
|
+
admin.initializeApp( {
|
|
17
|
+
credential: admin.credential.cert( serviceAccountPath ),
|
|
18
|
+
} );
|
|
19
|
+
|
|
20
|
+
const env=dotenv.config();
|
|
21
|
+
|
|
22
|
+
const app = express();
|
|
23
|
+
const PORT = process.env.PORT || 3000;
|
|
24
|
+
app.use( cors() );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if ( env.error ) {
|
|
28
|
+
logger.error( '.env not found' );
|
|
29
|
+
process.exit( 1 );
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
app.use( json( { limit: '500mb' } ) );
|
|
33
|
+
app.use( fileupload() );
|
|
34
|
+
app.use(
|
|
35
|
+
urlencoded( {
|
|
36
|
+
extended: true,
|
|
37
|
+
} ),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
app.use( responseMiddleware );
|
|
41
|
+
app.use( errorMiddleware );
|
|
42
|
+
|
|
43
|
+
app.use( '/trax/dashboard', traxDashboardRouter );
|
|
44
|
+
app.use( '/trax', traxRouter );
|
|
45
|
+
app.use( '/trax/flag', traxFlagRouter );
|
|
46
|
+
app.use( '/trax/downloads', downloadRouter );
|
|
47
|
+
app.use( '/trax/mobileAPI', mobileRouter );
|
|
48
|
+
app.use( '/trax/locusorder', locusOrderRouter );
|
|
49
|
+
app.use( '/trax/internalAPI', internalTraxRouter );
|
|
50
|
+
app.use( '/trax/activityLog', traxActivityLogRouter );
|
|
51
|
+
app.use( '/trax/gallery', galleryRouter );
|
|
52
|
+
|
|
53
|
+
app.listen( PORT, () => {
|
|
54
|
+
console.log( `server is running on port= ${PORT} ` );
|
|
55
|
+
connectdb();
|
|
56
|
+
} );
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-trax",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.3-runai-1",
|
|
4
4
|
"description": "Trax",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "app.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . && node
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node app.js\""
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=18.10.0"
|
|
@@ -2022,7 +2022,7 @@ export async function submitTask( req, res ) {
|
|
|
2022
2022
|
const updateQuery = {
|
|
2023
2023
|
_id: new ObjectId( processedcheckListId ),
|
|
2024
2024
|
userId: user._id,
|
|
2025
|
-
date_string: date,
|
|
2025
|
+
// date_string: date,
|
|
2026
2026
|
};
|
|
2027
2027
|
|
|
2028
2028
|
// questionAnswers.forEach( ( section ) => {
|
|
@@ -23,6 +23,8 @@ dayjs.extend( utc );
|
|
|
23
23
|
dayjs.extend( customParseFormat );
|
|
24
24
|
import * as clusterServices from '../services/cluster.service.js';
|
|
25
25
|
import * as teamsServices from '../services/teams.service.js';
|
|
26
|
+
import * as runAIFeatureServices from '../services/runAIFeatures.services.js';
|
|
27
|
+
import * as runAIRequestServices from '../services/runAIRequest.services.js';
|
|
26
28
|
|
|
27
29
|
|
|
28
30
|
export const checklist = async ( req, res ) => {
|
|
@@ -4529,7 +4531,6 @@ export async function updateAiConfigure( req, res ) {
|
|
|
4529
4531
|
}
|
|
4530
4532
|
}
|
|
4531
4533
|
|
|
4532
|
-
|
|
4533
4534
|
export async function getAiDetails( req, res ) {
|
|
4534
4535
|
try {
|
|
4535
4536
|
let storeList = [];
|
|
@@ -4587,3 +4588,162 @@ export async function getAiDetails( req, res ) {
|
|
|
4587
4588
|
return res.sendError( e, 500 );
|
|
4588
4589
|
}
|
|
4589
4590
|
}
|
|
4591
|
+
|
|
4592
|
+
export async function getRunAIFeatures( req, res ) {
|
|
4593
|
+
try {
|
|
4594
|
+
console.log( 'req.body =>', req.body );
|
|
4595
|
+
let reqestData = req.body;
|
|
4596
|
+
let getRunAIFeaturesQuery = [
|
|
4597
|
+
{
|
|
4598
|
+
$match: {
|
|
4599
|
+
$or: [ { client_id: reqestData.client_id }, { client_id: { $exists: false } } ],
|
|
4600
|
+
isdeleted: false,
|
|
4601
|
+
},
|
|
4602
|
+
},
|
|
4603
|
+
{ $addFields: { sortOrder: { $cond: [ { $eq: [ '$featureName', 'Others' ] }, 1, 0 ] } } },
|
|
4604
|
+
{ $sort: { sortOrder: 1, _id: 1 } },
|
|
4605
|
+
{ $project: { client_id: 1, featureName: 1, lableName: 1 } },
|
|
4606
|
+
];
|
|
4607
|
+
let response = await runAIFeatureServices.aggregate( getRunAIFeaturesQuery );
|
|
4608
|
+
if ( response && response.length > 0 ) {
|
|
4609
|
+
return res.sendSuccess( response );
|
|
4610
|
+
} else {
|
|
4611
|
+
return res.sendError( 'No Features Available', 204 );
|
|
4612
|
+
}
|
|
4613
|
+
} catch ( e ) {
|
|
4614
|
+
logger.error( { functionName: 'getRunAIFeatures', error: e } );
|
|
4615
|
+
return res.sendError( e, 500 );
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
|
|
4619
|
+
export async function updateRunAIRequest( req, res ) {
|
|
4620
|
+
try {
|
|
4621
|
+
let inputBody = req.body;
|
|
4622
|
+
inputBody.createdBy = req.user.email;
|
|
4623
|
+
let checkRunAIRequestQuery = {
|
|
4624
|
+
clientId: inputBody.clientId,
|
|
4625
|
+
checkListId: inputBody.checkListId,
|
|
4626
|
+
sectionNo: inputBody.sectionNo,
|
|
4627
|
+
qname: inputBody.qname,
|
|
4628
|
+
answer: inputBody.answer,
|
|
4629
|
+
};
|
|
4630
|
+
let checkRunAIRequest = await runAIRequestServices.findOne( checkRunAIRequestQuery );
|
|
4631
|
+
|
|
4632
|
+
// runAI Features Updated
|
|
4633
|
+
let incomeFeatures = inputBody.runAIFeatures;
|
|
4634
|
+
for ( let i = 0; i < incomeFeatures.length; i++ ) {
|
|
4635
|
+
// const element = array[i];
|
|
4636
|
+
if ( incomeFeatures[i].featureName == 'Others' ) {
|
|
4637
|
+
let insertData = {
|
|
4638
|
+
'client_id': inputBody.clientId,
|
|
4639
|
+
'featureName': incomeFeatures[i].lableName,
|
|
4640
|
+
'lableName': incomeFeatures[i].lableName,
|
|
4641
|
+
};
|
|
4642
|
+
console.log( 'insertData =>', insertData );
|
|
4643
|
+
await runAIFeatureServices.create( insertData );
|
|
4644
|
+
}
|
|
4645
|
+
}
|
|
4646
|
+
if ( checkRunAIRequest ) {
|
|
4647
|
+
let updateRunAIRequest = await runAIRequestServices.updateOne( checkRunAIRequestQuery, inputBody );
|
|
4648
|
+
if ( updateRunAIRequest ) {
|
|
4649
|
+
return res.sendSuccess( updateRunAIRequest );
|
|
4650
|
+
} else {
|
|
4651
|
+
return res.sendError( 'something went wrong please Try again', 500 );
|
|
4652
|
+
}
|
|
4653
|
+
} else {
|
|
4654
|
+
let insertRunAIRequest = await runAIRequestServices.create( inputBody );
|
|
4655
|
+
if ( insertRunAIRequest ) {
|
|
4656
|
+
return res.sendSuccess( insertRunAIRequest );
|
|
4657
|
+
} else {
|
|
4658
|
+
return res.sendError( 'something went wrong please Try again', 500 );
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4661
|
+
} catch ( e ) {
|
|
4662
|
+
logger.error( { functionName: 'updateRunAIRequest', error: e } );
|
|
4663
|
+
return res.sendError( e, 500 );
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4666
|
+
|
|
4667
|
+
export async function createChecklistName( req, res ) {
|
|
4668
|
+
try {
|
|
4669
|
+
// console.log( 'req.body =>', req.body );
|
|
4670
|
+
let inputBody = req.body;
|
|
4671
|
+
let checklistNameQuery = {
|
|
4672
|
+
client_id: inputBody.clientId,
|
|
4673
|
+
checkListName: inputBody.checkListName,
|
|
4674
|
+
};
|
|
4675
|
+
let checklistExist = await checklistService.findOne( checklistNameQuery );
|
|
4676
|
+
if ( checklistExist ) {
|
|
4677
|
+
return res.sendError( { message: 'checklist name Alrady Exist' }, 400 );
|
|
4678
|
+
}
|
|
4679
|
+
|
|
4680
|
+
let getMaxChecklistNumber = [
|
|
4681
|
+
{ $match: { client_id: inputBody.clientId } },
|
|
4682
|
+
{ $group: { _id: null, maxCheckListNumber: { $max: '$checkListNumber' } } },
|
|
4683
|
+
];
|
|
4684
|
+
let maxChecklistNumber = await checklistService.aggregate( getMaxChecklistNumber );
|
|
4685
|
+
|
|
4686
|
+
let checkListDetails = {
|
|
4687
|
+
type: 'checklist',
|
|
4688
|
+
checkListNumber: parseInt( maxChecklistNumber[0].maxCheckListNumber ) + 1,
|
|
4689
|
+
checkListName: inputBody.checkListName,
|
|
4690
|
+
checkListDescription: inputBody.checklistDescription,
|
|
4691
|
+
createdBy: req.user._id,
|
|
4692
|
+
createdByName: req.user.userName,
|
|
4693
|
+
questionCount: 0,
|
|
4694
|
+
client_id: req.body?.clientId,
|
|
4695
|
+
owner: req.user.userType == 'client' ? [ { name: req.user.userName, value: req.user.email } ] : [],
|
|
4696
|
+
runAIQuestionCount: 0,
|
|
4697
|
+
};
|
|
4698
|
+
let response = await checklistService.create( checkListDetails );
|
|
4699
|
+
if ( response ) {
|
|
4700
|
+
let insertSection = {
|
|
4701
|
+
'question': [
|
|
4702
|
+
{
|
|
4703
|
+
'qno': 1,
|
|
4704
|
+
'qname': '',
|
|
4705
|
+
'answerType': 'descriptive',
|
|
4706
|
+
'runAI': false,
|
|
4707
|
+
'runAIDescription': '',
|
|
4708
|
+
'allowUploadfromGallery': false,
|
|
4709
|
+
'linkType': false,
|
|
4710
|
+
'multiQuestionReferenceImage': [],
|
|
4711
|
+
'descriptivetype': 'text',
|
|
4712
|
+
'questionReferenceImage': '',
|
|
4713
|
+
'answers': [
|
|
4714
|
+
{
|
|
4715
|
+
'answer': '',
|
|
4716
|
+
'answeroptionNumber': 1,
|
|
4717
|
+
'sopFlag': false,
|
|
4718
|
+
'validation': false,
|
|
4719
|
+
'validationAnswer': '',
|
|
4720
|
+
'validationType': '',
|
|
4721
|
+
'multiReferenceImage': [],
|
|
4722
|
+
'showLinked': false,
|
|
4723
|
+
'linkedQuestion': 0,
|
|
4724
|
+
'referenceImage': '',
|
|
4725
|
+
'nestedQuestion': [],
|
|
4726
|
+
},
|
|
4727
|
+
],
|
|
4728
|
+
},
|
|
4729
|
+
],
|
|
4730
|
+
'section': 'Section 1',
|
|
4731
|
+
'checkList': inputBody.checkListName,
|
|
4732
|
+
'checkListId': new ObjectId( response._id ),
|
|
4733
|
+
'client_id': inputBody.clientId,
|
|
4734
|
+
'isdeleted': false,
|
|
4735
|
+
'sectionNumber': 1,
|
|
4736
|
+
};
|
|
4737
|
+
await questionService.create( insertSection );
|
|
4738
|
+
let resultData = {
|
|
4739
|
+
_id: response._id,
|
|
4740
|
+
};
|
|
4741
|
+
return res.sendSuccess( resultData );
|
|
4742
|
+
} else {
|
|
4743
|
+
return res.sendError( 'Something Went Wrong Please Try Again', 500 );
|
|
4744
|
+
}
|
|
4745
|
+
} catch ( e ) {
|
|
4746
|
+
logger.error( { functionName: 'createChecklistName', error: e } );
|
|
4747
|
+
return res.sendError( e, 500 );
|
|
4748
|
+
}
|
|
4749
|
+
}
|
|
@@ -157,4 +157,31 @@ export const selectAssign = {
|
|
|
157
157
|
body: selectAssignSchema,
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
+
export const createChecklistNameSchema = joi.object( {
|
|
161
|
+
clientId: joi.string().required(),
|
|
162
|
+
checkListName: joi.string().required(),
|
|
163
|
+
checklistDescription: joi.string().optional(),
|
|
164
|
+
} );
|
|
165
|
+
|
|
166
|
+
export const createChecklistNameValidation = {
|
|
167
|
+
body: createChecklistNameSchema,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export const runAIRequestSchema = joi.object( {
|
|
171
|
+
clientId: joi.string().required(),
|
|
172
|
+
checkListId: joi.string().required(),
|
|
173
|
+
checkListName: joi.string().optional().allow( '' ),
|
|
174
|
+
sectionNo: joi.number().required(),
|
|
175
|
+
sectionName: joi.string().optional().allow( '' ),
|
|
176
|
+
qname: joi.string().required(),
|
|
177
|
+
answerType: joi.string().optional().allow( '' ),
|
|
178
|
+
answer: joi.string().optional().allow( '' ),
|
|
179
|
+
runAI: joi.boolean().required(),
|
|
180
|
+
runAIFeatures: joi.array().optional().allow( '' ),
|
|
181
|
+
} );
|
|
182
|
+
|
|
183
|
+
export const runAIRequestValidation = {
|
|
184
|
+
body: runAIRequestSchema,
|
|
185
|
+
};
|
|
186
|
+
|
|
160
187
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { isAllowedSessionHandler, validate, accessVerification, isAllowedClient } from 'tango-app-api-middleware';
|
|
3
|
-
import { checklistValidation, checklistDetailsValidation, runaiValidation, checklistPageSchema, duplicateValidation, updateChecklistValidation, uploadUserValidation, aichecklistValidation, publishValidation, selectAssign } from '../dtos/validation.dtos.js';
|
|
3
|
+
import { checklistValidation, checklistDetailsValidation, runaiValidation, checklistPageSchema, duplicateValidation, updateChecklistValidation, uploadUserValidation, aichecklistValidation, publishValidation, selectAssign, createChecklistNameValidation, runAIRequestValidation } from '../dtos/validation.dtos.js';
|
|
4
4
|
import * as traxController from '../controllers/trax.controller.js';
|
|
5
5
|
|
|
6
6
|
export const traxRouter = express.Router();
|
|
@@ -30,7 +30,9 @@ traxRouter
|
|
|
30
30
|
// .post( '/assignUpload', isAllowedSessionHandler, traxController.assignChecklistUser )
|
|
31
31
|
.post( '/updateAssign', isAllowedSessionHandler, traxController.updateAssign )
|
|
32
32
|
.post( '/updateAiConfigure', isAllowedSessionHandler, traxController.updateAiConfigure )
|
|
33
|
-
.get( '/getAiDetails', isAllowedSessionHandler, traxController.getAiDetails )
|
|
34
|
-
|
|
33
|
+
.get( '/getAiDetails', isAllowedSessionHandler, traxController.getAiDetails )
|
|
34
|
+
.post( '/getRunAIFeatures', isAllowedSessionHandler, traxController.getRunAIFeatures )
|
|
35
|
+
.post( '/updateRunAIRequest', isAllowedSessionHandler, validate( runAIRequestValidation ), traxController.updateRunAIRequest )
|
|
36
|
+
.post( '/createChecklistName', isAllowedSessionHandler, validate( createChecklistNameValidation ), traxController.createChecklistName );
|
|
35
37
|
|
|
36
38
|
// isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ),
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import model from 'tango-api-schema';
|
|
2
|
+
|
|
3
|
+
export const findOne = async ( query={}, field={} ) => {
|
|
4
|
+
return model.runAIFeaturesModel.findOne( query, field );
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const find = async ( query={}, field={} ) => {
|
|
8
|
+
return model.runAIFeaturesModel.find( query, field );
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const create = async ( document = {} ) => {
|
|
12
|
+
return model.runAIFeaturesModel.create( document );
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const deleteOne = async ( query = {} ) => {
|
|
16
|
+
return model.runAIFeaturesModel.deleteOne( query );
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const updateOne = async ( query = {}, record={} ) => {
|
|
20
|
+
return model.runAIFeaturesModel.updateOne( query, { $set: record } );
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const aggregate = async ( query = {} ) => {
|
|
24
|
+
return model.runAIFeaturesModel.aggregate( query );
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const count = async ( query = {} ) => {
|
|
28
|
+
return model.runAIFeaturesModel.countDocuments( query );
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import model from 'tango-api-schema';
|
|
2
|
+
|
|
3
|
+
export const findOne = async ( query={}, field={} ) => {
|
|
4
|
+
return model.runAIRequestModel.findOne( query, field );
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export const find = async ( query={}, field={} ) => {
|
|
8
|
+
return model.runAIRequestModel.find( query, field );
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const create = async ( document = {} ) => {
|
|
12
|
+
return model.runAIRequestModel.create( document );
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const deleteOne = async ( query = {} ) => {
|
|
16
|
+
return model.runAIRequestModel.deleteOne( query );
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const updateOne = async ( query = {}, record={} ) => {
|
|
20
|
+
return model.runAIRequestModel.updateOne( query, { $set: record } );
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const aggregate = async ( query = {} ) => {
|
|
24
|
+
return model.runAIRequestModel.aggregate( query );
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const count = async ( query = {} ) => {
|
|
28
|
+
return model.runAIRequestModel.countDocuments( query );
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
|