-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapi.ts
More file actions
27 lines (21 loc) · 1.09 KB
/
api.ts
File metadata and controls
27 lines (21 loc) · 1.09 KB
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
import { mapDomainToStrikeRequest, mapStrikeToDomain } from './mapper';
import { Strike } from '../models/strike';
import { StrikeResponse } from './types';
import axios from 'axios';
export const getStrikes = async (traineeId: string) => {
const { data } = await axios.get<StrikeResponse[]>(`/api/trainees/${traineeId}/strikes`);
return data.map((strike) => mapStrikeToDomain(strike));
};
export const deleteStrike = async (traineeId: string, strikeId: string) => {
await axios.delete(`/api/trainees/${traineeId}/strikes/${strikeId}`);
};
export const addStrike = async (traineeId: string, strike: Strike) => {
const strikeRequest = mapDomainToStrikeRequest(strike);
const { data } = await axios.post<StrikeResponse>(`/api/trainees/${traineeId}/strikes`, strikeRequest);
return mapStrikeToDomain(data);
};
export const editStrike = async (traineeId: string, strike: Strike) => {
const strikeRequest = mapDomainToStrikeRequest(strike);
const { data } = await axios.put<StrikeResponse>(`/api/trainees/${traineeId}/strikes/${strike.id!}`, strikeRequest);
return mapStrikeToDomain(data);
};