30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { Injectable, inject } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { environment } from '../../../environments/environment';
|
|
import type { RecurringExpense } from '../../shared/models';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class RecurringExpensesService {
|
|
private readonly http = inject(HttpClient);
|
|
|
|
list() {
|
|
return this.http.get<{ items: RecurringExpense[] }>(`${environment.apiBaseUrl}/recurring-expenses`);
|
|
}
|
|
|
|
create(payload: Partial<RecurringExpense> & { categoryId: string }) {
|
|
return this.http.post<{ item: RecurringExpense }>(`${environment.apiBaseUrl}/recurring-expenses`, payload);
|
|
}
|
|
|
|
update(id: string, payload: Partial<RecurringExpense> & { categoryId: string }) {
|
|
return this.http.put<{ item: RecurringExpense }>(`${environment.apiBaseUrl}/recurring-expenses/${id}`, payload);
|
|
}
|
|
|
|
delete(id: string) {
|
|
return this.http.delete<void>(`${environment.apiBaseUrl}/recurring-expenses/${id}`);
|
|
}
|
|
|
|
runNow() {
|
|
return this.http.post<{ message: string }>(`${environment.apiBaseUrl}/recurring-expenses/run`, {});
|
|
}
|
|
}
|