Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import type { BaseEntity } from './types';
|
||||
import { BaseRemoteDataServices } from './base-remote.data-services';
|
||||
|
||||
/**
|
||||
* General-purpose remote data services.
|
||||
*
|
||||
* A concrete, non-abstract version of BaseRemoteDataServices that
|
||||
* can be instantiated directly for standard CRUD modules that don't
|
||||
* need additional custom methods.
|
||||
*
|
||||
* For modules requiring domain-specific operations beyond standard
|
||||
* CRUD + lifecycle, extend BaseRemoteDataServices instead and add
|
||||
* custom methods using `this.execute()` or `this.customRequest()`.
|
||||
*
|
||||
* @typeParam E - The domain entity type
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Direct instantiation for standard modules
|
||||
* const bookingServices = new CommonRemoteDataServices<BookingEntity>(
|
||||
* apiClient,
|
||||
* { apiUrl: '/bookings', moduleKey: 'BOOKING' },
|
||||
* );
|
||||
*
|
||||
* const { data } = await bookingServices.getMany();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // For modules needing custom operations, extend the base:
|
||||
* class InvoiceDataServices extends BaseRemoteDataServices<InvoiceEntity> {
|
||||
* async calculateTax(invoiceId: string) {
|
||||
* return this.customRequest<TaxResult>({
|
||||
* url: `/invoices/${invoiceId}/calculate-tax`,
|
||||
* method: 'POST',
|
||||
* });
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export class CommonRemoteDataServices<
|
||||
E extends BaseEntity = BaseEntity,
|
||||
> extends BaseRemoteDataServices<E> {}
|
||||
Reference in New Issue
Block a user