we_bstly-web/src/app/services/borrow.service.ts
2021-10-27 17:07:44 +02:00

106 lines
3.0 KiB
TypeScript

import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root',
})
export class BorrowItemsService {
constructor(private http: HttpClient) {
}
getItems(page: number, size: number, sort: string, desc: boolean, search: string, owner: boolean) {
let httpParams = new HttpParams();
if (page != undefined) {
httpParams = httpParams.set("page", "" + page);
}
if (size != undefined) {
httpParams = httpParams.set("size", "" + size);
}
if (sort != undefined) {
httpParams = httpParams.set("sort", sort);
}
if (desc != undefined) {
httpParams = httpParams.set("desc", "" + desc);
}
if (search != undefined) {
httpParams = httpParams.set("search", "" + search);
}
if (owner != undefined && owner) {
httpParams = httpParams.set("owner", "" + owner);
}
return this.http.get(environment.apiUrl + "/borrow/items", { params: httpParams });
}
getItem(id) {
return this.http.get(environment.apiUrl + "/borrow/items/" + id);
}
createOrUpdateItem(borrowItem) {
return this.http.post(environment.apiUrl + "/borrow/items", borrowItem);
}
deleteItem(id) {
return this.http.delete(environment.apiUrl + "/borrow/items/" + id);
}
}
@Injectable({
providedIn: 'root',
})
export class BorrowRequestsService {
constructor(private http: HttpClient) {
}
getRequests(page: number, size: number, sort: string, desc: boolean, owner: boolean) {
let httpParams = new HttpParams();
if (page != undefined) {
httpParams = httpParams.set("page", "" + page);
}
if (size != undefined) {
httpParams = httpParams.set("size", "" + size);
}
if (sort != undefined) {
httpParams = httpParams.set("sort", sort);
}
if (desc != undefined) {
httpParams = httpParams.set("desc", "" + desc);
}
if (owner != undefined && owner) {
httpParams = httpParams.set("owner", "" + owner);
}
return this.http.get(environment.apiUrl + "/borrow/requests", { params: httpParams });
}
createOrUpdateRequest(borrowRequest) {
return this.http.post(environment.apiUrl + "/borrow/requests", borrowRequest);
}
deleteRequest(id) {
return this.http.delete(environment.apiUrl + "/borrow/requests/" + id);
}
setRequestStatus(borrowRequest) {
return this.http.put(environment.apiUrl + "/borrow/requests", borrowRequest);
}
getRequestCode(id) {
return this.http.get(environment.apiUrl + "/borrow/requests/code/" + id);
}
verifyRequest(serialized) {
return this.http.post(environment.apiUrl + "/borrow/requests/verify", serialized);
}
}