mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2026-04-26 23:30:11 +00:00
BETTERZON-101: Adding service functions for pricealarms api (#55)
- Not properly tested though as login functionality is required to test but not yet implemented
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
export interface PriceAlarm {
|
||||
alarm_id: number;
|
||||
user_id: number;
|
||||
product_id: number;
|
||||
defined_price: number;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import {Product} from '../models/product';
|
||||
import {Price} from '../models/price';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {Vendor} from '../models/vendor';
|
||||
import {PriceAlarm} from '../models/pricealarm';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -98,4 +99,37 @@ export class ApiService {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
getPriceAlarms(): Observable<PriceAlarm[]> {
|
||||
try {
|
||||
const alarms = this.http.get<PriceAlarm[]>((this.apiUrl + '/pricealarms'));
|
||||
return alarms;
|
||||
} catch (exception) {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
createPriceAlarms(productId: number, definedPrice: number): Observable<any> {
|
||||
try {
|
||||
const res = this.http.post((this.apiUrl + '/pricealarms'), JSON.stringify({
|
||||
product_id: productId,
|
||||
defined_price: definedPrice
|
||||
}));
|
||||
return res;
|
||||
} catch (exception) {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
updatePriceAlarms(alarmId: number, definedPrice: number): Observable<any> {
|
||||
try {
|
||||
const res = this.http.put((this.apiUrl + '/pricealarms'), JSON.stringify({
|
||||
alarm_id: alarmId,
|
||||
defined_price: definedPrice
|
||||
}));
|
||||
return res;
|
||||
} catch (exception) {
|
||||
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user