Some checks failed
CI/CD Pipeline - Xpeditis PreProd / Backend - Build & Test (push) Failing after 5m51s
CI/CD Pipeline - Xpeditis PreProd / Backend - Docker Build & Push (push) Has been skipped
CI/CD Pipeline - Xpeditis PreProd / Frontend - Build & Test (push) Successful in 10m57s
CI/CD Pipeline - Xpeditis PreProd / Frontend - Docker Build & Push (push) Failing after 12m28s
CI/CD Pipeline - Xpeditis PreProd / Deploy to PreProd Server (push) Has been skipped
CI/CD Pipeline - Xpeditis PreProd / Run Smoke Tests (push) Has been skipped
120 lines
3.3 KiB
TypeScript
120 lines
3.3 KiB
TypeScript
/**
|
|
* Notifications API
|
|
*
|
|
* Endpoints for managing user notifications
|
|
*/
|
|
|
|
import { get, post, patch, del } from './client';
|
|
import type {
|
|
NotificationResponse,
|
|
NotificationListResponse,
|
|
SuccessResponse,
|
|
} from '@/types/api';
|
|
|
|
// TODO: These types should be moved to @/types/api.ts
|
|
export interface CreateNotificationRequest {
|
|
userId?: string;
|
|
type: string;
|
|
title: string;
|
|
message: string;
|
|
}
|
|
|
|
export interface UpdateNotificationPreferencesRequest {
|
|
emailNotifications?: boolean;
|
|
pushNotifications?: boolean;
|
|
smsNotifications?: boolean;
|
|
notificationTypes?: string[];
|
|
}
|
|
|
|
export interface NotificationPreferencesResponse {
|
|
userId: string;
|
|
emailNotifications: boolean;
|
|
pushNotifications: boolean;
|
|
smsNotifications: boolean;
|
|
notificationTypes: string[];
|
|
updatedAt: string;
|
|
}
|
|
|
|
/**
|
|
* List user notifications with pagination
|
|
* GET /api/v1/notifications?page=1&limit=20&isRead=false&type=BOOKING_CONFIRMED
|
|
*/
|
|
export async function listNotifications(params?: {
|
|
page?: number;
|
|
limit?: number;
|
|
isRead?: boolean;
|
|
type?: string;
|
|
}): Promise<NotificationListResponse> {
|
|
const queryParams = new URLSearchParams();
|
|
if (params?.page) queryParams.append('page', params.page.toString());
|
|
if (params?.limit) queryParams.append('limit', params.limit.toString());
|
|
if (params?.isRead !== undefined) queryParams.append('isRead', params.isRead.toString());
|
|
if (params?.type) queryParams.append('type', params.type);
|
|
|
|
const queryString = queryParams.toString();
|
|
return get<NotificationListResponse>(
|
|
`/api/v1/notifications${queryString ? `?${queryString}` : ''}`
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get notification by ID
|
|
* GET /api/v1/notifications/:id
|
|
*/
|
|
export async function getNotification(id: string): Promise<NotificationResponse> {
|
|
return get<NotificationResponse>(`/api/v1/notifications/${id}`);
|
|
}
|
|
|
|
/**
|
|
* Create notification (admin only)
|
|
* POST /api/v1/notifications
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function createNotification(
|
|
data: CreateNotificationRequest
|
|
): Promise<NotificationResponse> {
|
|
return post<NotificationResponse>('/api/v1/notifications', data);
|
|
}
|
|
|
|
/**
|
|
* Mark notification as read
|
|
* PATCH /api/v1/notifications/:id/read
|
|
*/
|
|
export async function markNotificationAsRead(id: string): Promise<SuccessResponse> {
|
|
return patch<SuccessResponse>(`/api/v1/notifications/${id}/read`, {});
|
|
}
|
|
|
|
/**
|
|
* Mark all notifications as read
|
|
* PATCH /api/v1/notifications/read-all
|
|
*/
|
|
export async function markAllNotificationsAsRead(): Promise<SuccessResponse> {
|
|
return patch<SuccessResponse>('/api/v1/notifications/read-all', {});
|
|
}
|
|
|
|
/**
|
|
* Delete notification
|
|
* DELETE /api/v1/notifications/:id
|
|
*/
|
|
export async function deleteNotification(id: string): Promise<SuccessResponse> {
|
|
return del<SuccessResponse>(`/api/v1/notifications/${id}`);
|
|
}
|
|
|
|
/**
|
|
* Get notification preferences
|
|
* GET /api/v1/notifications/preferences
|
|
*/
|
|
export async function getNotificationPreferences(): Promise<NotificationPreferencesResponse> {
|
|
return get<NotificationPreferencesResponse>('/api/v1/notifications/preferences');
|
|
}
|
|
|
|
/**
|
|
* Update notification preferences
|
|
* PATCH /api/v1/notifications/preferences
|
|
*/
|
|
export async function updateNotificationPreferences(
|
|
data: UpdateNotificationPreferencesRequest
|
|
): Promise<NotificationPreferencesResponse> {
|
|
return patch<NotificationPreferencesResponse>('/api/v1/notifications/preferences', data);
|
|
}
|