fix country params

This commit is contained in:
pakintada@gmail.com 2024-01-19 14:59:21 +07:00
parent 4ece2cf30c
commit 09d71ac61e
13 changed files with 299 additions and 242 deletions

View file

@ -2,7 +2,7 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { MaterialCode, MaterialSetting } from '../models/recipe.model';
import { environment } from 'src/environments/environment';
import { Observable } from 'rxjs';
import { Observable, count } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe';
import { AsyncStorage } from 'src/app/shared/helpers/asyncStorage';
@ -44,11 +44,13 @@ export class MaterialService {
"name": string,
"type": string
}[] | null>>{
console.log("getFullMaterialDetail", country, filename, country || this.getCurrentCountry(this.department!));
console.log("getFullMaterialDetail", country, "where filename = ",filename, "department.short = ", this.department!);
let asyncCountry = await AsyncStorage.getItem<string>('currentRecipeCountry');
let currentCountryWithoutDepartment = await this.getCurrentCountry();
let asyncCountry = await this.getCurrentCountry(this.department!);
country = country || asyncCountry;
console.log("[FullMatFetchService] get current country = ", currentCountryWithoutDepartment, " do switch tuple = ", getCountryMapSwitcher(currentCountryWithoutDepartment));
country = getCountryMapSwitcher(currentCountryWithoutDepartment);
filename = filename || this.getCurrentFile();
// finalize fetch from what?
@ -102,6 +104,8 @@ export class MaterialService {
console.log('Material.service::fullname: ', fullname);
await AsyncStorage.setItem('currentRecipeCountry', fullname);
// localStorage.setItem('currentRecipeCountry', fullname);
return fullname;
}

View file

@ -96,12 +96,16 @@ export class RecipeService {
}
async getRecipeDetail(productCode: string): Promise<Observable<RecipeDetail>> {
let asyncCountry = await this.getCurrentCountry(this.department!);
console.log('get detail by asyncCountry', asyncCountry);
return this._httpClient.get<RecipeDetail>(
environment.api + '/recipes/' + productCode,
{
params: {
filename: this.getCurrentFile(),
country: await this.getCurrentCountry(this.department!),
country: asyncCountry,
},
withCredentials: true,
responseType: 'json',
@ -112,12 +116,15 @@ export class RecipeService {
async getRecipeDetailMat(
productCode: string
): Promise<Observable<{ result: RecipeDetailMat[]; }>> {
let asyncCountry = await this.getCurrentCountry(this.department!);
return this._httpClient.get<{ result: RecipeDetailMat[] }>(
environment.api + '/recipes/' + productCode + '/mat',
{
params: {
filename: this.getCurrentFile(),
country: await this.getCurrentCountry(this.department!),
country: asyncCountry,
},
withCredentials: true,
responseType: 'json',
@ -251,6 +258,7 @@ export class RecipeService {
}
getSubMenus(country: string, filename: string, productCode: string) {
console.log('getSubMenus', country, filename, productCode);
return this._httpClient.get<Recipe01[]>(
environment.api +
'/recipes/' +

View file

@ -1,16 +1,22 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Observable, count } from 'rxjs';
import { environment } from 'src/environments/environment';
import { Topping, ToppingSet } from '../models/recipe.model';
import { RecipeService } from './recipe.service';
import { getCountryMapSwitcher } from 'src/app/shared/helpers/recipe';
@Injectable({
providedIn: 'root',
})
export class ToppingService {
constructor(private _httpClient: HttpClient) {}
constructor(private _httpClient: HttpClient, private _recipeService: RecipeService) {}
getToppings(country: string, filename: string): Observable<Topping> {
async getToppings(country: string, filename: string): Promise<Observable<Topping>> {
console.log("getToppings", country);
let asyncCountry = await this._recipeService.getCurrentCountry();
country = getCountryMapSwitcher(asyncCountry);
console.log("getToppingsPreFetch", country, asyncCountry);
return this._httpClient.get<Topping>(
`${environment.api}/recipes/${country}/${filename}/toppings`,
{
@ -23,7 +29,11 @@ export class ToppingService {
);
}
getToppingsOfRecipe(country: string, filename: string, productCode: string): Observable<ToppingSet[]> {
async getToppingsOfRecipe(country: string, filename: string, productCode: string): Promise<Observable<ToppingSet[]>> {
console.log("getToppingsOfRecipe", country);
let asyncCountry = await this._recipeService.getCurrentCountry();
country = country || asyncCountry;
console.log("getToppingsOfRecipePreFetch", country, asyncCountry);
return this._httpClient.get<ToppingSet[]>(
`${environment.api}/recipes/${country}/${filename}/${productCode}/toppings`,
{