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:
parent
8f9d4e3db3
commit
b2004c08dd
46
src/controllers/category.js
Normal file
46
src/controllers/category.js
Normal 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,
|
||||
});
|
||||
});
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user