tango-app-api-report 3.4.0-beta.2 → 3.4.0-beta.4
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,5 +1,5 @@
|
|
|
1
1
|
import { deleteOneReport, findOneReport, findReport, reportCreate, reportGet, reportGetSingle, reportUpdate } from '../service/report.service.js';
|
|
2
|
-
import { convertTimestampToDateTime, fileUpload, getObject, getOpenSearchData, insertOpenSearchData, listFileByPath, logger, sendMessageToQueue } from 'tango-app-api-middleware';
|
|
2
|
+
import { chunkArray, convertTimestampToDateTime, 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';
|
|
@@ -86,12 +86,12 @@ export async function updateReport( req, res ) {
|
|
|
86
86
|
} );
|
|
87
87
|
|
|
88
88
|
const user = req.user;
|
|
89
|
-
const oldData={
|
|
89
|
+
const oldData = {
|
|
90
90
|
ReportName: previousReport?.fileName,
|
|
91
91
|
FileType: previousReport?.fileType,
|
|
92
92
|
ReceiversEmail: previousReport?.email.join( ', ' ),
|
|
93
93
|
};
|
|
94
|
-
const newData={
|
|
94
|
+
const newData = {
|
|
95
95
|
ReportName: postReport?.fileName,
|
|
96
96
|
FileType: postReport?.fileType,
|
|
97
97
|
ReceiversEmail: postReport?.email.join( ', ' ),
|
|
@@ -130,7 +130,7 @@ export async function deleteReport( req, res ) {
|
|
|
130
130
|
_id: inputData?.id,
|
|
131
131
|
} );
|
|
132
132
|
const client = previousReport?.clientId;
|
|
133
|
-
const changes =[ `The Report ${previousReport?.fileName}.${previousReport?.fileType} has been` ];
|
|
133
|
+
const changes = [ `The Report ${previousReport?.fileName}.${previousReport?.fileType} has been` ];
|
|
134
134
|
|
|
135
135
|
await deleteOneReport( { _id: inputData?.id } );
|
|
136
136
|
|
|
@@ -160,7 +160,7 @@ export async function clientReportList( req, res ) {
|
|
|
160
160
|
try {
|
|
161
161
|
const inputData = req.body;
|
|
162
162
|
const limit = inputData.limit || 10;
|
|
163
|
-
const offset = inputData.offset? ( inputData.offset - 1 ) * inputData.limit : 0;
|
|
163
|
+
const offset = inputData.offset ? ( inputData.offset - 1 ) * inputData.limit : 0;
|
|
164
164
|
const daysDifference = Math.ceil( ( new Date( inputData.toDate ) - new Date( inputData.fromDate ) ) / ( 24 * 60 * 60 * 1000 ) );
|
|
165
165
|
const query = [
|
|
166
166
|
{
|
|
@@ -181,7 +181,7 @@ export async function clientReportList( req, res ) {
|
|
|
181
181
|
daysDifference: 1,
|
|
182
182
|
datesArray: {
|
|
183
183
|
$map: {
|
|
184
|
-
input: { $range: [ 0, { $toInt: daysDifference+1 } ] },
|
|
184
|
+
input: { $range: [ 0, { $toInt: daysDifference + 1 } ] },
|
|
185
185
|
as: 'day',
|
|
186
186
|
in: { $add: [ new Date( inputData.fromDate ), { $multiply: [ '$$day', 1000 * 60 * 60 * 24 ] } ] },
|
|
187
187
|
},
|
|
@@ -223,7 +223,7 @@ export async function clientReportList( req, res ) {
|
|
|
223
223
|
];
|
|
224
224
|
if ( inputData.sortColumnName ) {
|
|
225
225
|
const sortBy = inputData.sortBy || -1;
|
|
226
|
-
const sortColumnName =inputData.sortColumnName == 'clientId'? 'tangoId': inputData.sortColumnName;
|
|
226
|
+
const sortColumnName = inputData.sortColumnName == 'clientId' ? 'tangoId' : inputData.sortColumnName;
|
|
227
227
|
query.push(
|
|
228
228
|
{
|
|
229
229
|
$sort: { fileDate: -1 },
|
|
@@ -259,23 +259,102 @@ export async function clientReportList( req, res ) {
|
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
let count = await aggregateClient( query );
|
|
263
|
+
|
|
264
|
+
|
|
263
265
|
if ( count?.length == 0 ) {
|
|
264
266
|
return res.sendError( 'No Data Found', 204 );
|
|
265
267
|
}
|
|
268
|
+
let paginatedData = count;
|
|
269
|
+
if ( inputData?.reportStatus==='' ) {
|
|
270
|
+
paginatedData = await paginate( count, offset, limit );
|
|
271
|
+
}
|
|
266
272
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
+
if ( inputData.reportStatus&&inputData.reportStatus!=='' ) {
|
|
274
|
+
paginatedData = await splitArray( paginatedData );
|
|
275
|
+
paginatedData= paginatedData.filter( ( ele ) => {
|
|
276
|
+
return ele.reportStatus===inputData.reportStatus;
|
|
277
|
+
} );
|
|
278
|
+
|
|
279
|
+
count = paginatedData;
|
|
280
|
+
|
|
281
|
+
paginatedData =await paginate( paginatedData, offset, limit );
|
|
282
|
+
res.sendSuccess( { result: paginatedData, count: count?.length } );
|
|
283
|
+
} else {
|
|
284
|
+
paginatedData=await mapFunction( paginatedData );
|
|
285
|
+
res.sendSuccess( { result: paginatedData, count: count?.length } );
|
|
286
|
+
}
|
|
273
287
|
} catch ( error ) {
|
|
274
288
|
logger.info( { error: error, message: req.body, function: 'clientReportList' } );
|
|
275
289
|
return res.sendError( 'Internal Server Error', 500 );
|
|
276
290
|
}
|
|
277
291
|
}
|
|
278
292
|
|
|
293
|
+
export async function mapFunction( array ) {
|
|
294
|
+
for ( let [ client ] of array.entries() ) {
|
|
295
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
296
|
+
const reportLog = await getOpenSearchData( openSearch.auditLog,
|
|
297
|
+
{
|
|
298
|
+
'size': 100,
|
|
299
|
+
'query': {
|
|
300
|
+
'bool': {
|
|
301
|
+
'must': [
|
|
302
|
+
{
|
|
303
|
+
'term': {
|
|
304
|
+
'logType.keyword': 'report',
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
'term': {
|
|
309
|
+
'logSubType.keyword': 'sendReport',
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
'term': {
|
|
314
|
+
'logData.fileDate.keyword': dayjs( client.fileDate ).format( 'DD-MM-YYYY' ),
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
'term': {
|
|
319
|
+
'logData.clientId.keyword': client.clientId,
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
],
|
|
324
|
+
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
|
|
328
|
+
} );
|
|
329
|
+
client.reportStatus='notsent';
|
|
330
|
+
if ( reportLog.body.hits.hits.length > 0 ) {
|
|
331
|
+
const sourcesArray = reportLog.body.hits.hits.map( ( hit ) => hit._source );
|
|
332
|
+
if ( sourcesArray.length>0 ) {
|
|
333
|
+
client.reportStatus='sent';
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return array;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
export async function splitArray( array ) {
|
|
343
|
+
const chunkedMappingData = await chunkArray( array, 10 );
|
|
344
|
+
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
345
|
+
return mapFunction( chunk );
|
|
346
|
+
} );
|
|
347
|
+
const mappedArrays = await Promise.all( promises );
|
|
348
|
+
return mappedArrays.flat();
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export async function paginate( array, pageNumber, pageSize ) {
|
|
352
|
+
const startIndex = pageNumber * pageSize;
|
|
353
|
+
const endIndex = startIndex + pageSize;
|
|
354
|
+
|
|
355
|
+
return array.slice( startIndex, endIndex );
|
|
356
|
+
}
|
|
357
|
+
|
|
279
358
|
export async function generateReport( req, res ) {
|
|
280
359
|
try {
|
|
281
360
|
const sqs = JSON.parse( process.env.SQS );
|
|
@@ -395,7 +474,7 @@ export async function getReportList( req, res ) {
|
|
|
395
474
|
if ( folderPath?.data?.length == 0 ) {
|
|
396
475
|
return res.sendError( 'No Reports Found', 204 );
|
|
397
476
|
}
|
|
398
|
-
let temp =[];
|
|
477
|
+
let temp = [];
|
|
399
478
|
for ( const item of folderPath.data ) {
|
|
400
479
|
temp.push( { Key: item.Key, LastModified: dayjs( item.LastModified ).tz( 'Asia/Kolkata' ).format( 'YYYY-MM-DD HH:mm:ss' ) } );
|
|
401
480
|
}
|
|
@@ -542,7 +621,7 @@ export async function getReportLog( req, res ) {
|
|
|
542
621
|
try {
|
|
543
622
|
const inputData = req.body;
|
|
544
623
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
545
|
-
const logData =[];
|
|
624
|
+
const logData = [];
|
|
546
625
|
const reportLog = await getOpenSearchData( openSearch.auditLog,
|
|
547
626
|
{
|
|
548
627
|
'size': 100,
|
|
@@ -594,10 +673,10 @@ export async function getReportLog( req, res ) {
|
|
|
594
673
|
export async function updateBasePrice( req, res ) {
|
|
595
674
|
try {
|
|
596
675
|
const inputData = req.body;
|
|
597
|
-
let count=0;
|
|
676
|
+
let count = 0;
|
|
598
677
|
let increment = 0;
|
|
599
|
-
for ( let i =0; i< inputData.length; i++ ) {
|
|
600
|
-
increment = increment+1;
|
|
678
|
+
for ( let i = 0; i < inputData.length; i++ ) {
|
|
679
|
+
increment = increment + 1;
|
|
601
680
|
// await basePricingModel.create( {
|
|
602
681
|
// 'clientId': inputData[i].clientId,
|
|
603
682
|
// 'standard': [
|
|
@@ -619,7 +698,7 @@ export async function updateBasePrice( req, res ) {
|
|
|
619
698
|
'clientId': inputData[i].clientId,
|
|
620
699
|
'standard.productName': { $exists: true },
|
|
621
700
|
};
|
|
622
|
-
const record={
|
|
701
|
+
const record = {
|
|
623
702
|
'clientId': inputData[i].clientId,
|
|
624
703
|
'standard.$[elem].basePrice': inputData[i].pricePerStore,
|
|
625
704
|
'standard.$[elem].negotiatePrice': inputData[i].pricePerStore,
|
|
@@ -629,12 +708,11 @@ export async function updateBasePrice( req, res ) {
|
|
|
629
708
|
};
|
|
630
709
|
const result = await updateOneBasePriceModel( query, record );
|
|
631
710
|
if ( result ) {
|
|
632
|
-
count= count+1;
|
|
711
|
+
count = count + 1;
|
|
633
712
|
}
|
|
634
|
-
console.log( result, '.data' );
|
|
635
713
|
}
|
|
636
714
|
if ( increment == inputData.length ) {
|
|
637
|
-
res.sendSuccess( { result: `The given ${count
|
|
715
|
+
res.sendSuccess( { result: `The given ${count} recoeds updated` } );
|
|
638
716
|
}
|
|
639
717
|
} catch ( error ) {
|
|
640
718
|
logger.error( { error: error, message: req.params, function: 'updateBasePrice' } );
|
package/src/dtos/report.dtos.js
CHANGED
|
@@ -73,9 +73,9 @@ export const clientListTableSchema = joi.object( {
|
|
|
73
73
|
limit: joi.number().optional(),
|
|
74
74
|
offset: joi.number().optional(),
|
|
75
75
|
searchValue: joi.string().optional(),
|
|
76
|
-
filterByType: joi.array().optional(),
|
|
77
76
|
sortColumnName: joi.string().optional(),
|
|
78
77
|
sortBy: joi.number().optional(),
|
|
78
|
+
reportStatus: joi.string().optional().allow( '' ),
|
|
79
79
|
} );
|
|
80
80
|
|
|
81
81
|
export const clientListTableValid = {
|