ca-grow-ops-manager/frontend/src/lib/messagingApi.ts
fullsizemalt 1258aebb9f
Some checks are pending
Deploy to Production / deploy (push) Waiting to run
Test / backend-test (push) Waiting to run
Test / frontend-test (push) Waiting to run
fix: remove /api prefix from audit, documents, messaging, upload APIs
Same double /api/api issue that was in layoutApi
2025-12-12 22:28:20 -08:00

92 lines
2.8 KiB
TypeScript

import api from './api';
export interface Announcement {
id: string;
title: string;
body: string;
priority: 'INFO' | 'WARNING' | 'CRITICAL';
requiresAck: boolean;
targetRoles: string[];
expiresAt?: string;
createdBy: { id: string; name: string };
createdAt: string;
isRead?: boolean;
isAcknowledged?: boolean;
}
export interface ShiftNote {
id: string;
roomId?: string;
batchId?: string;
content: string;
importance: 'LOW' | 'NORMAL' | 'HIGH' | 'URGENT';
createdBy: { id: string; name: string };
createdAt: string;
isRead?: boolean;
}
export const messagingApi = {
// Announcements
async getAnnouncements(): Promise<Announcement[]> {
const response = await api.get('/messaging/announcements');
return response.data;
},
async getPendingAnnouncements(): Promise<{ count: number; announcements: Announcement[] }> {
const response = await api.get('/messaging/announcements/pending');
return response.data;
},
async createAnnouncement(data: {
title: string;
body: string;
priority?: 'INFO' | 'WARNING' | 'CRITICAL';
requiresAck?: boolean;
targetRoles?: string[];
expiresAt?: string;
}): Promise<Announcement> {
const response = await api.post('/messaging/announcements', data);
return response.data;
},
async markRead(id: string): Promise<void> {
await api.post(`/api/messaging/announcements/${id}/read`);
},
async acknowledge(id: string): Promise<{ success: boolean; acknowledgedAt: string }> {
const response = await api.post(`/api/messaging/announcements/${id}/acknowledge`);
return response.data;
},
async getAcknowledgements(id: string): Promise<{
announcement: { id: string; title: string };
requiresAck: boolean;
totalUsers: number;
acknowledged: number;
pending: { id: string; name: string; email: string }[];
}> {
const response = await api.get(`/api/messaging/announcements/${id}/acks`);
return response.data;
},
// Shift Notes
async getShiftNotes(params?: { roomId?: string; batchId?: string; limit?: number }): Promise<ShiftNote[]> {
const response = await api.get('/messaging/shift-notes', { params });
return response.data;
},
async createShiftNote(data: {
content: string;
roomId?: string;
batchId?: string;
importance?: 'LOW' | 'NORMAL' | 'HIGH' | 'URGENT';
expiresAt?: string;
}): Promise<ShiftNote> {
const response = await api.post('/messaging/shift-notes', data);
return response.data;
},
async markShiftNoteRead(id: string): Promise<void> {
await api.post(`/api/messaging/shift-notes/${id}/read`);
}
};