tango-app-api-report 3.0.7-dev → 3.0.8-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.
|
|
3
|
+
"version": "3.0.8-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
|
|
|
@@ -353,7 +356,7 @@ export async function sendReport( req, res ) {
|
|
|
353
356
|
for ( const data of getReportList ) {
|
|
354
357
|
const fetchData = {
|
|
355
358
|
Bucket: appConfig.cloud.aws.bucket.reportBucket,
|
|
356
|
-
Key:
|
|
359
|
+
Key: `reports/${inputData.fileDate}/${data.reportName}/${inputData.fileDate}_${data.fileName}.${data.fileType}`,
|
|
357
360
|
};
|
|
358
361
|
reportName.push( `${inputData.fileDate}_${data.fileName}` );
|
|
359
362
|
name.push( `${data.fileName}` );
|
|
@@ -387,7 +390,7 @@ export async function sendReport( req, res ) {
|
|
|
387
390
|
}
|
|
388
391
|
}
|
|
389
392
|
UserattachmentDetails.forEach( async ( userattach ) => {
|
|
390
|
-
await sendEmail( userattach.email, subject, messageBody, userattach.attachments,
|
|
393
|
+
await sendEmail( userattach.email, subject, messageBody, userattach.attachments, appConfig.cloud.aws.ses.reportEmail ).then( ( response ) => {
|
|
391
394
|
result.push( response );
|
|
392
395
|
} );
|
|
393
396
|
} );
|
|
@@ -436,6 +439,38 @@ export async function sendReport( req, res ) {
|
|
|
436
439
|
}
|
|
437
440
|
}
|
|
438
441
|
|
|
442
|
+
export async function getReportLog( req, res ) {
|
|
443
|
+
try {
|
|
444
|
+
const inputData = req.body;
|
|
445
|
+
const log = await getOpenSearchData( 'tango-retail-activity-logs',
|
|
446
|
+
{
|
|
447
|
+
'size': 100,
|
|
448
|
+
'query': {
|
|
449
|
+
'bool': {
|
|
450
|
+
'must': [
|
|
451
|
+
{
|
|
452
|
+
'term': {
|
|
453
|
+
'logType.keyword': 'report',
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
'term': {
|
|
458
|
+
'logData.fileDate.keyword': inputData.fileDate,
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
|
|
462
|
+
],
|
|
463
|
+
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
|
|
467
|
+
} );
|
|
468
|
+
return res.sendSuccess( { result: log } );
|
|
469
|
+
} catch ( error ) {
|
|
470
|
+
logger.info( { error: error } );
|
|
471
|
+
return res.sendError( error, 500 );
|
|
472
|
+
}
|
|
473
|
+
}
|
|
439
474
|
export async function updateBasePrice( req, res ) {
|
|
440
475
|
try {
|
|
441
476
|
const inputData = req.body;
|
|
@@ -487,4 +522,48 @@ export async function updateBasePrice( req, res ) {
|
|
|
487
522
|
}
|
|
488
523
|
}
|
|
489
524
|
|
|
525
|
+
export async function sendEmail( toEmail, mailSubject, htmlBody, attachment, sourceEmail ) {
|
|
526
|
+
return new Promise( async ( resolve, reject ) => {
|
|
527
|
+
try {
|
|
528
|
+
const ses = new aws.SES( {
|
|
529
|
+
apiVersion: 'latest',
|
|
530
|
+
region: appConfig.cloud.aws.region,
|
|
531
|
+
// accessKeyId: process.env.AWS_ACCESS_KEY_ID_SES,
|
|
532
|
+
// secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY_SES,
|
|
533
|
+
} );
|
|
534
|
+
|
|
535
|
+
let Attachment = [];
|
|
536
|
+
if ( attachment ) {
|
|
537
|
+
Attachment = attachment;
|
|
538
|
+
}
|
|
539
|
+
try {
|
|
540
|
+
let transporter = nodemailer.createTransport( {
|
|
541
|
+
SES: { ses, aws },
|
|
542
|
+
} );
|
|
543
|
+
let mailOptions = {
|
|
544
|
+
from: sourceEmail,
|
|
545
|
+
to: toEmail,
|
|
546
|
+
subject: mailSubject,
|
|
547
|
+
html: htmlBody,
|
|
548
|
+
attachments: Attachment,
|
|
549
|
+
};
|
|
550
|
+
transporter.sendMail( mailOptions )
|
|
551
|
+
.then( ( data ) => {
|
|
552
|
+
resolve( data );
|
|
553
|
+
} )
|
|
554
|
+
.catch( ( err ) => {
|
|
555
|
+
logger.error( err, 'Node Mailer EXCEPTION' );
|
|
556
|
+
reject( err );
|
|
557
|
+
} );
|
|
558
|
+
} catch ( error ) {
|
|
559
|
+
console.error( 'Error sending email:', error );
|
|
560
|
+
throw error;
|
|
561
|
+
}
|
|
562
|
+
} catch ( error ) {
|
|
563
|
+
console.error( 'Error sending email:', error );
|
|
564
|
+
throw error;
|
|
565
|
+
}
|
|
566
|
+
} );
|
|
567
|
+
}
|
|
568
|
+
|
|
490
569
|
|
package/src/docs/report.docs.js
CHANGED
|
@@ -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
|
|
package/src/dtos/report.dtos.js
CHANGED
|
@@ -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;
|