tango-app-api-infra 3.0.43-dev → 3.0.45-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/.eslintrc.cjs CHANGED
@@ -32,7 +32,7 @@ module.exports = {
32
32
  'keyword-spacing': 'error',
33
33
  'array-bracket-spacing': [ 'error', 'always' ],
34
34
  'spaced-comment': [ 'error', 'always' ],
35
- 'max-len': [ 'error', { 'code': 700 } ],
35
+ 'max-len': [ 'error', { 'code': 4000 } ],
36
36
  'no-unused-vars': 'error',
37
37
  'new-cap': [ 'error', { 'newIsCap': true, 'capIsNew': false } ],
38
38
  'prefer-const': 'off',
package/app.js ADDED
@@ -0,0 +1,41 @@
1
+
2
+ import express from 'express';
3
+ import { infraRouter, internalInfraRouter, userInfraRouter, storeInfraRouter, clientInfraRouter } from './index.js';
4
+ import dotenv from 'dotenv';
5
+ import responseMiddleware from './config/response/response.js';
6
+ import errorMiddleware from './config/response/error.js';
7
+ import { connectdb } from './config/database/database.js';
8
+ import pkg from 'body-parser';
9
+ import cors from 'cors';
10
+ const { json, urlencoded } = pkg;
11
+ import fileUpload from 'express-fileupload';
12
+ const env=dotenv.config();
13
+ const app = express();
14
+ const PORT = process.env.PORT || 3000;
15
+ app.use( fileUpload() );
16
+
17
+ if ( env.error ) {
18
+ logger.error( '.env not found' );
19
+ process.exit( 1 );
20
+ }
21
+ app.use( json( { limit: '500mb' } ) );
22
+ app.use(
23
+ urlencoded( {
24
+ extended: true,
25
+ } ),
26
+ );
27
+ app.use( cors() );
28
+ app.use( responseMiddleware );
29
+ app.use( errorMiddleware );
30
+ app.use( '/infra', infraRouter );
31
+ app.use( '/internalInfra', internalInfraRouter );
32
+ app.use( '/userInfra', userInfraRouter );
33
+ app.use( '/storeInfra', storeInfraRouter );
34
+ app.use( '/clientInfra', clientInfraRouter );
35
+
36
+
37
+ app.listen( PORT, () => {
38
+ console.log( `server is running on port= ${PORT} ` );
39
+ connectdb();
40
+ } );
41
+
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "tango-app-api-infra",
3
- "version": "3.0.43-dev",
3
+ "version": "3.0.45-dev",
4
4
  "description": "infra",
5
- "main": "index.js",
5
+ "main": "app.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "start": "nodemon --exec \"eslint --fix . && node index.js\""
8
+ "start": "nodemon --exec \"eslint --fix . && node app.js\""
9
9
  },
