diff --git a/prisma/migrations/20230525163656_add_item_visibility/migration.sql b/prisma/migrations/20230525163656_add_item_visibility/migration.sql new file mode 100644 index 0000000000000000000000000000000000000000..ad7b6137dc856df4cea4809627dcabf5ad75aaad --- /dev/null +++ b/prisma/migrations/20230525163656_add_item_visibility/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Item" ADD COLUMN "show" BOOLEAN NOT NULL DEFAULT true; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2c4e5ffbfbf769777942bc08770a04fafafa8758..00f3dfb564b889358834f21a33decaa55c2ab6e2 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -65,6 +65,7 @@ model Item { stock Int @default(0) bought Int @default(0) available Boolean @default(true) + show Boolean @default(true) restocks Restock[] transactions ItemTransaction[] } diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 629f83cc6558385af230b2e171c7b2ed9d5c4d64..65e13044d123ed99d565fc0b7ed0e21c37fe3a16 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -313,7 +313,7 @@ {#each categories as category, i} <h2 bind:this={categoryElements[i].element}>{category.name}</h2> <div class="item-list"> - <ItemList items={items.filter(item=>item.categoryId===category.id)} onClick={item=>addToCart({type: "article", code: item.code})} priceModifier={x=>x} bind:inView={elementsInView[i]} /> + <ItemList items={items.filter(item=>item.categoryId===category.id&&item.show)} onClick={item=>addToCart({type: "article", code: item.code})} priceModifier={x=>x} bind:inView={elementsInView[i]} /> </div> {/each} </div> diff --git a/src/routes/admin/api/articles.js b/src/routes/admin/api/articles.js index 794446765ee53bc5380c85f2e7bde7bcb329a08a..10b35fbe0bb9236e2247013fcfd4556592792eb7 100644 --- a/src/routes/admin/api/articles.js +++ b/src/routes/admin/api/articles.js @@ -47,12 +47,12 @@ export async function restockArticles(restocks){ return db.$transaction(restocks.map(({code, amount, cost})=>restockArticle(code, amount, cost))); } -export async function createArticle(code, name, price, categoryId, image, available=true){ - return db.item.create({data: {code, name, price, categoryId, image, available}}); +export async function createArticle(code, name, price, categoryId, image, available=true, show=true){ + return db.item.create({data: {code, name, price, categoryId, image, available, show}}); } -export async function updateArticle(code, name, price, categoryId, image, available){ - return db.item.update({where: {code}, data: {name, price, categoryId, image, available}}); +export async function updateArticle(code, name, price, categoryId, image, available, show){ + return db.item.update({where: {code}, data: {name, price, categoryId, image, available, show}}); } export async function createCategory(name, position){ diff --git a/src/routes/admin/product/+page.server.js b/src/routes/admin/product/+page.server.js index 1ac8c7d4c8bbb1aebdcfdd3be72fdcb6c50640c7..bc83a6700f1b3f88a0ae8e736fb0c10c41c4a94c 100644 --- a/src/routes/admin/product/+page.server.js +++ b/src/routes/admin/product/+page.server.js @@ -18,6 +18,7 @@ export const actions = { const image = data.get('image'); const oldImage = data.get('oldImage'); const available = !!data.get('available'); + const show = !!data.get('show'); const deleteImage = data.get("deleteImage") === "true"; if(!code || !name || Number.isNaN(price) || price < 0 || !categoryId) return { errors: { failed: "Invalid form data" } }; let imagePath = oldImage; @@ -35,7 +36,7 @@ export const actions = { // TODO decide whether to await this or not /*await */fs.writeFile(`/app/article-images/${imageName}`, buffer); } - const product = await updateArticle(code, name, price, categoryId, imagePath, available); + const product = await updateArticle(code, name, price, categoryId, imagePath, available, show); delete product.createdAt; return {success: true, product}; }, @@ -47,6 +48,7 @@ export const actions = { const categoryId = parseInt(data.get('categoryId')); const image = data.get('image'); const available = !!data.get('available'); + const show = !!data.get('show'); if(!code || !name || Number.isNaN(price) || price < 0 || !categoryId) return { error: "Invalid form data" }; if(image.size > 0 && !image.type.startsWith("image/")) return { error: "Invalid image" }; let imageUrl; @@ -57,7 +59,7 @@ export const actions = { // TODO decide whether to await this or not /*await */fs.writeFile(`/app/article-images/${imageName}`, buffer); } - const product = await createArticle(code, name, price, categoryId, imageUrl, available); + const product = await createArticle(code, name, price, categoryId, imageUrl, available, show); delete product.createdAt; return {success: true, article: product}; }, diff --git a/src/routes/admin/product/ProductItem.svelte b/src/routes/admin/product/ProductItem.svelte index c7e5068492edbbbb063337256b526e7cf2779c3f..4bc70575476e230db416ffedb0db9aa6a5f9f770 100644 --- a/src/routes/admin/product/ProductItem.svelte +++ b/src/routes/admin/product/ProductItem.svelte @@ -1,7 +1,7 @@ <script> import ItemIcon from "../../../components/ItemIcon.svelte"; - export let name, price, image, code, categoryId, available, categories, stock; + export let name, price, image, code, categoryId, available, show, categories, stock; export let edit, deleteImage; let newImage = image; </script> @@ -28,6 +28,7 @@ {/each} </select></td> <td><input form={"form" + code} type="checkbox" name="available" id="available" checked={available} /></td> + <td><input form={"form" + code} type="checkbox" name="show" id="show" checked={show} /></td> <td> <button type="submit" form={"form" + code}>Speichern</button> <button type="button" on:click={() => {edit = false; deleteImage = false; newImage = image;}}>Abbrechen</button> @@ -40,6 +41,7 @@ <td><ItemIcon icon={image} size="40px" name={name} /></td> <td>{categories[categoryId].name}</td> <td>{available ? "Ja" : "Nein"} ({stock})</td> + <td>{show ? "Ja" : "Nein"}</td> <td><button on:click={() => edit = true}>Bearbeiten</button></td> </tr> {/if} diff --git a/src/routes/admin/product/ProductList.svelte b/src/routes/admin/product/ProductList.svelte index 3b480b52a0bd6ae2e1de5977ee73fea645a49f14..df207117225fb8161700333327d8cca3875ef367 100644 --- a/src/routes/admin/product/ProductList.svelte +++ b/src/routes/admin/product/ProductList.svelte @@ -19,6 +19,7 @@ <th>Bild</th> <th>Kategorie</th> <th>verfügbar</th> + <th>Sichtbar</th> <th></th> </tr> {#each products as product, i} @@ -40,6 +41,7 @@ {/each} </select></td> <td><input form="form-new" type="checkbox" name="available" id="available" checked /></td> + <td><input form="form-new" type="checkbox" name="show" id="show" checked /></td> <td><button type="submit" form="form-new">Erstellen</button></td> </tr> </table>