1
0
mirror of https://github.com/franjsco/tick3t-api synced 2025-06-05 22:09:20 +02:00

add controller: category

This commit is contained in:
Francesco Esposito 2019-08-06 18:41:42 +02:00
parent 8f9d4e3db3
commit b2004c08dd

View File

@ -0,0 +1,46 @@
import CategoryModel from '../models/category';
export const getById = (req, res, next) => {
const { type } = req.query;
const filter = Object.assign({}, type ? { type } : {});
CategoryModel.find(filter, (err, category) => {
if (err) {
next(err);
}
if (category.length) {
res.json({
success: true,
message: 'Categories Found',
data: category,
});
} else {
res.json({
success: false,
message: 'Categories not found',
});
}
});
};
export const create = (req, res, next) => {
const categoryMod = new CategoryModel({
type: req.body.type,
value: req.body.value,
});
categoryMod.save((err, category) => {
if (err) {
next(err);
}
res.json({
success: true,
message: 'Category added',
data: category,
});
});
};