Skip to content

Commit

Permalink
bug(Transaction concatenate instead of adding or substracting):Transa…
Browse files Browse the repository at this point in the history
…ction concatenate instead of adding or substracting

Transaction concatenate instead of performing mathematical operation
[Deliver #165699638]
  • Loading branch information
Cavdy committed Apr 29, 2019
1 parent a3e82b4 commit bc47e9c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/v1/services/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const CreateAccountService = {
const ACNumberGenerator = Math.floor(Math.random() * 1000000000) + 3000000000;
const date = new Date();
const createdOn = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}`;
const balance = 0.00;
const balance = parseFloat(0.00).toFixed(2);
const status = 'draft';

// pulling users data from database
Expand Down
4 changes: 2 additions & 2 deletions server/v1/services/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const TransactionService = {

if (/^[0-9]{1,}$/.test(transactionData.amount)) {
// substract the passed in amount from the current balance
const newBalance = balance - transactionData.amount;
const newBalance = Number.parseFloat(balance) - Number.parseFloat(transactionData.amount);

// check if account balance is zero
if (newBalance < 0) {
Expand Down Expand Up @@ -132,7 +132,7 @@ const TransactionService = {

if (/^[0-9]{1,}$/.test(transactionData.amount)) {
// add the passed in amount from the current balance
const newBalance = balance + transactionData.amount;
const newBalance = Number.parseFloat(balance) + Number.parseFloat(transactionData.amount);
const transactionDbData = await dbConnection
.dbConnect('INSERT into transactions(createdon, type, accountNumber, cashier, amount, oldbalance, newbalance) values($1, $2, $3, $4, $5,$6, $7) RETURNING id, accountnumber, amount, cashier, type',
[createdOn, 'credit', accountnumber, id, transactionData.amount, balance, newBalance]);
Expand Down
2 changes: 1 addition & 1 deletion server/v1/test/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('Testing Transactions Controller', () => {
.post('/api/v1/transactions/3404704124/debit')
.set('Authorization', `Bearer ${token}`)
.send({
amount: 500,
amount: 5000,
});
expect(res.body).to.be.an('object');
expect(res.body.status).to.equal(422);
Expand Down

0 comments on commit bc47e9c

Please sign in to comment.