mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { effect, inject, Injectable, resource, signal } from '@angular/core';
|
|
import { CrmSearchService, CrmTabMetadataService } from '../services';
|
|
import { TabService } from '@isa/core/tabs';
|
|
|
|
@Injectable()
|
|
export class CustomerBonusCardsResource {
|
|
#customerService = inject(CrmSearchService);
|
|
|
|
#params = signal<{ customerId: number | undefined }>({
|
|
customerId: undefined,
|
|
});
|
|
|
|
params(params: { customerId?: number }) {
|
|
this.#params.update((p) => ({ ...p, ...params }));
|
|
}
|
|
|
|
readonly resource = resource({
|
|
params: () => this.#params(),
|
|
loader: async ({ params, abortSignal }) => {
|
|
if (!params.customerId) {
|
|
return undefined;
|
|
}
|
|
const res = await this.#customerService.fetchCustomerCards(
|
|
{
|
|
customerId: params.customerId,
|
|
},
|
|
abortSignal,
|
|
);
|
|
return res.result;
|
|
},
|
|
});
|
|
}
|
|
|
|
@Injectable()
|
|
export class SelectedCustomerBonusCardsResource extends CustomerBonusCardsResource {
|
|
#tabId = inject(TabService).activatedTabId;
|
|
#customerMetadata = inject(CrmTabMetadataService);
|
|
|
|
constructor() {
|
|
super();
|
|
effect(() => {
|
|
const tabId = this.#tabId();
|
|
const customerId = tabId
|
|
? this.#customerMetadata.selectedCustomerId(tabId)
|
|
: undefined;
|
|
this.params({ customerId });
|
|
});
|
|
}
|
|
}
|