This commit is contained in:
2026-04-07 15:05:03 +03:00
parent 38ef10da4d
commit 90c84a0bda
4 changed files with 578 additions and 1 deletions
+36 -1
View File
@@ -1,7 +1,7 @@
import { CrudClient } from "../infra/crud-client"
import type { ApiClientOptions } from "../infra/client"
import type { ApiOperationResponse, ApiPath, ApiRequestBody, ApiResponse } from "../infra/types"
import { ApiBaseResponse } from "src/contracts/types"
import { ApiBaseResponse } from "../contracts/types"
export const JOB_CARD_ROUTES = {
INDEX: "/api/job-cards",
@@ -24,6 +24,12 @@ export const JOB_CARD_ROUTES = {
ADD_PART: "/api/job-cards/{id}/add-part",
UPDATE_PART: "/api/job-cards/{id}/update-part",
DELETE_PART: "/api/job-cards/{id}/delete-part",
GET_SERVICES: "/api/job-cards/{id}/get-services",
ADD_SERVICE: "/api/job-cards/{id}/add-service",
UPDATE_SERVICE: "/api/job-cards/{id}/update-service",
DELETE_SERVICE: "/api/job-cards/{id}/delete-service",
ADD_SERVICE_ATTACHMENT: "/api/job-cards/{id}/add-service-attachment",
DELETE_SERVICE_ATTACHMENT: "/api/job-cards/{id}/delete-service-attachment",
} as const satisfies Record<string, ApiPath>
@@ -122,4 +128,33 @@ export class JobCardsClient extends CrudClient<
async deletePart(id: string, jobCardPartId: number) {
return this.delete(JOB_CARD_ROUTES.DELETE_PART, { params: { id }, body: { job_card_part_id: jobCardPartId } } as never)
}
async getServices(id: string, params?: Record<string, unknown>) {
return this.get(JOB_CARD_ROUTES.GET_SERVICES, { params: { id }, query: params as any })
}
async addService(id: string, payload: ApiRequestBody<typeof JOB_CARD_ROUTES.ADD_SERVICE, "post">) {
return this.post(JOB_CARD_ROUTES.ADD_SERVICE, payload, { params: { id } })
}
async updateService(id: string, payload: ApiRequestBody<typeof JOB_CARD_ROUTES.UPDATE_SERVICE, "put">) {
return this.put(JOB_CARD_ROUTES.UPDATE_SERVICE, payload, { params: { id } })
}
async deleteService(id: string, jobCardServiceId: number) {
return this.delete(JOB_CARD_ROUTES.DELETE_SERVICE, { params: { id }, body: { job_card_service_id: jobCardServiceId } } as never)
}
async addServiceAttachment(id: string, jobCardServiceId: number, files: File[]) {
const fd = new FormData()
fd.append("job_card_service_id", String(jobCardServiceId))
for (const file of files) {
fd.append("attachments[]", file)
}
return this.postFormData(`/api/job-cards/${id}/add-service-attachment`, fd)
}
async deleteServiceAttachment(id: string, jobCardServiceId: number, attachmentId: number) {
return this.delete(JOB_CARD_ROUTES.DELETE_SERVICE_ATTACHMENT, { params: { id }, body: { job_card_service_id: jobCardServiceId, attachment_id: attachmentId } } as never)
}
}