164 lines
4.8 KiB
TypeScript
164 lines
4.8 KiB
TypeScript
import { Injectable } from "@angular/core";
|
|
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
|
import { Observable } from "rxjs";
|
|
|
|
const httpOptions = {
|
|
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
|
|
};
|
|
|
|
@Injectable({
|
|
providedIn: "root",
|
|
})
|
|
export class BuildingService {
|
|
private readonly apiBaseURL = 'https://kapi.absys.ninja/hemat';
|
|
private readonly apiKey = 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT';
|
|
private readonly headers = new HttpHeaders({
|
|
"Content-Type": "application/json",
|
|
"x-api-key": this.apiKey,
|
|
});
|
|
|
|
loadDataIcon = null;
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
private get<T>(endpoint: string, params: any = {}): Observable<T> {
|
|
const url = `${this.apiBaseURL}/${endpoint}`;
|
|
return this.http.get<T>(url, { headers: this.headers, params });
|
|
}
|
|
|
|
private post<T>(endpoint: string, data: any): Observable<T> {
|
|
const url = `${this.apiBaseURL}/${endpoint}`;
|
|
return this.http.post<T>(url, data, { headers: this.headers });
|
|
}
|
|
|
|
private put<T>(endpoint: string, data: any): Observable<T> {
|
|
const url = `${this.apiBaseURL}/${endpoint}`;
|
|
return this.http.put<T>(url, data, { headers: this.headers });
|
|
}
|
|
|
|
private delete<T>(endpoint: string, params: any = {}): Observable<T> {
|
|
const url = `${this.apiBaseURL}/${endpoint}`;
|
|
return this.http.delete<T>(url, { headers: this.headers, params });
|
|
}
|
|
|
|
postLogin(data: any): Observable<any> {
|
|
return this.post<any>('users/login', data);
|
|
}
|
|
|
|
listBuilding(): Observable<any> {
|
|
return this.get<any>('building/dashboard/list');
|
|
}
|
|
|
|
getRoomByBuildingId(buildingId: string): Observable<any> {
|
|
return this.get<any>('room-building/list/byIds', { buildingId });
|
|
}
|
|
|
|
getDeviceById(deviceId: string): Observable<any> {
|
|
return this.get<any>(`devices/${deviceId}`);
|
|
}
|
|
|
|
getMasterListData(): Observable<any> {
|
|
return this.get<any>('header-param/list');
|
|
}
|
|
|
|
getMasterData(page: number = 1, limit: number = 100): Observable<any> {
|
|
return this.get<any>('header-param', { page, limit });
|
|
}
|
|
|
|
getMasterDataListFloor(buildingId: string): Observable<any> {
|
|
return this.get<any>('header-detail-param/list', { headerId: 6, building_id: buildingId });
|
|
}
|
|
|
|
getMasterBuildingData(page: number = 1, limit: number = 100): Observable<any> {
|
|
return this.get<any>('building', { page, limit });
|
|
}
|
|
|
|
getBuildingList(): Observable<any> {
|
|
return this.get<any>('building/list');
|
|
}
|
|
|
|
getListRoomData(): Observable<any> {
|
|
return this.get<any>('room/list');
|
|
}
|
|
|
|
getListRoomDataUnmap(): Observable<any> {
|
|
return this.get<any>('room/list/unmap');
|
|
}
|
|
|
|
getListFloorDataUnmap(id: any): Observable<any> {
|
|
return this.get<any>('header-detail-param/list/unmap-room-building', { headerId: id });
|
|
}
|
|
|
|
getMasterRoomData(page: number = 1, limit: number = 100): Observable<any> {
|
|
return this.get<any>('room', { page, limit });
|
|
}
|
|
|
|
getCostManagement(page: number = 1, limit: number = 100): Observable<any> {
|
|
return this.get<any>('cost_management', { page, limit, building_id: 4, periode: '2024-06' });
|
|
}
|
|
|
|
postHeaderDetailParam(data: any): Observable<any> {
|
|
return this.post<any>('header-detail-param', data);
|
|
}
|
|
|
|
putHeaderDetailParam(data: any, id: string): Observable<any> {
|
|
return this.put<any>(`header-detail-param/${id}`, data);
|
|
}
|
|
|
|
deleteHeaderDetailParam(id: string): Observable<any> {
|
|
return this.delete<any>(`header-detail-param/${id}`);
|
|
}
|
|
|
|
postMasterBuildingParam(data: any): Observable<any> {
|
|
return this.post<any>('building', data);
|
|
}
|
|
|
|
putMasterBuildingParam(data: any, id: string): Observable<any> {
|
|
return this.put<any>(`building/${id}`, data);
|
|
}
|
|
|
|
deleteMasterBuildingParam(id: string): Observable<any> {
|
|
return this.delete<any>(`building/${id}`);
|
|
}
|
|
|
|
postMasterRoomParam(data: any): Observable<any> {
|
|
return this.post<any>('room', data);
|
|
}
|
|
|
|
putMasterRoomParam(data: any, id: string): Observable<any> {
|
|
return this.put<any>(`room/${id}`, data);
|
|
}
|
|
|
|
deleteRoom(id: string): Observable<any> {
|
|
return this.delete<any>(`room/${id}`);
|
|
}
|
|
|
|
postBatchBuilding(data: any): Observable<any> {
|
|
return this.post<any>('room-building/post-batch/room', data);
|
|
}
|
|
|
|
getBuildingRoomList(page: number = 1, limit: number = 1000): Observable<any> {
|
|
return this.get<any>('room-building', { page, limit });
|
|
}
|
|
|
|
putBuildingRoom(data: any, id: string): Observable<any> {
|
|
return this.put<any>(`room-building/${id}`, data);
|
|
}
|
|
|
|
putDevice(data: any, id: string): Observable<any> {
|
|
return this.put<any>(`devices/${id}`, data);
|
|
}
|
|
|
|
getRoomBuildingById(roomBuildingId: string): Observable<any> {
|
|
return this.get<any>(`room-building/${roomBuildingId}`);
|
|
}
|
|
|
|
deleteRoomBuilding(id: string): Observable<any> {
|
|
return this.delete<any>(`room-building/${id}`);
|
|
}
|
|
|
|
getIconData(): Observable<any> {
|
|
return this.http.get(this.loadDataIcon, httpOptions);
|
|
}
|
|
}
|