tango-app-api-payment-subscription 3.0.16-dev → 3.0.18-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-payment-subscription",
3
- "version": "3.0.16-dev",
3
+ "version": "3.0.18-dev",
4
4
  "description": "paymentSubscription",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -128,15 +128,16 @@ export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
128
128
  let differenceInDays = 14;
129
129
  if ( element?.trialEndDate ) {
130
130
  differenceInDays = dateDifference( element?.trialEndDate, currentDate );
131
+ if ( element.trialEndDate < currentDate ) {
132
+ expiredProducts.push( { 'productName': element.productName, 'aliseProductName': element.aliseProductName, 'toolTip': 'Trial Expired' } );
133
+ element.toolTip = 'Trial Expired';
134
+ element.active = true;
135
+ } else {
136
+ trialProducts.push( { 'productName': element.productName, 'aliseProductName': element.aliseProductName, 'toolTip': differenceInDays +' days trial left' } );
137
+ element.toolTip = 'On Trial';
138
+ element.active = true;
139
+ }
131
140
  }
132
- trialProducts.push( { 'productName': element.productName, 'aliseProductName': element.aliseProductName, 'toolTip': differenceInDays +' days trial left' } );
133
- element.toolTip = 'On Trial';
134
- element.active = true;
135
- }
136
- if ( element.status == 'trial' && ( element.trialEndDate < currentDate ) ) {
137
- expiredProducts.push( { 'productName': element.productName, 'aliseProductName': element.aliseProductName, 'toolTip': 'Trial Expired' } );
138
- element.toolTip = 'Trial Expired';
139
- element.active = true;
140
141
  }
141
142
  } );
142
143
  }
