Untitled
unknown
plain_text
a year ago
2.5 kB
11
Indexable
/** @format */
var createError = require("http-errors");
const {
handleUpdateCoinPrice,
handleGetSingleCoinDetails,
handleGetCoinPrice,
handleGetCoinDetails,
handleGetCoinList,
handleGetTrendingCoinDetails,
} = require("../../model/others/coinModel");
class CoinCOntroller {
constructor() {}
async getCoinLists(req, res, next) {
try {
const coinsId = Object.keys(req.body);
const result = await handleUpdateCoinPrice(coinsId);
return res.status(200).json(result);
} catch (error) {
next(error);
}
}
async getSingleCoin(req, res, next) {
try {
if (!req.params.id) {
throw createError.BadRequest("Coin ID is not present");
} else {
const result = await handleGetSingleCoinDetails(req.params.id);
return res.status(200).json(result);
}
} catch (error) {
next(error);
}
}
async getCoinPriceDetails(req, res, next) {
try {
if (!req.params.id) {
throw createError.BadRequest("Coin ID is not present");
} else {
const type = req.query.timeSpan;
const result = await handleGetCoinPrice(req.params.id, type);
return res.status(200).json(result);
}
} catch (error) {
next(error);
}
}
async getCoinDetails(req, res, next) {
try {
if (!req.params.id) {
throw createError.BadRequest("Coin ID is not present");
} else {
const result = await handleGetCoinDetails(req.params.id);
return res.status(200).json(result);
}
} catch (error) {
next(error);
}
}
async getCoinsList(req, res, next) {
try {
const page = req.query.page || 1;
const limit = req.query.limit || 10;
const searchParam = req.query.search;
const result = await handleGetCoinList(page, limit, searchParam);
return res.status(200).json(result);
} catch (error) {
next(error);
}
}
async getTrendingCoinDetails(req, res, next) {
try {
if (!req.params.id) {
throw createError.BadRequest("User id is not present");
} else {
const result = await handleGetTrendingCoinDetails(req.params.id);
return res.status(200).json(result);
}
} catch (error) {
throw createError.BadRequest(error.message);
}
}
}
module.exports = new CoinCOntroller();
Editor is loading...
Leave a Comment