-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add controller function for pagination article - Add route for article controller - Add swagger documentation - Add test for article pagination
- Loading branch information
Showing
6 changed files
with
115 additions
and
163 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,10 @@ | ||
|
||
const createSlug = (text) => { | ||
let gen = `${text} ${(Math.floor(Math.random() * Math.floor(100000)))}`; | ||
while (gen.match(/ /g)) { | ||
gen = gen.replace(' ', '-'); | ||
} | ||
return gen; | ||
}; | ||
|
||
export default createSlug; |
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,27 @@ | ||
|
||
import model from '../../models'; | ||
|
||
const { Articles } = model; | ||
const getAllArticles = async (req, res) => { | ||
try { | ||
const articles = await Articles.findAll(); | ||
return Articles.findAll() && res.status(200).json({ articles }); | ||
} catch (error) { | ||
return res.status(404).json({ error: 'No article found' }); | ||
} | ||
}; | ||
|
||
const articlePagination = async (req, res) => { | ||
try { | ||
const { offset, limit } = req.query; | ||
const articles = await Articles.findAll({ offset, limit }); | ||
return articles.length ? res.status(200).json({ articles }) : res.status(404).json({ message: 'page not found' }); | ||
} catch (error) { | ||
return res.status(404).json({ error: 'No article found' }); | ||
} | ||
}; | ||
|
||
export { | ||
getAllArticles, | ||
articlePagination | ||
}; |
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
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