From 5596ec790a9cf7144bf24f51807edc019d9ee153 Mon Sep 17 00:00:00 2001 From: Tara Aqeel Date: Fri, 16 Oct 2026 16:31:24 +0200 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20legg=20til=20ingredienser,=20allerg?= =?UTF-8?q?ener=20og=20n=C3=A6ringsinnhold=20i=20GraphQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/index.ts | 94 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 20 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index f5aca64..8d93e27 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -23,6 +23,19 @@ const typeDefs = `#graphql url: String } + type Nutrition { + code: String! + displayName: String! + amount: Float! + unit: String! + } + + type Allergen { + code: String! + displayName: String! + contains: String! + } + type Product { ean: String! name: String! @@ -31,6 +44,10 @@ const typeDefs = `#graphql categoryId: ID category: Category prices: [Price!]! + + ingredients: String + nutrition: [Nutrition!]! + allergens: [Allergen!]! } type Query { @@ -225,23 +242,26 @@ const resolvers = { return result.rows; }, - product: async (_parent: unknown, args: { ean: string }) => { - const result = await pool.query( - ` - SELECT - ean, - name, - brand, - image_url AS "imageUrl", - category_id AS "categoryId" - FROM products - WHERE ean = $1 - `, - [args.ean], - ); - - return result.rows[0] ?? null; - }, + product: async (_parent: unknown, args: { ean: string }) => { + const result = await pool.query( + ` + SELECT + ean, + name, + brand, + image_url AS "imageUrl", + category_id AS "categoryId", + ingredients, + nutrition, + allergens + FROM products + WHERE ean = $1 + `, + [args.ean], + ); + + return result.rows[0] ?? null; + }, products: async ( @@ -602,10 +622,44 @@ const resolvers = { [product.ean], ); - return result.rows; + return result.rows; + }, + + nutrition: ( + product: { + nutrition?: { + code: string; + display_name: string; + amount: number; + unit: string; + }[] | null; + }, + ) => { + return (product.nutrition ?? []).map((item) => ({ + code: item.code, + displayName: item.display_name, + amount: item.amount, + unit: item.unit, + })); + }, + + allergens: ( + product: { + allergens?: { + code: string; + display_name: string; + contains: string; + }[] | null; + }, + ) => { + return (product.allergens ?? []).map((item) => ({ + code: item.code, + displayName: item.display_name, + contains: item.contains, + })); + }, }, - }, -}; + }; const server = new ApolloServer({ typeDefs, resolvers, introspection: true, }); From 945f9f87a531191526acdd6e7a3eb7705afed03d Mon Sep 17 00:00:00 2001 From: Tara Aqeel Date: Thu, 22 Oct 2026 16:44:38 +0200 Subject: [PATCH 2/2] feat: display product ingredients allergens and nutrition (#55) --- frontend/src/App.tsx | 17 +++++ .../productDetails/ProductDetailsPage.css | 21 ++++++ .../productDetails/ProductDetailsPage.tsx | 72 ++++++++++++++++--- .../pages/productDetails/productQueries.ts | 24 +++++++ 4 files changed, 126 insertions(+), 8 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index ce45843..1d23415 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -2,6 +2,7 @@ import { useState } from "react"; import NavigationMenu from "./components/navigationMenu/NavigationMenu"; import ShoppingListsPage from "./pages/shoppingLists/ShoppingListsPage"; import ShoppingListDetailPage from "./pages/shoppingLists/ShoppingListDetailPage"; +import ProductDetailsPage from "./pages/productDetails/ProductDetailsPage"; import { BrowserRouter, @@ -9,6 +10,7 @@ import { Route, useLocation, useNavigate, + useParams, } from "react-router"; import Header from "./components/header/Header"; @@ -24,6 +26,16 @@ import { createCategoryUrl } from "./pages/home/categoryNavigation"; import "./App.css"; +function ProductDetailsRoute() { + const { ean } = useParams<{ ean: string }>(); + + if (!ean) { + return

Fant ikke produktet.

