BillCare 초기 소스 등록
비즈케어 홈즈 홈상품 운용관리(BillCare) 프론트/백엔드/Docker 구성을 exdev git에 등록합니다. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import client, { apiPrefix, unwrap, type ApiResponse } from './client'
|
||||
import type { Entity } from '../types'
|
||||
|
||||
export type PageResult<T = Entity> = { total: number; list: T[] }
|
||||
|
||||
export const resourceApi = {
|
||||
async list(path: string, params: Record<string, unknown> = {}) {
|
||||
const { data } = await client.get<ApiResponse<PageResult> | ApiResponse<Record<string, unknown>>>(
|
||||
`${apiPrefix()}/${path}`,
|
||||
{ params },
|
||||
)
|
||||
const body = unwrap(data) as PageResult | Record<string, unknown>
|
||||
if (body && typeof body === 'object' && 'list' in body) {
|
||||
const page = body as PageResult
|
||||
return { items: page.list ?? [], total: Number(page.total ?? 0) }
|
||||
}
|
||||
// dashboard / summary style
|
||||
return { items: [body as Entity], total: 1, raw: body }
|
||||
},
|
||||
|
||||
async get(path: string, params: Record<string, unknown> = {}) {
|
||||
const { data } = await client.get<ApiResponse>(`${apiPrefix()}/${path}`, { params })
|
||||
return unwrap(data)
|
||||
},
|
||||
|
||||
async create(path: string, payload: Record<string, unknown>) {
|
||||
const { data } = await client.post<ApiResponse<Entity>>(`${apiPrefix()}/${path}`, payload)
|
||||
return unwrap(data)
|
||||
},
|
||||
|
||||
async update(path: string, id: number | string, payload: Record<string, unknown>) {
|
||||
const { data } = await client.put<ApiResponse<Entity>>(`${apiPrefix()}/${path}/${id}`, payload)
|
||||
return unwrap(data)
|
||||
},
|
||||
|
||||
async put(path: string, payload: Record<string, unknown>, params?: Record<string, unknown>) {
|
||||
const { data } = await client.put<ApiResponse>(`${apiPrefix()}/${path}`, payload, { params })
|
||||
return unwrap(data)
|
||||
},
|
||||
|
||||
async remove(path: string, id: number) {
|
||||
const { data } = await client.delete<ApiResponse>(`${apiPrefix()}/${path}/${id}`)
|
||||
return unwrap(data)
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user