fix(striker-ui-api): extract link from UPS type description

main
Tsu-ba-me 2 years ago committed by digimer
parent b94e459e0a
commit d8efd72c21
  1. 23
      striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts
  2. 11
      striker-ui-api/src/types/APIUPS.d.ts

@ -21,11 +21,28 @@ export const getUPSTemplate: RequestHandler = (request, response) => {
const upsData: AnvilDataUPSHash = Object.entries(
rawUPSData,
).reduce<AnvilDataUPSHash>((previous, [upsTypeId, value]) => {
const { brand } = value;
).reduce<UPSTemplate>((previous, [upsTypeId, value]) => {
const { brand, description: rawDescription, ...rest } = value;
const matched = rawDescription.match(
/^(.+)\s+[-]\s+[<][^>]+href=[\\"]+([^\s]+)[\\"]+.+[>]([^<]+)[<]/,
);
const result: UPSTemplate[string] = {
...rest,
brand,
description: rawDescription,
links: {},
};
if (matched) {
const [, description, linkHref, linkLabel] = matched;
result.description = description;
result.links[0] = { linkHref, linkLabel };
}
if (/apc/i.test(brand)) {
previous[upsTypeId] = value;
previous[upsTypeId] = result;
}
return previous;

@ -4,3 +4,14 @@ type UPSOverview = {
upsName: string;
upsUUID: string;
};
type UPSTemplate = {
[upsName: string]: AnvilDataUPSHash[string] & {
links: {
[linkId: string]: {
linkHref: string;
linkLabel: string;
};
};
};
};

Loading…
Cancel
Save