tango-app-api-trax 3.4.0-soplink2-0 → 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-soplink2-0",
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.73",
30
- "tango-app-api-middleware": "^3.1.66",
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;
@@ -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 ) {
@@ -384,12 +384,13 @@ export async function redoChecklist( req, res ) {
384
384
  }
385
385
 
386
386
  let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.uniqueNo == req.body.payload.uniqueNo );
387
+
387
388
  let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
388
389
  // if ( checklistDetails.client_id == '458' ) {
389
390
  data.answers.forEach( ( item ) => {
390
391
  if ( item.showLinked ) {
391
392
  item.nestedQuestion.forEach( ( ele ) => {
392
- let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.uniqueNo == parseInt( ele ) );
393
+ let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
393
394
  let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
394
395
  question[sectionIndex].questions[eleIndex] = element;
395
396
  question[sectionIndex].questions[eleIndex].userAnswer = [];
@@ -449,7 +450,7 @@ export async function redoChecklist( req, res ) {
449
450
  submitTime: checklistDetails.submitTime,
450
451
  };
451
452
  await checklistLogs.create( data );
452
- console.log( req.body );
453
+
453
454
  const requestOptions = {
454
455
  method: 'POST',
455
456
  headers: {
@@ -467,7 +468,7 @@ export async function redoChecklist( req, res ) {
467
468
  'checkListName': checklistDetails.checkListName,
468
469
  'fromCheckListName': checklistDetails.checkListName,
469
470
  'type': 'checklist',
470
- 'action': 'redo',
471
+ 'action': checklistDetails.redoStatus?'multiredo': 'redo',
471
472
  'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
472
473
  'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
473
474
  'userName': checklistDetails.userName,
@@ -476,10 +477,11 @@ export async function redoChecklist( req, res ) {
476
477
  'createdBy': req.user.userName,
477
478
  'coverage': checklistDetails.coverage,
478
479
  'logDetails': {},
480
+ 'userType': req.user.userType,
479
481
  };
480
482
  let urlopensearch = JSON.parse( process.env.OPENSEARCH );
481
483
  console.log( 'logData', logData );
482
- await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
484
+ insertOpenSearchData( urlopensearch.traxActivityLog, logData );
483
485
  if ( searchResponse.ok ) {
484
486
  return res.sendSuccess( 'Question redo successfully' );
485
487
  } else {
@@ -493,6 +495,7 @@ export async function redoChecklist( req, res ) {
493
495
  return res.sendError( e, 500 );
494
496
  }
495
497
  }
498
+
496
499
  export async function redomultiChecklist( req, res ) {
497
500
  try {
498
501
  let inputData = req.body.payload.coverage==='user'?req.body.payload.userEmail:req.body.payload.storeName;
@@ -614,7 +617,7 @@ export async function redomultiChecklist( req, res ) {
614
617
  'checkListName': checklistDetails.checkListName,
615
618
  'fromCheckListName': checklistDetails.checkListName,
616
619
  'type': 'checklist',
617
- 'action': 'redo',
620
+ 'action': checklistDetails.redoStatus?'multiredo': 'redo',
618
621
  'storeName': checklistDetails?.storeName?checklistDetails?.storeName:'',
619
622
  'store_id': checklistDetails?.store_id?checklistDetails?.store_id:'',
620
623
  'userName': checklistDetails.userName,
@@ -623,10 +626,11 @@ export async function redomultiChecklist( req, res ) {
623
626
  'createdBy': req.user.userName,
624
627
  'coverage': checklistDetails.coverage,
625
628
  'logDetails': {},
629
+ 'userType': req.user.userType,
626
630
  };
627
631
  let urlopensearch = JSON.parse( process.env.OPENSEARCH );
628
632
  console.log( 'logData', logData );
629
- await insertOpenSearchData( urlopensearch.traxActivityLog, logData );
633
+ insertOpenSearchData( urlopensearch.traxActivityLog, logData );
630
634
  }
631
635
  }
632
636
  return res.sendSuccess( 'Question redo successfully' );