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';
|
2026-04-29 01:21:16 +12:00
|
|
|
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: []
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 01:21:16 +12:00
|
|
|
const session = getStoredClientSession();
|
2026-05-10 09:46:07 +12:00
|
|
|
if (!canOpenMixMaster(session)) {
|
|
|
|
|
throw redirect(307, getWorkspaceHomeHref(session));
|
2026-04-29 01:21:16 +12:00
|
|
|
}
|
|
|
|
|
|
2026-04-25 22:51:36 +12:00
|
|
|
try {
|
2026-04-29 01:21:16 +12:00
|
|
|
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-29 01:21:16 +12:00
|
|
|
]);
|
2026-04-25 22:51:36 +12:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
mix,
|
|
|
|
|
rawMaterials
|
|
|
|
|
};
|
|
|
|
|
} catch {
|
|
|
|
|
throw error(404, 'Mix not found');
|
|
|
|
|
}
|
|
|
|
|
}
|