tango-app-api-trax 3.4.0-flag-11 → 3.4.1-activitylog-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/index.js CHANGED
@@ -9,4 +9,5 @@ import { mobileRouter } from './src/routes/mobileTrax.routes.js';
9
9
  import { internalTraxRouter } from './src/routes/internalTraxApi.router.js';
10
10
  import { locusOrderRouter } from './src/routes/locus.router.js';
11
11
  import { traxActivityLogRouter } from './src/routes/activityLog.router.js';
12
+
12
13
  export { traxDashboardRouter, traxFlagRouter, traxRouter, galleryRouter, downloadRouter, mobileRouter, internalTraxRouter, locusOrderRouter, traxActivityLogRouter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.4.0-flag-11",
3
+ "version": "3.4.1-activitylog-1",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "mongodb": "^6.8.0",
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
- "tango-api-schema": "^2.2.70",
30
- "tango-app-api-middleware": "^3.1.55",
29
+ "tango-api-schema": "^2.2.101",
30
+ "tango-app-api-middleware": "^3.1.72",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
33
33
  "winston-daily-rotate-file": "^5.0.0"
@@ -1,6 +1,7 @@
1
1
  // import mongoose from 'mongoose';
2
2
  import { insertOpenSearchData, updateOpenSearchData, getOpenSearchData } from 'tango-app-api-middleware';
3
3
  import * as checklistService from '../services/checklist.service.js';
4
+ import * as taskconfigService from '../services/taskConfig.service.js';
4
5
 
5
6
  export const insertLog = async ( req, res ) => {
6
7
  try {
@@ -112,13 +113,13 @@ export const listLog = async ( req, res ) => {
112
113
  let requestBody = req.body;
113
114
  let from = ( requestBody.offset ) * requestBody.limit;
114
115
 
115
- // let start = new Date( requestBody.fromDate );
116
- // let userTimezoneOffset = start.getTimezoneOffset() * 60000;
117
- // start = new Date( start.getTime() - userTimezoneOffset );
118
- // start.setUTCHours( 0, 0, 0, 0 );
119
- // let end = new Date( requestBody.toDate );
120
- // end = new Date( end.getTime() - userTimezoneOffset );
121
- // end.setUTCHours( 23, 59, 59, 59 );
116
+ let start = new Date( requestBody.fromDate );
117
+ let userTimezoneOffset = start.getTimezoneOffset() * 60000;
118
+ start = new Date( start.getTime() - userTimezoneOffset );
119
+ start.setUTCHours( 0, 0, 0, 0 );
120
+ let end = new Date( requestBody.toDate );
121
+ end = new Date( end.getTime() - userTimezoneOffset );
122
+ end.setUTCHours( 23, 59, 59, 59 );
122
123
 
123
124
  // console.log( 'list' );
124
125
  const mustConditions = [];
@@ -130,23 +131,36 @@ export const listLog = async ( req, res ) => {
130
131
  if ( requestBody.type ) {
131
132
  mustConditions.push( { term: { type: requestBody.type } } );
132
133
  }
133
-
134
- if ( requestBody.action ) {
134
+ if ( requestBody.action && requestBody.action.length > 0 ) {
135
135
  mustConditions.push( { terms: { action: requestBody.action } } );
136
136
  }
137
137
 
138
138
  if ( req.user.userType == 'client' && req.user.role == 'user' ) {
139
139
  return res.sendError( 'no data found', 204 );
140
140
  }
141
+ let sourceCheckListIds;
142
+ if ( req.user.userType === 'client' && req.user.role == 'admin' ) {
143
+ if ( requestBody.type === 'checklist' ) {
144
+ const sourceCheckListResult = await checklistService.aggregate( [
145
+ // { $match: { 'owner.value': req.user.email } },
146
+ { $match: { $or: [ { 'owner.value': req.user.email }, { 'approver.value': req.user.email } ] } },
147
+ { $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
148
+ { $project: { _id: 0, checklistIds: 1 } },
149
+ ] );
150
+ sourceCheckListIds = sourceCheckListResult.length > 0 ? sourceCheckListResult[0].checklistIds : [];
151
+ // console.log( 'sourceCheckListIds', sourceCheckListIds );
152
+ }
153
+ if ( requestBody.type === 'task' ) {
154
+ const sourceCheckListResult = await taskconfigService.aggregate( [
155
+ // { $match: { 'owner.value': req.user.email } },
156
+ { $match: { $or: [ { 'owner.value': req.user.email }, { 'approver.value': req.user.email } ] } },
157
+ { $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
158
+ { $project: { _id: 0, checklistIds: 1 } },
159
+ ] );
160
+ sourceCheckListIds = sourceCheckListResult.length > 0 ? sourceCheckListResult[0].checklistIds : [];
161
+ // console.log( 'sourceCheckListIds', sourceCheckListIds );
162
+ }
141
163
 
142
- if ( req.user.userType == 'client' && req.user.role == 'admin' ) {
143
- const sourceCheckListResult = await checklistService.aggregate( [
144
- { $match: { 'owner.value': req.user.email } },
145
- { $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
146
- { $project: { _id: 0, checklistIds: 1 } },
147
- ] );
148
- const sourceCheckListIds = sourceCheckListResult.length > 0 ? sourceCheckListResult[0].checklistIds : [];
149
- console.log( 'sourceCheckListIds', sourceCheckListIds );
150
164
  // mustConditions.push( { terms: { $or: [ { store_id: { $in: requestBody.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestBody.userEmailes } }, { sourceCheckList_id: { $in: sourceCheckListIds } } ] } } );
151
165
  mustConditions.push( {
152
166
  'bool': {
@@ -166,6 +180,12 @@ export const listLog = async ( req, res ) => {
166
180
  },
167
181
  } );
168
182
  }
183
+ if ( req.user.userType === 'client' ) {
184
+ mustConditions.push( {
185
+ term: { userType: 'client' },
186
+ } );
187
+ }
188
+
169
189
 
170
190
  if ( requestBody.searchValue ) {
171
191
  mustConditions.push( { multi_match: {
@@ -178,16 +198,16 @@ export const listLog = async ( req, res ) => {
178
198
  // console.log( 'Generated Query:', JSON.stringify( mustConditions, null, 2 ) );
179
199
 
180
200
  // console.log( 'mustConditions =>', mustConditions );
181
- // if ( requestBody.dateRange ) {
182
- // mustConditions.push( {
183
- // range: {
184
- // createdAt: {
185
- // gte: start, // Start date
186
- // lte: end, // End date
187
- // },
188
- // },
189
- // } );
190
- // }
201
+ if ( requestBody.fromDate && requestBody.toDate ) {
202
+ mustConditions.push( {
203
+ range: {
204
+ createAt: {
205
+ gte: start, // Start date
206
+ lte: end, // End date
207
+ },
208
+ },
209
+ } );
210
+ }
191
211
  let sortCreatedAt = 'desc';
192
212
  if ( requestBody.sortColumnName && requestBody.sortColumnName != '' ) {
193
213
  if ( requestBody.sortBy == '1' ) {
@@ -210,7 +230,9 @@ export const listLog = async ( req, res ) => {
210
230
  },
211
231
  ],
212
232
  };
233
+ // console.log( 'Executing OpenSearch Query:', JSON.stringify( query, null, 2 ) );
213
234
  let result = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, query );
235
+ // console.log( 'OpenSearch Raw Response', JSON.stringify( result, null, 2 ) );
214
236
  if ( !result || !result.body.hits.hits.length ) {
215
237
  return res.sendError( 'no data found', 204 );
216
238
  }
@@ -6,6 +6,7 @@ import * as processedTaskService from '../services/processedTaskList.service.js'
6
6
  import * as taskConfigService from '../services/taskConfig.service.js';
7
7
  import * as checklistService from '../services/checklist.service.js';
8
8
  // import * as processedTaskconfigService from '../services/processedTaskConfig.service.js';
9
+ import * as processedcheklistconfigService from '../services/processedchecklistconfig.services.js';
9
10
  import * as clientService from '../services/clients.services.js';
10
11
  import * as storeService from '../services/store.service.js';
11
12
 
@@ -143,8 +144,9 @@ export const downloadInsert = async ( req, res ) => {
143
144
  'viewRedo': requestData.viewRedo || false,
144
145
  'userEmailList': requestData.userEmailList || [],
145
146
  'filtertype': requestData.filtertype || 'Clusters',
146
-
147
+ 'checkListType': requestData.checkListType,
147
148
  };
149
+ console.log( insertData );
148
150
  let resultData = await downloadService.insert( insertData );
149
151
  if ( resultData ) {
150
152
  let sqsMessageRequestData = {
@@ -171,7 +173,93 @@ export const downloadInsert = async ( req, res ) => {
171
173
  return res.sendError( e, 500 );
172
174
  }
173
175
  };
174
-
176
+ export const downloadInsertAI = async ( req, res ) => {
177
+ try {
178
+ let requestData = req.body;
179
+ let name;
180
+ let fileType = requestData?.fileType || 'pdfzip';
181
+ if ( requestData.fileType == 'pdf' ) {
182
+ if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
183
+ fileType = 'pdfzip';
184
+ }
185
+ if ( requestData?.checklistId && requestData?.checklistId.length > 1 ) {
186
+ fileType = 'pdfzip';
187
+ }
188
+ }
189
+ if ( requestData.checklistName != '' ) {
190
+ name = requestData.checklistName + '_' + dayjs( requestData.fromDate ).format( 'DD/MM/YYYY' );
191
+ if ( requestData?.toDate ) {
192
+ name = name + '-' + dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
193
+ }
194
+ let regexName = new RegExp( `^${name.split( '(' )[0]} \\(.*\\)$`, 'i' );
195
+ let type = requestData.fileType || 'pdfzip';
196
+ let downloadDetails = await downloadService.getCount( { $and: [ { $or: [ { name: { $regex: regexName } }, { name: name } ] }, { fileType: type } ] } );
197
+ if ( downloadDetails ) {
198
+ name = name + ' (' + downloadDetails + ')';
199
+ }
200
+ } else {
201
+ name = requestData?.checklistName;
202
+ }
203
+ let findchecklist = await processedcheklistconfigService.findOne( { 'checkListType': requestData.checkListType, 'client_id': requestData.clientId } ).sort( { _id: -1 } );
204
+ console.log( findchecklist );
205
+ name = name + '-' + requestData.fileType;
206
+ let insertData = {
207
+ 'date_string': requestData.fromDate || '',
208
+ 'sourceCheckList_id': requestData?.sourceCheckList_id || '',
209
+ 'checklistIdList': requestData?.checklistId || [],
210
+ 'status': 'inprogress',
211
+ 'client_id': requestData.clientId || '',
212
+ 'date_iso': new Date( requestData.fromDate ) || '',
213
+ 'createdBy': req.user._id || '',
214
+ 'name': name,
215
+ 'fileType': fileType,
216
+ 'storeIds': requestData.storeIds || [],
217
+ 'questions': requestData.questions || [],
218
+ 'fromDate': requestData.fromDate || '',
219
+ 'toDate': requestData.toDate || '',
220
+ 'previewType': requestData.previewType || '',
221
+ 'viewFlag': requestData.viewFlag || false,
222
+ 'userEmail': req.user.email || '',
223
+ 'createdBy': req.user._id || '',
224
+ 'downloadInsertFrom': requestData.downloadInsertFrom || '',
225
+ 'answerType': requestData.answerType || '',
226
+ 'searchValue': requestData.searchValue || '',
227
+ 'insertType': requestData.insertType || '',
228
+ 'viewRedo': requestData.viewRedo || false,
229
+ 'userEmailList': requestData.userEmailList || [],
230
+ 'filtertype': requestData.filtertype || 'Clusters',
231
+ 'checkListType': requestData.checkListType,
232
+ 'checkListName': findchecklist.checkListName,
233
+ 'checkListDescription': findchecklist.checkListDescription,
234
+ };
235
+ console.log( requestData );
236
+ console.log( insertData );
237
+ let resultData = await downloadService.insert( insertData );
238
+ console.log( resultData );
239
+ if ( resultData ) {
240
+ let sqsMessageRequestData = {
241
+ 'zipId': resultData._id,
242
+ 'fileType': fileType || 'zip',
243
+ 'storeId': requestData.storeIds || [],
244
+ };
245
+ console.log( sqsMessageRequestData );
246
+ if ( fileType === 'csv' || fileType === 'pdf' || fileType === 'csvzip' || fileType === 'pdfzip' || fileType === 'zipfiles' ) {
247
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
248
+ console.log( 'Send SQS Message CSV/PDF=>', msg );
249
+ }
250
+ if ( fileType === 'ppt' || fileType === 'pptzip' ) {
251
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
252
+ console.log( 'Send SQS Message PPT=>', msg );
253
+ }
254
+ res.sendSuccess( 'Success' );
255
+ } else {
256
+ return res.sendError( 'something went wrong, please try again', 500 );
257
+ }
258
+ } catch ( e ) {
259
+ console.log( 'insertdownloadRequest =>', e );
260
+ return res.sendError( e, 500 );
261
+ }
262
+ };
175
263
  export const downloadInsertOld = async ( req, res ) => {
176
264
  try {
177
265
  let requestData = req.body;
@@ -482,7 +570,33 @@ export const getChecklistFromZipId = async ( req, res ) => {
482
570
  return res.sendError( error, 500 );
483
571
  }
484
572
  };
485
-
573
+ export const getAiChecklistDataFromZipId = async ( req, res ) => {
574
+ try {
575
+ let reqquery = req.query;
576
+ let getzipdata = await downloadService.findOne( { _id: new mongoose.Types.ObjectId( reqquery.zipId ) } );
577
+ let brandInfo = {
578
+ clientName: '',
579
+ brandLogo: '',
580
+ checkListDescription: '',
581
+ };
582
+ if ( getzipdata ) {
583
+ let getClientData = await clientService.findOne( { clientId: getzipdata.client_id } );
584
+ if ( getClientData ) {
585
+ brandInfo.clientName = getClientData.clientName;
586
+ brandInfo.brandLogo = getzipdata.client_id + '/logo/' + getClientData.profileDetails.logo;
587
+ }
588
+ getzipdata.brandInfo = brandInfo;
589
+ console.log( getzipdata );
590
+ return res.sendSuccess( getzipdata );
591
+ } else {
592
+ return res.sendError( { error: 'No Data Found' }, 204 );
593
+ }
594
+ } catch ( error ) {
595
+ console.log( 'error =>', error );
596
+ logger.error( { error: error, function: 'getChecklistFromZipId' } );
597
+ return res.sendError( error, 500 );
598
+ }
599
+ };
486
600
  export const getPDFCSVChecklistDetails = async ( req, res ) => {
487
601
  try {
488
602
  let requestData = req.body;
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { logger } from 'tango-app-api-middleware';
3
+ import { logger, insertOpenSearchData } from 'tango-app-api-middleware';
4
4
  import * as storeService from '../services/store.service.js';
5
5
  import * as groupService from '../services/group.service.js';
6
6
  import * as clusterService from '../services/cluster.service.js';
@@ -282,7 +282,7 @@ export async function approveChecklist( req, res ) {
282
282
  if ( req.body?.storeId?.length ) {
283
283
  query['store_id'] = { $in: req.body.storeId };
284
284
  }
285
- let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1, client_id: 1, coverage: 1 } );
285
+ let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1, client_id: 1, coverage: 1, checkListName: 1 } );
286
286
  if ( !checklistDetails.length ) {
287
287
  return res.sendError( 'No data found', 204 );
288
288
  }
@@ -291,6 +291,7 @@ export async function approveChecklist( req, res ) {
291
291
  let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList } }, { approvalStatus: true } );
292
292
  if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
293
293
  let inputstores = checklistDetails.filter( ( data ) => data.checklistStatus == 'submit' );
294
+ let storeNames = inputstores.map( ( data ) => data.storeName );
294
295
 
295
296
 
296
297
  let params = {
@@ -315,15 +316,12 @@ export async function approveChecklist( req, res ) {
315
316
  };
316
317
  let url = JSON.parse( process.env.LAMBDAURL );
317
318
  let searchResponse = await fetch( url.approveChecklist, requestOptions );
318
-
319
- console.log( searchResponse.ok );
320
-
321
319
  let logData= {
322
320
  'client_id': checklistDetails[0].client_id,
323
321
  'createAt': new Date(),
324
322
  'sourceCheckList_id': req.body.sourceCheckList_id,
325
323
  'checkListName': checklistDetails[0].checkListName,
326
- 'fromCheckListName': checklistDetails[0].checkListName,
324
+ 'fromCheckListName': '',
327
325
  'type': 'checklist',
328
326
  'action': 'approved',
329
327
  'storeName': '',
@@ -332,12 +330,14 @@ export async function approveChecklist( req, res ) {
332
330
  'createdBy': req.user._id,
333
331
  'coverage': checklistDetails[0].coverage,
334
332
  'logDetails': {
335
- 'approved': [ 'LKST011', 'LKST022', 'LKST3444', 'LKST455', 'LKST566', 'LKST666', 'LKST766', 'LKST866', 'LkST966' ],
333
+ 'approved': storeNames,
336
334
  },
335
+ 'userType': req.user.userType,
337
336
  };
338
- let urlopensearch = JSON.parse( process.env.OPENSEARCH );
339
337
  console.log( 'logData', logData );
340
- await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
338
+ let urlopensearch = JSON.parse( process.env.OPENSEARCH );
339
+ insertOpenSearchData( urlopensearch.traxActivityLog, logData );
340
+ console.log( searchResponse.ok );
341
341
  if ( searchResponse.ok ) {
342
342
  let pendingstores = checklistDetails.filter( ( data ) => data.checklistStatus != 'submit' );
343
343
  if ( pendingstores && pendingstores.length > 0 ) {
@@ -383,7 +383,7 @@ export async function redoChecklist( req, res ) {
383
383
  return res.sendError( 'section is not found', 400 );
384
384
  }
385
385
 
386
- let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
386
+ let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.uniqueNo == req.body.payload.uniqueNo );
387
387
 
388
388
  let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
389
389
  // if ( checklistDetails.client_id == '458' ) {
@@ -450,7 +450,7 @@ export async function redoChecklist( req, res ) {
450
450
  submitTime: checklistDetails.submitTime,
451
451
  };
452
452
  await checklistLogs.create( data );
453
- console.log( req.body );
453
+
454
454
  const requestOptions = {
455
455
  method: 'POST',
456
456
  headers: {
@@ -468,7 +468,7 @@ export async function redoChecklist( req, res ) {
468
468
  'checkListName': checklistDetails.checkListName,
469
469
  'fromCheckListName': checklistDetails.checkListName,
470
470
  'type': 'checklist',
471
- 'action': 'redo',
471
+ 'action': checklistDetails.redoStatus?'multiredo': 'redo',
472
472
  'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
473
473
  'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
474
474
  'userName': checklistDetails.userName,
@@ -477,10 +477,11 @@ export async function redoChecklist( req, res ) {
477
477
  'createdBy': req.user.userName,
478
478
  'coverage': checklistDetails.coverage,
479
479
  'logDetails': {},
480
+ 'userType': req.user.userType,
480
481
  };
481
482
  let urlopensearch = JSON.parse( process.env.OPENSEARCH );
482
483
  console.log( 'logData', logData );
483
- await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
484
+ insertOpenSearchData( urlopensearch.traxActivityLog, logData );
484
485
  if ( searchResponse.ok ) {
485
486
  return res.sendSuccess( 'Question redo successfully' );
486
487
  } else {
@@ -494,6 +495,7 @@ export async function redoChecklist( req, res ) {
494
495
  return res.sendError( e, 500 );
495
496
  }
496
497
  }
498
+
497
499
  export async function redomultiChecklist( req, res ) {
498
500
  try {
499
501
  let inputData = req.body.payload.coverage==='user'?req.body.payload.userEmail:req.body.payload.storeName;
@@ -615,7 +617,7 @@ export async function redomultiChecklist( req, res ) {
615
617
  'checkListName': checklistDetails.checkListName,
616
618
  'fromCheckListName': checklistDetails.checkListName,
617
619
  'type': 'checklist',
618
- 'action': 'redo',
620
+ 'action': checklistDetails.redoStatus?'multiredo': 'redo',
619
621
  'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
620
622
  'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
621
623
  'userName': checklistDetails.userName,
@@ -624,10 +626,11 @@ export async function redomultiChecklist( req, res ) {
624
626
  'createdBy': req.user.userName,
625
627
  'coverage': checklistDetails.coverage,
626
628
  'logDetails': {},
629
+ 'userType': req.user.userType,
627
630
  };
628
631
  let urlopensearch = JSON.parse( process.env.OPENSEARCH );
629
632
  console.log( 'logData', logData );
630
- await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
633
+ insertOpenSearchData( urlopensearch.traxActivityLog, logData );
631
634
  }
632
635
  }
633
636
  return res.sendSuccess( 'Question redo successfully' );