26 lines
991 B
TypeScript
26 lines
991 B
TypeScript
// dvbooking-cli/src/templates/angular-generic/data-provider.service.ts.tpl
|
|
|
|
// Generated by the CLI
|
|
import { inject, Injectable } from '@angular/core';
|
|
import { DataProvider, GetDataOptions, GetDataResponse } from '../../../../components/generic-table/data-provider.interface';
|
|
import { Event } from '../../models/event.model';
|
|
import { map, Observable } from 'rxjs';
|
|
import { EventService } from '../../services/event.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class EventDataProvider implements DataProvider<Event> {
|
|
private eventService = inject(EventService);
|
|
|
|
getData(options?: GetDataOptions): Observable<GetDataResponse<Event>> {
|
|
const {q,page,limit} = options?.params ?? {};
|
|
// The generic table's params are compatible with our NestJS Query DTO
|
|
return this.eventService.search(q ?? '',page,limit, ).pipe(
|
|
map((res) => {
|
|
// Adapt the paginated response to the GetDataResponse format
|
|
return { data: res };
|
|
})
|
|
);
|
|
}
|
|
} |