feat: add location field to PantryItem model and update related functionality
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `PantryItem`
|
||||
ADD COLUMN `location` VARCHAR(191) NULL;
|
||||
@@ -172,6 +172,7 @@ model PantryItem {
|
||||
id Int @id @default(autoincrement())
|
||||
userId Int
|
||||
productId Int
|
||||
location String?
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { IsInt, IsPositive } from 'class-validator';
|
||||
import { IsInt, IsOptional, IsPositive, IsString, MaxLength } from 'class-validator';
|
||||
|
||||
export class CreatePantryItemDto {
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
productId: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(50)
|
||||
location?: string;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,11 @@ export class PantryService {
|
||||
}
|
||||
|
||||
return this.prisma.pantryItem.create({
|
||||
data: { userId, productId: data.productId },
|
||||
data: {
|
||||
userId,
|
||||
productId: data.productId,
|
||||
location: data.location?.trim() || null,
|
||||
},
|
||||
include: { product: true },
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user