fix: removed collage

fix: removing collage

feat: added ingredient type to server for testing and a config"

chore: setup deno server package
This commit is contained in:
Daniel Ledda
2022-06-20 22:22:42 +02:00
parent 47301a822d
commit c628f6b46e
18 changed files with 288 additions and 130 deletions

34
server/Ingredient.ts Normal file
View File

@@ -0,0 +1,34 @@
import { StoccaTreDbConn, WithoutId } from "./database.ts";
export type Ingredient = {
id: number,
name: string,
displayName: string,
displayNameDE: string,
};
export default class IngredientService {
private dbConnection: StoccaTreDbConn;
private mapById: Map<number, Ingredient> = new Map<number, Ingredient>();
private allGotten = false;
constructor(database: StoccaTreDbConn) {
this.dbConnection = database;
}
async addIngredient(ingredient: WithoutId<Ingredient>): Promise<any> {
const result = 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<IterableIterator<Ingredient>> {
if (!this.allGotten) {
const result = await this.dbConnection.query<Ingredient[]>("SELECT * FROM ingredients");
result.forEach((ingredient) => this.mapById.set(ingredient.id, ingredient));
this.allGotten = true;
}
return this.mapById.values();
}
}