From 2a0da005ff91d3b92c192c54f6b96cca78c03701 Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Thu, 16 Apr 2026 21:22:34 +0200 Subject: [PATCH] feat: add receiptName field to InventoryItem model and update related DTOs and service --- .../migration.sql | 2 ++ backend/prisma/schema.prisma | 1 + backend/src/inventory/dto/create-inventory.dto.ts | 4 ++++ backend/src/inventory/dto/update-inventory.dto.ts | 4 ++++ backend/src/inventory/inventory.service.ts | 5 +++++ data/seed_products.sql | 7 +++++++ frontend/app/kvitto/ReceiptImportClient.tsx | 4 ++-- 7 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 backend/prisma/migrations/20260416210000_add_receipt_name_to_inventory/migration.sql diff --git a/backend/prisma/migrations/20260416210000_add_receipt_name_to_inventory/migration.sql b/backend/prisma/migrations/20260416210000_add_receipt_name_to_inventory/migration.sql new file mode 100644 index 00000000..f5f4b00a --- /dev/null +++ b/backend/prisma/migrations/20260416210000_add_receipt_name_to_inventory/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE `InventoryItem` ADD COLUMN `receiptName` VARCHAR(191) NULL; diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 5604a034..dbd84bae 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -30,6 +30,7 @@ model InventoryItem { quantity Decimal @db.Decimal(10, 2) unit String brand String? + receiptName String? location String? priority Int? purchaseDate DateTime? diff --git a/backend/src/inventory/dto/create-inventory.dto.ts b/backend/src/inventory/dto/create-inventory.dto.ts index 50d177a1..87f578e5 100644 --- a/backend/src/inventory/dto/create-inventory.dto.ts +++ b/backend/src/inventory/dto/create-inventory.dto.ts @@ -36,6 +36,10 @@ export class CreateInventoryDto { @IsString() brand?: string; + @IsOptional() + @IsString() + receiptName?: string; + @IsOptional() @IsBoolean() opened?: boolean; diff --git a/backend/src/inventory/dto/update-inventory.dto.ts b/backend/src/inventory/dto/update-inventory.dto.ts index f3360d48..c3511107 100644 --- a/backend/src/inventory/dto/update-inventory.dto.ts +++ b/backend/src/inventory/dto/update-inventory.dto.ts @@ -39,6 +39,10 @@ export class UpdateInventoryDto { @IsString() brand?: string; + @IsOptional() + @IsString() + receiptName?: string; + @IsOptional() @IsBoolean() opened?: boolean; diff --git a/backend/src/inventory/inventory.service.ts b/backend/src/inventory/inventory.service.ts index 12a11a68..4dc4ee98 100644 --- a/backend/src/inventory/inventory.service.ts +++ b/backend/src/inventory/inventory.service.ts @@ -143,6 +143,7 @@ export class InventoryService { quantity: new Prisma.Decimal(data.quantity), location: data.location?.trim() || undefined, brand: data.brand?.trim() || undefined, + receiptName: data.receiptName?.trim() || undefined, suitableFor: data.suitableFor?.trim() || undefined, comment: data.comment?.trim() || undefined, purchaseDate: data.purchaseDate @@ -200,6 +201,10 @@ export class InventoryService { if (typeof data.brand === 'string') { updateData.brand = data.brand.trim(); } + + if (typeof data.receiptName === 'string') { + updateData.receiptName = data.receiptName.trim(); + } if (typeof data.priority === 'number') { updateData.priority = data.priority; diff --git a/data/seed_products.sql b/data/seed_products.sql index 7a3f1a2f..70140299 100644 --- a/data/seed_products.sql +++ b/data/seed_products.sql @@ -24,6 +24,7 @@ INSERT IGNORE INTO `Product` (`name`, `normalizedName`, `isActive`, `createdAt`, ('Chips', 'chips', 1, NOW(), NOW()), ('Choklad', 'choklad', 1, NOW(), NOW()), ('Citron', 'citron', 1, NOW(), NOW()), +('Crème fraiche', 'cremefraiche', 1, NOW(), NOW()), ('Curry (mild)', 'currymild', 1, NOW(), NOW()), ('Curry (stark)', 'currystark', 1, NOW(), NOW()), ('Dill', 'dill', 1, NOW(), NOW()), @@ -54,6 +55,7 @@ INSERT IGNORE INTO `Product` (`name`, `normalizedName`, `isActive`, `createdAt`, ('Grädde', 'gradde', 1, NOW(), NOW()), ('Gräddfil', 'graddfil', 1, NOW(), NOW()), ('Grönkål', 'gronkal', 1, NOW(), NOW()), +('Gröna druvor', 'gronadruvor', 1, NOW(), NOW()), ('Gurka', 'gurka', 1, NOW(), NOW()), ('Gås', 'gas', 1, NOW(), NOW()), ('Hallon', 'hallon', 1, NOW(), NOW()), @@ -111,12 +113,15 @@ INSERT IGNORE INTO `Product` (`name`, `normalizedName`, `isActive`, `createdAt`, ('Lime', 'lime', 1, NOW(), NOW()), ('Linser', 'linser', 1, NOW(), NOW()), ('Läsk', 'lask', 1, NOW(), NOW()), +('Lättmjölk', 'lattmjolk', 1, NOW(), NOW()), ('Lök', 'lok', 1, NOW(), NOW()), ('Macka', 'macka', 1, NOW(), NOW()), ('Majonnäs', 'majonnas', 1, NOW(), NOW()), ('Malen kanel', 'malenkanel', 1, NOW(), NOW()), ('Malet kummin', 'maletkummin', 1, NOW(), NOW()), ('Mango', 'mango', 1, NOW(), NOW()), +('Marmelad', 'marmelad', 1, NOW(), NOW()), +('Mellanmjölk', 'mellanmjolk', 1, NOW(), NOW()), ('Mjöl', 'mjol', 1, NOW(), NOW()), ('Mjölk', 'mjolk', 1, NOW(), NOW()), ('Morot', 'morot', 1, NOW(), NOW()), @@ -150,6 +155,7 @@ INSERT IGNORE INTO `Product` (`name`, `normalizedName`, `isActive`, `createdAt`, ('Russin', 'russin', 1, NOW(), NOW()), ('Räkor', 'rakor', 1, NOW(), NOW()), ('Råbiff', 'rabiff', 1, NOW(), NOW()), +('Röda druvor', 'rodadruvor', 1, NOW(), NOW()), ('Rödbeta', 'rodbeta', 1, NOW(), NOW()), ('Rödlök', 'rodlok', 1, NOW(), NOW()), ('Rökt paprikapulver', 'roktpaprikapulver', 1, NOW(), NOW()), @@ -163,6 +169,7 @@ INSERT IGNORE INTO `Product` (`name`, `normalizedName`, `isActive`, `createdAt`, ('Socker', 'socker', 1, NOW(), NOW()), ('Spaghetti', 'spaghetti', 1, NOW(), NOW()), ('Spenat', 'spenat', 1, NOW(), NOW()), +('Standardmjölk', 'standardmjolk', 1, NOW(), NOW()), ('Stark paprikapulver', 'starkpaprikapulver', 1, NOW(), NOW()), ('Strömming', 'stromming', 1, NOW(), NOW()), ('Svartpeppar', 'svartpeppar', 1, NOW(), NOW()), diff --git a/frontend/app/kvitto/ReceiptImportClient.tsx b/frontend/app/kvitto/ReceiptImportClient.tsx index cf25785d..67425362 100644 --- a/frontend/app/kvitto/ReceiptImportClient.tsx +++ b/frontend/app/kvitto/ReceiptImportClient.tsx @@ -162,7 +162,7 @@ export default function ReceiptImportClient() { productId: r.selectedProductId, quantity: parseFloat(r.editQty) || r.quantity, unit: r.editUnit, - brand: r.rawName, + receiptName: r.rawName, }), }), ), @@ -299,4 +299,4 @@ export default function ReceiptImportClient() { function primaryBtn(disabled: boolean): React.CSSProperties { return { padding: '0.6rem 1.25rem', background: disabled ? '#aaa' : '#0070f3', color: '#fff', border: 'none', borderRadius: '6px', cursor: disabled ? 'not-allowed' : 'pointer', fontWeight: 600, fontSize: '0.95rem' }; -} +}