All files / src/lib/api/admin communications.ts

100% Statements 19/19
100% Branches 16/16
100% Functions 2/2
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                                                                95x                   4x 4x 4x 4x 4x 4x 4x 4x 4x 4x         2x      
import { request } from "../base";
 
export type CommunicationLogEntry = {
	id: number;
	proId: string | null;
	userId: string | null;
	eventType: string;
	channel: string;
	recipient: string;
	actualRecipient: string | null;
	status: string;
	provider: string | null;
	environment: string | null;
	externalId: string | null;
	subject: string | null;
	contentSummary: string | null;
	previewHtml: string | null;
	previewText: string | null;
	transactional: boolean;
	errorMessage: string | null;
	metadataJson: string | null;
	dateCreated: string;
	dateUpdated: string | null;
};
 
type CommunicationListResponse = {
	items: CommunicationLogEntry[];
	total: number;
	limit: number;
	offset: number;
};
 
export const adminCommunicationsApi = {
	list(filters?: {
		channel?: string;
		status?: string;
		eventType?: string;
		environment?: string;
		search?: string;
		limit?: number;
		offset?: number;
	}) {
		const params = new URLSearchParams();
		if (filters?.channel) params.set("channel", filters.channel);
		if (filters?.status) params.set("status", filters.status);
		if (filters?.eventType) params.set("eventType", filters.eventType);
		if (filters?.environment) params.set("environment", filters.environment);
		if (filters?.search) params.set("search", filters.search);
		if (filters?.limit) params.set("limit", String(filters.limit));
		if (filters?.offset) params.set("offset", String(filters.offset));
		const qs = params.toString();
		return request<CommunicationListResponse>(
			`/api/admin/communications${qs ? `?${qs}` : ""}`,
		);
	},
	getById(id: number) {
		return request<CommunicationLogEntry>(`/api/admin/communications/${id}`);
	},
};