Files
syscom-master-admin-ui/src/app/core/services/country/country.service.ts
T

44 lines
1.5 KiB
TypeScript

import { HttpClient, HttpParams } from "@angular/common/http";
import { Injectable, inject } from "@angular/core";
import { COUNTRY_ENDPOINTS } from "../../../core/end-points/country/country.endpoints";
import { Observable } from "rxjs";
import { DataTableQuery, DataTableResult } from "../../../shared/components/data-table/data-table.types";
import {
CountryDto,
CountryLookupDto,
CreateCountryRequest,
UpdateCountryRequest
} from "../../models/country/country.model";
@Injectable({
providedIn: 'root'
})
export class CountryService {
private readonly http = inject(HttpClient);
getCountryDataTable(query: DataTableQuery): Observable<DataTableResult<CountryDto>> {
return this.http.post<DataTableResult<CountryDto>>(`${COUNTRY_ENDPOINTS.dataTable}`, query);
}
createCountry(request: CreateCountryRequest): Observable<CountryDto> {
return this.http.post<CountryDto>(COUNTRY_ENDPOINTS.create, request);
}
updateCountry(id: string, request: UpdateCountryRequest): Observable<CountryDto> {
return this.http.put<CountryDto>(COUNTRY_ENDPOINTS.update(id), request);
}
getCountryById(id: string): Observable<CountryDto> {
return this.http.get<CountryDto>(COUNTRY_ENDPOINTS.getById(id));
}
autocomplete(term = '', limit = 50): Observable<CountryLookupDto[]> {
return this.http.get<CountryLookupDto[]>(COUNTRY_ENDPOINTS.autocomplete, {
params: new HttpParams()
.set('term', term)
.set('limit', limit)
});
}
}