In progress Sales import and Recipe import.

First I will finish Sales Import. Then move on to recipe import
This commit is contained in:
tanshu committed 2026-09-11 10:43:23 +00:00
1 parent 75ccbdc6f9
commit b425b299bf
50 files changed
+5306 -123

No files matched your search

@@ -0,0 +1,43 @@
import { HttpClient, httpResource } from '@angular/common/http';
import { inject, Injectable, Signal } from '@angular/core';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { ErrorLoggerService } from '../core/error-logger.service';
import { Voucher } from '../core/voucher';
import { ExecuteResponse, ImportRequest, MappingUpdate, MappingEntry, PreviewResponse } from './sales-import';
const url = '/api/sales-import';
@Injectable({
providedIn: 'root',
})
export class SalesImportService {
private http = inject(HttpClient);
private log = inject(ErrorLoggerService);
voucher(id: Signal<string | null>) {
return httpResource<Voucher>(() => {
const id_ = id();
return id_ === null ? undefined : `${url}/voucher/${id_}`;
});
}
preview(request: ImportRequest): Observable<PreviewResponse> {
return this.http
.post<PreviewResponse>(`${url}/preview`, request)
.pipe(catchError(this.log.handleError('SalesImportService', 'preview'))) as Observable<PreviewResponse>;
}
execute(request: ImportRequest): Observable<ExecuteResponse> {
return this.http
.post<ExecuteResponse>(`${url}/execute`, request)
.pipe(catchError(this.log.handleError('SalesImportService', 'execute'))) as Observable<ExecuteResponse>;
}
saveMapping(mapping: MappingUpdate): Observable<MappingEntry[]> {
return this.http
.put<MappingEntry[]>(`${url}/mapping`, mapping)
.pipe(catchError(this.log.handleError('SalesImportService', 'saveMapping'))) as Observable<MappingEntry[]>;
}
}