30 lines
586 B
TypeScript
30 lines
586 B
TypeScript
|
|
import { error } from '@sveltejs/kit';
|
||
|
|
import { api } from '$lib/api';
|
||
|
|
import { hasStoredClientSession } from '$lib/session';
|
||
|
|
|
||
|
|
export async function load({ params }) {
|
||
|
|
const mixId = Number(params.id);
|
||
|
|
|
||
|
|
if (!Number.isFinite(mixId)) {
|
||
|
|
throw error(404, 'Mix not found');
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!hasStoredClientSession()) {
|
||
|
|
return {
|
||
|
|
mix: null,
|
||
|
|
rawMaterials: []
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
const [mix, rawMaterials] = await Promise.all([api.mix(mixId), api.rawMaterials()]);
|
||
|
|
|
||
|
|
return {
|
||
|
|
mix,
|
||
|
|
rawMaterials
|
||
|
|
};
|
||
|
|
} catch {
|
||
|
|
throw error(404, 'Mix not found');
|
||
|
|
}
|
||
|
|
}
|