Files
data-entry-app/frontend/src/routes/mixes/new/+page.ts
T

31 lines
817 B
TypeScript
Raw Normal View History

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