updates
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { ApiClient, type ApiClientOptions } from "../infra/client"
|
||||
import { CrudClient } from "../infra/crud-client"
|
||||
import type { ApiClientOptions } from "../infra/client"
|
||||
import type { ApiPath, ApiRequestBody } from "../infra/types"
|
||||
import type { ApiListQueryParams } from "../contracts/types"
|
||||
|
||||
@@ -19,9 +20,12 @@ export const INSPECTION_ROUTES = {
|
||||
CHECKPOINT_MEDIA: "/api/inspection-check-points/{id}/media",
|
||||
} as const satisfies Record<string, ApiPath>
|
||||
|
||||
export class InspectionsClient extends ApiClient {
|
||||
export class InspectionsClient extends CrudClient<
|
||||
typeof INSPECTION_ROUTES.INDEX,
|
||||
typeof INSPECTION_ROUTES.BY_ID
|
||||
> {
|
||||
constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
|
||||
super(baseUrl, defaultOptions)
|
||||
super(baseUrl, defaultOptions, INSPECTION_ROUTES.INDEX, INSPECTION_ROUTES.BY_ID)
|
||||
}
|
||||
|
||||
// ── Categories ──
|
||||
@@ -41,28 +45,11 @@ export class InspectionsClient extends ApiClient {
|
||||
return this.delete(INSPECTION_ROUTES.CATEGORY_BY_ID, { params: { id } })
|
||||
}
|
||||
|
||||
// ── Inspections ──
|
||||
async list(query?: ApiListQueryParams) {
|
||||
return this.get(INSPECTION_ROUTES.INDEX, query ? { query } as never : undefined)
|
||||
}
|
||||
|
||||
async getById(id: string) {
|
||||
const res = await this.list({ query: { id } } as never)
|
||||
const res = await super.list({ query: { id } } as never)
|
||||
return {...res, data: res.data[0] }
|
||||
}
|
||||
|
||||
async create(payload: ApiRequestBody<typeof INSPECTION_ROUTES.INDEX, "post">) {
|
||||
return this.post(INSPECTION_ROUTES.INDEX, payload)
|
||||
}
|
||||
|
||||
async update(id: string, payload: ApiRequestBody<typeof INSPECTION_ROUTES.BY_ID, "put">) {
|
||||
return this.put(INSPECTION_ROUTES.BY_ID, payload, { params: { id } })
|
||||
}
|
||||
|
||||
async destroy(id: string) {
|
||||
return this.delete(INSPECTION_ROUTES.BY_ID, { params: { id } })
|
||||
}
|
||||
|
||||
async changeStatus(payload: ApiRequestBody<typeof INSPECTION_ROUTES.CHANGE_STATUS, "post">) {
|
||||
return this.post(INSPECTION_ROUTES.CHANGE_STATUS, payload)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user