implements a category route
This commit is contained in:
29
services/CategoryService.js
Normal file
29
services/CategoryService.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const createError = require('http-errors');
|
||||
const CategoryModel = require('../models/CategoryModel');
|
||||
const CategoryInstance = new CategoryModel();
|
||||
|
||||
module.exports = class CategoryService {
|
||||
async getAll() {
|
||||
const result = await CategoryInstance.getAll();
|
||||
if (!result) throw createError(404, "Resource not found.");
|
||||
return result;
|
||||
}
|
||||
|
||||
async getById(id) {
|
||||
const result = await CategoryInstance.getById(id);
|
||||
if (!result) throw createError(404, "Resource not found.");
|
||||
return result;
|
||||
}
|
||||
|
||||
async getByName(name) {
|
||||
const result = await CategoryInstance.getByName(name);
|
||||
if (!result) throw createError(404, "Resource not found.");
|
||||
return result;
|
||||
}
|
||||
|
||||
async create(data) {
|
||||
const result = await CategoryInstance.insertOne(data);
|
||||
if (!result) throw createError(404, "Resource not found.");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user