feat: implementing server framework

This commit is contained in:
Daniel Ledda
2022-06-29 08:24:00 +02:00
parent c628f6b46e
commit bd177c7f09
17 changed files with 210 additions and 55 deletions

View File

@@ -0,0 +1,30 @@
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: "",
};
}
}