feat: implementing server framework
This commit is contained in:
30
server/resources/ingredient/IngredientResource.ts
Normal file
30
server/resources/ingredient/IngredientResource.ts
Normal 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: "",
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user