fix(striker-ui-api): extract link from UPS type description
This commit is contained in:
parent
4ff8905509
commit
58549eb3ed
@ -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;
|
||||
|
11
striker-ui-api/src/types/APIUPS.d.ts
vendored
11
striker-ui-api/src/types/APIUPS.d.ts
vendored
@ -4,3 +4,14 @@ type UPSOverview = {
|
||||
upsName: string;
|
||||
upsUUID: string;
|
||||
};
|
||||
|
||||
type UPSTemplate = {
|
||||
[upsName: string]: AnvilDataUPSHash[string] & {
|
||||
links: {
|
||||
[linkId: string]: {
|
||||
linkHref: string;
|
||||
linkLabel: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user