fix bugs phase 2 (excel ) , download sample feature
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { CrudClient } from "../infra/crud-client"
|
||||
import { ApiClient, type ApiClientOptions } from "../infra/client"
|
||||
import type { ApiPath, ApiRequestBody } from "../infra/types"
|
||||
import type { ApiClientOptions } from "../infra/client"
|
||||
import type { ApiPath } from "../infra/types"
|
||||
import type { ApiListQueryParams } from "../contracts/types"
|
||||
|
||||
export const CUSTOMER_ROUTES = {
|
||||
@@ -8,6 +8,7 @@ export const CUSTOMER_ROUTES = {
|
||||
BY_ID: "/api/customers/{id}",
|
||||
EXPORT: "/api/customers/export",
|
||||
IMPORT: "/api/customers/import",
|
||||
IMPORT_SAMPLE: "/api/customers/import/sample",
|
||||
CUSTOMER_TYPES: "/api/customer-types",
|
||||
NOTES: "/api/customers/{id}/notes/{note_id}",
|
||||
} as const satisfies Record<string, ApiPath>
|
||||
@@ -15,7 +16,15 @@ export const CUSTOMER_ROUTES = {
|
||||
export class CustomersClient extends CrudClient<typeof CUSTOMER_ROUTES.INDEX, typeof CUSTOMER_ROUTES.BY_ID> {
|
||||
|
||||
constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
|
||||
super(baseUrl, defaultOptions, CUSTOMER_ROUTES.INDEX, CUSTOMER_ROUTES.BY_ID)
|
||||
super(
|
||||
baseUrl,
|
||||
defaultOptions,
|
||||
CUSTOMER_ROUTES.INDEX,
|
||||
CUSTOMER_ROUTES.BY_ID,
|
||||
CUSTOMER_ROUTES.IMPORT,
|
||||
CUSTOMER_ROUTES.EXPORT,
|
||||
"GET",
|
||||
)
|
||||
}
|
||||
|
||||
async getById(id: string) {
|
||||
@@ -26,12 +35,8 @@ export class CustomersClient extends CrudClient<typeof CUSTOMER_ROUTES.INDEX, ty
|
||||
return this.get(CUSTOMER_ROUTES.CUSTOMER_TYPES, query ? { query } as never : undefined)
|
||||
}
|
||||
|
||||
async export() {
|
||||
return this.get(CUSTOMER_ROUTES.EXPORT)
|
||||
}
|
||||
|
||||
async import(payload: ApiRequestBody<typeof CUSTOMER_ROUTES.IMPORT, "post">) {
|
||||
return this.post(CUSTOMER_ROUTES.IMPORT, payload)
|
||||
async downloadImportSample() {
|
||||
return this.fetchBlob(CUSTOMER_ROUTES.IMPORT_SAMPLE, { method: "GET" })
|
||||
}
|
||||
|
||||
async addNote(id: string, payload: { note: string }) {
|
||||
|
||||
@@ -8,6 +8,7 @@ export const VEHICLE_ROUTES = {
|
||||
BY_ID: "/api/vehicles/{id}",
|
||||
EXPORT: "/api/vehicles/export",
|
||||
IMPORT: "/api/vehicles/import",
|
||||
IMPORT_SAMPLE: "/api/vehicles/import/sample",
|
||||
GET_OWNERS: "/api/get-vehicle-owners",
|
||||
LINK_CUSTOMER: "/api/link-customer-to-vehicle",
|
||||
UNLINK_CUSTOMER: "/api/unlink-customer-from-vehicle",
|
||||
@@ -31,7 +32,15 @@ export class VehiclesClient extends CrudClient<
|
||||
typeof VEHICLE_ROUTES.BY_ID
|
||||
> {
|
||||
constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
|
||||
super(baseUrl, defaultOptions, VEHICLE_ROUTES.INDEX, VEHICLE_ROUTES.BY_ID)
|
||||
super(
|
||||
baseUrl,
|
||||
defaultOptions,
|
||||
VEHICLE_ROUTES.INDEX,
|
||||
VEHICLE_ROUTES.BY_ID,
|
||||
VEHICLE_ROUTES.IMPORT,
|
||||
VEHICLE_ROUTES.EXPORT,
|
||||
"GET",
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -53,12 +62,8 @@ export class VehiclesClient extends CrudClient<
|
||||
return this.postFormData(url, fd)
|
||||
}
|
||||
|
||||
async export() {
|
||||
return this.get(VEHICLE_ROUTES.EXPORT)
|
||||
}
|
||||
|
||||
async import(payload: ApiRequestBody<typeof VEHICLE_ROUTES.IMPORT, "post">) {
|
||||
return this.post(VEHICLE_ROUTES.IMPORT, payload)
|
||||
async downloadImportSample() {
|
||||
return this.fetchBlob(VEHICLE_ROUTES.IMPORT_SAMPLE, { method: "GET" })
|
||||
}
|
||||
|
||||
async getOwners(vehicleId: string | number, query?: ApiListQueryParams) {
|
||||
|
||||
@@ -72,7 +72,7 @@ export abstract class CrudClient<
|
||||
if (this.exportMethod === "POST") {
|
||||
return this.fetchBlob(route, { method: "POST", body: filters ?? {} })
|
||||
}
|
||||
return this.fetchBlob(route)
|
||||
return this.fetchBlob(route, { method: "GET" })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user