import {StoccaTreDbConn} from "/database.ts"; import IngredientCollection from "IngredientCollection.ts"; import StoccaTreRequest from "/StoccaTreRequest.ts"; export default class IngredientResource { private dbConnection: StoccaTreDbConn; private collection: IngredientCollection; constructor(dbConnection: StoccaTreDbConn) { this.dbConnection = dbConnection; this.collection = new IngredientCollection(dbConnection); } async handleRequest(request: StoccaTreRequest): Promise> { return await this.allIngredients(request); } async allIngredients(request: StoccaTreRequest): Promise> { const getAllIngredientResult = await this.collection.getAllIngredients(); if (!getAllIngredientResult.error) { return getAllIngredientResult.just; } return { just: { ingredients: Array.from(getAllIngredientResult.just), }, error: "", }; } }