| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import http from '@/core/api/http'
- import type {
- GetUserResponse,
- GetUserDetailResponse,
- CreateUserPayload,
- } from '@/types/users.types'
- import type { ApiResponse, PaginationParams } from '@/types/common.types'
- const BASE_URL = '/admin/users'
- export const usersService = {
- list: async (params?: PaginationParams): Promise<GetUserResponse> => {
- const searchParams = new URLSearchParams()
- if (params?.page) searchParams.set('page', String(params.page))
- if (params?.per_page) searchParams.set('per_page', String(params.per_page))
- const query = searchParams.toString()
- const url = query ? `${BASE_URL}?${query}` : BASE_URL
- return http.get<GetUserResponse>(url)
- },
- detail: async (userId: number | string) => {
- const res = await http.get<GetUserDetailResponse>(`${BASE_URL}/${userId}`)
- return res?.data?.user
- },
- create: async (payload: CreateUserPayload) => {
- const res = await http.post<ApiResponse<void>>(BASE_URL, payload)
- return res?.data
- },
- update: async (id: number, payload: CreateUserPayload) => {
- const res = await http.put<ApiResponse<void>>(`${BASE_URL}/${id}`, payload)
- return res?.data
- },
- delete: async (userId: number | string) => {
- return http.delete(`${BASE_URL}/${userId}`)
- },
- }
|