tango-app-api-report 3.0.15-dev → 3.0.17-dev

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-report",
3
- "version": "3.0.15-dev",
3
+ "version": "3.0.17-dev",
4
4
  "description": "report",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,8 +25,8 @@
25
25
  "nodemailer": "^6.9.13",
26
26
  "nodemon": "^3.1.0",
27
27
  "swagger-ui-express": "^5.0.0",
28
- "tango-api-schema": "^2.0.104",
29
- "tango-app-api-middleware": "^1.0.73-test",
28
+ "tango-api-schema": "^2.0.111",
29
+ "tango-app-api-middleware": "^3.1.15",
30
30
  "winston": "^3.12.0",
31
31
  "winston-daily-rotate-file": "^5.0.0"
32
32
  },
@@ -1,5 +1,5 @@
1
1
  import { deleteOneReport, findOneReport, findReport, reportCreate, reportGet, reportGetSingle, reportUpdate } from '../service/report.service.js';
2
- import { appConfig, fileUpload, getObject, getOpenSearchData, insertOpenSearchData, listFileByPath, logger, sendMessageToQueue } from 'tango-app-api-middleware';
2
+ import { fileUpload, getObject, getOpenSearchData, insertOpenSearchData, listFileByPath, logger, sendMessageToQueue } from 'tango-app-api-middleware';
3
3
  import { findOneUser, getUserNameEmailById } from '../service/user.service.js';
4
4
  import { updateOneBasePriceModel } from '../service/basePrice.service.js';
5
5
  import { aggregateClient } from '../service/client.service.js';
@@ -15,6 +15,7 @@ dayjs.extend( timezone );
15
15
 
