add: added some api endpoints

This commit is contained in:
Lukian 2025-04-23 08:25:25 +02:00
parent 217c763abd
commit 736f097d20
4 changed files with 89 additions and 5 deletions

View file

@ -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,
};