mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2024-11-22 14:23:57 +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:
parent
1581184b57
commit
712f6c9034
|
@ -36,7 +36,7 @@ pricealarmsRouter.get('/', async (req: Request, res: Response) => {
|
|||
});
|
||||
|
||||
// POST pricealarms/create
|
||||
pricealarmsRouter.post('/create', async (req: Request, res: Response) => {
|
||||
pricealarmsRouter.post('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
|
@ -69,7 +69,7 @@ pricealarmsRouter.post('/create', async (req: Request, res: Response) => {
|
|||
});
|
||||
|
||||
// PUT pricealarms/update
|
||||
pricealarmsRouter.put('/update', async (req: Request, res: Response) => {
|
||||
pricealarmsRouter.put('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
|
|
6
Frontend/src/app/models/pricealarm.ts
Normal file
6
Frontend/src/app/models/pricealarm.ts
Normal file
|
@ -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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user