Skip to content

Commit

Permalink
chore(endpoint):owner name on accounts
Browse files Browse the repository at this point in the history
Add owner name when creating and fetching accounts

[Finishes #165813280]
  • Loading branch information
tolulope-od committed May 7, 2019
1 parent aa073e4 commit 7998469
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 16 deletions.
54 changes: 48 additions & 6 deletions server/controllers/AccountController.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,27 @@ export default class AccountController {
error: 'Account not found'
});
}
const { id, balance, owner, createdon, type, owneremail, status } = accountDetails[0];
const data = { id, accountNumber, owner, balance, createdon, type, owneremail, status };
const {
id,
balance,
owner,
createdon,
type,
owneremail,
status,
ownername
} = accountDetails[0];
const data = {
id,
accountNumber,
owner,
balance,
createdon,
type,
owneremail,
status,
ownername
};
return res.status(200).json({
status: 200,
data: [data]
Expand All @@ -79,8 +98,27 @@ export default class AccountController {
error: 'Account not found'
});
}
const { id, balance, owner, createdon, type, owneremail, status } = userAccountDetails[0];
const data = { id, accountNumber, owner, balance, createdon, type, owneremail, status };
const {
id,
balance,
owner,
createdon,
type,
owneremail,
status,
ownername
} = userAccountDetails[0];
const data = {
id,
accountNumber,
owner,
balance,
createdon,
type,
owneremail,
status,
ownername
};
return res.status(200).json({
status: 200,
data: [data]
Expand All @@ -101,8 +139,12 @@ export default class AccountController {
if (req.decoded.type === 'client') {
const accountNumber = Math.floor(Math.random() * 10 ** 10);
const newAccount = await accounts.create(
['accountNumber', 'owner', 'ownerEmail', 'type', 'status', 'balance'],
[`${accountNumber}, ${id}, '${email}', '${type}', 'active', 0.0`]
['accountNumber', 'owner', 'ownerName', 'ownerEmail', 'type', 'status', 'balance'],
[
`${accountNumber}, ${id}, '${req.decoded.firstName} ${
req.decoded.lastName
}', '${email}', '${type}', 'active', 0.0`
]
);
const data = {
accountNumber: newAccount[0].accountnumber,
Expand Down
21 changes: 11 additions & 10 deletions server/db/seeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const createTable = async () => {
id SERIAL PRIMARY KEY,
accountNumber BIGINT NOT NULL,
owner INT NOT NULL,
ownerName VARCHAR NOT NULL,
type VARCHAR NOT NULL,
status VARCHAR NOT NULL,
balance NUMERIC NOT NULL,
Expand Down Expand Up @@ -74,16 +75,16 @@ const createTable = async () => {
VALUES('olegunnar@manutd.com', 'Ole', 'Solksjaer', '${userPass}', 'Old Trafford, Manchester', '/uploads/avatar/ole.jpg', 08739084, 'client', false);
INSERT INTO users (email, firstName, lastName, password, address, avatar, phoneNumber, type, isAdmin)
VALUES('kyloren@vader.com', 'Kylo', 'Ren', '${adminPass}', 'Tatooine, Planet C53', '/uploads/avatar/kylo.jpg', 08939084, 'staff', false);
INSERT INTO accounts (accountNumber, owner, ownerEmail, type, status, balance)
VALUES(5563847290, 2, 'thor@avengers.com', 'current', 'active', 349876358.08);
INSERT INTO accounts (accountNumber, owner, ownerEmail, type, status, balance)
VALUES(8897654324, 3, 'olegunnar@manutd.com', 'savings', 'dormant', 7665435.97);
INSERT INTO accounts (accountNumber, owner, ownerEmail, type, status, balance)
VALUES(8894354324, 3, 'olegunnar@manutd.com', 'current', 'draft', 43435.97);
INSERT INTO accounts (accountNumber, owner, ownerEmail, type, status, balance)
VALUES(4294354324, 2, 'thor@avengers.com', 'current', 'draft', 43435.97);
INSERT INTO accounts (accountNumber, owner, ownerEmail, type, status, balance)
VALUES(6754354123, 4, 'kyloren@vader.com', 'savings', 'dormant', 321324.7);
INSERT INTO accounts (accountNumber, owner, ownerName, ownerEmail, type, status, balance)
VALUES(5563847290, 2, 'Thor Odinson','thor@avengers.com', 'current', 'active', 349876358.08);
INSERT INTO accounts (accountNumber, owner, ownerName, ownerEmail, type, status, balance)
VALUES(8897654324, 3, 'Ole Solksjaer', 'olegunnar@manutd.com', 'savings', 'dormant', 7665435.97);
INSERT INTO accounts (accountNumber, owner, ownerName, ownerEmail, type, status, balance)
VALUES(8894354324, 3, 'Ole Solksjaer', 'olegunnar@manutd.com', 'current', 'draft', 43435.97);
INSERT INTO accounts (accountNumber, owner, ownerName, ownerEmail, type, status, balance)
VALUES(4294354324, 2, 'Thor Odinson', 'thor@avengers.com', 'current', 'draft', 43435.97);
INSERT INTO accounts (accountNumber, owner, ownerName, ownerEmail, type, status, balance)
VALUES(6754354123, 4, 'Kylo Ren', 'kyloren@vader.com', 'savings', 'dormant', 321324.7);
INSERT INTO transactions (type, accountNumber, owner, cashier, cashierName, amount, oldBalance, newBalance)
VALUES('credit', 8897654324, 3, 4, 'Kylo Ren', 400500.0, 7264935.97, 7665435.97);
INSERT INTO transactions (type, accountNumber, owner, cashier, cashierName, amount, oldBalance, newBalance)
Expand Down
2 changes: 2 additions & 0 deletions test/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ describe('Account Route', () => {
.eql(200);
expect(res.body).to.have.nested.property('data[0].accountNumber');
expect(res.body).to.have.nested.property('data[0].status');
expect(res.body).to.have.nested.property('data[0].ownername');
expect(res.status).to.equal(200);
done();
});
Expand All @@ -547,6 +548,7 @@ describe('Account Route', () => {
.eql(200);
expect(res.body).to.have.nested.property('data[0].accountNumber');
expect(res.body).to.have.nested.property('data[0].status');
expect(res.body).to.have.nested.property('data[0].ownername');
expect(res.status).to.equal(200);
done();
});
Expand Down

0 comments on commit 7998469

Please sign in to comment.