tango-app-api-report 3.0.1-dev → 3.0.3-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.3-dev",
|
|
4
4
|
"description": "report",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,10 +19,12 @@
|
|
|
19
19
|
"express": "^4.18.3",
|
|
20
20
|
"express-fileupload": "^1.5.0",
|
|
21
21
|
"handlebars": "^4.7.8",
|
|
22
|
+
"joi-to-swagger": "^6.2.0",
|
|
22
23
|
"mongodb": "^6.5.0",
|
|
23
24
|
"nodemon": "^3.1.0",
|
|
24
|
-
"
|
|
25
|
-
"tango-
|
|
25
|
+
"swagger-ui-express": "^5.0.0",
|
|
26
|
+
"tango-api-schema": "^2.0.103",
|
|
27
|
+
"tango-app-api-middleware": "^1.0.77-dev",
|
|
26
28
|
"winston": "^3.12.0",
|
|
27
29
|
"winston-daily-rotate-file": "^5.0.0"
|
|
28
30
|
},
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { reportCreate, reportGet, reportGetSingle, reportUpdate } from '../service/report.service.js';
|
|
2
|
-
import { insertOpenSearchData, logger } from 'tango-app-api-middleware';
|
|
2
|
+
import { appConfig, insertOpenSearchData, logger, sendMessageToQueue } from 'tango-app-api-middleware';
|
|
3
3
|
import { getUserNameEmailById } from '../service/user.service.js';
|
|
4
|
+
import { updateOneBasePriceModel } from '../service/basePrice.service.js';
|
|
5
|
+
import { aggregateClient, findOneClient } from '../service/client.service.js';
|
|
6
|
+
// import basePricingModel from 'tango-api-schema/schema/basePricing.model.js';
|
|
4
7
|
|
|
5
8
|
|
|
6
9
|
export async function createReport( req, res ) {
|
|
@@ -88,3 +91,330 @@ export async function updateReport( req, res ) {
|
|
|
88
91
|
return res.sendError( error, 500 );
|
|
89
92
|
}
|
|
90
93
|
}
|
|
94
|
+
|
|
95
|
+
export async function clientReportList( req, res ) {
|
|
96
|
+
try {
|
|
97
|
+
const inputData = req.body;
|
|
98
|
+
const limit = inputData.limit || 10;
|
|
99
|
+
const offset = inputData.offset? ( inputData.offset - 1 ) * inputData.limit : 0;
|
|
100
|
+
logger.info( { inputData: inputData } );
|
|
101
|
+
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
|
+
const query = [
|
|
104
|
+
{
|
|
105
|
+
$match: {
|
|
106
|
+
'reportConfigs.report': { $eq: true },
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
$project: {
|
|
111
|
+
clientId: 1,
|
|
112
|
+
clientName: 1,
|
|
113
|
+
daysDifference: 1,
|
|
114
|
+
datesArray: {
|
|
115
|
+
$map: {
|
|
116
|
+
input: { $range: [ 0, { $toInt: daysDifference+1 } ] },
|
|
117
|
+
as: 'day',
|
|
118
|
+
in: { $add: [ new Date( inputData.fromDate ), { $multiply: [ '$$day', 1000 * 60 * 60 * 24 ] } ] },
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
$unwind: '$datesArray',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
$sort: {
|
|
128
|
+
datesArray: -1,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
{
|
|
133
|
+
$project: {
|
|
134
|
+
clientId: 1,
|
|
135
|
+
clientName: 1,
|
|
136
|
+
fileDate: '$datesArray',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
if ( inputData.searchValue ) {
|
|
141
|
+
query.push(
|
|
142
|
+
{
|
|
143
|
+
$match: {
|
|
144
|
+
$or: [
|
|
145
|
+
{
|
|
146
|
+
clientName: { $regex: inputData.searchValue, $options: 'i' },
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
clientId: { $regex: inputData.searchValue, $options: 'i' },
|
|
150
|
+
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if ( inputData.sortColumnName ) {
|
|
158
|
+
const sortBy = inputData.sortBy || -1;
|
|
159
|
+
query.push( {
|
|
160
|
+
$sort: { [inputData.sortColumnName]: sortBy },
|
|
161
|
+
} );
|
|
162
|
+
}
|
|
163
|
+
const count = await aggregateClient( query );
|
|
164
|
+
|
|
165
|
+
query.push(
|
|
166
|
+
{ $skip: offset },
|
|
167
|
+
{ $limit: limit },
|
|
168
|
+
);
|
|
169
|
+
const result = await aggregateClient( query );
|
|
170
|
+
res.sendSuccess( { result: result, count: count.length } );
|
|
171
|
+
} catch ( error ) {
|
|
172
|
+
logger.info( { error: error, message: req.body, function: 'clientReportList' } );
|
|
173
|
+
return res.sendError( 'Internal Server Error', 500 );
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function generateReport( req, res ) {
|
|
178
|
+
try {
|
|
179
|
+
const inputdata = req.body;
|
|
180
|
+
const getReportName = await findOneClient( { 'clientId': inputdata.clientId, 'reportConfigs.report': true }, { reportName: '$reportConfigs.reportName', clientName: 1 } );
|
|
181
|
+
if ( !getReportName ) {
|
|
182
|
+
return res.sendError( 'reportName is not there in the client', 204 );
|
|
183
|
+
}
|
|
184
|
+
const sqsProduceQueue = {
|
|
185
|
+
QueueUrl: `${appConfig.cloud.aws.sqs.url}${appConfig.cloud.aws.sqs.generateReport}`,
|
|
186
|
+
MessageBody: JSON.stringify( {
|
|
187
|
+
file_date: inputdata.fileDate,
|
|
188
|
+
client_name: getReportName.reportName,
|
|
189
|
+
client_id: Number( inputdata.ClientId ),
|
|
190
|
+
message: 'good to trigger',
|
|
191
|
+
} ),
|
|
192
|
+
};
|
|
193
|
+
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
194
|
+
if ( sqsQueue.MessageId ) {
|
|
195
|
+
const log = {
|
|
196
|
+
userName: req.user.userName,
|
|
197
|
+
Date: new Date(),
|
|
198
|
+
userId: req.user._id,
|
|
199
|
+
logType: 'report',
|
|
200
|
+
logSubType: 'generateReport',
|
|
201
|
+
logData: {
|
|
202
|
+
clientName: getReportName.clientName,
|
|
203
|
+
fileDate: inputdata.fileDate,
|
|
204
|
+
reportName: getReportName.reportName,
|
|
205
|
+
clientId: inputdata.ClientId,
|
|
206
|
+
sqsMessageId: sqsQueue.MessageId,
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
await insertOpenSearchData( 'tango-retail-activity-logs', log );
|
|
210
|
+
|
|
211
|
+
return res.sendSuccess( { result: 'Report has been Initiated Sucessfully' } );
|
|
212
|
+
}
|
|
213
|
+
} catch ( err ) {
|
|
214
|
+
return res.sendError( err, 500 );
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export async function sendReport( req, res ) {
|
|
219
|
+
try {
|
|
220
|
+
// let record = await reportModel.find( { clientId: req.body.clientId } );
|
|
221
|
+
// if ( record.length == 0 ) {
|
|
222
|
+
// return res.sendError( 'No report Found', 204 );
|
|
223
|
+
// }
|
|
224
|
+
// let reportname = [];
|
|
225
|
+
// let name = [];
|
|
226
|
+
// let regionalKey = [];
|
|
227
|
+
// let result = [];
|
|
228
|
+
// let file = {};
|
|
229
|
+
// let sendMailCount = 0;
|
|
230
|
+
// let subject = 'Fwd: Tango Eye\'s Customer Intelligence Report - ' + req.body.fileDate;
|
|
231
|
+
// let messageBody = `<br>Hi Team,<br><br> Please find attached Tango RetailEye report on customer footfall and shopping patterns for ${req.body.fileDate}.<br><br> Thanks <br> Team Tango`;
|
|
232
|
+
// let UserattachmentDetails = [];
|
|
233
|
+
// for ( const data of record ) {
|
|
234
|
+
// // const email = data.email; // Extract the email property from the current object
|
|
235
|
+
// // toemail.push( email );
|
|
236
|
+
// const fetchData = {
|
|
237
|
+
// Bucket: `${config.r2.bucketName.reportBucket}`,
|
|
238
|
+
// Key: `${req.body.fileDate}/${data.reportName}/${req.body.fileDate}_${data.fileName}.${data.fileType}`,
|
|
239
|
+
// };
|
|
240
|
+
// reportname.push( `${req.body.fileDate}_${data.fileName}` );
|
|
241
|
+
// name.push( `${data.fileName}` );
|
|
242
|
+
// regionalKey.push( `${req.body.fileDate}_${data.fileName}.${data.fileType}` );
|
|
243
|
+
// file = await getFileImg( fetchData );
|
|
244
|
+
// if ( file.statusCode == 404 ) {
|
|
245
|
+
// logger.info( 'File not available in bucket ' + `${JSON.stringify( file )}` );
|
|
246
|
+
// sendMailCount += 1;
|
|
247
|
+
// } else {
|
|
248
|
+
// data.email.forEach( ( email ) => {
|
|
249
|
+
// let UserIndex = UserattachmentDetails.findIndex( ( user ) => user.email == email );
|
|
250
|
+
// if ( UserIndex == -1 ) {
|
|
251
|
+
// UserattachmentDetails.push( {
|
|
252
|
+
// email: email,
|
|
253
|
+
// attachments: [
|
|
254
|
+
// {
|
|
255
|
+
// filename: `${req.body.fileDate}_${data.fileName}.${data.fileType}`,
|
|
256
|
+
// content: file.Body,
|
|
257
|
+
// contentType: file.ContentType,
|
|
258
|
+
// },
|
|
259
|
+
// ],
|
|
260
|
+
// } );
|
|
261
|
+
// } else {
|
|
262
|
+
// UserattachmentDetails[UserIndex].attachments.push( {
|
|
263
|
+
// filename: `${req.body.fileDate}_${data.fileName}.${data.fileType}`,
|
|
264
|
+
// content: file.Body,
|
|
265
|
+
// contentType: file.ContentType,
|
|
266
|
+
// } );
|
|
267
|
+
// }
|
|
268
|
+
// } );
|
|
269
|
+
// }
|
|
270
|
+
// }
|
|
271
|
+
// UserattachmentDetails.forEach( async ( userattach ) => {
|
|
272
|
+
// await sendEmail( userattach.email, subject, messageBody, userattach.attachments, config.ses.reportEmail ).then( ( response ) => {
|
|
273
|
+
// result.push( response );
|
|
274
|
+
// } );
|
|
275
|
+
// } );
|
|
276
|
+
// if ( sendMailCount == record.length ) {
|
|
277
|
+
// return res.sendError( 'File not available in bucket', 404 );
|
|
278
|
+
// }
|
|
279
|
+
// let user = await userModel.findOne( { _id: req.user._id } );
|
|
280
|
+
|
|
281
|
+
// const log = {
|
|
282
|
+
// userName: user.name,
|
|
283
|
+
// Date: new Date(),
|
|
284
|
+
// userId: user._id,
|
|
285
|
+
// logType: 'report',
|
|
286
|
+
// logSubType: 'sendReport',
|
|
287
|
+
// logData: {
|
|
288
|
+
// fileDate: req.body.fileDate,
|
|
289
|
+
// reportName: record[0].reportName,
|
|
290
|
+
// clientId: record[0].clientId,
|
|
291
|
+
// },
|
|
292
|
+
// };
|
|
293
|
+
// await activityModel.create( log );
|
|
294
|
+
// let client = await clientModel.findOne( { clientId: req.body.clientId } );
|
|
295
|
+
|
|
296
|
+
// const sqsProduceQueue = {
|
|
297
|
+
// QueueUrl: `${config.aws.sqs.queue.url}${config.aws.sqs.queueName.sentNotify}`,
|
|
298
|
+
// MessageBody: JSON.stringify( {
|
|
299
|
+
// file_date: req.body.fileDate,
|
|
300
|
+
// client_name: record[0].reportName,
|
|
301
|
+
// client_id: Number( client.clientId ),
|
|
302
|
+
// file_name: regionalKey,
|
|
303
|
+
// report_name: name,
|
|
304
|
+
// } ),
|
|
305
|
+
// };
|
|
306
|
+
// const sqsQueue = await produceQueue( sqsProduceQueue );
|
|
307
|
+
// logger.info( 'successfully Pushed to SQS ' + `${JSON.stringify( sqsQueue )}`, 'Send Report' );
|
|
308
|
+
|
|
309
|
+
return res.sendSuccess( 'Report Send Successfully', 200 );
|
|
310
|
+
} catch ( err ) {
|
|
311
|
+
console.log( err );
|
|
312
|
+
return res.sendError( err, 500 );
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export async function uploadManualReport( req, res ) {
|
|
317
|
+
try {
|
|
318
|
+
const inputData = req.body;
|
|
319
|
+
return res.sendSuccess( inputData );
|
|
320
|
+
// const name = inputdata.fileName;
|
|
321
|
+
// const regex = /^(\d{2}-\d{2}-\d{4})_(.*?)\.([a-zA-Z0-9]+)$/;
|
|
322
|
+
// const matches = name.match( regex );
|
|
323
|
+
// if ( matches ) {
|
|
324
|
+
// const date = matches[1];
|
|
325
|
+
// const filenameWithoutExtension = matches[2];
|
|
326
|
+
// const extension = matches[3];
|
|
327
|
+
// if ( inputdata.fileDate !== date ) {
|
|
328
|
+
// return res.sendError( 'file date not match with input file name', 400 );
|
|
329
|
+
// }
|
|
330
|
+
// const data = await reportModel.findOne( { 'fileName': filenameWithoutExtension, 'fileType': extension, 'clientId': inputdata.clientId } );
|
|
331
|
+
// if ( !data ) {
|
|
332
|
+
// return res.sendError( 'Something Went wrong', 400 );
|
|
333
|
+
// }
|
|
334
|
+
// const uploadDataParams = {
|
|
335
|
+
// Bucket: config.r2.bucketName.reportBucket,
|
|
336
|
+
// Key: `${inputdata.fileDate}/${data.reportName}/`,
|
|
337
|
+
// fileName: inputdata.filename,
|
|
338
|
+
// Body: req.files.fileuplaod_data.data,
|
|
339
|
+
// };
|
|
340
|
+
// const result = await fileUpload( uploadDataParams );
|
|
341
|
+
// if ( !result ) {
|
|
342
|
+
// return res.sendError( 'file upload error', 500 );
|
|
343
|
+
// } else {
|
|
344
|
+
// let user = await userModel.findOne( { _id: req.user._id } );
|
|
345
|
+
|
|
346
|
+
// const log = {
|
|
347
|
+
// userName: user.name,
|
|
348
|
+
// Date: new Date(),
|
|
349
|
+
// userId: req.user._id,
|
|
350
|
+
// logType: 'report',
|
|
351
|
+
// logSubType: 'uploadReport',
|
|
352
|
+
// logData: {
|
|
353
|
+
// fileDate: inputdata.fileDate,
|
|
354
|
+
// reportName: data.reportName,
|
|
355
|
+
// clientId: data.clientId,
|
|
356
|
+
// },
|
|
357
|
+
// };
|
|
358
|
+
// await activityModel.create( log );
|
|
359
|
+
// }
|
|
360
|
+
// res.sendSuccess( 'uploaded Sucessfully', 200 );
|
|
361
|
+
// } else {
|
|
362
|
+
// }
|
|
363
|
+
} catch ( err ) {
|
|
364
|
+
console.log( err, 'err' );
|
|
365
|
+
return res.sendError( err, 500 );
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export async function updateBasePrice( req, res ) {
|
|
370
|
+
try {
|
|
371
|
+
const inputData = req.body;
|
|
372
|
+
let count=0;
|
|
373
|
+
let increment = 0;
|
|
374
|
+
for ( let i =0; i< inputData.length; i++ ) {
|
|
375
|
+
increment = increment+1;
|
|
376
|
+
// await basePricingModel.create( {
|
|
377
|
+
// 'clientId': inputData[i].clientId,
|
|
378
|
+
// 'standard': [
|
|
379
|
+
// {
|
|
380
|
+
// 'productName': 'tangoTraffic',
|
|
381
|
+
|
|
382
|
+
// },
|
|
383
|
+
|
|
384
|
+
// ],
|
|
385
|
+
// 'step': [
|
|
386
|
+
// {
|
|
387
|
+
// 'productName': 'tangoTraffic',
|
|
388
|
+
|
|
389
|
+
// },
|
|
390
|
+
|
|
391
|
+
// ],
|
|
392
|
+
// } );
|
|
393
|
+
const query = {
|
|
394
|
+
'clientId': inputData[i].clientId,
|
|
395
|
+
'standard.productName': { $exists: true },
|
|
396
|
+
};
|
|
397
|
+
const record={
|
|
398
|
+
'clientId': inputData[i].clientId,
|
|
399
|
+
'standard.$[elem].basePrice': inputData[i].pricePerStore,
|
|
400
|
+
'standard.$[elem].negotiatePrice': inputData[i].pricePerStore,
|
|
401
|
+
'step.$[elem].basePrice': inputData[i].pricePerStore,
|
|
402
|
+
'step.$[elem].negotiatePrice': inputData[i].pricePerStore,
|
|
403
|
+
'step.$[elem].storeRange': '1-100',
|
|
404
|
+
};
|
|
405
|
+
const result = await updateOneBasePriceModel( query, record );
|
|
406
|
+
if ( result ) {
|
|
407
|
+
count= count+1;
|
|
408
|
+
}
|
|
409
|
+
console.log( result, '.data' );
|
|
410
|
+
}
|
|
411
|
+
if ( increment == inputData.length ) {
|
|
412
|
+
res.sendSuccess( { result: `The given ${count } recoeds updated` } );
|
|
413
|
+
}
|
|
414
|
+
} catch ( error ) {
|
|
415
|
+
logger.error( { error: error, message: req.params, function: 'updateBasePrice' } );
|
|
416
|
+
return res.sendError( error, 500 );
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import j2s from 'joi-to-swagger';
|
|
2
|
+
|
|
3
|
+
import { clientListTableSchema, generateReportSchema } from '../dtos/report.dtos.js';
|
|
4
|
+
|
|
5
|
+
export const reportDocs = {
|
|
6
|
+
|
|
7
|
+
'/v3/report/client-list-table': {
|
|
8
|
+
post: {
|
|
9
|
+
tags: [ 'Report' ],
|
|
10
|
+
description: `Get list of client with date range`,
|
|
11
|
+
operationId: 'client-list-table',
|
|
12
|
+
parameters: {},
|
|
13
|
+
requestBody: {
|
|
14
|
+
content: {
|
|
15
|
+
'application/json': {
|
|
16
|
+
schema: j2s( clientListTableSchema ).swagger,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
responses: {
|
|
21
|
+
200: { description: 'Get user permission successfully' },
|
|
22
|
+
401: { description: 'Unauthorized User' },
|
|
23
|
+
422: { description: 'Field Error' },
|
|
24
|
+
500: { description: 'Server Error' },
|
|
25
|
+
204: { description: 'Not Found' },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
'/v3/report/generate-report': {
|
|
32
|
+
post: {
|
|
33
|
+
tags: [ 'Report' ],
|
|
34
|
+
description: `Push message to Qeueue to Generate Report Manually`,
|
|
35
|
+
operationId: 'generate-report',
|
|
36
|
+
parameters: {},
|
|
37
|
+
requestBody: {
|
|
38
|
+
content: {
|
|
39
|
+
'application/json': {
|
|
40
|
+
schema: j2s( generateReportSchema ).swagger,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
responses: {
|
|
45
|
+
200: { description: 'Report Genrate Initiated Successfully' },
|
|
46
|
+
401: { description: 'Unauthorized User' },
|
|
47
|
+
422: { description: 'Field Error' },
|
|
48
|
+
500: { description: 'Server Error' },
|
|
49
|
+
204: { description: 'Not Found' },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
};
|
|
55
|
+
|
package/src/dtos/report.dtos.js
CHANGED
|
@@ -55,3 +55,52 @@ export const updateReportValid = {
|
|
|
55
55
|
params: updateReportSchemaParam,
|
|
56
56
|
|
|
57
57
|
};
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
export const clientListTableSchema = joi.object( {
|
|
61
|
+
fromDate: joi.string().required(),
|
|
62
|
+
toDate: joi.string().required(),
|
|
63
|
+
limit: joi.number().optional(),
|
|
64
|
+
offset: joi.number().optional(),
|
|
65
|
+
searchValue: joi.string().optional(),
|
|
66
|
+
filterByType: joi.array().optional(),
|
|
67
|
+
sortColumnName: joi.string().optional(),
|
|
68
|
+
sortBy: joi.number().optional(),
|
|
69
|
+
} );
|
|
70
|
+
|
|
71
|
+
export const clientListTableValid = {
|
|
72
|
+
body: clientListTableSchema,
|
|
73
|
+
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const generateReportSchema = joi.object( {
|
|
77
|
+
fileDate: joi.string().required(),
|
|
78
|
+
clientId: joi.string().required(),
|
|
79
|
+
} );
|
|
80
|
+
|
|
81
|
+
export const generateReportValid = {
|
|
82
|
+
body: generateReportSchema,
|
|
83
|
+
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const sendReportSchema = joi.object( {
|
|
87
|
+
fileDate: joi.string().required(),
|
|
88
|
+
clientId: joi.string().required(),
|
|
89
|
+
} );
|
|
90
|
+
|
|
91
|
+
export const sendReportValid = {
|
|
92
|
+
body: sendReportSchema,
|
|
93
|
+
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const uploadManualReportSchema = joi.object( {
|
|
97
|
+
fileDate: joi.string().required(),
|
|
98
|
+
clientId: joi.string().required(),
|
|
99
|
+
fileName: joi.string().required(),
|
|
100
|
+
} );
|
|
101
|
+
|
|
102
|
+
export const uploadManualReportValid = {
|
|
103
|
+
body: uploadManualReportSchema,
|
|
104
|
+
|
|
105
|
+
};
|
|
106
|
+
|
|
@@ -1,15 +1,50 @@
|
|
|
1
1
|
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
-
import { addReportValid, getReportValid, getSingleReportValid, updateReportValid } from '../dtos/report.dtos.js';
|
|
5
|
-
import { createReport, getReport, getSingleReport, updateReport } from '../controllers/report.controllers.js';
|
|
3
|
+
import { authorize, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
+
import { addReportValid, clientListTableValid, generateReportValid, getReportValid, getSingleReportValid, sendReportValid, updateReportValid, uploadManualReportValid } from '../dtos/report.dtos.js';
|
|
5
|
+
import { clientReportList, createReport, generateReport, getReport, getSingleReport, sendReport, updateBasePrice, updateReport, uploadManualReport } from '../controllers/report.controllers.js';
|
|
6
6
|
|
|
7
7
|
export const reportRouter = express.Router();
|
|
8
8
|
|
|
9
|
-
reportRouter.post( '/create-report/:id', isAllowedSessionHandler,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
reportRouter.
|
|
9
|
+
reportRouter.post( '/create-report/:id', isAllowedSessionHandler, authorize( { userType: [ 'tango' ], access: [
|
|
10
|
+
{ featureName: 'settings', name: 'configuration', permissions: [ 'isEdit' ] },
|
|
11
|
+
] } ), validate( addReportValid ), createReport );
|
|
12
|
+
reportRouter.get( '/get-client-reports/:id', isAllowedSessionHandler, authorize( { userType: [ 'tango' ], access: [
|
|
13
|
+
{ featureName: 'settings', name: 'configuration', permissions: [ 'isView' ] },
|
|
14
|
+
] } ), validate( getReportValid ), getReport );
|
|
15
|
+
reportRouter.get( '/get-report/:id', isAllowedSessionHandler, authorize( { userType: [ 'tango' ], access: [
|
|
16
|
+
{ featureName: 'settings', name: 'configuration', permissions: [ 'isView' ] },
|
|
17
|
+
] } ), validate( getSingleReportValid ), getSingleReport );
|
|
18
|
+
|
|
19
|
+
reportRouter.put( '/update-report/:id', isAllowedSessionHandler, authorize( { userType: [ 'tango' ], access: [
|
|
20
|
+
{ featureName: 'settings', name: 'configuration', permissions: [ 'isEdit' ] },
|
|
21
|
+
] } ), validate( updateReportValid ), updateReport );
|
|
22
|
+
|
|
23
|
+
reportRouter.post( '/client-list-table', isAllowedSessionHandler,
|
|
24
|
+
authorize( { userType: [ 'tango' ], access: [
|
|
25
|
+
{ featureName: 'settings', name: 'configuration', permissions: [ 'isView' ] },
|
|
26
|
+
] } ),
|
|
27
|
+
validate( clientListTableValid ), clientReportList );
|
|
28
|
+
|
|
29
|
+
reportRouter.post( '/generate-report', isAllowedSessionHandler,
|
|
30
|
+
authorize( { userType: [ 'tango' ], access: [
|
|
31
|
+
{ featureName: 'settings', name: 'configuration', permissions: [ 'isEdit' ] },
|
|
32
|
+
] } ),
|
|
33
|
+
validate( generateReportValid ), generateReport );
|
|
34
|
+
|
|
35
|
+
reportRouter.post( '/send-report', isAllowedSessionHandler,
|
|
36
|
+
authorize( { userType: [ 'tango' ], access: [
|
|
37
|
+
{ featureName: 'settings', name: 'configuration', permissions: [ 'isEdit' ] },
|
|
38
|
+
] } ),
|
|
39
|
+
validate( sendReportValid ), sendReport );
|
|
40
|
+
|
|
41
|
+
reportRouter.post( '/upload-manual-report', isAllowedSessionHandler,
|
|
42
|
+
authorize( { userType: [ 'tango' ], access: [
|
|
43
|
+
{ featureName: 'settings', name: 'configuration', permissions: [ 'isEdit' ] },
|
|
44
|
+
] } ),
|
|
45
|
+
validate( uploadManualReportValid ), uploadManualReport );
|
|
46
|
+
|
|
47
|
+
reportRouter.post( '/invoice', updateBasePrice );
|
|
13
48
|
|
|
14
49
|
export default reportRouter;
|
|
15
50
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import basePricingModel from 'tango-api-schema/schema/basePricing.model.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function updateOneBasePriceModel( query, record ) {
|
|
5
|
+
return basePricingModel.updateOne( query, { $set: record }, { arrayFilters: [ { 'elem.productName': 'tangoTraffic' } ], upsert: true } );
|
|
6
|
+
}
|