All files / services macros.service.ts

100% Statements 17/17
100% Branches 2/2
100% Functions 6/6
100% Lines 17/17

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                                3x 27x 22x           3x 3x 2x           3x 5x 3x           3x 3x 2x           3x 3x           3x 8x 5x    
/**
 * Macros service for managing SQL macros
 */
 
import { apiClient } from '@/lib/api';
import type {
    Macro,
    MacroCreate,
    MacroUpdate,
    MacroTestRequest,
    MacroTestResponse,
} from '@/types/macro';
 
/**
 * List all SQL macros
 */
export const listMacros = async (skip = 0, limit = 100): Promise<Macro[]> => {
    const response = await apiClient.get<Macro[]>('/macros', { params: { skip, limit } });
    return response.data;
};
 
/**
 * Get a SQL macro by ID
 */
export const getMacro = async (macroId: number): Promise<Macro> => {
    const response = await apiClient.get<Macro>(`/macros/${macroId}`);
    return response.data;
};
 
/**
 * Create a new SQL macro
 */
export const createMacro = async (macro: MacroCreate): Promise<Macro> => {
    const response = await apiClient.post<Macro>('/macros', macro);
    return response.data;
};
 
/**
 * Update a SQL macro
 */
export const updateMacro = async (macroId: number, macro: MacroUpdate): Promise<Macro> => {
    const response = await apiClient.put<Macro>(`/macros/${macroId}`, macro);
    return response.data;
};
 
/**
 * Delete a SQL macro
 */
export const deleteMacro = async (macroId: number): Promise<void> => {
    await apiClient.delete(`/macros/${macroId}`);
};
 
/**
 * Test a SQL macro execution
 */
export const testMacro = async (macroId: number, testRequest: MacroTestRequest): Promise<MacroTestResponse> => {
    const response = await apiClient.post<MacroTestResponse>(`/macros/${macroId}/test`, testRequest);
    return response.data;
};