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

39 lines
993 B
TypeScript
Raw Normal View History

2026-05-10 09:46:07 +12:00
import { error, redirect } from '@sveltejs/kit';
2026-04-25 22:51:36 +12:00
import { api } from '$lib/api';
import { getStoredClientSession, hasModuleAccess, hasStoredClientSession } from '$lib/session';
2026-05-10 09:46:07 +12:00
import { canOpenMixMaster, getWorkspaceHomeHref } from '$lib/workspace-access';
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();
2026-05-10 09:46:07 +12:00
if (!canOpenMixMaster(session)) {
throw redirect(307, getWorkspaceHomeHref(session));
}
2026-04-25 22:51:36 +12:00
try {
const [mix, rawMaterials] = await Promise.all([
api.mix(mixId, fetch),
2026-05-10 09:46:07 +12:00
hasModuleAccess(session, 'raw_materials') || session?.role === 'internal' ? api.rawMaterials(fetch) : Promise.resolve([])
]);
2026-04-25 22:51:36 +12:00
return {
mix,
rawMaterials
};
} catch {
throw error(404, 'Mix not found');
}
}