tango-app-api-audio-analytics 1.0.10 → 1.0.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audio-analytics",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "audioAnalytics",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -45,6 +45,51 @@ export async function createCohort( req, res ) {
45
45
  }
46
46
  }
47
47
 
48
+ export async function createBulkCohort( req, res ) {
49
+ try {
50
+ const { clientId, cohorts } = req.body;
51
+
52
+ const results = [];
53
+ const failed = [];
54
+
55
+ for ( const cohortItem of cohorts ) {
56
+ const cohortId = `cohort_${clientId}_${randomUUID()}`;
57
+
58
+ const cohortData = {
59
+ clientId,
60
+ cohortId,
61
+ source: [],
62
+ cohortName: cohortItem.cohortName,
63
+ cohortDescription: cohortItem.cohortDescription,
64
+ metrics: [],
65
+ createdAt: new Date().toISOString(),
66
+ updatedAt: new Date().toISOString(),
67
+ };
68
+
69
+ const result = await insertWithId( 'tango-audio-config', cohortId, cohortData );
70
+ logger.info( { result } );
71
+
72
+ if ( result && result.body && result.body.result === 'created' ) {
73
+ results.push( { cohortId, cohortName: cohortItem.cohortName } );
74
+ } else {
75
+ failed.push( { cohortName: cohortItem.cohortName, reason: 'Insert failed' } );
76
+ }
77
+ }
78
+
79
+ return res.sendSuccess( {
80
+ message: 'Bulk cohort creation completed',
81
+ created: results,
82
+ failed,
83
+ totalCreated: results.length,
84
+ totalFailed: failed.length,
85
+ } );
86
+ } catch ( error ) {
87
+ const err = error.message || 'Internal Server Error';
88
+ logger.error( { error: error, message: req.body, function: 'createBulkCohort' } );
89
+ return res.sendError( err, 500 );
90
+ }
91
+ }
92
+
48
93
  export async function updateCohort( req, res ) {
49
94
  try {
50
95
  const { cohortId, ...updateFields } = req.body;
@@ -34,7 +34,7 @@ export const getConversationsList = async ( req, res ) => {
34
34
  endDate,
35
35
  storeId,
36
36
  clientId,
37
- cohortId,
37
+ cohortType,
38
38
  isAI,
39
39
  analyticsType,
40
40
  searchValue,
@@ -61,7 +61,7 @@ export const getConversationsList = async ( req, res ) => {
61
61
  isExport,
62
62
  } );
63
63
 
64
- let conversations;
64
+ // let conversations;
65
65
  // let totalCount;
66
66
 
67
67
  // If export is requested, call the export Lambda function
@@ -72,7 +72,7 @@ export const getConversationsList = async ( req, res ) => {
72
72
  endDate,
73
73
  storeId,
74
74
  clientId,
75
- cohortId,
75
+ cohortType,
76
76
  isExport,
77
77
  limit,
78
78
  offset,
@@ -83,7 +83,7 @@ export const getConversationsList = async ( req, res ) => {
83
83
 
84
84
  logger.info( {
85
85
  message: 'Export Lambda response received',
86
- recordCount: conversations.length,
86
+ recordCount: exportResponse.data.length,
87
87
  } );
88
88
 
89
89
  // Apply search filter if provided
@@ -111,6 +111,7 @@ export const getConversationsList = async ( req, res ) => {
111
111
  endDate,
112
112
  storeId,
113
113
  clientId,
114
+ cohortType,
114
115
  isAI,
115
116
  analyticsType,
116
117
  searchValue,
@@ -588,6 +588,20 @@ export const createCohortValid = {
588
588
  body: createCohortSchema,
589
589
  };
590
590
 
591
+ const bulkCohortItemSchema = joi.object( {
592
+ cohortName: joi.string().required(),
593
+ cohortDescription: joi.string().required(),
594
+ } );
595
+
596
+ export const createBulkCohortSchema = joi.object( {
597
+ clientId: joi.string().required(),
598
+ cohorts: joi.array().items( bulkCohortItemSchema ).min( 1 ).required(),
599
+ } );
600
+
601
+ export const createBulkCohortValid = {
602
+ body: createBulkCohortSchema,
603
+ };
604
+
591
605
  const cohortUpdateMetricSchema = joi.object( {
592
606
  metricName: joi.string().required(),
593
607
  metricDescription: joi.string().required(),
@@ -1,9 +1,9 @@
1
1
 
2
2
  import express from 'express';
3
3
  import { validate } from 'tango-app-api-middleware';
4
- import { createCohortValid, updateCohortValid, getCohortValid, listCohortsByClientValid } from '../dtos/audioAnalytics.dtos.js';
4
+ import { createCohortValid, createBulkCohortValid, updateCohortValid, getCohortValid, listCohortsByClientValid } from '../dtos/audioAnalytics.dtos.js';
5
5
  import { cohortAnalysisCardValid, conversationsListValid, conversationDetailsValid, chatStreamValid } from '../dtos/audioAnalytics.dtos.js';
6
- import { createCohort, updateCohort, getCohort, listCohortsByClient, chatStream } from '../controllers/audioAnalytics.controller.js';
6
+ import { createCohort, createBulkCohort, updateCohort, getCohort, listCohortsByClient, chatStream } from '../controllers/audioAnalytics.controller.js';
7
7
  import { getCohortAnalysisCard } from '../controllers/cohortAnalytics.controller.js';
8
8
  import { getConversationsList, getConversationDetails } from '../controllers/conversationAnalytics.controller.js';
9
9
 
@@ -17,6 +17,7 @@ audioAnalyticsrouter.get( '/test', ( req, res ) => {
17
17
 
18
18
  // Cohort Management Routes
19
19
  audioAnalyticsrouter.post( '/create-cohort', validate( createCohortValid ), createCohort );
20
+ audioAnalyticsrouter.post( '/create-bulk-cohort', validate( createBulkCohortValid ), createBulkCohort );
20
21
  audioAnalyticsrouter.post( '/update-cohort', validate( updateCohortValid ), updateCohort );
21
22
  audioAnalyticsrouter.get( '/get-cohort/:cohortId', validate( getCohortValid ), getCohort );
22
23
  audioAnalyticsrouter.get( '/list-cohorts', validate( listCohortsByClientValid ), listCohortsByClient );
@@ -72,6 +72,7 @@ export async function getConversationsListFromLambda( params ) {
72
72
  endDate: params.endDate,
73
73
  storeId: params.storeId,
74
74
  clientId: params.clientId,
75
+ cohort_id: params.cohortType,
75
76
  isAI: params.isAI,
76
77
  analyticsType: params.analyticsType,
77
78
  searchValue: params.searchValue,
@@ -108,17 +109,18 @@ export async function exportConversationsFromLambda( params ) {
108
109
  const payload = {
109
110
  startDate: params.startDate,
110
111
  endDate: params.endDate,
111
- storeId: Array.isArray( params.storeId ) ? params.storeId : [ params.storeId ],
112
- clientId: Array.isArray( params.clientId ) ? params.clientId : [ params.clientId ],
113
- cohortId: params.cohortId,
114
- isExport: params.isExport ?? true,
115
- limit: params.limit || 10,
116
- offset: params.offset || 0,
112
+ store_id: Array.isArray( params.storeId ) ? params.storeId : [ params.storeId ],
113
+ // clientId: Array.isArray( params.clientId ) ? params.clientId : [ params.clientId ],
114
+ cohort_id: params.cohortType?.[0],
115
+ // isExport: params.isExport ?? true,
116
+ // limit: params.limit || 10,
117
+ // offset: params.offset || 0,
117
118
  };
118
119
 
119
120
  logger.info( { message: 'Calling Lambda for conversations export', url: LAMBDA_ENDPOINT.cohortConversationList, payload } );
120
121
 
121
- const response = await axios.post( `${LAMBDA_ENDPOINT.cohortConversationList}`, payload, {
122
+ // const response = await axios.post( `${LAMBDA_ENDPOINT.cohortConversationExport}`, payload, {
123
+ const response = await axios.post( `https://p2wmglvvtfj7nh2pdzljaiidnm0beycj.lambda-url.ap-south-1.on.aws/`, payload, {
122
124
  headers: {
123
125
  'Content-Type': 'application/json',
124
126
  },