ingredient route
This commit is contained in:
@@ -1,21 +1,46 @@
|
||||
import createError from "http-errors";
|
||||
import { IIngredient } from "../schemas";
|
||||
import { Ingredient } from "../models/ingredient";
|
||||
const IngredientInstance = new Ingredient();
|
||||
|
||||
export default class IngredientCtl {
|
||||
async getAll() {
|
||||
|
||||
try {
|
||||
const result = await IngredientInstance.getAll();
|
||||
if (!result) throw createError('404', 'No ingredients found');
|
||||
return result;
|
||||
} catch (e: any) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async getOne(id: string) {
|
||||
|
||||
try {
|
||||
const result = await IngredientInstance.getOne(id);
|
||||
if (!result) throw createError('404', 'No ingredient found with id ' + id);
|
||||
return result;
|
||||
} catch (e: any) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async post(data: IIngredient) {
|
||||
|
||||
try {
|
||||
const result = await IngredientInstance.post(data);
|
||||
if (!result) throw createError('400', 'Bad request');
|
||||
return result;
|
||||
} catch (e: any) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async put(id: string, data: IIngredient) {
|
||||
|
||||
try {
|
||||
const result = await IngredientInstance.put(id, data);
|
||||
if (!result) throw createError('400', 'Bad request');
|
||||
return result;
|
||||
} catch (e: any) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
server/controllers/index.ts
Normal file
9
server/controllers/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import CollectionCtl from "./CollectionCtl";
|
||||
import GroceryListCtl from "./GroceryListCtl";
|
||||
import IngredientCtl from "./IngredientCtl";
|
||||
import RecipeCtl from "./RecipeCtl";
|
||||
import UserCtl from "./UserCtl";
|
||||
|
||||
export {
|
||||
CollectionCtl, GroceryListCtl, IngredientCtl, RecipeCtl, UserCtl
|
||||
}
|
||||
Reference in New Issue
Block a user