mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merged PR 2046: feature(crm-data-access): Update Transactions Endpoint
feature(crm-data-access): Update Transactions Endpoint Ref: #5336
This commit is contained in:
committed by
Lorenz Hilpert
parent
bb717975a0
commit
4107641e75
@@ -28,7 +28,7 @@
|
||||
}
|
||||
|
||||
<crm-customer-card-transactions
|
||||
[cardCode]="activeCardCode ?? firstCardCode()"
|
||||
[customerId]="customerId()"
|
||||
class="mt-8"
|
||||
(reload)="reloadCardTransactionsAndCards()"
|
||||
/>
|
||||
|
||||
@@ -72,15 +72,6 @@ export class KundenkarteMainViewComponent implements OnDestroy {
|
||||
*/
|
||||
readonly customerId = toSignal(this.customerId$);
|
||||
|
||||
/**
|
||||
* Get the first card code
|
||||
*/
|
||||
readonly firstCardCode = computed(() => {
|
||||
const cards = this.#bonusCardsResource.resource.value();
|
||||
const firstCard = cards?.[0];
|
||||
return firstCard?.code;
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the first active card code
|
||||
*/
|
||||
|
||||
@@ -22,6 +22,7 @@ import { ResponseArgsOfNullableBoolean } from '../models/response-args-of-nullab
|
||||
class LoyaltyCardService extends __BaseService {
|
||||
static readonly LoyaltyCardListBookingsPath = '/loyalty/{cardCode}/booking';
|
||||
static readonly LoyaltyCardAddBookingPath = '/loyalty/{cardCode}/booking';
|
||||
static readonly LoyaltyCardListCustomerBookingsPath = '/customer/{customerId}/loyalty/booking';
|
||||
static readonly LoyaltyCardBookingReasonPath = '/loyalty/booking/reason';
|
||||
static readonly LoyaltyCardCurrentBookingPartnerStorePath = '/loyalty/booking/partner/store/current';
|
||||
static readonly LoyaltyCardLoyaltyBonCheckPath = '/loyalty/{cardCode}/bon/check';
|
||||
@@ -131,6 +132,51 @@ class LoyaltyCardService extends __BaseService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bookings / Buchungen
|
||||
* @param params The `LoyaltyCardService.LoyaltyCardListCustomerBookingsParams` containing the following parameters:
|
||||
*
|
||||
* - `customerId`:
|
||||
*
|
||||
* - `locale`:
|
||||
*/
|
||||
LoyaltyCardListCustomerBookingsResponse(params: LoyaltyCardService.LoyaltyCardListCustomerBookingsParams): __Observable<__StrictHttpResponse<ResponseArgsOfIQueryResultOfLoyaltyBookingInfoDTO>> {
|
||||
let __params = this.newParams();
|
||||
let __headers = new HttpHeaders();
|
||||
let __body: any = null;
|
||||
|
||||
if (params.locale != null) __params = __params.set('locale', params.locale.toString());
|
||||
let req = new HttpRequest<any>(
|
||||
'GET',
|
||||
this.rootUrl + `/customer/${encodeURIComponent(String(params.customerId))}/loyalty/booking`,
|
||||
__body,
|
||||
{
|
||||
headers: __headers,
|
||||
params: __params,
|
||||
responseType: 'json'
|
||||
});
|
||||
|
||||
return this.http.request<any>(req).pipe(
|
||||
__filter(_r => _r instanceof HttpResponse),
|
||||
__map((_r) => {
|
||||
return _r as __StrictHttpResponse<ResponseArgsOfIQueryResultOfLoyaltyBookingInfoDTO>;
|
||||
})
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Bookings / Buchungen
|
||||
* @param params The `LoyaltyCardService.LoyaltyCardListCustomerBookingsParams` containing the following parameters:
|
||||
*
|
||||
* - `customerId`:
|
||||
*
|
||||
* - `locale`:
|
||||
*/
|
||||
LoyaltyCardListCustomerBookings(params: LoyaltyCardService.LoyaltyCardListCustomerBookingsParams): __Observable<ResponseArgsOfIQueryResultOfLoyaltyBookingInfoDTO> {
|
||||
return this.LoyaltyCardListCustomerBookingsResponse(params).pipe(
|
||||
__map(_r => _r.body as ResponseArgsOfIQueryResultOfLoyaltyBookingInfoDTO)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Booking reason / Buchungsgründe
|
||||
*/
|
||||
@@ -412,6 +458,14 @@ module LoyaltyCardService {
|
||||
locale?: null | string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for LoyaltyCardListCustomerBookings
|
||||
*/
|
||||
export interface LoyaltyCardListCustomerBookingsParams {
|
||||
customerId: number;
|
||||
locale?: null | string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for LoyaltyCardLoyaltyBonCheck
|
||||
*/
|
||||
|
||||
@@ -34,7 +34,7 @@ export class CustomerCardTransactionsResource {
|
||||
context: 'CustomerCardTransactionsResource',
|
||||
}));
|
||||
|
||||
readonly #cardCode = signal<string | undefined>(undefined);
|
||||
readonly #customerId = signal<number | undefined>(undefined);
|
||||
|
||||
/**
|
||||
* Resource that loads transactions based on current parameters.
|
||||
@@ -46,29 +46,29 @@ export class CustomerCardTransactionsResource {
|
||||
* - `status()` - Current status ('idle' | 'loading' | 'resolved' | 'error')
|
||||
*/
|
||||
readonly resource = resource({
|
||||
params: computed(() => ({ cardCode: this.#cardCode() })),
|
||||
params: computed(() => ({ customerId: this.#customerId() })),
|
||||
loader: async ({
|
||||
params,
|
||||
abortSignal,
|
||||
}): Promise<LoyaltyBookingInfoDTO[] | undefined> => {
|
||||
const { cardCode } = params;
|
||||
const { customerId } = params;
|
||||
|
||||
if (!cardCode) {
|
||||
this.#logger.debug('No cardCode provided, skipping load');
|
||||
if (!customerId) {
|
||||
this.#logger.debug('No customerId provided, skipping load');
|
||||
return undefined;
|
||||
}
|
||||
|
||||
this.#logger.debug('Loading loyalty card transactions', () => ({
|
||||
cardCode,
|
||||
customerId,
|
||||
}));
|
||||
|
||||
const transactions = await this.#crmSearchService.fetchLoyaltyBookings(
|
||||
cardCode,
|
||||
customerId,
|
||||
abortSignal,
|
||||
);
|
||||
|
||||
this.#logger.debug('Transactions loaded', () => ({
|
||||
cardCode,
|
||||
customerId,
|
||||
count: transactions.length,
|
||||
}));
|
||||
|
||||
@@ -81,10 +81,10 @@ export class CustomerCardTransactionsResource {
|
||||
* Update resource parameters to trigger a reload.
|
||||
*
|
||||
* @param params - Parameters for loading transactions
|
||||
* @param params.cardCode - Card code to load transactions for (undefined clears data)
|
||||
* @param params.customerId - Card code to load transactions for (undefined clears data)
|
||||
*/
|
||||
params(params: { cardCode?: string }): void {
|
||||
params(params: { customerId?: number }): void {
|
||||
this.#logger.debug('Updating params', () => params);
|
||||
this.#cardCode.set(params.cardCode);
|
||||
this.#customerId.set(params.customerId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,13 +97,13 @@ export class CrmSearchService {
|
||||
}
|
||||
|
||||
async fetchLoyaltyBookings(
|
||||
cardCode: string,
|
||||
customerId: number,
|
||||
abortSignal?: AbortSignal,
|
||||
): Promise<LoyaltyBookingInfoDTO[]> {
|
||||
this.#logger.info('Fetching loyalty bookings from API');
|
||||
|
||||
let req$ = this.#loyaltyCardService
|
||||
.LoyaltyCardListBookings({ cardCode })
|
||||
.LoyaltyCardListCustomerBookings({ customerId })
|
||||
.pipe(catchResponseArgsErrorPipe());
|
||||
|
||||
if (abortSignal) {
|
||||
|
||||
@@ -52,7 +52,7 @@ export class CrmFeatureCustomerCardTransactionsComponent {
|
||||
* Card code to load transactions for.
|
||||
* Should be the code of the first activated card.
|
||||
*/
|
||||
readonly cardCode = input<string | undefined>(undefined);
|
||||
readonly customerId = input<number | undefined>(undefined);
|
||||
|
||||
readonly reload = output<void>();
|
||||
|
||||
@@ -85,11 +85,11 @@ export class CrmFeatureCustomerCardTransactionsComponent {
|
||||
readonly trackByDate = (_index: number, item: { date: Date }) => item.date;
|
||||
|
||||
constructor() {
|
||||
// React to cardCode input changes
|
||||
// React to customerId input changes
|
||||
effect(() => {
|
||||
const code = this.cardCode();
|
||||
this.#logger.debug('Card code changed', () => ({ cardCode: code }));
|
||||
this.#transactionsResource.params({ cardCode: code });
|
||||
const customerId = this.customerId();
|
||||
this.#logger.debug('CustomerId changed', () => ({ customerId }));
|
||||
this.#transactionsResource.params({ customerId });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user