// dvbooking-cli/src/templates/angular/service.ts.tpl // Generated by the CLI import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Booking } from '../models/booking.model'; import { ConfigurationService } from '../../../services/configuration.service'; import { PaginatedResponse } from '../../../../types'; export interface SearchResponse { data: T[]; total: number; } @Injectable({ providedIn: 'root' }) export class BookingService { private readonly apiUrl: string; constructor( private http: HttpClient, private configService: ConfigurationService ) { this.apiUrl = `${this.configService.getApiUrl()}/bookings`; } /** * Find records with pagination and filtering. */ public find(filter: Record): Observable> { // --- THIS IS THE FIX --- // The incorrect line: .filter(([_, v]) for v != null) // is now correctly written with an arrow function. const cleanFilter = Object.fromEntries( Object.entries(filter).filter(([_, v]) => v != null) ); // --- END OF FIX --- const params = new HttpParams({ fromObject: cleanFilter }); return this.http.get>(this.apiUrl, { params }); } /** * Search across multiple fields with a single term. * @param term The search term (q). */ public search(term: string, page: number = 1, limit: number = 10): Observable> { const params = new HttpParams() .set('q', term) .set('page', page.toString()) .set('limit', limit.toString()); return this.http.get>(`${this.apiUrl}/search`, { params }); } /** * Find a single record by its ID. */ public findOne(id: number): Observable { return this.http.get(`${this.apiUrl}/${id}`); } /** * Create a new record. */ public create(data: Omit): Observable { return this.http.post(this.apiUrl, data); } /** * Update an existing record. */ public update(id: number, data: Partial>): Observable { return this.http.patch(`${this.apiUrl}/${id}`, data); } /** * Remove a record by its ID. */ public remove(id: number): Observable { return this.http.delete(`${this.apiUrl}/${id}`); } }