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
import React, { useState, useEffect } from 'react'; | |
import Pagination from 'react-bootstrap/Pagination'; | |
const PaginationComponent = ({ pageCount = 0, goToPage }) => { | |
const [currentPage, setCurrentPage] = useState(0); | |
const [start, setStart] = useState(0); | |
const [end, setEnd] = useState(0); | |
const elements_per_page = 10; | |
const pageIndexTotal = parseInt(pageCount, 10) / elements_per_page; |
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
exports.getOne = async function (req, res) { | |
const post = await req.post; | |
res.json(post); | |
}; |
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
exports.params = async function (req, res, next, id) { | |
console.log(id); | |
await PostModel.findById(id) | |
.populate('author') | |
.exec() | |
.then((post) => { | |
if (!post) { | |
return res.status(400).send(' post with that Particular id'); | |
} | |
req.post = post; |
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
exports.delete = async function (req, res) { | |
await PostModel.remove((req.post), (err, removed) => { | |
if (err) { | |
res.status(400).send('post not deleted'); | |
} else { | |
res.json(removed); | |
} | |
}); | |
}; |
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
npm install express body-parser eslint mongoose lodash |
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
def my_inject | |
result = first | |
updated_result = [] | |
each do |item| | |
updated_result << item | |
end | |
updated_result.delete_at(0) | |
updated_result.each do |val| | |
result = yield(result, val) |
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
exports.update = function (req, res) { | |
const newAuthorId = req.params.authorId; | |
const { postId } = req.params; | |
const newPost = req.body; | |
PostModel.findOne({ _id: postId }, (err, post) => { | |
if (!post) { | |
return err; | |
} |
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
exports.get = async function (req, res) { | |
await PostModel.find({}) | |
.populate('author') | |
.exec() | |
.then((posts) => { | |
res.json(posts); | |
}, (err) => { | |
res.send(err); | |
}); | |
}; |
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
exports.post = async function (req, res) { | |
const authorId = await req.params.authorID; | |
const postObject = await req.body; | |
const newPost = new PostModel(postObject); | |
await AuthorModel.findOne({ _id: authorId }, async (err, foundAuthor) => { | |
if (!foundAuthor) { | |
return err; | |
} | |
foundAuthor.posts.push(newPost); |
NewerOlder