Skip to content

Commit

Permalink
bug(Credit and debit transactions accepts strings):Credit and debit t…
Browse files Browse the repository at this point in the history
…ransactions accepts strings

Credit and debit transactions accepts strings and other values
[Starts #165638356]
  • Loading branch information
Cavdy committed Apr 26, 2019
1 parent 17bc949 commit f40055b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions server/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"v1/auth/signup": {
"post": {
"tags": [
"Signup"
"Auth"
],
"summary": "Users can signup",
"description": "this endpoint uses get request to create users",
Expand Down Expand Up @@ -65,7 +65,7 @@
"v1/auth/signup/addstaff": {
"post": {
"tags": [
"Signup"
"Auth"
],
"summary": "Admin can signup staffs",
"description": "this endpoint uses get request to create users",
Expand Down Expand Up @@ -135,7 +135,7 @@
"v1/auth/signin": {
"post": {
"tags": [
"Signin"
"Auth"
],
"summary": "Users can signup",
"description": "this endpoint uses get request to create users",
Expand Down
10 changes: 10 additions & 0 deletions server/v1/model/transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default class Transaction {
constructor() {
this.transactionId = null;
this.accountNumber = null;
this.amount = null;
this.cashier = null; // cashier id
this.transactionType = null; // credit or debit
this.accountBalance = null;
}
}
2 changes: 1 addition & 1 deletion server/v1/services/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const CreateAccountService = {

// pulling users data from database
const userDetails = await dbConnection
.dbConnect('SELECT id,firstname,lastname FROM users WHERE email=$1',
.dbConnect('SELECT * FROM users WHERE email=$1',
[userData.email]);
const { firstname, lastname, id } = userDetails.rows[0];

Expand Down
8 changes: 2 additions & 6 deletions server/v1/services/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ const TransactionService = {
);
const { accountnumber, balance } = accountDbData.rows[0];

// check if a string
const checkForDigit = /^-?\d+\.?\d*$/;
if (checkForDigit.test(transactionData.amount)) {
if (typeof transactionData.amount === 'number') {
// substract the passed in amount from the current balance
const newBalance = balance - transactionData.amount;

Expand Down Expand Up @@ -132,9 +130,7 @@ const TransactionService = {
);
const { accountnumber, balance } = accountDbData.rows[0];

// check if a string
const checkForDigit = /^-?\d+\.?\d*$/;
if (checkForDigit.test(transactionData.amount)) {
if (typeof transactionData.amount === 'number') {
if (transactionData.amount <= 0) {
returnStatus = 422;
returnError = 'please credit an account with positive value';
Expand Down

0 comments on commit f40055b

Please sign in to comment.