Allow editing of product version with the right permission.

This commit is contained in:
2021-09-04 12:52:05 +05:30
parent f929a731cb
commit 4a12ee0834
11 changed files with 370 additions and 196 deletions

View File

@ -17,11 +17,11 @@ const serviceName = 'ProductService';
export class ProductService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
get(id: string | null): Observable<Product> {
get(id: string | null): Observable<Product[]> {
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
return this.http
.get<Product>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<Product>;
.get<Product[]>(getUrl)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<Product[]>;
}
list(): Observable<Product[]> {
@ -48,16 +48,16 @@ export class ProductService {
>;
}
save(product: Product): Observable<Product> {
save(product: Product): Observable<void> {
return this.http
.post<Product>(`${url}`, product, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<Product>;
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<void>;
}
update(product: Product): Observable<Product> {
update(product: Product): Observable<void> {
return this.http
.put<Product>(`${url}/${product.id}`, product, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<Product>;
.put<Product>(`${url}/${product.versionId}`, product, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<void>;
}
updateSortOrder(list: Product[]): Observable<Product[]> {
@ -68,17 +68,17 @@ export class ProductService {
>;
}
saveOrUpdate(product: Product): Observable<Product> {
if (!product.id) {
saveOrUpdate(product: Product): Observable<void> {
if (!product.versionId) {
return this.save(product);
}
return this.update(product);
}
delete(id: string): Observable<Product> {
delete(id: string): Observable<void> {
return this.http
.delete<Product>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<Product>;
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<void>;
}
balance(id: string, date: string): Observable<number> {