Initial content

This commit is contained in:
Adam Freeman
2024-05-29 18:54:49 +01:00
parent 2dbc1a8088
commit 5215a1d919
1944 changed files with 203378 additions and 0 deletions
@@ -0,0 +1,23 @@
export interface CartLine {
productId: number;
quantity: number;
}
export interface Cart {
lines: CartLine[];
}
export const createCart = () : Cart => ({ lines: [] });
export const addLine = (cart: Cart, productId: number, quantity: number) => {
const line = cart.lines.find(l => l.productId == productId);
if (line !== undefined) {
line.quantity += quantity;
} else {
cart.lines.push({ productId, quantity })
}
}
export const removeLine = (cart: Cart, productId: number) => {
cart.lines = cart.lines.filter(l => l.productId !== productId);
}