-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kafka): implement fetch all categories
- ensure all categories in the system are fetched [Delivers #164143948]
- Loading branch information
Showing
5 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import models from '../db/models'; | ||
import Response from '../helpers/response'; | ||
|
||
const { | ||
Category | ||
} = models; | ||
|
||
/** Arts Controller Class */ | ||
class CategoriesController { | ||
/** | ||
* @desc GET /api/v1/categories | ||
* @param {object} req | ||
* @param {object} res | ||
* @memberof CategoriesController | ||
* @returns {Object} All Articles | ||
*/ | ||
static async getCategories(req, res) { | ||
try { | ||
const categories = await Category.findAndCountAll({ | ||
order: [ | ||
['categoryName', 'ASC'], | ||
], | ||
attributes: [ | ||
'id', | ||
'categoryName' | ||
] | ||
}); | ||
|
||
const response = new Response( | ||
'Ok', | ||
200, | ||
'All Categories', | ||
{ | ||
categories | ||
} | ||
); | ||
return res.status(response.code).json(response); | ||
} catch (err) { | ||
const response = new Response( | ||
'Internal Server Error', | ||
500, | ||
`${err}`, | ||
); | ||
return res.status(response.code).json(response); | ||
} | ||
} | ||
} | ||
|
||
export default CategoriesController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import express from 'express'; | ||
import CategoriesController from '../controllers/CategoriesController'; | ||
|
||
const categoriesRoute = express.Router(); | ||
|
||
categoriesRoute.get('/', CategoriesController.getCategories); | ||
|
||
export default categoriesRoute; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'babel-polyfill'; | ||
import chai from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import { app } from '../../src/index'; | ||
|
||
chai.use(chaiHttp); | ||
const { expect } = chai; | ||
|
||
|
||
describe('Categories Endpoint API Test', () => { | ||
describe('Categories GET REQUESTS', () => { | ||
it('it should get all categories', (done) => { | ||
chai.request(app) | ||
.get('/api/v1/categories') | ||
.end((err, res) => { | ||
expect(res.body.messages).eql('All Categories'); | ||
expect(res.body.data).to.have.property('categories'); | ||
expect(res.status).to.equal(200); | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
}); |