Blame view

美国版/Food Labeling Management Platform/src/services/labelService.ts 2.43 KB
0e27ddc8   杨鑫   标签
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  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<PagedResultDto<LabelDto>> {
    return api.requestJson<PagedResultDto<LabelDto>>({
      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<LabelDto> {
    return api.requestJson<LabelDto>({
      path: `${PATH}/${encodeURIComponent(labelCode)}`,
      method: "GET",
      signal,
    });
  }
  
  export async function createLabel(input: LabelCreateInput): Promise<LabelDto> {
    return api.requestJson<LabelDto>({
      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<LabelDto> {
    return api.requestJson<LabelDto>({
      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<void> {
    await api.requestJson<unknown>({
      path: `${PATH}/${encodeURIComponent(labelCode)}`,
      method: "DELETE",
    });
  }