1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 10:09:35 +01:00
effigenix/frontend/packages/api-client/src/resources/recipes.ts
Sebastian Frick ec736cf294 feat(frontend): TUI-Screens für Rezept-Filter, Archivierung und Chargen-Einbuchung
Production: Rezeptliste mit Status-Filter (Draft/Active/Archived), Rezept
archivieren für aktive Rezepte, list() gibt RecipeSummaryDTO zurück.
Inventory: Charge einbuchen (AddBatch) mit neuem Stocks-Resource und Screens.
2026-02-19 22:54:56 +01:00

86 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** Recipes resource Production BC. */
import type { AxiosInstance } from 'axios';
import type {
RecipeDTO,
RecipeSummaryDTO,
IngredientDTO,
ProductionStepDTO,
CreateRecipeRequest,
AddRecipeIngredientRequest,
AddProductionStepRequest,
} from '@effigenix/types';
export type RecipeType = 'RAW_MATERIAL' | 'INTERMEDIATE' | 'FINISHED_PRODUCT';
export type RecipeStatus = 'DRAFT' | 'ACTIVE' | 'ARCHIVED';
export const RECIPE_TYPE_LABELS: Record<RecipeType, string> = {
RAW_MATERIAL: 'Rohstoff',
INTERMEDIATE: 'Halbfabrikat',
FINISHED_PRODUCT: 'Fertigprodukt',
};
export type {
RecipeDTO,
RecipeSummaryDTO,
IngredientDTO,
ProductionStepDTO,
CreateRecipeRequest,
AddRecipeIngredientRequest,
AddProductionStepRequest,
};
// ── Resource factory ─────────────────────────────────────────────────────────
const BASE = '/api/recipes';
export function createRecipesResource(client: AxiosInstance) {
return {
async list(status?: RecipeStatus): Promise<RecipeSummaryDTO[]> {
const params: Record<string, string> = {};
if (status) params['status'] = status;
const res = await client.get<RecipeSummaryDTO[]>(BASE, { params });
return res.data;
},
async getById(id: string): Promise<RecipeDTO> {
const res = await client.get<RecipeDTO>(`${BASE}/${id}`);
return res.data;
},
async create(request: CreateRecipeRequest): Promise<RecipeDTO> {
const res = await client.post<RecipeDTO>(BASE, request);
return res.data;
},
async addIngredient(id: string, request: AddRecipeIngredientRequest): Promise<RecipeDTO> {
const res = await client.post<RecipeDTO>(`${BASE}/${id}/ingredients`, request);
return res.data;
},
async removeIngredient(recipeId: string, ingredientId: string): Promise<void> {
await client.delete(`${BASE}/${recipeId}/ingredients/${ingredientId}`);
},
async addProductionStep(id: string, request: AddProductionStepRequest): Promise<RecipeDTO> {
const res = await client.post<RecipeDTO>(`${BASE}/${id}/steps`, request);
return res.data;
},
async removeProductionStep(id: string, stepNumber: number): Promise<void> {
await client.delete(`${BASE}/${id}/steps/${stepNumber}`);
},
async activateRecipe(id: string): Promise<RecipeDTO> {
const res = await client.post<RecipeDTO>(`${BASE}/${id}/activate`);
return res.data;
},
async archiveRecipe(id: string): Promise<RecipeDTO> {
const res = await client.post<RecipeDTO>(`${BASE}/${id}/archive`);
return res.data;
},
};
}
export type RecipesResource = ReturnType<typeof createRecipesResource>;