backend/source/value_objects/access_level.ts

75 lines
2 KiB
TypeScript
Raw Normal View History

2025-09-25 17:18:16 +02:00
/*
This file is part of »zeitbild«.
Copyright 2025 'kcf' <fenris@folksprak.org>
»zeitbild« is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
»zeitbild« is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with »zeitbild«. If not, see <http://www.gnu.org/licenses/>.
*/
2024-09-21 10:56:00 +02:00
/**
*/
namespace _zeitbild.value_object.access_level
{
/**
*/
export function to_string(
2024-09-21 11:05:24 +02:00
access_level : _zeitbild.enum_access_level
2024-09-21 10:56:00 +02:00
) : string
{
switch (access_level) {
2024-09-21 11:05:24 +02:00
case _zeitbild.enum_access_level.none: {return "none";}
case _zeitbild.enum_access_level.view: {return "view";}
case _zeitbild.enum_access_level.edit: {return "edit";}
case _zeitbild.enum_access_level.admin: {return "admin";}
2024-09-21 10:56:00 +02:00
default: {throw (new Error("invalid access level: " + String(access_level)));}
}
}
/**
*/
export function from_string(
access_level_ : string
2024-09-21 11:05:24 +02:00
) : _zeitbild.enum_access_level
2024-09-21 10:56:00 +02:00
{
switch (access_level_) {
2024-09-21 11:05:24 +02:00
case "none": {return _zeitbild.enum_access_level.none;}
case "view": {return _zeitbild.enum_access_level.view;}
case "edit": {return _zeitbild.enum_access_level.edit;}
case "admin": {return _zeitbild.enum_access_level.admin;}
2024-09-21 10:56:00 +02:00
default: {throw (new Error("invalid encoded access level: " + String(access_level_)));}
}
}
/**
*/
export function order(
2024-09-21 11:05:24 +02:00
x : _zeitbild.enum_access_level,
y : _zeitbild.enum_access_level
2024-09-21 10:56:00 +02:00
) : boolean
{
2024-09-21 11:05:24 +02:00
const list : Array<_zeitbild.enum_access_level> = [
_zeitbild.enum_access_level.none,
_zeitbild.enum_access_level.view,
_zeitbild.enum_access_level.edit,
_zeitbild.enum_access_level.admin,
2024-09-21 10:56:00 +02:00
];
return (list.indexOf(x) <= list.indexOf(y));
}
}