Files
syscom-master-admin-ui/src/app/features/global-masters/countries/data-access/country.service.ts
T

55 lines
1.7 KiB
TypeScript

import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import {
DataTableQuery,
DataTableResult,
} from '../../../../shared/components/data-table/data-table.types';
import {
CountryDto,
CountryLookupDto,
CreateCountryRequest,
UpdateCountryRequest,
UpdateCountryStatusRequest,
} from '../models/country.model';
import { COUNTRY_ENDPOINTS } from './country.endpoints';
@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);
}
updateStatus(id: string, request: UpdateCountryStatusRequest): Observable<CountryDto> {
return this.http.patch<CountryDto>(COUNTRY_ENDPOINTS.changeStatus(id), request);
}
delete(id: string): Observable<void> {
return this.http.delete<void>(COUNTRY_ENDPOINTS.delete(id));
}
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),
});
}
}