Merged PR 2046: feature(crm-data-access): Update Transactions Endpoint

feature(crm-data-access): Update Transactions Endpoint

Ref: #5336
This commit is contained in:
Nino Righi
2025-11-21 17:39:57 +00:00
committed by Lorenz Hilpert
parent bb717975a0
commit 4107641e75
6 changed files with 73 additions and 28 deletions

View File

@@ -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);
}
}

View File

@@ -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) {

View File

@@ -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 });
});
}