This commit is contained in:
pakintada@gmail.com 2023-12-29 16:11:14 +07:00
commit 8568004d36
9 changed files with 79 additions and 8 deletions

View 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
}
}