@@ -5,35 +5,14 @@ import { Logger } from "~/Helpers/Logger";
55import { EmptyDB } from "./Status" ;
66import { IncidentEntityV2 , NameEnum , StatusEntityV2 , StatusEnum } from "./Status.Entities" ;
77import { IStatusContext , Models } from "./Status.Models" ;
8+ import regionIdMap from "./regionIdMap.json" ;
89
910const 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 */
3817export 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 ) {
0 commit comments