Files
stocca-tre/server/resources/ingredient/IngredientResource.ts
2022-06-29 08:24:00 +02:00

30 lines
1.0 KiB
TypeScript

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<Maybe<JSONObject>> {
return await this.allIngredients(request);
}
async allIngredients(request: StoccaTreRequest): Promise<Maybe<JSONObject>> {
const getAllIngredientResult = await this.collection.getAllIngredients();
if (!getAllIngredientResult.error) {
return getAllIngredientResult.just;
}
return {
just: {
ingredients: Array.from(getAllIngredientResult.just),
},
error: "",
};
}
}