98 lines
2.9 KiB
TypeScript
98 lines
2.9 KiB
TypeScript
import { Injectable, Inject } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { LotInfo } from './model/lotInfo.interface';
|
|
import { SaleInfo } from './model/saleInfo.interface';
|
|
import { Sale } from './model/sale.interface';
|
|
import { Lot } from './model/lot.interface';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class apiService {
|
|
ApiURL = "http://localhost:3000/api";
|
|
|
|
constructor(private http: HttpClient){}
|
|
|
|
// Lot
|
|
getLotInfo(url: string): Observable<LotInfo> {
|
|
let encodeUrl = encodeURIComponent(url);
|
|
return this.http.get<LotInfo>(this.ApiURL+'/lot/getInfos/'+encodeUrl);
|
|
}
|
|
|
|
getPictures(url: string): Observable<String[]> {
|
|
let encodeUrl = encodeURIComponent(url);
|
|
return this.http.get<String[]>(this.ApiURL+'/lot/getPictures/'+encodeUrl);
|
|
}
|
|
|
|
getLotsBySale(_id: String): Observable<Lot[]> {
|
|
return this.http.get<Lot[]>(this.ApiURL+'/lot/getLotsBySale/'+_id);
|
|
}
|
|
|
|
// Sale
|
|
getSaleInfos(url: string): Observable<SaleInfo> {
|
|
let encodeUrl = encodeURIComponent(url);
|
|
|
|
return this.http.get<SaleInfo>(this.ApiURL+'/sale/getSaleInfos/'+encodeUrl);
|
|
}
|
|
|
|
prepareSale(Sale: Sale): Observable<any> {
|
|
|
|
let follow = this.http.get<any>(this.ApiURL+'/sale/prepareSale/'+Sale._id);
|
|
return follow
|
|
}
|
|
|
|
followSale(Sale: Sale): Observable<any> {
|
|
|
|
let follow = this.http.get<any>(this.ApiURL+'/sale/followSale/'+Sale._id);
|
|
return follow
|
|
}
|
|
|
|
resetSaleToReady(_id: String): void {
|
|
this.getSale(_id).subscribe((sale: Sale) => {
|
|
sale.status = "ready";
|
|
this.updateSale(sale).subscribe();
|
|
});
|
|
}
|
|
|
|
// Sale CRUD
|
|
|
|
getSale(_id: String): Observable<Sale> {
|
|
return this.http.get<Sale>(this.ApiURL+'/sale/sale/'+_id);
|
|
}
|
|
|
|
saveSale(Sale: Sale): Observable<Sale> {
|
|
return this.http.post<Sale>(this.ApiURL+'/sale/sale', Sale);
|
|
}
|
|
|
|
updateSale(Sale: Sale): Observable<Sale> {
|
|
return this.http.put<Sale>(this.ApiURL+'/sale/sale/'+Sale._id, Sale);
|
|
}
|
|
|
|
deleteSale(_id: String): Observable<any> {
|
|
return this.http.delete<any>(this.ApiURL+'/sale/sale/'+_id);
|
|
}
|
|
|
|
// Function DB Sale
|
|
|
|
|
|
getAllSale(): Observable<SaleInfo[]> {
|
|
return this.http.get<SaleInfo[]>(this.ApiURL+'/sale/getAll');
|
|
}
|
|
|
|
postProcessing(_id: String): Observable<any> {
|
|
return this.http.get<any>(this.ApiURL+'/sale/postProcessing/'+_id);
|
|
}
|
|
|
|
|
|
//Favorites
|
|
saveFavorite(lotInfo: LotInfo, saleInfo: SaleInfo, picture: String, dateTime: string, buyProject: boolean, maxPrice: number, Note: string): Observable<any> {
|
|
return this.http.post(this.ApiURL+'/favorite/save', {lotInfo, saleInfo, picture, dateTime, buyProject, maxPrice, Note});
|
|
}
|
|
|
|
getAllFavorite(): Observable<any> {
|
|
return this.http.get(this.ApiURL+'/favorite/getAll');
|
|
}
|
|
}
|