Add and edit recipes (#3)
Co-authored-by: clfreville2 <clement.freville2@etu.uca.fr> Reviewed-on: https://codefirst.iut.uca.fr/git/clement.freville2/tiramisu/pulls/3
This commit is contained in:
@@ -29,4 +29,20 @@ export class RecipeService {
|
||||
get(id: number): Recipe | null {
|
||||
return this.#recipes.find((recipe) => recipe.id === id) || null;
|
||||
}
|
||||
|
||||
add(recipe: Omit<Recipe, 'id'>): void {
|
||||
const id = this.#recipes.length ? Math.max(...this.#recipes.map((recipe) => recipe.id)) + 1 : 1;
|
||||
this.#recipes.push({
|
||||
id,
|
||||
...recipe,
|
||||
});
|
||||
}
|
||||
|
||||
edit(recipe: Recipe): void {
|
||||
for (let i = 0; i < this.#recipes.length; ++i) {
|
||||
if (this.#recipes[i].id === recipe.id) {
|
||||
this.#recipes[i] = recipe;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user