File size: 3,402 Bytes
b24b684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import api from "./client";
import type {
  AdminWorker,
  AppUser,
  Booking,
  BookingStatus,
  Category,
  DashboardStats,
  KycStatus,
  ReviewLite,
  Token,
} from "./types";

// ---- Auth ----
export const login = (email: string, password: string) =>
  api.post<Token>("/auth/admin/login", { email, password }).then((r) => r.data);

export const fetchMe = () => api.get<AppUser>("/auth/me").then((r) => r.data);

export const logoutRequest = (refreshToken: string) =>
  api.post("/auth/logout", { refresh_token: refreshToken }).then((r) => r.data);

// ---- Dashboard ----
export const fetchDashboard = () =>
  api.get<DashboardStats>("/admin/dashboard").then((r) => r.data);

// ---- Workers ----
export const fetchWorkers = (kycStatus?: KycStatus) =>
  api
    .get<AdminWorker[]>("/admin/workers", {
      params: kycStatus ? { kyc_status: kycStatus } : {},
    })
    .then((r) => r.data);

export const verifyWorker = (userId: number, approve: boolean) =>
  api.post(`/admin/workers/${userId}/verify`, { approve }).then((r) => r.data);

export const suspendWorker = (userId: number, suspend: boolean) =>
  api.post(`/admin/workers/${userId}/suspend`, { suspend }).then((r) => r.data);

// ---- Customers ----
export const fetchCustomers = () =>
  api.get<AppUser[]>("/admin/customers").then((r) => r.data);

export const blockUser = (userId: number, suspend: boolean) =>
  api.post(`/admin/users/${userId}/block`, { suspend }).then((r) => r.data);

export const deleteUser = (userId: number) =>
  api.delete(`/admin/users/${userId}`).then((r) => r.data);

// ---- Categories ----
export const fetchCategories = () =>
  api.get<Category[]>("/admin/categories").then((r) => r.data);

export const createCategory = (data: { name: string; icon?: string; is_active?: boolean }) =>
  api.post<Category>("/admin/categories", data).then((r) => r.data);

export const updateCategory = (

  id: number,

  data: { name?: string; icon?: string; is_active?: boolean },

) => api.put<Category>(`/admin/categories/${id}`, data).then((r) => r.data);

export const deleteCategory = (id: number) =>
  api.delete(`/admin/categories/${id}`).then((r) => r.data);

// ---- Bookings ----
export const fetchBookings = (status?: BookingStatus) =>
  api
    .get<Booking[]>("/admin/bookings", { params: status ? { status } : {} })
    .then((r) => r.data);

export const updateBookingStatus = (

  id: number,

  status: BookingStatus,

  amount?: number,

) =>
  api
    .put<Booking>(`/admin/bookings/${id}/status`, { status, amount })
    .then((r) => r.data);

export const approveJob = (bookingId: number, amount: number) =>
  api.post<Booking>(`/admin/jobs/${bookingId}/approve`, { amount }).then((r) => r.data);

export const rejectJob = (bookingId: number) =>
  api.post<Booking>(`/admin/jobs/${bookingId}/reject`).then((r) => r.data);

export const assignWorker = (bookingId: number, workerId: number) =>
  api
    .post<Booking>(`/admin/bookings/${bookingId}/assign`, null, {
      params: { worker_id: workerId },
    })
    .then((r) => r.data);

// ---- Reviews ----
export const fetchReviews = () =>
  api.get<ReviewLite[]>("/admin/reviews").then((r) => r.data);

export const hideReview = (id: number, suspend: boolean) =>
  api.post<ReviewLite>(`/admin/reviews/${id}/hide`, { suspend }).then((r) => r.data);