Skip to content

Instantly share code, notes, and snippets.

View OdongAlican's full-sized avatar
🎯
Focusing

Odong Sunday OdongAlican

🎯
Focusing
View GitHub Profile
@OdongAlican
OdongAlican / pagination.js
Created April 13, 2023 22:25
Pagination Component
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;
exports.getOne = async function (req, res) {
const post = await req.post;
res.json(post);
};
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;
exports.get = async function (req, res) {
await AuthorModel.find({}).populate('posts')
.exec()
.then((authors) => {
res.json(authors);
}, (err) => {
res.send(err);
});
};
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);
}
});
};
npm install express body-parser eslint mongoose lodash
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)
@OdongAlican
OdongAlican / update-post.js
Created April 14, 2020 20:43
updating a post
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;
}
@OdongAlican
OdongAlican / get-post.js
Created April 14, 2020 20:39
Getting the articles
exports.get = async function (req, res) {
await PostModel.find({})
.populate('author')
.exec()
.then((posts) => {
res.json(posts);
}, (err) => {
res.send(err);
});
};
@OdongAlican
OdongAlican / Post-controller-article.js
Created April 14, 2020 20:33
Creating a post request for an article
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);