; + } + + return ; +} + function AppLayout() { const location = useLocation(); const navigate = useNavigate(); @@ -122,6 +134,11 @@ function AppLayout() { } /> + } + /> + } diff --git a/frontend/src/pages/productDetails/ProductDetailsPage.css b/frontend/src/pages/productDetails/ProductDetailsPage.css index 3c9a3ce..8eee3bf 100644 --- a/frontend/src/pages/productDetails/ProductDetailsPage.css +++ b/frontend/src/pages/productDetails/ProductDetailsPage.css @@ -463,6 +463,27 @@ margin-top: 38px; } + +.product-details-page .product-nutrition__table { + width: 100%; + border-collapse: collapse; +} + +.product-details-page .product-nutrition__table th { + text-align: left; + font-weight: 600; + color: var(--text-primary); + padding: 5px 0; +} + +.product-details-page .product-nutrition__table td { + text-align: right; + color: var(--text-primary); + padding: 5px 0; + white-space: nowrap; +} + + .product-details-page .product-nutrition dl { display: grid; grid-template-columns: minmax(0, 1fr) auto; diff --git a/frontend/src/pages/productDetails/ProductDetailsPage.tsx b/frontend/src/pages/productDetails/ProductDetailsPage.tsx index 6723a18..294b3d5 100644 --- a/frontend/src/pages/productDetails/ProductDetailsPage.tsx +++ b/frontend/src/pages/productDetails/ProductDetailsPage.tsx @@ -55,6 +55,14 @@ export default function ProductDetailsPage({ ); } + const containsAllergens = product.allergens.filter( + (allergen) => allergen.contains === "YES" + ); + + const traceAllergens = product.allergens.filter( + (allergen) => allergen.contains === "CAN_CONTAIN_TRACES" + ); + const storePrices = [...product.prices].sort( (a, b) => a.price - b.price ); @@ -96,17 +104,46 @@ export default function ProductDetailsPage({ +
-

A — INGREDIENSER

-

Ingrediensinformasjon er ikke tilgjengelig.

+

A — INGREDIENSER

+

+ {product.ingredients?.trim() || + "Ingrediensinformasjon er ikke tilgjengelig."} +

-

B — ALLERGENER

+

B — ALLERGENER

+ + {product.allergens.length === 0 ? (

Allergeninformasjon er ikke tilgjengelig.

+ ) : containsAllergens.length === 0 && + traceAllergens.length === 0 ? ( +

Ingen oppgitte allergener.

+ ) : ( + <> + {containsAllergens.length > 0 && ( +

+ Inneholder: + {containsAllergens + .map((allergen) => allergen.displayName) + .join(", ")} +

+ )} + + {traceAllergens.length > 0 && ( +

+ Kan inneholde spor av: + {traceAllergens + .map((allergen) => allergen.displayName) + .join(", ")} +

+ )} + + )}
- {/* Høyre side: Produktinformasjon */} @@ -234,10 +271,29 @@ export default function ProductDetailsPage({ /> -
-

C — NÆRINGSINNHOLD

-

Næringsinnhold er ikke tilgjengelig.

-
+ +
+

C — NÆRINGSINNHOLD

+ + {product.nutrition.length > 0 ? ( + + + {product.nutrition.map((nutrient) => ( + + + + + ))} + +
{nutrient.displayName} + {nutrient.amount.toLocaleString("nb-NO")}{" "} + {nutrient.unit} +
+ ) : ( +

Næringsinnhold er ikke tilgjengelig.

+ )} +
+ diff --git a/frontend/src/pages/productDetails/productQueries.ts b/frontend/src/pages/productDetails/productQueries.ts index 83fca79..7eba68e 100644 --- a/frontend/src/pages/productDetails/productQueries.ts +++ b/frontend/src/pages/productDetails/productQueries.ts @@ -1,3 +1,4 @@ + import { gql } from "@apollo/client"; import type { TypedDocumentNode } from "@apollo/client"; @@ -16,6 +17,19 @@ export type Product = { unitPrice: number | null; url: string | null; }[]; + + ingredients: string | null; + + allergens: { + displayName: string; + contains: string; + }[]; + + nutrition: { + displayName: string; + amount: number; + unit: string; + }[]; }; type ProductQueryData = { @@ -46,6 +60,16 @@ export const PRODUCT_QUERY: TypedDocumentNode< unitPrice url } + ingredients + allergens { + displayName + contains + } + nutrition { + displayName + amount + unit + } } } `; \ No newline at end of file