Taobin-Recipe-Manager/client/src/app/core/services/material.service.ts

64 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-10-06 15:33:10 +07:00
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';
@Injectable({ providedIn: 'root' })
export class MaterialService {
constructor(private _httpClient: HttpClient) {}
getMaterialCodes(
matIds?: number[],
2023-10-24 18:01:52 +07:00
country?: string,
filename?: string
2023-10-06 15:33:10 +07:00
): Observable<MaterialCode[]> {
return this._httpClient.get<MaterialCode[]>(
`${environment.api}/materials/code`,
{
params: {
2023-10-27 16:13:04 +07:00
country: country || this.getCurrentCountry(),
filename: filename || this.getCurrentFile(),
2023-10-06 15:33:10 +07:00
mat_ids: matIds?.join(',') || '',
},
withCredentials: true,
}
);
}
getMaterialSettingById(
id: number,
2023-10-24 18:01:52 +07:00
country?: string,
filename?: string
2023-10-06 15:33:10 +07:00
): Observable<MaterialSetting> {
return this._httpClient.get<MaterialSetting>(
`${environment.api}/materials/setting/${id}`,
{
params: {
2023-10-27 16:13:04 +07:00
country: country || this.getCurrentCountry(),
filename: filename || this.getCurrentFile(),
2023-10-06 15:33:10 +07:00
},
withCredentials: true,
}
);
}
2023-10-27 16:13:04 +07:00
getCurrentFile(): string {
const currentRecipeFile = localStorage.getItem('currentRecipeFile');
if (currentRecipeFile) {
return currentRecipeFile;
}
return 'coffeethai02_580.json';
}
getCurrentCountry(): string {
const currentRecipeCountry = localStorage.getItem('currentRecipeCountry');
if (currentRecipeCountry) {
return currentRecipeCountry;
}
return 'Thailand';
}
2023-10-06 15:33:10 +07:00
}