53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
import CategoryService from "../services/category.js";
|
|
import translate from "../utils/translate.js";
|
|
import responseCodes from "../response/responseCodes.js";
|
|
import notify from "../utils/notify.js";
|
|
|
|
const TAG = "controllers/category.js";
|
|
|
|
class CategoryController {
|
|
async create(req, res) {
|
|
const { localId, categoryName, groupId } = req.body;
|
|
|
|
await CategoryService.create(groupId, localId, categoryName);
|
|
|
|
notify(req.headers.authorization.split(' ')[1], groupId, 'create', 'category', {
|
|
localId, categoryName
|
|
});
|
|
|
|
return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok));
|
|
}
|
|
|
|
async update(req, res) {
|
|
const { localId, groupId, categoryName } = req.body;
|
|
|
|
await CategoryService.update(groupId, localId, categoryName);
|
|
|
|
let data = { localId }
|
|
if (categoryName) data.categoryName = categoryName
|
|
|
|
notify(req.headers.authorization.split(' ')[1], groupId, 'update', 'category', data);
|
|
|
|
return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok));
|
|
}
|
|
|
|
async getByLocalId(req, res) {
|
|
const { groupId, localId } = req.params;
|
|
|
|
let result = await CategoryService.getById(groupId, localId)
|
|
|
|
return res.status(200).send(result)
|
|
}
|
|
|
|
async delete(req, res) {
|
|
const { groupId, localId } = req.params;
|
|
|
|
await CategoryService.delete(groupId, localId);
|
|
|
|
notify(req.headers.authorization.split(' ')[1], groupId, 'delete', 'category', { localId });
|
|
|
|
return res.status(200).send(translate(req.headers["accept-language"], responseCodes.responses.general.ok))
|
|
}
|
|
};
|
|
|
|
export default new CategoryController(); |