39 lines
978 B
TypeScript
39 lines
978 B
TypeScript
|
|
import { get } from 'svelte/store';
|
||
|
|
import { departmentStore } from '../stores/departments';
|
||
|
|
import { sendMessage } from '../handlers/ws_messageSender';
|
||
|
|
import { auth } from '../stores/auth';
|
||
|
|
import { extractCookieOnNonBrowser } from '$lib/helpers/cookie';
|
||
|
|
import { browser } from '$app/environment';
|
||
|
|
|
||
|
|
export async function getRecipes() {
|
||
|
|
if (browser && !get(departmentStore)) {
|
||
|
|
console.log('cannot get dep', get(departmentStore));
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
|
||
|
|
let countryTarget = get(departmentStore);
|
||
|
|
let country = '';
|
||
|
|
|
||
|
|
// if (!countryTarget && !browser) {
|
||
|
|
// countryTarget = extractCookieOnNonBrowser()['department'];
|
||
|
|
// }
|
||
|
|
|
||
|
|
// construct path. fetch (GET) {server}/recipe/{countryTarget}/{version}
|
||
|
|
let idToken = await get(auth)?.getIdToken();
|
||
|
|
|
||
|
|
console.log('country target get recipe', country);
|
||
|
|
|
||
|
|
sendMessage({
|
||
|
|
type: 'recipe',
|
||
|
|
payload: {
|
||
|
|
auth: idToken ?? '',
|
||
|
|
partial: false,
|
||
|
|
country: countryTarget ?? '',
|
||
|
|
version: -1,
|
||
|
|
parameters: ''
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
return [];
|
||
|
|
}
|