Skip to content

Commit

Permalink
JNG-5966 enum ordinal helpers (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg authored Oct 8, 2024
1 parent c097185 commit 810827d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions judo-ui-typescript-rest-api/src/main/resources/model/enum.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,31 @@ export enum {{ restParamName enumerationType }} {
{{ member.name }} = '{{ member.name }}',
{{/ each}}
}

type OrdinalOf{{ restParamName enumerationType }} = {{# each enumerationType.members as | member | }}{{ member.ordinal }}{{# unless @last }} | {{/ unless }}{{/ each }}

export function get{{ restParamName enumerationType }}LiteralByOrdinal(ordinal: OrdinalOf{{ restParamName enumerationType }}): {{ restParamName enumerationType }} {
switch(ordinal) {
{{# each enumerationType.members as | member | }}
{{# unless @last }}
case {{ member.ordinal }}:
{{ else }}
default:
{{/ unless }}
return {{ restParamName enumerationType }}.{{ member.name }};
{{/ each}}
}
}

export function get{{ restParamName enumerationType }}OrdinalByLiteral(literal: {{ restParamName enumerationType }}): OrdinalOf{{ restParamName enumerationType }} {
switch(literal) {
{{# each enumerationType.members as | member | }}
{{# unless @last }}
case {{ restParamName enumerationType }}.{{ member.name }}:
{{ else }}
default:
{{/ unless }}
return {{ member.ordinal }};
{{/ each}}
}
}

0 comments on commit 810827d

Please sign in to comment.