generated from lucien/api-template
add: added some api endpoints
This commit is contained in:
parent
217c763abd
commit
736f097d20
4 changed files with 89 additions and 5 deletions
|
@ -72,6 +72,47 @@ function getUserByEmail(connection, email) {
|
|||
});
|
||||
}
|
||||
|
||||
// +-------------------------------+
|
||||
// | Accounts |
|
||||
// +-------------------------------+
|
||||
|
||||
function getUserAccounts(connection, id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT * FROM accounts WHERE client_id = ?`,
|
||||
[id],
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
reject(new Error(error));
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// +-------------------------------+
|
||||
// | Cards |
|
||||
// +-------------------------------+
|
||||
|
||||
function getUserCards(connection, id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(
|
||||
`SELECT cards.*
|
||||
FROM cards
|
||||
JOIN accounts ON cards.account_id = accounts.id
|
||||
WHERE client_id = ?`,
|
||||
[id],
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
reject(new Error(error));
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getConnection,
|
||||
|
||||
|
@ -79,4 +120,8 @@ module.exports = {
|
|||
getUsers,
|
||||
getUser,
|
||||
getUserByEmail,
|
||||
|
||||
getUserAccounts,
|
||||
|
||||
getUserCards,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue