Files
barker/bookie/src/app/temporal-product/temporal-product.service.ts
Amritanshu 1b8ab2857f Mostly working with Product + Version and Sku + Version.
There will still be many errors. But this is working somewhat
2026-01-23 02:30:57 +00:00

45 lines
1.5 KiB
TypeScript

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { ErrorLoggerService } from '../core/error-logger.service';
import { StockKeepingUnit as Product } from '../core/stock-keeping-unit';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
const url = '/api/temporal-products';
const serviceName = 'ProductService';
@Injectable({ providedIn: 'root' })
export class TemporalProductService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
get(id: string): Observable<Product> {
return this.http
.get<Product>(`${url}/${id}`)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<Product>;
}
list(): Observable<Product[][]> {
return this.http
.get<Product[][]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<Product[][]>;
}
update(product: Product): Observable<void> {
return this.http
.put<Product>(`${url}/${product.versionId}`, product, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<void>;
}
delete(id: string): Observable<void> {
return this.http
.delete<Product>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<void>;
}
}