Implement recipe retrieval methods and enhance inventory item types for better data handling
This commit is contained in:
@@ -270,4 +270,35 @@ export class RecipesService {
|
|||||||
summary,
|
summary,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findAll() {
|
||||||
|
return this.prisma.recipe.findMany({
|
||||||
|
include: {
|
||||||
|
ingredients: {
|
||||||
|
include: {
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async findOne(id: number) {
|
||||||
|
const recipe = await this.prisma.recipe.findUnique({
|
||||||
|
where: { id },
|
||||||
|
include: {
|
||||||
|
ingredients: {
|
||||||
|
include: {
|
||||||
|
product: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!recipe) {
|
||||||
|
throw new NotFoundException(`Recipe with id ${id} not found`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,13 @@ const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:
|
|||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
const id = request.nextUrl.searchParams.get('id');
|
const id = request.nextUrl.searchParams.get('id');
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: 'Missing id parameter' },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const res = await fetch(`${API_BASE}/api/recipes/${id}/inventory-preview`, {
|
const res = await fetch(`${API_BASE}/api/recipes/${id}/inventory-preview`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
|
|||||||
@@ -80,11 +80,18 @@ export type RecipePreviewInventoryItem = {
|
|||||||
id: number;
|
id: number;
|
||||||
quantity: string;
|
quantity: string;
|
||||||
unit: string;
|
unit: string;
|
||||||
brand?: string | null;
|
};
|
||||||
location?: string | null;
|
|
||||||
bestBeforeDate?: string | null;
|
export type RecipePreviewMatchingInventoryItem = RecipePreviewInventoryItem & {
|
||||||
canConvert?: boolean;
|
brand: string | null;
|
||||||
convertedQuantity?: number;
|
location: string | null;
|
||||||
|
bestBeforeDate: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type RecipePreviewOtherInventoryItem = RecipePreviewInventoryItem & {
|
||||||
|
location: string | null;
|
||||||
|
canConvert: boolean;
|
||||||
|
convertedQuantity: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RecipeInventoryPreviewIngredient = {
|
export type RecipeInventoryPreviewIngredient = {
|
||||||
@@ -96,8 +103,8 @@ export type RecipeInventoryPreviewIngredient = {
|
|||||||
note: string | null;
|
note: string | null;
|
||||||
availableQuantity: number;
|
availableQuantity: number;
|
||||||
availableUnit: string | null;
|
availableUnit: string | null;
|
||||||
matchingInventoryItems: RecipePreviewInventoryItem[];
|
matchingInventoryItems: RecipePreviewMatchingInventoryItem[];
|
||||||
otherInventoryItems: RecipePreviewInventoryItem[];
|
otherInventoryItems: RecipePreviewOtherInventoryItem[];
|
||||||
status: 'enough' | 'missing' | 'unit_mismatch';
|
status: 'enough' | 'missing' | 'unit_mismatch';
|
||||||
missingQuantity: number;
|
missingQuantity: number;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user