Files
data-entry-app/frontend/src/routes/mixes/[id]/+page.ts
T

41 lines
888 B
TypeScript
Raw Normal View History

2026-04-25 22:51:36 +12:00
import { error } from '@sveltejs/kit';
import { api } from '$lib/api';
import { getStoredClientSession, hasModuleAccess, hasStoredClientSession } from '$lib/session';
2026-04-25 22:51:36 +12:00
2026-04-27 21:53:36 +12:00
export async function load({ params, fetch }) {
2026-04-25 22:51:36 +12:00
const mixId = Number(params.id);
if (!Number.isFinite(mixId)) {
throw error(404, 'Mix not found');
}
if (!hasStoredClientSession()) {
return {
mix: null,
rawMaterials: []
};
}
const session = getStoredClientSession();
if (!hasModuleAccess(session, 'mix_master')) {
return {
mix: null,
rawMaterials: []
};
}
2026-04-25 22:51:36 +12:00
try {
const [mix, rawMaterials] = await Promise.all([
api.mix(mixId, fetch),
hasModuleAccess(session, 'raw_materials') ? api.rawMaterials(fetch) : Promise.resolve([])
]);
2026-04-25 22:51:36 +12:00
return {
mix,
rawMaterials
};
} catch {
throw error(404, 'Mix not found');
}
}