parent
ed4236fd21
commit
803a8dac00
12 changed files with 344 additions and 203 deletions
140
src/lib/data/recipeService.ts
Normal file
140
src/lib/data/recipeService.ts
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
import {
|
||||
materialFromServerQuery,
|
||||
recipeData,
|
||||
recipeFromServerQuery,
|
||||
recipeOverviewData
|
||||
} from '$lib/core/stores/recipeStore';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
import type { RecipeOverview } from '../../routes/(authed)/recipe/overview/columns';
|
||||
|
||||
function getMenuStatus(ms: number): RecipeOverview['status'] {
|
||||
switch (ms) {
|
||||
case 0:
|
||||
return 'ready';
|
||||
case 2:
|
||||
return 'obsolete';
|
||||
case 11:
|
||||
return 'pending/online';
|
||||
case 12:
|
||||
return 'pending/offline';
|
||||
default:
|
||||
return 'drafted';
|
||||
}
|
||||
}
|
||||
|
||||
function getMenuCategory(pd: string): string {
|
||||
// [country_code]-[category_code]-[drink_Type]-[id]
|
||||
let pd_spl = pd.split('-');
|
||||
let category = pd_spl[1] ?? '';
|
||||
|
||||
if (category) {
|
||||
if (category.endsWith('1')) {
|
||||
let result = 'coffee';
|
||||
if (category === '01') {
|
||||
result += ',v1';
|
||||
} else {
|
||||
result += ',v2+';
|
||||
}
|
||||
|
||||
return result;
|
||||
} else if (category.endsWith('2')) {
|
||||
return 'tea';
|
||||
} else if (category.endsWith('3')) {
|
||||
return 'milk';
|
||||
} else if (category.endsWith('4')) {
|
||||
return 'whey';
|
||||
} else if (category.endsWith('5')) {
|
||||
return 'soda';
|
||||
} else if (category == '99') {
|
||||
return 'special';
|
||||
}
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
function getDrinkType(pd: string): string {
|
||||
// [country_code]-[category_code]-[drink_Type]-[id]
|
||||
let pd_spl = pd.split('-');
|
||||
let drink_type = pd_spl[2] ?? '';
|
||||
|
||||
if (drink_type) {
|
||||
if (drink_type.endsWith('1')) {
|
||||
return 'hot';
|
||||
} else if (drink_type.endsWith('2')) {
|
||||
return 'cold / iced';
|
||||
} else if (drink_type.endsWith('3')) {
|
||||
return 'smoothie / frappe';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// set material used in recipe to tags for using in filter
|
||||
function getMainMaterialOfRecipe(rp: any): string {
|
||||
let recipeList = rp['recipes'] ?? [];
|
||||
let mat_lists = '';
|
||||
|
||||
for (let rpl of recipeList) {
|
||||
let mat_id = rpl['materialPathId'];
|
||||
let mat_in_use = rpl['isUse'];
|
||||
|
||||
if (mat_in_use && !mat_lists.includes(mat_id)) {
|
||||
mat_lists += mat_id + ',';
|
||||
}
|
||||
}
|
||||
|
||||
mat_lists = mat_lists.substring(0, mat_lists.length - 1);
|
||||
|
||||
return mat_lists;
|
||||
}
|
||||
|
||||
function buildTags(rp: any): string {
|
||||
let result = '';
|
||||
|
||||
result += getMenuCategory(rp['productCode']);
|
||||
|
||||
let dt = getDrinkType(rp['productCode']);
|
||||
let mats = getMainMaterialOfRecipe(rp);
|
||||
|
||||
if (dt !== '') result += ',' + dt;
|
||||
if (mats !== '') result += ',' + mats;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function buildOverviewFromServer() {
|
||||
let server_recipe01 = get(recipeData);
|
||||
let result = [];
|
||||
|
||||
let r01_query: any = {};
|
||||
|
||||
if (server_recipe01) {
|
||||
recipeOverviewData.set([]);
|
||||
for (let rp of server_recipe01) {
|
||||
result.push({
|
||||
productCode: rp['productCode'] ?? '<not set>',
|
||||
name: rp['name'] ? rp['name'] : (rp['otherName'] ?? '<not set>'),
|
||||
description: rp['desciption'] ? rp['desciption'] : (rp['otherDescription'] ?? '<not set>'),
|
||||
tags: buildTags(rp),
|
||||
status: getMenuStatus(rp['MenuStatus'])
|
||||
});
|
||||
|
||||
r01_query[rp['productCode']] = rp;
|
||||
}
|
||||
|
||||
let currentQuery = get(recipeFromServerQuery);
|
||||
let currentMaterial = get(materialFromServerQuery);
|
||||
|
||||
currentQuery = {
|
||||
recipe: r01_query,
|
||||
material: currentMaterial
|
||||
};
|
||||
|
||||
recipeOverviewData.set(result);
|
||||
recipeFromServerQuery.set(currentQuery);
|
||||
}
|
||||
}
|
||||
|
||||
export { buildOverviewFromServer };
|
||||
Loading…
Add table
Add a link
Reference in a new issue