tango-app-api-report 3.0.7-dev → 3.0.9-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.7-dev",
3
+ "version": "3.0.9-dev",
4
4
  "description": "report",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -21,6 +21,7 @@
21
21
  "handlebars": "^4.7.8",
22
22
  "joi-to-swagger": "^6.2.0",
23
23
  "mongodb": "^6.5.0",
24
+ "nodemailer": "^6.9.13",
24
25
  "nodemon": "^3.1.0",
25
26
  "swagger-ui-express": "^5.0.0",
26
27
  "tango-api-schema": "^2.0.103",
@@ -1,8 +1,11 @@
1
1
  import { findOneReport, findReport, reportCreate, reportGet, reportGetSingle, reportUpdate } from '../service/report.service.js';
2
- import { appConfig, fileUpload, getObject, insertOpenSearchData, listFileByPath, logger, sendMessageToQueue } from 'tango-app-api-middleware';
2
+ import { appConfig, 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';
6
+ import aws from 'aws-sdk';
7
+ import * as nodemailer from 'nodemailer';
8
+
6
9
  // import basePricingModel from 'tango-api-schema/schema/basePricing.model.js';
7
10
 
8
11
 
@@ -141,16 +144,18 @@ export async function clientReportList( req, res ) {
141
144
  },
142
145
  },
143
146
  ];
144
-
145
147
  if ( inputData.sortColumnName ) {
146
148
  const sortBy = inputData.sortBy || -1;
147
149
  const sortColumnName =inputData.sortColumnName == 'clientId'? 'tangoId': inputData.sortColumnName;
148
- query.push( {
149
- $sort: { [sortColumnName]: sortBy },
150
- },
151
- {
152
- $sort: { fileDate: -1 },
153
- } );
150
+ query.push(
151
+ {
152
+ $sort: { fileDate: -1 },
153
+ },
154
+ {
155
+ $sort: { [sortColumnName]: sortBy },
156
+ },
157
+
158
+ );
154
159
  }
155
160
 
156
161
 
