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:
34
server/Ingredient.ts
Normal file
34
server/Ingredient.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user