16
16
  export async function createReport( req, res ) {
17
17
  try {
18
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
18
19
  const createReport = await reportCreate( {
19
20
  clientId: req.params?.id, fileName: req.body?.fileName, fileType: req.body?.fileType, email: req.body?.email,
20
21
  } );
@@ -33,7 +34,7 @@ export async function createReport( req, res ) {
33
34
  showTo: [ 'tango' ],
34
35
  };
35
36
 
36
- await insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
37
+ await insertOpenSearchData( openSearch.activityLog, logObj );
37
38
  if ( createReport ) {
38
39
  res.sendSuccess( { result: 'Created Successfully' } );
39
40
  }
@@ -73,6 +74,7 @@ export async function getSingleReport( req, res ) {
73
74
 
74
75
  export async function updateReport( req, res ) {
75
76
  try {
77
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
76
78
  const previousReport = await reportGetSingle( {
77
79
  _id: req.params?.id,
78
80
  } );
@@ -97,7 +99,7 @@ export async function updateReport( req, res ) {
97
99
 
98
100
  };
99
101
 
100
- await insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
102
+ await insertOpenSearchData( openSearch.activityLog, logObj );
101
103
  if ( updateAck ) {
102
104
  res.sendSuccess( { result: 'Updated Successfully' } );
103
105
  }
@@ -220,9 +222,10 @@ export async function clientReportList( req, res ) {
220
222
 
221
223
  export async function generateReport( req, res ) {
222
224
  try {
225
+ const sqs = JSON.parse( process.env.SQS );
223
226
  const inputData = req.body;
224
227
  const sqsProduceQueue = {
225
- QueueUrl: `${appConfig.cloud.aws.sqs.url}${appConfig.cloud.aws.sqs.generateReport}`,
228
+ QueueUrl: `${sqs.url}${sqs.generateReport}`,
226
229
  MessageBody: JSON.stringify( {
227
230
  file_date: inputData.fileDate,
228
231
  client_name: req.report?.reportConfigs?.reportName,
@@ -259,6 +262,7 @@ export async function generateReport( req, res ) {
259
262
 
260
263
  export async function uploadManualReport( req, res ) {
261
264
  try {
265
+ const bucket = JSON.parse( process.env.BUCKET );
262
266
  const inputData = req.body;
263
267
  const name = inputData.fileName;
264
268
  const regex = /^(\d{2}-\d{2}-\d{4})_(.*?)\.([a-zA-Z0-9]+)$/;
@@ -281,8 +285,8 @@ export async function uploadManualReport( req, res ) {
281
285
  }
282
286
  logger.info( { files: req.files } );
283
287
  const uploadDataParams = {
284
- Bucket: appConfig.cloud.aws.bucket.reportBucket,
285
- Key: `reports/${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
288
+ Bucket: bucket.reportBucket,
289
+ Key: `${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
286
290
  fileName: inputData.fileName,
287
291
  body: req.files.files.data,
288
292
  };
@@ -321,10 +325,11 @@ export async function uploadManualReport( req, res ) {
321
325
 
322
326
  export async function getReportList( req, res ) {
323
327
  try {
328
+ const bucket = JSON.parse( process.env.BUCKET );
324
329
  const inputData = req.query;
325
330
  const fetchData = {
326
- Bucket: appConfig.cloud.aws.bucket.reportBucket,
327
- file_path: `reports/${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
331
+ Bucket: bucket.reportBucket,
332
+ file_path: `${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
328
333
  };
329
334
  const folderPath = await listFileByPath( fetchData );
330
335
 
@@ -345,9 +350,10 @@ export async function getReportList( req, res ) {
345
350
 
346
351
  export async function dowloadReport( req, res ) {
347
352
  try {
353
+ const bucket = JSON.parse( process.env.BUCKET );
348
354
  const inputData = req.query;
349
355
  const params = {
350
- Bucket: appConfig.cloud.aws.bucket.reportBucket,
356
+ Bucket: bucket.reportBucket,
351
357
  Key: inputData.filePath,
352
358
  };
353
359
  const fileName = inputData.filePath.split( '/' );
@@ -371,6 +377,9 @@ export async function dowloadReport( req, res ) {
371
377
  }
372
378
  export async function sendReport( req, res ) {
373
379
  try {
380
+ const bucket = JSON.parse( process.env.BUCKET );
381
+ const sqs = JSON.parse( process.env.SQS );
382
+ const sesConfig = JSON.parse( process.env.SES );
374
383
  const inputData = req.body;
375
384
  const getReportList = await findReport( { clientId: inputData.clientId } );
376
385
  let reportName = [];
@@ -384,8 +393,8 @@ export async function sendReport( req, res ) {
384
393
  let UserattachmentDetails = [];
385
394
  for ( const data of getReportList ) {
386
395
  const fetchData = {
387
- Bucket: appConfig.cloud.aws.bucket.reportBucket,
388
- Key: `reports/${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/${inputData.fileDate}_${data.fileName}.${data.fileType}`,
396
+ Bucket: bucket.reportBucket,
397
+ Key: `${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/${inputData.fileDate}_${data.fileName}.${data.fileType}`,
389
398
  };
390
399
  reportName.push( `${inputData.fileDate}_${data.fileName}` );
391
400
  name.push( `${data.fileName}` );
@@ -419,7 +428,7 @@ export async function sendReport( req, res ) {
419
428
  }
420
429
  }
421
430
  UserattachmentDetails.forEach( async ( userattach ) => {
422
- await sendEmail( userattach.email, subject, messageBody, userattach.attachments, appConfig.cloud.aws.ses.reportEmail ).then( ( response ) => {
431
+ await sendEmail( userattach.email, subject, messageBody, userattach.attachments, sesConfig.reportEmail ).then( ( response ) => {
423
432
  result.push( response );
424
433
  } );
425
434
  } );
@@ -431,7 +440,7 @@ export async function sendReport( req, res ) {
431
440
  return res.sendError( 'Forbiddon to Access', 403 );
432
441
  }
433
442
  const sqsProduceQueue = {
434
- QueueUrl: `${appConfig.cloud.aws.sqs.url}${appConfig.cloud.aws.sqs.sendReport}`,
443
+ QueueUrl: `${sqs.url}${sqs.sendReport}`,
435
444
  MessageBody: JSON.stringify( {
436
445
  file_date: inputData.fileDate,
437
446
  client_name: req.report?.reportConfigs?.reportName,
@@ -554,9 +563,10 @@ export async function updateBasePrice( req, res ) {
554
563
  export async function sendEmail( toEmail, mailSubject, htmlBody, attachment, sourceEmail ) {
555
564
  return new Promise( async ( resolve, reject ) => {
556
565
  try {
566
+ const awsConfig = JSON.parse( process.env.AWS_CONFIG );
557
567
  const ses = new aws.SES( {
558
568
  apiVersion: 'latest',
559
- region: appConfig.cloud.aws.region,
569
+ region: awsConfig.region,
560
570
  // accessKeyId: process.env.AWS_ACCESS_KEY_ID_SES,
561
571
  // secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY_SES,
562
572
  } );
@@ -2,7 +2,7 @@ import clientModel from 'tango-api-schema/schema/client.model.js';
2
2
 
3
3
 
4
4
  export function aggregateClient( query ) {
5
- return clientModel.aggregate( query );
5
+ return clientModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
6
6
  }
7
7
 
8
8
  export function findOneClient( query, fields ) {
@@ -1,4 +1,4 @@
1
- import { appConfig, checkFileExist, logger } from 'tango-app-api-middleware';
1
+ import { checkFileExist, logger } from 'tango-app-api-middleware';
2
2
  import { findOneClient } from '../service/client.service.js';
3
3
 
4
4
 
@@ -19,10 +19,11 @@ export async function isReportEnable( req, res, next ) {
19
19
 
20
20
  export async function isFolderExist( req, res, next ) {
21
21
  try {
22
+ const bucket = JSON.parse( process.env.BUCKET );
22
23
  const inputData = req.query;
23
24
  const fetchData = {
24
- Bucket: appConfig.cloud.aws.bucket.reportBucket,
25
- Key: `reports/${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
25
+ Bucket: bucket.reportBucket,
26
+ Key: `${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
26
27
  };
27
28
  logger.info( { fetchData: fetchData, report: req.report?.reportConfigs?.reportName } );
28
29
  const isExist = await checkFileExist( fetchData );
@@ -39,9 +40,10 @@ export async function isFolderExist( req, res, next ) {
39
40
 
40
41
  export async function isFileExist( req, res, next ) {
41
42
  try {
43
+ const bucket = JSON.parse( process.env.BUCKET );
42
44
  const inputData = req.query;
43
45
  const fetchData = {
44
- Bucket: appConfig.cloud.aws.bucket.reportBucket,
46
+ Bucket: bucket.reportBucket,
45
47
  Key: inputData.Key,
46
48
  };
47
49
  const isExist = await checkFileExist( fetchData );