File size: 1,750 Bytes
453520f
 
 
 
 
 
 
 
 
 
 
 
30fd5f3
 
453520f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 * Points service for EVG Ultimate Team frontend.
 *
 * Handles all points-related API calls.
 */

import apiClient from './api';
import {
  PointsTransaction,
  PointsHistory,
  PointsAdd,
  PointsSubtract,
} from '@/types/points';
import { APIResponse } from '@/types/api';

/**
 * Add points to a participant (admin only).
 */
export const addPoints = async (data: PointsAdd): Promise<PointsTransaction> => {
  const response = await apiClient.post<APIResponse<PointsTransaction>>('/points/add', data);

  if (response.data.data) {
    return response.data.data;
  }

  throw new Error('Failed to add points');
};

/**
 * Subtract points from a participant (admin only).
 */
export const subtractPoints = async (data: PointsSubtract): Promise<PointsTransaction> => {
  const response = await apiClient.post<APIResponse<PointsTransaction>>(
    '/points/subtract',
    data
  );

  if (response.data.data) {
    return response.data.data;
  }

  throw new Error('Failed to subtract points');
};

/**
 * Get points history for a participant.
 */
export const getPointsHistory = async (
  participantId: number,
  skip = 0,
  limit = 100
): Promise<PointsHistory> => {
  const response = await apiClient.get<APIResponse<PointsHistory>>(
    `/points/history/${participantId}`,
    { params: { skip, limit } }
  );

  if (response.data.data) {
    return response.data.data;
  }

  throw new Error('Failed to get points history');
};

/**
 * Get recent transactions across all participants.
 */
export const getRecentTransactions = async (limit = 10): Promise<PointsTransaction[]> => {
  const response = await apiClient.get<APIResponse<PointsTransaction[]>>('/points/recent', {
    params: { limit },
  });

  return response.data.data || [];
};