@@ -353,7 +358,7 @@ export async function sendReport( req, res ) {
353
358
  for ( const data of getReportList ) {
354
359
  const fetchData = {
355
360
  Bucket: appConfig.cloud.aws.bucket.reportBucket,
356
- Key: `${inputData.fileDate}/${data.reportName}/${inputData.fileDate}_${data.fileName}.${data.fileType}`,
361
+ Key: `reports/${inputData.fileDate}/${data.reportName}/${inputData.fileDate}_${data.fileName}.${data.fileType}`,
357
362
  };
358
363
  reportName.push( `${inputData.fileDate}_${data.fileName}` );
359
364
  name.push( `${data.fileName}` );
@@ -387,7 +392,7 @@ export async function sendReport( req, res ) {
387
392
  }
388
393
  }
389
394
  UserattachmentDetails.forEach( async ( userattach ) => {
390
- await sendEmail( userattach.email, subject, messageBody, userattach.attachments, config.ses.reportEmail ).then( ( response ) => {
395
+ await sendEmail( userattach.email, subject, messageBody, userattach.attachments, appConfig.cloud.aws.ses.reportEmail ).then( ( response ) => {
391
396
  result.push( response );
392
397
  } );
393
398
  } );
@@ -436,6 +441,38 @@ export async function sendReport( req, res ) {
436
441
  }
437
442
  }
438
443
 
444
+ export async function getReportLog( req, res ) {
445
+ try {
446
+ const inputData = req.body;
447
+ const log = await getOpenSearchData( 'tango-retail-activity-logs',
448
+ {
449
+ 'size': 100,
450
+ 'query': {
451
+ 'bool': {
452
+ 'must': [
453
+ {
454
+ 'term': {
455
+ 'logType.keyword': 'report',
456
+ },
457
+ },
458
+ {
459
+ 'term': {
460
+ 'logData.fileDate.keyword': inputData.fileDate,
461
+ },
462
+ },
463
+
464
+ ],
465
+
466
+ },
467
+ },
468
+
469
+ } );
470
+ return res.sendSuccess( { result: log } );
471
+ } catch ( error ) {
472
+ logger.info( { error: error } );
473
+ return res.sendError( error, 500 );
474
+ }
475
+ }
439
476
  export async function updateBasePrice( req, res ) {
440
477
  try {
441
478
  const inputData = req.body;
@@ -487,4 +524,48 @@ export async function updateBasePrice( req, res ) {
487
524
  }
488
525
  }
489
526
 
527
+ export async function sendEmail( toEmail, mailSubject, htmlBody, attachment, sourceEmail ) {
528
+ return new Promise( async ( resolve, reject ) => {
529
+ try {
530
+ const ses = new aws.SES( {
531
+ apiVersion: 'latest',
532
+ region: appConfig.cloud.aws.region,
533
+ // accessKeyId: process.env.AWS_ACCESS_KEY_ID_SES,
534
+ // secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY_SES,
535
+ } );
536
+
537
+ let Attachment = [];
538
+ if ( attachment ) {
539
+ Attachment = attachment;
540
+ }
541
+ try {
542
+ let transporter = nodemailer.createTransport( {
543
+ SES: { ses, aws },
544
+ } );
545
+ let mailOptions = {
546
+ from: sourceEmail,
547
+ to: toEmail,
548
+ subject: mailSubject,
549
+ html: htmlBody,
550
+ attachments: Attachment,
551
+ };
552
+ transporter.sendMail( mailOptions )
553
+ .then( ( data ) => {
554
+ resolve( data );
555
+ } )
556
+ .catch( ( err ) => {
557
+ logger.error( err, 'Node Mailer EXCEPTION' );
558
+ reject( err );
559
+ } );
560
+ } catch ( error ) {
561
+ console.error( 'Error sending email:', error );
562
+ throw error;
563
+ }
564
+ } catch ( error ) {
565
+ console.error( 'Error sending email:', error );
566
+ throw error;
567
+ }
568
+ } );
569
+ }
570
+
490
571
 
@@ -1,6 +1,6 @@
1
1
  import j2s from 'joi-to-swagger';
2
2
 
3
- import { clientListTableSchema, downloadReportSchema, generateReportSchema, getReportListSchema, sendReportSchema, uploadManualReportSchema, uploadManualReportSchema2 } from '../dtos/report.dtos.js';
3
+ import { clientListTableSchema, downloadReportSchema, generateReportSchema, getReportListSchema, getReportLogSchema, sendReportSchema, uploadManualReportSchema, uploadManualReportSchema2 } from '../dtos/report.dtos.js';
4
4
 
5
5
  export const reportDocs = {
6
6
 
@@ -152,5 +152,28 @@ export const reportDocs = {
152
152
  },
153
153
  },
154
154
 
155
+ '/v3/report/get-report-log': {
156
+ post: {
157
+ tags: [ 'Report' ],
158
+ description: `get report log`,
159
+ operationId: 'get-report-log',
160
+ parameters: {},
161
+ requestBody: {
162
+ content: {
163
+ 'application/json': {
164
+ schema: j2s( getReportLogSchema ).swagger,
165
+ },
166
+ },
167
+ },
168
+ responses: {
169
+ 200: { description: 'Successful' },
170
+ 401: { description: 'Unauthorized User' },
171
+ 422: { description: 'Field Error' },
172
+ 500: { description: 'Server Error' },
173
+ 204: { description: 'Not Found' },
174
+ },
175
+ },
176
+ },
177
+
155
178
  };
156
179
 
@@ -128,3 +128,14 @@ export const sendReportValid = {
128
128
 
129
129
  };
130
130
 
131
+ export const getReportLogSchema = joi.object( {
132
+ fileDate: joi.string().required(),
133
+ clientId: joi.string().required(),
134
+ } );
135
+
136
+ export const getReportLogValid = {
137
+ body: getReportLogSchema,
138
+
139
+ };
140
+
141
+
@@ -1,8 +1,8 @@
1
1
 
2
2
  import express from 'express';
3
3
  import { authorize, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
- import { addReportValid, clientListTableValid, downloadReportValid, generateReportValid, getReportListValid, getReportValid, getSingleReportValid, sendReportValid, updateReportValid } from '../dtos/report.dtos.js';
5
- import { clientReportList, createReport, dowloadReport, generateReport, getReport, getReportList, getSingleReport, sendReport, updateBasePrice, updateReport, uploadManualReport } from '../controllers/report.controllers.js';
4
+ import { addReportValid, clientListTableValid, downloadReportValid, generateReportValid, getReportListValid, getReportLogValid, getReportValid, getSingleReportValid, sendReportValid, updateReportValid } from '../dtos/report.dtos.js';
5
+ import { clientReportList, createReport, dowloadReport, generateReport, getReport, getReportList, getReportLog, getSingleReport, sendReport, updateBasePrice, updateReport, uploadManualReport } from '../controllers/report.controllers.js';
6
6
  import { isFileExist, isFolderExist, isReportEnable } from '../validations/report.validations.js';
7
7
 
8
8
  export const reportRouter = express.Router();
@@ -59,6 +59,12 @@ reportRouter.post( '/send-report', isAllowedSessionHandler,
59
59
  ] } ),
60
60
  validate( sendReportValid ), isReportEnable, sendReport );
61
61
 
62
+ reportRouter.post( '/get-report-log', isAllowedSessionHandler,
63
+ authorize( { userType: [ 'tango' ], access: [
64
+ { featureName: 'settings', name: 'configuration', permissions: [ 'isView' ] },
65
+ ] } ),
66
+ validate( getReportLogValid ), getReportLog );
67
+
62
68
  reportRouter.post( '/invoice', updateBasePrice );
63
69
 
64
70
  export default reportRouter;