harris_paint / src /controllers /blog.controller.js
aliroohan179's picture
Upload 58 files
10821c7 verified
Raw
History Blame Contribute Delete
1.17 kB
const blogService = require('../services/blog.service');
exports.list = async (req, res, next) => {
try { res.json(await blogService.list(req.query)); }
catch (error) { next(error); }
};
exports.getById = async (req, res, next) => {
try { res.json({ post: await blogService.getById(req.params.id) }); }
catch (error) { next(error); }
};
exports.create = async (req, res, next) => {
try { res.status(201).json({ post: await blogService.create(req.body, req.admin._id, req.ip) }); }
catch (error) { next(error); }
};
exports.update = async (req, res, next) => {
try { res.json({ post: await blogService.update(req.params.id, req.body, req.admin._id, req.ip) }); }
catch (error) { next(error); }
};
exports.updateStatus = async (req, res, next) => {
try {
const post = await blogService.updateStatus(req.params.id, req.body, req.admin._id, req.ip);
res.json({ post, message: `Post ${req.body.status}.` });
} catch (error) { next(error); }
};
exports.remove = async (req, res, next) => {
try { await blogService.remove(req.params.id, req.admin._id, req.ip); res.json({ message: 'Post deleted.' }); }
catch (error) { next(error); }
};