import { createApiClient } from "../lib/apiClient"; import type { LabelCreateInput, LabelDto, LabelGetListInput, LabelUpdateInput, PagedResultDto, } from "../types/label"; const api = createApiClient({ getToken: () => { try { return localStorage.getItem("access_token") ?? localStorage.getItem("token") ?? null; } catch { return null; } }, }); const PATH = "/label"; export async function getLabels(input: LabelGetListInput, signal?: AbortSignal): Promise> { return api.requestJson>({ path: PATH, method: "GET", query: { SkipCount: input.skipCount, MaxResultCount: input.maxResultCount, Sorting: input.sorting, Keyword: input.keyword, LocationId: input.locationId, ProductId: input.productId, LabelCategoryId: input.labelCategoryId, LabelTypeId: input.labelTypeId, TemplateCode: input.templateCode, State: input.state, }, signal, }); } export async function getLabel(labelCode: string, signal?: AbortSignal): Promise { return api.requestJson({ path: `${PATH}/${encodeURIComponent(labelCode)}`, method: "GET", signal, }); } export async function createLabel(input: LabelCreateInput): Promise { return api.requestJson({ path: PATH, method: "POST", body: { labelCode: input.labelCode, labelName: input.labelName, templateCode: input.templateCode, locationId: input.locationId, labelCategoryId: input.labelCategoryId, labelTypeId: input.labelTypeId, productIds: input.productIds, labelInfoJson: input.labelInfoJson, state: input.state ?? true, }, }); } export async function updateLabel(labelCode: string, input: LabelUpdateInput): Promise { return api.requestJson({ path: `${PATH}/${encodeURIComponent(labelCode)}`, method: "PUT", body: { labelName: input.labelName, templateCode: input.templateCode, locationId: input.locationId, labelCategoryId: input.labelCategoryId, labelTypeId: input.labelTypeId, productIds: input.productIds, labelInfoJson: input.labelInfoJson, state: input.state ?? true, }, }); } export async function deleteLabel(labelCode: string): Promise { await api.requestJson({ path: `${PATH}/${encodeURIComponent(labelCode)}`, method: "DELETE", }); }