quetre/controllers/apiController.js
2022-04-17 17:54:23 +05:30

35 lines
1.2 KiB
JavaScript

////////////////////////////////////////////////////////
// IMPORTS
////////////////////////////////////////////////////////
import catchAsyncErrors from '../utils/catchAsyncErrors.js';
import getAnswers from '../fetchers/getAnswers.js';
////////////////////////////////////////////////////////
// EXPORTS
////////////////////////////////////////////////////////
export const about = (req, res, next) => {
res
.status(200)
.json({
status: 'success',
message:
"make a request. available endpoints are: '/some-slug', '/unanswered/some-slug'",
});
};
export const unansweredQuestion = catchAsyncErrors(async (req, res, next) => {
const data = await getAnswers(`/unanswered/${req.params.slug}`);
res.status(200).json({ status: 'success', data });
});
export const answeredQuestion = catchAsyncErrors(async (req, res, next) => {
const data = await getAnswers(req.params.slug);
res.status(200).json({ status: 'success', data });
});
export const unimplemented = (req, res, next) => {
res.status(503).json({
status: 'fail',
message: "This route isn't yet implemented. Check back sometime later!",
});
};