diff --git a/striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts b/striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts index ea014049..3c4a8b9c 100644 --- a/striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts +++ b/striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts @@ -21,11 +21,28 @@ export const getUPSTemplate: RequestHandler = (request, response) => { const upsData: AnvilDataUPSHash = Object.entries( rawUPSData, - ).reduce((previous, [upsTypeId, value]) => { - const { brand } = value; + ).reduce((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; diff --git a/striker-ui-api/src/types/APIUPS.d.ts b/striker-ui-api/src/types/APIUPS.d.ts index 4eb25534..5199e348 100644 --- a/striker-ui-api/src/types/APIUPS.d.ts +++ b/striker-ui-api/src/types/APIUPS.d.ts @@ -4,3 +4,14 @@ type UPSOverview = { upsName: string; upsUUID: string; }; + +type UPSTemplate = { + [upsName: string]: AnvilDataUPSHash[string] & { + links: { + [linkId: string]: { + linkHref: string; + linkLabel: string; + }; + }; + }; +};