implements a category route

This commit is contained in:
Mikayla Dobson
2022-09-27 17:08:59 -05:00
parent 388f3a5ba9
commit d99cf5bb8a
4 changed files with 130 additions and 0 deletions

View 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;
}
}