tango-app-api-report 3.0.5-dev → 3.0.6-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.5-dev",
3
+ "version": "3.0.6-dev",
4
4
  "description": "report",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "nodemon": "^3.1.0",
25
25
  "swagger-ui-express": "^5.0.0",
26
26
  "tango-api-schema": "^2.0.103",
27
- "tango-app-api-middleware": "^1.0.77-dev",
27
+ "tango-app-api-middleware": "^1.0.81-dev",
28
28
  "winston": "^3.12.0",
29
29
  "winston-daily-rotate-file": "^5.0.0"
30
30
  },
@@ -1,5 +1,5 @@
1
1
  import { findOneReport, findReport, reportCreate, reportGet, reportGetSingle, reportUpdate } from '../service/report.service.js';
2
- import { appConfig, fileUpload, getObject, insertOpenSearchData, listFoldersByPath, logger, sendMessageToQueue } from 'tango-app-api-middleware';
2
+ import { appConfig, fileUpload, getObject, 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';
@@ -97,9 +97,7 @@ export async function clientReportList( req, res ) {
97
97
  const inputData = req.body;
98
98
  const limit = inputData.limit || 10;
99
99
  const offset = inputData.offset? ( inputData.offset - 1 ) * inputData.limit : 0;
100
- logger.info( { inputData: inputData } );
101
100
  const daysDifference = Math.ceil( ( new Date( inputData.toDate ) - new Date( inputData.fromDate ) ) / ( 24 * 60 * 60 * 1000 ) );
102
- logger.info( { daysDifference: daysDifference, value: ( new Date( inputData.toDate ) - new Date( inputData.fromDate ) ) / ( 24 * 60 * 60 * 1000 ), fromdate: inputData.fromDate, toDate: inputData.toDate } );
103
101
  const query = [
104
102
  {
105
103
  $match: {
@@ -143,6 +141,19 @@ export async function clientReportList( req, res ) {
143
141
  },
144
142
  },
145
143
  ];
144
+
145
+ if ( inputData.sortColumnName ) {
146
+ const sortBy = inputData.sortBy || -1;
147
+ const sortColumnName =inputData.sortColumnName == 'clientId'? 'tangoId': inputData.sortColumnName;
148
+ query.push( {
149
+ $sort: { [sortColumnName]: sortBy },
150
+ },
151
+ {
152
+ $sort: { fileDate: -1 },
153
+ } );
154
+ }
155
+
156
+
146
157
  if ( inputData.searchValue ) {
147
158
  query.push(
148
159
  {
@@ -160,13 +171,8 @@ export async function clientReportList( req, res ) {
160
171
  },
161
172
  );
162
173
  }
163
- if ( inputData.sortColumnName ) {
164
- const sortBy = inputData.sortBy || -1;
165
- const sortColumnName =inputData.sortColumnName == 'clientId'? 'tangoId': inputData.sortColumnName;
166
- query.push( {
167
- $sort: { [sortColumnName]: sortBy },
168
- } );
169
- }
174
+
175
+
170
176
  const count = await aggregateClient( query );
171
177
  if ( count?.length == 0 ) {
172
178
  return res.sendError( 'No Data Found', 204 );
@@ -245,11 +251,12 @@ export async function uploadManualReport( req, res ) {
245
251
  if ( !data ) {
246
252
  return res.sendError( 'Report does not configured', 400 );
247
253
  }
254
+ logger.info( { files: req.files } );
248
255
  const uploadDataParams = {
249
256
  Bucket: appConfig.cloud.aws.bucket.reportBucket,
250
- Key: `${inputData.fileDate}/${data.reportName}/`,
251
- fileName: inputData.filename,
252
- Body: req.files.fileuplaod_data.data,
257
+ Key: `reports/${inputData.fileDate}/${data.reportName}/`,
258
+ fileName: inputData.fileName,
259
+ Body: req.files,
253
260
  };
254
261
  const result = await fileUpload( uploadDataParams );
255
262
  logger.info( { result: result, value: 'file upload response' } );
@@ -272,14 +279,14 @@ export async function uploadManualReport( req, res ) {
272
279
  clientId: data.clientId,
273
280
  },
274
281
  };
275
-
276
- await insertOpenSearchData( 'tango-retail-activity-logs', log );
282
+ logger.info( { log: log } );
283
+ // await insertOpenSearchData( 'tango-retail-activity-logs', log );
277
284
  return res.sendSuccess( { result: 'uploaded Sucessfully' } );
278
285
  } else {
279
286
  return res.sendError( 'File Name is Incorrect', 400 );
280
287
  }
281
288
  } catch ( error ) {
282
- logger.error( { error: error, message: req.body, function: 'generateReport' } );
289
+ logger.error( { error: error, message: req.body, function: 'uploadManualReport' } );
283
290
  return res.sendError( error, 500 );
284
291
  }
285
292
  }
@@ -289,9 +296,10 @@ export async function getReportList( req, res ) {
289
296
  const inputData = req.query;
290
297
  const fetchData = {
291
298
  Bucket: appConfig.cloud.aws.bucket.reportBucket,
292
- file_path: `${inputData.fileDate}/${inputData.getReportName?.reportName}/`,
299
+ file_path: `reports/${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
293
300
  };
294
- const folderPath = await listFoldersByPath( fetchData );
301
+ const folderPath = await listFileByPath( fetchData );
302
+
295
303
  logger.info( { folderPath: folderPath, value: 'report list from bucket' } );
296
304
  if ( folderPath.length == 0 ) {
297
305
  return res.sendError( 'No Reports Found', 204 );
@@ -1,6 +1,6 @@
1
1
  import j2s from 'joi-to-swagger';
2
2
 
3
- import { clientListTableSchema, downloadReportSchema, generateReportSchema, getReportListSchema, sendReportSchema, uploadManualReportSchema } from '../dtos/report.dtos.js';
3
+ import { clientListTableSchema, downloadReportSchema, generateReportSchema, getReportListSchema, sendReportSchema, uploadManualReportSchema, uploadManualReportSchema2 } from '../dtos/report.dtos.js';
4
4
 
5
5
  export const reportDocs = {
6
6
 
@@ -59,6 +59,9 @@ export const reportDocs = {
59
59
  parameters: {},
60
60
  requestBody: {
61
61
  content: {
62
+ 'multipart/form-data': {
63
+ schema: j2s( uploadManualReportSchema2 ).swagger,
64
+ },
62
65
  'application/json': {
63
66
  schema: j2s( uploadManualReportSchema ).swagger,
64
67
  },
@@ -88,6 +88,11 @@ export const uploadManualReportSchema = joi.object( {
88
88
  fileDate: joi.string().required(),
89
89
  clientId: joi.string().required(),
90
90
  fileName: joi.string().required(),
91
+ file: joi.string().required(),
92
+ } );
93
+
94
+ export const uploadManualReportSchema2 = joi.object( {
95
+ file: joi.binary().required(),
91
96
  } );
92
97
 
93
98
  export const uploadManualReportValid = {
@@ -1,7 +1,7 @@
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, uploadManualReportValid } from '../dtos/report.dtos.js';
4
+ import { addReportValid, clientListTableValid, downloadReportValid, generateReportValid, getReportListValid, getReportValid, getSingleReportValid, sendReportValid, updateReportValid } from '../dtos/report.dtos.js';
5
5
  import { clientReportList, createReport, dowloadReport, generateReport, getReport, getReportList, getSingleReport, sendReport, updateBasePrice, updateReport, uploadManualReport } from '../controllers/report.controllers.js';
6
6
  import { isFileExist, isFolderExist, isReportEnable } from '../validations/report.validations.js';
7
7
 
@@ -39,7 +39,7 @@ reportRouter.post( '/upload-manual-report', isAllowedSessionHandler,
39
39
  authorize( { userType: [ 'tango' ], access: [
40
40
  { featureName: 'settings', name: 'configuration', permissions: [ 'isEdit' ] },
41
41
  ] } ),
42
- validate( uploadManualReportValid ), isReportEnable, uploadManualReport );
42
+ isReportEnable, uploadManualReport );
43
43
 
44
44
  reportRouter.get( '/get-report-list', isAllowedSessionHandler,
45
45
  authorize( { userType: [ 'tango' ], access: [
@@ -5,6 +5,6 @@ export function aggregateClient( query ) {
5
5
  return clientModel.aggregate( query );
6
6
  }
7
7
 
8
- export function findOneClient( query ) {
9
- return clientModel.findOne( query );
8
+ export function findOneClient( query, fields ) {
9
+ return clientModel.findOne( query, fields );
10
10
  }
@@ -1,15 +1,15 @@
1
- import { checkFileExist, logger } from 'tango-app-api-middleware';
1
+ import { appConfig, checkFileExist, logger } from 'tango-app-api-middleware';
2
2
  import { findOneClient } from '../service/client.service.js';
3
3
 
4
4
 
5
5
  export async function isReportEnable( req, res, next ) {
6
6
  try {
7
7
  const inputData = req.method !== 'GET'? req.body: req.query;
8
- const getReportName = await findOneClient( { 'clientId': inputData.clientId, 'reportConfigs.report': true }, { reportName: '$reportConfigs.reportName', clientName: 1 } );
8
+ const getReportName = await findOneClient( { 'clientId': inputData.clientId, 'reportConfigs.report': true }, { '_id': 0, 'reportConfigs.reportName': 1, 'clientName': 1 } );
9
9
  if ( !getReportName ) {
10
10
  return res.sendError( 'reportName is not there in the client', 204 );
11
11
  }
12
- req.body.reportName = getReportName;
12
+ req.report = getReportName;
13
13
  return next();
14
14
  } catch ( error ) {
15
15
  logger.error( { error: error, message: req.body, function: 'isReportEnable' } );
@@ -22,8 +22,9 @@ export async function isFolderExist( req, res, next ) {
22
22
  const inputData = req.query;
23
23
  const fetchData = {
24
24
  Bucket: appConfig.cloud.aws.bucket.reportBucket,
25
- Key: `${inputData.fileDate}/${inputData.getReportName?.reportName}/`,
25
+ Key: `reports/${inputData.fileDate}/${req.report?.reportConfigs?.reportName}/`,
26
26
  };
27
+ logger.info( { fetchData: fetchData, report: req.report?.reportConfigs?.reportName } );
27
28
  const isExist = await checkFileExist( fetchData );
28
29
  if ( isExist ) {
29
30
  return next();