feat: improving infrastructure

This commit is contained in:
Daniel Ledda
2022-06-30 08:33:13 +02:00
parent bd177c7f09
commit 3e5c53f9f5
12 changed files with 76 additions and 61 deletions

View File

@@ -1,5 +1,6 @@
import {StoccaTreDbConn, WithoutId} from "../../database.ts";
import {IngredientModel} from "./IngredientModel.ts";
import {Maybe} from "../../Maybe.ts";
export default class IngredientCollection {
private dbConnection: StoccaTreDbConn;
@@ -11,17 +12,16 @@ export default class IngredientCollection {
}
async addIngredient(ingredient: WithoutId<IngredientModel>): Promise<any> {
const result = await this.dbConnection.query<any>(
return await this.dbConnection.query<any>(
`INSERT INTO ingredients (id, name, displayName, displayNameDE) VALUES (NULL, '${ingredient.name}', '${ingredient.displayName}', '${ingredient.displayNameDE}');`
);
return result;
}
async getAllIngredients(): Promise<Maybe<IterableIterator<IngredientModel>>> {
if (!this.allGotten) {
const result = await this.dbConnection.query<IngredientModel[]>("SELECT * FROM ingredients");
if (result.just) {
result.just.forEach((ingredient) => this.mapById.set(ingredient.id, ingredient));
if (!result.error) {
result.just.forEach((ingredient: IngredientModel) => this.mapById.set(ingredient.id, ingredient));
} else {
return result;
}
@@ -29,7 +29,6 @@ export default class IngredientCollection {
}
return {
just: this.mapById.values(),
error: null,
};
}
}