add system preferences to frontend

This commit is contained in:
rubikscraft
2022-03-19 19:30:47 +01:00
parent 49f3b01558
commit 8db5917bbc
14 changed files with 371 additions and 16 deletions

View File

@@ -14,7 +14,8 @@ import {
export class UpdateSysPreferenceRequest {
@IsNotEmpty()
value: string;
@IsSysPrefValue()
value: SysPrefValueType;
}
export class SysPreferenceResponse {

View File

@@ -10,7 +10,6 @@ import tuple from '../types/tuple';
const SysPreferencesTuple = tuple(
'jwt_secret',
'jwt_expires_in',
'upload_require_auth',
'test_string',
'test_number',
'test_boolean',
@@ -19,6 +18,16 @@ const SysPreferencesTuple = tuple(
export const SysPreferences: string[] = SysPreferencesTuple;
export type SysPreferences = typeof SysPreferencesTuple[number];
export const SysPreferenceFriendlyNames: {
[key in SysPreferences]: string;
} = {
jwt_secret: 'JWT Secret',
jwt_expires_in: 'JWT Expiry Time',
test_string: 'Test String',
test_number: 'Test Number',
test_boolean: 'Test Boolean',
};
// Syspref Values
export type SysPrefValueType = string | number | boolean;
@@ -30,7 +39,6 @@ export const SysPreferenceValueTypes: {
} = {
jwt_secret: 'string',
jwt_expires_in: 'string',
upload_require_auth: 'boolean',
test_string: 'string',
test_number: 'number',
test_boolean: 'boolean',

View File

@@ -17,9 +17,11 @@ export type AsyncFailable<T> = Promise<Failable<T>>;
// TODO: prevent promise from being allowed in these 2 functions
export function HasFailed<T>(failable: Failable<T>): failable is Failure {
if (failable instanceof Promise) throw new Error('Invalid use of HasFailed');
return failable instanceof Failure;
}
export function HasSuccess<T>(failable: Failable<T>): failable is T {
if (failable instanceof Promise) throw new Error('Invalid use of HasSuccess');
return !(failable instanceof Failure);
}