Skip to content

Commit d7b9426

Browse files
committed
feat: refactor ReprintParcelFunction to accept individual parameters for reprint request
1 parent 1fb01a2 commit d7b9426

1 file changed

Lines changed: 73 additions & 11 deletions

File tree

actions/gls-action/src/functions/reprintParcelFunction.ts

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import {
1414
} from "@code0-tech/hercules";
1515
import { getAuthToken } from "../helpers.js";
1616
import {
17-
ReprintParcelRequestData,
1817
ReprintParcelResponseData,
1918
ReprintParcelResponseDataSchema,
2019
} from "../data_types/glsReprintParcel.js";
20+
import { ReturnLabels } from "../data_types/glsPrintingOptions.js";
2121

2222
@Identifier("reprintParcel")
2323
@DisplayIcon("codezero:gls")
24-
@Signature("(data: GLS_REPRINT_PARCEL_REQUEST_DATA): GLS_REPRINT_PARCEL_RESPONSE_DATA")
24+
@Signature("(CreationDate: string, TemplateSet: \"NONE\"|\"D_200\"|\"PF_4_I\"|\"PF_4_I_200\"|\"PF_4_I_300\"|\"PF_8_D_200\"|\"T_200_BF\"|\"T_300_BF\"|\"ZPL_200\"|\"ZPL_200_TRACKID_EAN_128\"|\"ZPL_200_TRACKID_CODE_39\"|\"ZPL_200_REFNO_EAN_128\"|\"ZPL_200_REFNO_CODE_39\"|\"ZPL_300\"|\"ZPL_300_TRACKID_EAN_128\"|\"ZPL_300_TRACKID_CODE_39\"|\"ZPL_300_REFNO_EAN_128\"|\"ZPL_300_REFNO_CODE_39\", LabelFormat: \"PDF\"|\"ZEBRA\"|\"INTERMEC\"|\"DATAMAX\"|\"TOSHIBA\"|\"PNG\", TrackID?: string, ParcelNumber?: number, ShipmentReference?: string, ShipmentUnitReference?: string, PartnerParcelNumber?: string): GLS_REPRINT_PARCEL_RESPONSE_DATA")
2525
@Name({ code: "en-US", content: "Reprint parcel" })
2626
@DisplayMessage({ code: "en-US", content: "Reprint parcel" })
2727
@Documentation({
@@ -33,21 +33,83 @@ import {
3333
content: "Reprints the label for an existing parcel.\nUse this if the original label is damaged, lost, or needs to be printed in a different format.",
3434
})
3535
@Parameter({
36-
runtimeName: "data",
37-
name: [{ code: "en-US", content: "Data" }],
38-
description: [{ code: "en-US", content: "The reprint parcel request data." }],
36+
runtimeName: "CreationDate",
37+
name: [{ code: "en-US", content: "Creation date" }],
38+
description: [{ code: "en-US", content: "The creation date of the parcel, in ISO format (YYYY-MM-DD)." }],
39+
})
40+
@Parameter({
41+
runtimeName: "TemplateSet",
42+
name: [{ code: "en-US", content: "Template set" }],
43+
description: [{ code: "en-US", content: "The template set to use for the reprinted label." }],
44+
})
45+
@Parameter({
46+
runtimeName: "LabelFormat",
47+
name: [{ code: "en-US", content: "Label format" }],
48+
description: [{ code: "en-US", content: "The format of the reprinted label." }],
49+
})
50+
@Parameter({
51+
runtimeName: "TrackID",
52+
name: [{ code: "en-US", content: "Track ID" }],
53+
description: [{ code: "en-US", content: "The Track ID of the parcel to reprint. Max length is 8 characters." }],
54+
})
55+
@Parameter({
56+
runtimeName: "ParcelNumber",
57+
name: [{ code: "en-US", content: "Parcel number" }],
58+
description: [{ code: "en-US", content: "The parcel number of the parcel to reprint." }],
59+
})
60+
@Parameter({
61+
runtimeName: "ShipmentReference",
62+
name: [{ code: "en-US", content: "Shipment reference" }],
63+
description: [{ code: "en-US", content: "The shipment reference of the parcel to reprint. Max length is 40 characters." }],
64+
})
65+
@Parameter({
66+
runtimeName: "ShipmentUnitReference",
67+
name: [{ code: "en-US", content: "Shipment unit reference" }],
68+
description: [{ code: "en-US", content: "The shipment unit reference of the parcel to reprint. Max length is 40 characters." }],
69+
})
70+
@Parameter({
71+
runtimeName: "PartnerParcelNumber",
72+
name: [{ code: "en-US", content: "Partner parcel number" }],
73+
description: [{ code: "en-US", content: "The partner parcel number of the parcel to reprint. Max length is 50 characters." }],
3974
})
4075
export class ReprintParcelFunction {
41-
async run(context: FunctionContext, data: ReprintParcelRequestData): Promise<ReprintParcelResponseData> {
76+
async run(
77+
context: FunctionContext,
78+
CreationDate: string,
79+
TemplateSet: ReturnLabels["TemplateSet"],
80+
LabelFormat: ReturnLabels["LabelFormat"],
81+
TrackID?: string,
82+
ParcelNumber?: number,
83+
ShipmentReference?: string,
84+
ShipmentUnitReference?: string,
85+
PartnerParcelNumber?: string
86+
): Promise<ReprintParcelResponseData> {
4287
const url = context.matchedConfig.findConfig("ship_it_api_url") as string;
4388

4489
try {
45-
const result = await axios.post(`${url}/rs/shipments/reprintparcel`, data, {
46-
headers: {
47-
Authorization: `Bearer ${await getAuthToken(context)}`,
48-
"Content-Type": "application/glsVersion1+json",
90+
const result = await axios.post(
91+
`${url}/rs/shipments/reprintparcel`,
92+
{
93+
TrackID,
94+
ParcelNumber,
95+
ShipmentReference,
96+
ShipmentUnitReference,
97+
PartnerParcelNumber,
98+
CreationDate,
99+
PrintingOptions: {
100+
ReturnLabels: {
101+
TemplateSet,
102+
LabelFormat,
103+
},
104+
},
49105
},
50-
});
106+
{
107+
headers: {
108+
Authorization: `Bearer ${await getAuthToken(context)}`,
109+
"Content-Type": "application/glsVersion1+json",
110+
},
111+
}
112+
);
51113
return ReprintParcelResponseDataSchema.parse(result.data);
52114
} catch (error: any) {
53115
console.log(error);

0 commit comments

Comments
 (0)