@@ -202,7 +203,6 @@ export const clientBillingSubscriptionInfo = async ( req, res, next ) => {
202
203
  export const pricingInfo = async ( req, res ) => {
203
204
  try {
204
205
  let pricingDetails = await calculatePricing( req, res );
205
- console.log( await calculatePricing( req, res ), 'details' );
206
206
  return res.sendSuccess( pricingDetails );
207
207
  } catch ( e ) {
208
208
  logger.error( { error: e, function: 'pricingInfo' } );
@@ -213,7 +213,6 @@ export const pricingInfo = async ( req, res ) => {
213
213
  async function calculatePricing( req, res ) {
214
214
  try {
215
215
  let input = req.body;
216
- console.log( input, 'input' );
217
216
  let finalPrice = 0;
218
217
  let dummy = [];
219
218
  let camaraArray = [];
@@ -309,7 +308,7 @@ async function calculatePricing( req, res ) {
309
308
  } );
310
309
  return ( { OriginalPrice: Math.round( OriginalPrice ), price: Math.round( finalPrice ), camaraCount: camaraCount } );
311
310
  } catch ( e ) {
312
- console.log( e );
311
+ logger.error( { error: e, function: 'calculatePricing' } );
313
312
  return false;
314
313
  }
315
314
  }
@@ -601,6 +600,7 @@ export const notificationList = async ( req, res ) => {
601
600
  query.status = 'pending';
602
601
  if ( req?.query?.clientId ) {
603
602
  query.clientId = req?.query?.clientId;
603
+ query.category = { $ne: 'TrialExtend' };
604
604
  }
605
605
  let notificationList = await clientRequestService.find( query, { createdAt: 0, updatedAt: 0 } );
606
606
  query = [
@@ -627,22 +627,24 @@ export const notificationList = async ( req, res ) => {
627
627
  let getClientInfo = await paymentService.aggregate( query );
628
628
  if ( getClientInfo.length ) {
629
629
  getClientInfo.forEach( ( item ) => {
630
- let [ firstWord, secondWord ] = item.product.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
631
- firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
632
- let startDate = dayjs( item.product.trialStartDate );
633
- let endDate = dayjs( item.product.trialEndDate ).startOf( 'day' );
634
- let date = dayjs().startOf( 'day' );
635
- let days = date.diff( startDate, 'day' );
636
- let totalDays = endDate.diff( startDate, 'day' );
637
- let percentage = Math.round( ( days / totalDays )* 100 );
638
- let leftDays = endDate.diff( date, 'day' ) + 1;
639
- notificationList.push( {
640
- product: item.product.productName,
641
- name: `${firstWord} ${secondWord}`,
642
- day: leftDays < 0 ? 0 : leftDays,
643
- percentage: percentage > 100 ? 100 : percentage,
644
- category: 'trial product',
645
- } );
630
+ if ( item.product?.trialStartDate && item.product?.trialEndDate ) {
631
+ let [ firstWord, secondWord ] = item.product.productName.replace( /([a-z])([A-Z])/g, '$1 $2' ).split( ' ' );
632
+ firstWord = firstWord.charAt( 0 ).toUpperCase() + firstWord.slice( 1 );
633
+ let startDate = dayjs( item.product.trialStartDate );
634
+ let endDate = dayjs( item.product.trialEndDate ).startOf( 'day' );
635
+ let date = dayjs().startOf( 'day' );
636
+ let days = date.diff( startDate, 'day' );
637
+ let totalDays = endDate.diff( startDate, 'day' );
638
+ let percentage = Math.round( ( days / totalDays )* 100 );
639
+ let leftDays = endDate.diff( date, 'day' ) + 1;
640
+ notificationList.push( {
641
+ product: item.product.productName,
642
+ name: `${firstWord} ${secondWord}`,
643
+ day: leftDays < 0 ? 0 : leftDays,
644
+ percentage: percentage > 100 ? 100 : percentage,
645
+ category: 'trial product',
646
+ } );
647
+ }
646
648
  } );
647
649
  }
648
650
 
@@ -1221,6 +1223,21 @@ export const invoiceList = async ( req, res ) => {
1221
1223
  } );
1222
1224
  }
1223
1225
 
1226
+ query.push( {
1227
+ $project: {
1228
+ _id: 1,
1229
+ invoice: 1,
1230
+ stores: 1,
1231
+ billingDate: 1,
1232
+ status: 1,
1233
+ paymentMethod: 1,
1234
+ amount: 1,
1235
+ discount: 1,
1236
+ revisedAmount: 1,
1237
+ products: 1,
1238
+ },
1239
+ } );
1240
+
1224
1241
  query.push(
1225
1242
  {
1226
1243
  $facet: {
@@ -1240,6 +1257,16 @@ export const invoiceList = async ( req, res ) => {
1240
1257
  if ( !invoiceDetails[0]?.data.length ) {
1241
1258
  return res.sendError( 'no data found', 204 );
1242
1259
  }
1260
+ invoiceDetails[0].data.forEach( ( item ) => {
1261
+ item.billingDate = dayjs( item.billingDate ).format( 'DD MMM, YYYY' );
1262
+ } );
1263
+ if ( req.user.userType == 'client' ) {
1264
+ invoiceDetails[0].data.forEach( ( item ) => {
1265
+ delete item.discount;
1266
+ delete item.revisedAmount;
1267
+ delete item.products;
1268
+ } );
1269
+ }
1243
1270
  let data = {
1244
1271
  data: invoiceDetails[0].data,
1245
1272
  count: invoiceDetails[0].count[0].count,
@@ -1247,6 +1274,16 @@ export const invoiceList = async ( req, res ) => {
1247
1274
  if ( !req.body.export ) {
1248
1275
  return res.sendSuccess( data );
1249
1276
  } else {
1277
+ invoiceDetails[0].data.forEach( ( item ) => {
1278
+ if ( item.status == 'trial' ) {
1279
+ item.amount = 'Trial';
1280
+ }
1281
+ if ( item.status == 'free' ) {
1282
+ item.amount = 'Free';
1283
+ }
1284
+ delete item._id;
1285
+ delete item.paymentMethod;
1286
+ } );
1250
1287
  download( invoiceDetails[0].data, res );
1251
1288
  }
1252
1289
  } catch ( e ) {
@@ -1377,7 +1414,7 @@ export const pricingListUpdate = async ( req, res ) => {
1377
1414
  productName: product,
1378
1415
  discountPercentage: baseDetails.discoutPercentage,
1379
1416
  basePrice: baseDetails.basePrice,
1380
- negotiatePrice: baseDetails.basePrice - discountPrice,
1417
+ negotiatePrice: discountPrice,
1381
1418
  },
1382
1419
  );
1383
1420
  stepList.push(
@@ -1385,7 +1422,7 @@ export const pricingListUpdate = async ( req, res ) => {
1385
1422
  productName: product,
1386
1423
  discountPercentage: baseDetails.discoutPercentage,
1387
1424
  basePrice: baseDetails.basePrice,
1388
- negotiatePrice: baseDetails.basePrice - discountPrice,
1425
+ negotiatePrice: discountPrice,
1389
1426
  storeRange: '1-100',
1390
1427
  },
1391
1428
  );
@@ -1455,7 +1492,6 @@ export const pricingListUpdate = async ( req, res ) => {
1455
1492
  return res.sendSuccess( 'Pricig Updated Successfully' );
1456
1493
  } );
1457
1494
  } catch ( e ) {
1458
- console.log( e );
1459
1495
  logger.error( { error: e, function: 'addPricingList' } );
1460
1496
  return res.sendError( e, 500 );
1461
1497
  }
@@ -1555,7 +1591,7 @@ export const getRemindClients = async ( req, res ) => {
1555
1591
  username: userDetails.userName,
1556
1592
  product: firstWord + ' ' + secondWord,
1557
1593
  };
1558
- const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trailReminderEmail.hbs', 'utf8' );
1594
+ const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialReminderEmail.hbs', 'utf8' );
1559
1595
  const template = Handlebars.compile( templateHtml );
1560
1596
  const html = template( { data: data } );
1561
1597
  let params = {
@@ -1618,7 +1654,7 @@ export const getExpiredClients = async ( req, res ) => {
1618
1654
  username: userDetails.userName,
1619
1655
  product: firstWord +' '+secondWord,
1620
1656
  };
1621
- const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trailExpiredEmail.hbs', 'utf8' );
1657
+ const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/trialExpiredEmail.hbs', 'utf8' );
1622
1658
  const template = Handlebars.compile( templateHtml );
1623
1659
  const html = template( { data: data } );
1624
1660
  let params = {
@@ -1641,12 +1677,12 @@ export const getExpiredClients = async ( req, res ) => {
1641
1677
 
1642
1678
  export const invoiceDownload = async ( req, res ) => {
1643
1679
  try {
1644
- const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/invoicePdf.hbs', 'utf8' );
1645
- const template = Handlebars.compile( templateHtml );
1646
- const html = template( { data: '' } );
1647
- console.log( html );
1680
+ // const templateHtml = fs.readFileSync( path.resolve( path.dirname( '' ) ) + '/src/hbs/invoicePdf.hbs', 'utf8' );
1681
+ // const template = Handlebars.compile( templateHtml );
1682
+ // const html = template( { data: '' } );
1683
+ // console.log( html );
1648
1684
  } catch ( e ) {
1649
- console.log( e );
1685
+ // console.log( e );
1650
1686
  logger.error( { error: e, function: 'invoiceDownload' } );
1651
1687
  return res.sendError( e, 500 );
1652
1688
  }
@@ -1661,7 +1697,7 @@ export const updateInvoiceStatus = async ( req, res ) => {
1661
1697
  if ( !invoiceDetails ) {
1662
1698
  return res.sendError( 'no data found', 204 );
1663
1699
  }
1664
- invoiceDetails.status = req.body?.status || 'paid';
1700
+ invoiceDetails.status = req.body?.status || 'Payment Received';
1665
1701
  invoiceDetails.save().then( async () => {
1666
1702
  let clientInfo = await paymentService.findOne( { clientId: invoiceDetails.clientId } );
1667
1703
  if ( clientInfo ) {
@@ -1682,12 +1718,13 @@ export const invoiceCreate = async ( req, res ) => {
1682
1718
  let products = req.body.client.planDetails.product.map( ( item ) => item.productName );
1683
1719
  let storeDetails = await storeService.count( { clientId: req.body.clientId, status: 'active' } );
1684
1720
  let data;
1721
+ let clientId = req.body.clientId;
1685
1722
  data = {
1686
1723
  invoice: `invoice #0${req.body.client.clientId} - ${Math.floor( Math.random() * 100 ) + 1}`,
1687
1724
  billingDate: new Date(),
1688
1725
  products: products,
1689
1726
  stores: storeDetails,
1690
- status: '',
1727
+ status: 'pending',
1691
1728
  clientId: req.body.clientId,
1692
1729
  };
1693
1730
  req.body = {
@@ -1700,14 +1737,14 @@ export const invoiceCreate = async ( req, res ) => {
1700
1737
  let pricingDetails = await calculatePricing( req, res );
1701
1738
  data.amount = pricingDetails.price;
1702
1739
  await invoiceService.create( data );
1703
- let clientInfo = await paymentService.findOne( { clientId: req.body.clientId } );
1740
+ let clientInfo = await paymentService.findOne( { clientId: clientId } );
1704
1741
  if ( clientInfo ) {
1705
1742
  clientInfo.planDetails.paymentStatus = 'due';
1706
1743
  clientInfo.save();
1707
1744
  }
1708
1745
  return res.sendSuccess( 'Invoice Created Successfully' );
1709
1746
  } catch ( e ) {
1710
- console.log( e );
1747
+ // console.log( e );
1711
1748
  logger.error( { error: e, function: 'invoiceDownload' } );
1712
1749
  return res.sendError( e, 500 );
1713
1750
  }
@@ -33,7 +33,7 @@ export const validateProducts = {
33
33
  export const validateunsubscribeParams = {
34
34
  body: joi.object( {
35
35
  reason: joi.string().required(),
36
- description: joi.string().required(),
36
+ description: joi.string().optional().empty( '' ),
37
37
  clientId: joi.string().required(),
38
38
  } ),
39
39
  };
@@ -97,7 +97,7 @@ export const validateInvoiceParams = {
97
97
  body: joi.object( {
98
98
  limit: joi.number().required(),
99
99
  offset: joi.number().required(),
100
- searchValue: joi.string().optional(),
100
+ searchValue: joi.string().optional().empty( '' ),
101
101
  filter: joi.string().optional(),
102
102
  sortColumn: joi.string().optional(),
103
103
  sortBy: joi.number().optional(),
@@ -8,7 +8,7 @@ export const paymentSubscriptionRouter = express.Router();
8
8
 
9
9
  paymentSubscriptionRouter.post( '/addBilling', isAllowedSessionHandler, authorize( {
10
10
  userType: [ 'tango', 'client' ], access: [
11
- { featureName: 'settings', name: 'tangotraffic', permissions: [ 'isEdit' ] },
11
+ { featureName: 'settings', name: 'paymentSubscriptions', permissions: [ 'isEdit' ] },
12
12
  ],
13
13
  } ), validate( validationDtos.validateBillingParams ), validateClient, paymentController.addBilling );
14
14
 
@@ -1,7 +1,7 @@
1
1
  import model from 'tango-api-schema';
2
2
 
3
3
  export const aggregate = async ( query ={} ) => {
4
- return await model.invoiceModel.aggregate( query );
4
+ return await model.invoiceModel.aggregate( query, { collation: { locale: 'en_US', numericOrdering: true } } );
5
5
  };
6
6
 
7
7
  export const findOne = async ( query ={}, record={} ) => {