Skip to content

Commit ae24b16

Browse files
authored
[feat] Standardizes region IDs using external mapping (#277)
1 parent 405e936 commit ae24b16

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

src/Services/Status.Trans.V2.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,14 @@ import { Logger } from "~/Helpers/Logger";
55
import { EmptyDB } from "./Status";
66
import { IncidentEntityV2, NameEnum, StatusEntityV2, StatusEnum } from "./Status.Entities";
77
import { IStatusContext, Models } from "./Status.Models";
8+
import regionIdMap from "./regionIdMap.json";
89

910
const log = new Logger("Service", "Status", "TransformerV2");
1011

1112
/**
12-
* Transforms the provided components and events into a status context.
13-
*
14-
* This function processes the given components and events, organizing them into
15-
* categories, regions, and services. It also handles event statuses and histories,
16-
* ensuring that the data is structured and ready for further use.
17-
*
18-
* Note: This function assumes that all components have valid attributes and that
19-
* all events have valid impact values. It also assumes that the input data is
20-
* already sorted in the desired order.
21-
*
22-
* @param {Object} param - The input object containing components and events.
23-
* @param {StatusEntityV2[]} param.Components - The list of status components to be processed.
24-
* @param {IncidentEntityV2[]} param.Events - The list of incident events to be processed.
25-
* @returns {IStatusContext} The transformed status context containing organized data.
26-
*
27-
* @example
28-
* const context = TransformerV2({ Components: [], Events: [] });
29-
* console.log(context);
30-
*
31-
* @throws {Error} If any component or event is missing required attributes.
32-
* @throws {Error} If any event has an invalid impact value.
33-
*
3413
* @author Aloento
3514
* @since 1.0.0
36-
* @version 0.2.0
15+
* @version 0.2.1
3716
*/
3817
export function TransformerV2({ Components, Events }: { Components: StatusEntityV2[], Events: IncidentEntityV2[] }): IStatusContext {
3918
let id = 0;
@@ -74,7 +53,8 @@ export function TransformerV2({ Components, Events }: { Components: StatusEntity
7453

7554
let dbRegion = db.Regions.find((x) => x.Name === targetRegion);
7655
if (!dbRegion) {
77-
dbRegion = { Id: id++, Name: targetRegion, Services: new Set() };
56+
const regionId = regionIdMap[targetRegion as keyof typeof regionIdMap] ?? id++;
57+
dbRegion = { Id: regionId, Name: targetRegion, Services: new Set() };
7858
db.Regions.push(dbRegion);
7959
}
8060

@@ -118,6 +98,8 @@ export function TransformerV2({ Components, Events }: { Components: StatusEntity
11898
}
11999
}
120100

101+
db.Regions.sort((a, b) => a.Id - b.Id);
102+
121103
log.debug("Component data loaded.");
122104

123105
for (const event of Events) {

src/Services/regionIdMap.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"EU-DE": 0,
3+
"EU-NL": 1,
4+
"Global": 2
5+
}

0 commit comments

Comments
 (0)