Skip to content

Commit

Permalink
feat: add exchanges api, sql utils
Browse files Browse the repository at this point in the history
  • Loading branch information
adityak74 committed Dec 1, 2021
1 parent 72c1462 commit b5f1921
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 18 additions & 0 deletions config/api-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ app.get('/coins', async (req, res) => {
}
});

app.get('/exchanges', async (req, res) => {
const { select } = sql;
const { selectAllExchanges } = select;
try {
const exchangesData = await selectAllExchanges();
res.send({
success: true,
exchanges: exchangesData.length,
exchangesData,
});
} catch (error) {
return res.send({
error,
success: false,
});
}
});

app.get('/coinsData', async (req, res) => {
const handleFailure = (statusCode, error) => {
const errorObj = {
Expand Down
8 changes: 7 additions & 1 deletion utils/sql-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ const countAllCoinsDataAndCache = async () => {
};

const selectAllCoins = async (options = {}) => {
coins = await db.cacher.model('Coins').findAll({ where: options });
const coins = await db.cacher.model('Coins').findAll({ where: options });
return coins;
};

const selectAllExchanges = async (options = {}) => {
const exchanges = await db.cacher.model('Exchanges').findAll({ where: options });
return exchanges;
};

const selectCoinsByPredicate = async (predicateObject) => {
const CoinByPredicate = await db.cacher.model('Coins').findOne({ where: predicateObject });
return CoinByPredicate;
Expand Down Expand Up @@ -65,6 +70,7 @@ module.exports = {
countAllCoinsData,
countAllCoinsDataAndCache,
selectAllCoins,
selectAllExchanges,
selectCoinsDataByPredicate,
selectCoinsByPredicate,
};

0 comments on commit b5f1921

Please sign in to comment.