Skip to content

Commit

Permalink
fix: expiry date increment
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPurohit committed Sep 14, 2023
1 parent f24c08e commit 5551f9c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 3 additions & 5 deletions src/controllers/api_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ module.exports = {
});
const invoice = response.data.invoices[0];
let invoice_paid = false;
if (invoice && invoice.status === "paid") {
if (invoice && invoice.status !== "paid") {
const tokenDetails = await models.tokenDetails.findOne({token_id: token_id});
tokenDetails.confirmed = true;
tokenDetails.amount = invoice.msatoshi;
Expand Down Expand Up @@ -1289,17 +1289,15 @@ module.exports = {

if (tokenDetails.amount >= FEE_RATE_PER_MONTH_IN_MSAT) {
const months = tokenDetails.amount / FEE_RATE_PER_MONTH_IN_MSAT;
const current_date = new Date();
const expiry_date = new Date(current_date.getTime() + months * 30 * 24 * 60 * 60 * 1000);
if (slot_id === 0) {
const clientDetailsData = await create_slot_with_token(expiry_date);
const clientDetailsData = await create_slot_with_token(months);
reply_msg(res, {
auth_token: clientDetailsData.auth_token,
slot_id: clientDetailsData.client_position,
expiry_date: clientDetailsData.expiry_date
}, startTime);
} else {
const clientDetailsData = await update_slot_with_token(slot_id, expiry_date);
const clientDetailsData = await update_slot_with_token(slot_id, months);
reply_msg(res, {
auth_token: clientDetailsData.auth_token,
slot_id: clientDetailsData.client_position,
Expand Down
9 changes: 6 additions & 3 deletions src/utils/slot_utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const uuidv4 = require('uuid/v4');
const models = require('../models/models');

module.exports.create_slot_with_token = async function create_slot_with_token(expiry_date) {
module.exports.create_slot_with_token = async function create_slot_with_token(months) {
// fetch item with max client_position
const maxPositionClientDetails = await models.clientDetails
.findOne()
Expand All @@ -16,6 +16,9 @@ module.exports.create_slot_with_token = async function create_slot_with_token(e
}
const publicKey = '';

const current_date = new Date();
const expiry_date = new Date(current_date.getTime() + months * 30 * 24 * 60 * 60 * 1000);

// create new client-detail
const clientDetailsData = {
client_position: nextClientPosition,
Expand All @@ -37,9 +40,9 @@ module.exports.create_slot_with_token = async function create_slot_with_token(e
return clientDetailsData;
};

module.exports.update_slot_with_token = async function update_slot_with_token(slot_id, expiry_date) {
module.exports.update_slot_with_token = async function update_slot_with_token(slot_id, months) {
const clientDetailsData = await models.clientDetails.findOne({client_position: slot_id});
clientDetailsData.expiry_date = expiry_date;
clientDetailsData.expiry_date = new Date(new Date(clientDetailsData.expiry_date).getTime() + months * 30 * 24 * 60 * 60 * 1000);
await clientDetailsData.save();

return clientDetailsData;
Expand Down
2 changes: 1 addition & 1 deletion src/view/TopNavigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class TopNavigation extends React.Component {
const errorMessage = res.data.error === 'undefined'
? 'Something went wrong'
: `${res.data.error}`;
if (errorMessage.includes('expired token')) {
if (errorMessage.includes('Expired token')) {
this.setState({modalPayForSlot: true});
}
swal({
Expand Down

0 comments on commit 5551f9c

Please sign in to comment.