26 lines
1.0 KiB
TypeScript
26 lines
1.0 KiB
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 { UserGroup } from '../../models/user-group.model';
|
|
import { map, Observable } from 'rxjs';
|
|
import { UserGroupService } from '../../services/user-group.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class UserGroupDataProvider implements DataProvider<UserGroup> {
|
|
private userGroupService = inject(UserGroupService);
|
|
|
|
getData(options?: GetDataOptions): Observable<GetDataResponse<UserGroup>> {
|
|
const {q,page,limit} = options?.params ?? {};
|
|
// The generic table's params are compatible with our NestJS Query DTO
|
|
return this.userGroupService.search(q ?? '',page,limit, ).pipe(
|
|
map((res) => {
|
|
// Adapt the paginated response to the GetDataResponse format
|
|
return { data: res };
|
|
})
|
|
);
|
|
}
|
|
} |