10
10
  "engines": {
11
11
  "node": ">=18.10.0"
@@ -21,6 +21,7 @@
21
21
  "express": "^4.18.3",
22
22
  "express-fileupload": "^1.5.0",
23
23
  "handlebars": "^4.7.8",
24
+ "html-pdf-node": "^1.0.8",
24
25
  "mongodb": "^6.4.0",
25
26
  "nodemon": "^3.1.0",
26
27
  "tango-api-schema": "^2.0.77",
@@ -266,9 +266,9 @@ export async function infraIssuesTable( req, res ) {
266
266
  ticketId: 1,
267
267
  storeName: '$basicDetails.storeName',
268
268
  status: 1,
269
- createdAt: { $dateToString: { format: '%d-%m-%Y', date: '$createdAt' } },
270
- issueIdentifiedDate: { $dateToString: { format: '%d-%m-%Y', date: '$ticketDetails.issueIdentifiedDate' } },
271
- issueClosedDate: { $dateToString: { format: '%d-%m-%Y', date: '$issueClosedDate' } },
269
+ createdAt: 1,
270
+ issueIdentifiedDate: '$ticketDetails.issueIdentifiedDate',
271
+ issueClosedDate: '$issueClosedDate',
272
272
  primaryIssue: {
273
273
  $filter: {
274
274
  input: '$ticketActivity',
@@ -301,8 +301,8 @@ export async function infraIssuesTable( req, res ) {
301
301
  createdAt: 1,
302
302
  ticketId: 1,
303
303
  actionBy: '$primaryIssue.actionBy',
304
- issueIdentifiedDate: { $ifNull: [ '$issueIdentifiedDate', '-' ] },
305
- issueClosedDate: { $ifNull: [ '$issueClosedDate', '-' ] },
304
+ issueIdentifiedDate: { $ifNull: [ '$issueIdentifiedDate', '' ] },
305
+ issueClosedDate: { $ifNull: [ '$issueClosedDate', '' ] },
306
306
  status: 1,
307
307
  primaryIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '-' ] },
308
308
  secondaryIssue: { $ifNull: [ '$primaryIssue.reasons.secondaryIssue.name', '-' ] },
@@ -11,6 +11,7 @@ import { readFileSync } from 'fs';
11
11
  import { join } from 'path';
12
12
  import handlebars from 'handlebars';
13
13
  import { findOneGroup } from '../services/group.service.js';
14
+ import htmlpdf from 'html-pdf-node';
14
15
  export async function createTicket( req, res ) {
15
16
  try {
16
17
  req.body.issueDate = new Date( req.body.Date );
@@ -514,3 +515,59 @@ export async function saveInfraEmailConfig( req, res ) {
514
515
  return res.sendError( error, 500 );
515
516
  }
516
517
  }
518
+ export async function invoice( req, res ) {
519
+ let options = {
520
+ path: '../../invoice/invoice-TCNS.pdf',
521
+ format: 'A4', margin: {
522
+ top: '0.5in',
523
+ right: '0.5in',
524
+ bottom: '0.5in',
525
+ left: '0.5in',
526
+ },
527
+ printBackground: true, preferCSSPageSize: true,
528
+ };
529
+
530
+ const fileContent = readFileSync( join() + '/src/hbs/invoice.hbs', 'utf8' );
531
+ handlebars.registerHelper( 'ifKeyExists', function( context, key, options ) {
532
+ console.log( context, key, options );
533
+ if ( context.hasOwnProperty( key ) ) {
534
+ return options.fn( context ); // invoking as function
535
+ } else {
536
+ return options.inverse( context ); // invoking as function
537
+ }
538
+ } );
539
+ const htmlContent = handlebars.compile( fileContent );
540
+
541
+ req.body.subtotal = 0;
542
+ for ( const [ index, item ] of req.body.product.entries() ) {
543
+ item.Amount = item.Price * item.Stores;
544
+ item.index = index + 1;
545
+ req.body.subtotal += item.Amount;
546
+ item.HSNnumber = Math.floor( Math.random() * 1000000 );
547
+ }
548
+ req.body.totaltax = 0;
549
+ if ( req.body.tax.length > 0 ) {
550
+ for ( let element of req.body.tax ) {
551
+ element.taxAmount = ( ( req.body.subtotal / 100 ) * element.value ).toFixed( 2 );
552
+ req.body.totaltax += Number( element.taxAmount );
553
+ }
554
+ };
555
+ req.body.total = ( Number( req.body.totaltax ) + Number( req.body.subtotal ) ).toFixed( 2 ); ;
556
+
557
+ const html = htmlContent( { ...req.body } );
558
+
559
+ let file = {
560
+ content: html,
561
+ };
562
+
563
+ htmlpdf.generatePdf( file, options ).then( async function( pdfBuffer ) {
564
+ // console.log( 'PDF Buffer:-', pdfBuffer );
565
+ // let attachments = {
566
+ // filename: `invoice.pdf`,
567
+ // content: pdfBuffer,
568
+ // contentType: 'application/pdf', // e.g., 'application/pdf'
569
+ // };
570
+ // const result = await sendEmailWithSES( 'ayyanar@tangotech.co.in', '', '', attachments, 'no-reply@tangotech.ai' );
571
+ // res.sendSuccess( result );
572
+ } );
573
+ }
@@ -10,7 +10,7 @@ import handlebars from 'handlebars';
10
10
  dayjs.extend( utc );
11
11
  dayjs.extend( timezone );
12
12
  import { sendEmailWithSES } from 'tango-app-api-middleware';
13
- import { createClient, findClient, aggregateClient } from '../services/client.service.js';
13
+ import { createClient, findClient, aggregateClient, findOneClient } from '../services/client.service.js';
14
14
  import { createStore, findStore, updateOneStore, findOneStore } from '../services/store.service.js';
15
15
  import { findTangoTicket, findOneTangoTicket, countDocumentsTangoTicket, aggregateTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
16
16
  import { findOneGroup } from '../services/group.service.js';
@@ -435,17 +435,15 @@ export async function infraReportSent( req, res ) {
435
435
  let date;
436
436
  if ( req.body.type == 'start' ) {
437
437
  date = dayjs().subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
438
- } else if ( req.body.storeList == 'start' ) {
438
+ } else if ( req.body.type == 'end' ) {
439
439
  date = dayjs().format( 'YYYY-MM-DD' );
440
440
  };
441
-
442
441
  let query = [ {
443
442
  $match: {
444
443
  $and: [
445
444
  { issueDate: new Date( date ) },
446
445
  { 'basicDetails.storeId': { $in: req.body.storeList } },
447
446
  { issueType: 'infra' },
448
- { 'ticketDetails.issueStatus': 'identified' },
449
447
  ],
450
448
  },
451
449
  },
@@ -530,57 +528,16 @@ export async function infraReportSent( req, res ) {
530
528
  'Activity Log': '',
531
529
  } );
532
530
  }
533
- let issueCount = await countDocumentsTangoTicket( {
534
531
 
532
+ let issueCount = await countDocumentsTangoTicket( {
535
533
  $and: [
536
534
  { issueDate: new Date( date ) },
537
535
  { 'basicDetails.storeId': { $in: req.body.storeList } },
538
536
  { issueType: 'infra' },
539
- { 'ticketDetails.issueStatus': 'identified' },
540
537
  ],
541
-
542
538
  } );
543
- let finalcount = 0;
544
- for ( let storedata of req.body.storeList ) {
545
- let downTimeQuery = {
546
- 'size': 1,
547
- 'query': {
548
- 'bool': {
549
- 'must': [
550
- {
551
- 'term': {
552
- 'doc.date.keyword': dayjs( date ).format( 'DD-MM-YYYY' ),
553
- },
554
- },
555
- {
556
- 'term': {
557
- 'doc.store_id.keyword': storedata,
558
- },
559
- },
560
-
561
- ],
562
-
563
- },
564
- },
565
- };
566
- let downtimetotal;
567
- const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
568
- let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
569
- if ( streamwiseDowntime.length > 0 ) {
570
- const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
571
- return accumulator + currentValue.down_time;
572
- }, 0 );
573
- const average = sum / streamwiseDowntime.length;
574
- downtimetotal = Math.round( average );
575
- } else {
576
- downtimetotal = 0;
577
- }
578
-
579
- finalcount = finalcount + downtimetotal;
580
- }
581
- let avgDownTime = Math.round( finalcount / req.body.storeList.length );
582
-
583
-
539
+ let client = await findOneClient( { clientId: req.body.clientId } );
540
+ let avgDownTime = client.ticketConfigs.infraDownTime*60;
584
541
  let issueList = await findinfraReason( { parentId: { '$exists': false } } );
585
542
  const categoryCounts = {};
586
543
  let response;
@@ -59,7 +59,7 @@ export async function userTicketList( req, res ) {
59
59
  } else {
60
60
  query.push( {
61
61
  $match: {
62
- issueClosedDate: { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
62
+ updatedAt: { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
63
63
  },
64
64
  } );
65
65
  }