dcb-backoffice/src/app/modules/notifications/services/notifications.service.ts

55 lines
1.4 KiB
TypeScript

import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '@environments/environment';
import { Observable } from 'rxjs';
export interface Notification {
id: string;
type: 'SMS' | 'EMAIL' | 'PUSH' | 'SYSTEM';
title: string;
message: string;
recipient: string;
status: 'SENT' | 'DELIVERED' | 'FAILED' | 'PENDING';
createdAt: Date;
sentAt?: Date;
errorMessage?: string;
}
export interface NotificationFilter {
type?: string;
status?: string;
startDate?: Date;
endDate?: Date;
recipient?: string;
}
@Injectable({ providedIn: 'root' })
export class NotificationService {
private http = inject(HttpClient);
private apiUrl = `${environment.localServiceTestApiUrl}/notifications`;
getNotifications(filters?: NotificationFilter): Observable<Notification[]> {
return this.http.post<Notification[]>(
`${this.apiUrl}/list`,
filters
);
}
sendNotification(notification: Partial<Notification>): Observable<Notification> {
return this.http.post<Notification>(
`${this.apiUrl}/send`,
notification
);
}
getNotificationStats(): Observable<any> {
return this.http.get(`${this.apiUrl}/stats`);
}
retryNotification(notificationId: string): Observable<Notification> {
return this.http.post<Notification>(
`${this.apiUrl}/${notificationId}/retry`,
{}
);
}
}