garage-erp/packages/api/src/clients/inventory-adjustments.ts
2026-04-06 02:32:47 +03:00

32 lines
1.3 KiB
TypeScript

import { CrudClient } from "../infra/crud-client"
import { type ApiClientOptions } from "../infra/client"
import type { ApiPath } from "../infra/types"
export const INVENTORY_ADJUSTMENT_ROUTES = {
INDEX: "/api/inventory-adjustments",
BY_ID: "/api/inventory-adjustments/{id}",
ADD_ATTACHMENT: "/api/inventory-adjustments/{id}/add-attachment",
DELETE_ATTACHMENT: "/api/inventory-adjustments/{id}/delete-attachment",
} as const satisfies Record<string, ApiPath>
export class InventoryAdjustmentsClient extends CrudClient<
typeof INVENTORY_ADJUSTMENT_ROUTES.INDEX,
typeof INVENTORY_ADJUSTMENT_ROUTES.BY_ID
> {
constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
super(baseUrl, defaultOptions, INVENTORY_ADJUSTMENT_ROUTES.INDEX, INVENTORY_ADJUSTMENT_ROUTES.BY_ID)
}
async addAttachment(id: string, files: File[]) {
const fd = new FormData()
for (const file of files) {
fd.append("attachments[]", file)
}
return this.postFormData(`/api/inventory-adjustments/${id}/add-attachment`, fd)
}
async deleteAttachment(id: string, attachmentId: number) {
return this.delete(INVENTORY_ADJUSTMENT_ROUTES.DELETE_ATTACHMENT, { params: { id }, body: { attachment_id: attachmentId } } as never)
}
}