Merge branch 'main' of https://github.com/Poomipat-Ch/taobin_recipe_manager
This commit is contained in:
commit
8568004d36
9 changed files with 79 additions and 8 deletions
26
client/src/app/core/services/department.service.ts
Normal file
26
client/src/app/core/services/department.service.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {
|
||||
BehaviorSubject, lastValueFrom, Observable,
|
||||
} from 'rxjs';
|
||||
import {environment} from "../../../environments/environment";
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class DepartmentService {
|
||||
private departmentSubject = new BehaviorSubject<string | null>(null);
|
||||
|
||||
constructor(private readonly http: HttpClient) {}
|
||||
|
||||
private _getDepartment(): Observable<{result: string[]}> {
|
||||
return this.http.get<{result: string[]}>(environment.api + "/departments", {
|
||||
withCredentials: true,
|
||||
})
|
||||
}
|
||||
|
||||
async fetchDepartment() : Promise<string[]> {
|
||||
return lastValueFrom(this._getDepartment()).then(({result}) => result).catch(err => {throw err})
|
||||
}
|
||||
|
||||
get currentDepartment(): string | null {
|
||||
return this.departmentSubject.value
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue