This commit is contained in:
Michel Fedde 2025-06-18 22:53:54 +02:00
parent 441715675c
commit a79898b2e9
48 changed files with 2062 additions and 1503 deletions

View file

@ -4,63 +4,63 @@ import {Nullable} from "../types/Nullable";
import {ArrayUtils} from "../Utilities/ArrayUtils";
export enum TransformerType {
Locale,
Channel,
PermissionBoolean,
Locale,
Channel,
PermissionBoolean,
}
type GroupConfigurationTransformer = {
path: string[];
type: TransformerType,
path: string[];
type: TransformerType,
}
export type GroupConfigurationResult =
ChannelId | Intl.Locale | boolean
export type GroupConfigurationResult =
ChannelId | Intl.Locale | boolean
export class GroupConfigurationTransformers {
static TRANSFORMERS: GroupConfigurationTransformer[] = [
{
path: ['channels', 'newPlaydates'],
type: TransformerType.Channel,
},
{
path: ['channels', 'playdateReminders'],
type: TransformerType.Channel,
},
{
path: ['locale'],
type: TransformerType.Locale,
},
{
path: ['permissions', 'allowMemberManagingPlaydates'],
type: TransformerType.PermissionBoolean
}
];
public getValue(configValue: GroupConfigurationModel): GroupConfigurationResult {
const transformerType = this.getTransformerType(configValue.key);
if (transformerType === undefined || transformerType === null) {
throw new Error(`Can't find transformer for ${configValue.key}`);
}
switch (transformerType) {
case TransformerType.Locale:
return new Intl.Locale(configValue.value)
case TransformerType.Channel:
return <ChannelId>configValue.value;
case TransformerType.PermissionBoolean:
return configValue.value === '1';
}
static TRANSFORMERS: GroupConfigurationTransformer[] = [
{
path: ['channels', 'newPlaydates'],
type: TransformerType.Channel,
},
{
path: ['channels', 'playdateReminders'],
type: TransformerType.Channel,
},
{
path: ['locale'],
type: TransformerType.Locale,
},
{
path: ['permissions', 'allowMemberManagingPlaydates'],
type: TransformerType.PermissionBoolean
}
public getTransformerType(configKey: string): Nullable<TransformerType> {
const path = configKey.split('.');
return GroupConfigurationTransformers.TRANSFORMERS.find(
transformer => {
return ArrayUtils.arraysEqual(transformer.path, path);
}
)?.type;
];
public getValue(configValue: GroupConfigurationModel): GroupConfigurationResult {
const transformerType = this.getTransformerType(configValue.key);
if (transformerType === undefined || transformerType === null) {
throw new Error(`Can't find transformer for ${configValue.key}`);
}
switch (transformerType) {
case TransformerType.Locale:
return new Intl.Locale(configValue.value)
case TransformerType.Channel:
return <ChannelId>configValue.value;
case TransformerType.PermissionBoolean:
return configValue.value === '1';
}
}
public getTransformerType(configKey: string): Nullable<TransformerType> {
const path = configKey.split('.');
return GroupConfigurationTransformers.TRANSFORMERS.find(
transformer => {
return ArrayUtils.arraysEqual(transformer.path, path);
}
)?.type;
}
}