tango-app-api-infra 3.0.44-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.44-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
+ }
@@ -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
  }