refactor: DRY some code related to answers

as there are two routes for answers(/unanswered/:slug and /:slug), and both contained similar code, reduced controllers(for the routes) in api as well as in views to just one controller handling the logic to fetch data.
This commit is contained in:
zyachel 2022-05-21 12:56:12 +05:30
parent 56994854d7
commit d8515d5edd
4 changed files with 16 additions and 37 deletions

View file

@ -1,10 +1,5 @@
import express from 'express';
import {
about,
unimplemented,
unansweredQuestion,
answeredQuestion,
} from '../controllers/apiController.js';
import { about, unimplemented, answers } from '../controllers/apiController.js';
const apiRouter = express.Router();
@ -12,7 +7,7 @@ apiRouter.get('/', about);
apiRouter.get('/search', unimplemented);
apiRouter.get('/profile/:name', unimplemented);
apiRouter.get('/topic/:name', unimplemented);
apiRouter.get('/unanswered/:slug', unansweredQuestion);
apiRouter.get('/:slug', answeredQuestion);
apiRouter.get('/unanswered/:slug', answers);
apiRouter.get('/:slug', answers);
export default apiRouter;