[task-193] [int]

This commit is contained in:
roydfalk 2025-04-03 12:18:01 +00:00
parent b522514c26
commit a73e11c6f6
6 changed files with 81 additions and 69 deletions

View file

@ -18,10 +18,10 @@ namespace _espe.api
/** /**
*/ */
export function register_invite_accept( export function register_invite_accept(
rest_subject : lib_plankton.rest.type_rest rest_subject : lib_plankton.rest_http.type_rest
) : void ) : void
{ {
register< lib_plankton.rest_http.register<
{ {
key : string; key : string;
membership_number_value : (null | string); membership_number_value : (null | string);
@ -33,12 +33,12 @@ namespace _espe.api
>( >(
rest_subject, rest_subject,
lib_plankton.http.enum_method.post, lib_plankton.http.enum_method.post,
"/invite/accept", _espe.api.full_path("/invite/accept"),
{ {
/** /**
* @todo translation * @todo translation
*/ */
"description": "nimmt eine Einladung an", "description": () => "nimmt eine Einladung an",
/** /**
* @todo * @todo
*/ */
@ -51,8 +51,8 @@ namespace _espe.api
"output_schema": () => ({ "output_schema": () => ({
"nullable": true, "nullable": true,
}), }),
"restriction": restriction_none, "restriction": () => restriction_none,
"execution": async ({"input": input}) => { "execution": () => async ({"input": input}) => {
if (input === null) { if (input === null) {
return Promise.resolve({ return Promise.resolve({
"status_code": 400, "status_code": 400,

View file

@ -19,10 +19,10 @@ namespace _espe.api
/** /**
*/ */
export function register_invite_create( export function register_invite_create(
rest_subject : lib_plankton.rest.type_rest rest_subject : lib_plankton.rest_http.type_rest
) : void ) : void
{ {
register< lib_plankton.rest_http.register<
{ {
membership_number_mode : int; membership_number_mode : int;
membership_number_value : (null | string); membership_number_value : (null | string);
@ -46,12 +46,12 @@ namespace _espe.api
>( >(
rest_subject, rest_subject,
lib_plankton.http.enum_method.post, lib_plankton.http.enum_method.post,
"/invite/create", _espe.api.full_path("/invite/create"),
{ {
/** /**
* @todo translation * @todo translation
*/ */
"description": "erstellt eine Einladung und gibt die erzeugte ID und den erzeugten Schlüssel aus", "description": () => "erstellt eine Einladung und gibt die erzeugte ID und den erzeugten Schlüssel aus",
"input_schema": () => ({ "input_schema": () => ({
"type": "object", "type": "object",
"nullable": false, "nullable": false,
@ -145,8 +145,8 @@ namespace _espe.api
"key", "key",
] ]
}), }),
"restriction": restriction_logged_in, "restriction": () => restriction_logged_in,
"execution": async ({"input": input}) => { "execution": () => async ({"input": input}) => {
if (input === null) { if (input === null) {
return Promise.reject(new Error("impossible")); return Promise.reject(new Error("impossible"));
} }

View file

@ -18,25 +18,28 @@ namespace _espe.api
/** /**
*/ */
export function register_invite_examine( export function register_invite_examine(
rest_subject : lib_plankton.rest.type_rest rest_subject : lib_plankton.rest_http.type_rest
) : void ) : void
{ {
register< lib_plankton.rest_http.register<
any, any,
any any
>( >(
rest_subject, rest_subject,
lib_plankton.http.enum_method.get, lib_plankton.http.enum_method.get,
"/invite/examine", _espe.api.full_path("/invite/examine"),
{ {
/** /**
* @todo translation * @todo translation
*/ */
"description": "gibt die Daten einer Einladung anhand ihres Schlüssels aus", "description": () => "gibt die Daten einer Einladung anhand ihres Schlüssels aus",
"input_schema": () => ({ "query_parameters": () => [
"type": "string", {
"nullable": false, "name": "key",
}), "required": true,
"description": "key",
}
],
"output_schema": () => ({ "output_schema": () => ({
"type": "object", "type": "object",
"nullable": false, "nullable": false,
@ -77,7 +80,7 @@ namespace _espe.api
"nullable": true, "nullable": true,
"description": "E-Mail-Adresse | Wert" "description": "E-Mail-Adresse | Wert"
}, },
"groups_integer": { "groups_mode": {
"type": "integer", "type": "integer",
"nullable": true, "nullable": true,
"description": "Gruppen | Modus" "description": "Gruppen | Modus"
@ -104,9 +107,9 @@ namespace _espe.api
"groups_value", "groups_value",
] ]
}), }),
"restriction": restriction_none, "restriction": () => restriction_none,
"execution": ({"input": input}) => { "execution": () => ({"query_parameters": query_parameters, "input": input}) => {
const invite_key : _espe.type.invite_key = input; const invite_key : _espe.type.invite_key = query_parameters["key"];
return ( return (
_espe.service.invite.examine(invite_key) _espe.service.invite.examine(invite_key)
.then( .then(

View file

@ -271,7 +271,7 @@ namespace _espe
"hidden": true, "hidden": true,
}), }),
"conf_path": lib_plankton.args.class_argument.volatile({ "conf_path": lib_plankton.args.class_argument.volatile({
"indicators_long": ["conf_path"], "indicators_long": ["conf-path"],
"indicators_short": ["c"], "indicators_short": ["c"],
"type": lib_plankton.args.enum_type.string, "type": lib_plankton.args.enum_type.string,
"mode": lib_plankton.args.enum_mode.replace, "mode": lib_plankton.args.enum_mode.replace,

View file

@ -157,7 +157,9 @@ namespace _espe.repository.invite
"groups_mode": _espe.helpers.invite_prefill_mode_decode(dispersal.core_row["groups_mode"]), "groups_mode": _espe.helpers.invite_prefill_mode_decode(dispersal.core_row["groups_mode"]),
"groups_value": lib_plankton.list.sorted<string>( "groups_value": lib_plankton.list.sorted<string>(
dispersal.group_rows.map(row => row["group_name"]), dispersal.group_rows.map(row => row["group_name"]),
(group1, group2) => ((group1 <= group2) ? 0 : 1) {
"compare_element": (group1, group2) => (group1 <= group2)
}
), ),
}; };
} }
@ -280,6 +282,7 @@ namespace _espe.repository.invite
/** /**
* @todo optimize
*/ */
export async function identify( export async function identify(
key : _espe.type.invite_key key : _espe.type.invite_key

View file

@ -112,7 +112,7 @@ namespace _espe.service.invite
{ {
let invite_object : (null | _espe.type.invite_object); let invite_object : (null | _espe.type.invite_object);
try { try {
invite_object = await get(key) invite_object = await get(key);
} }
catch (error) { catch (error) {
invite_object = null; invite_object = null;
@ -122,7 +122,7 @@ namespace _espe.service.invite
} }
else { else {
const now : int = lib_plankton.base.get_current_timestamp(true); const now : int = lib_plankton.base.get_current_timestamp(true);
if ((invite_object.expiry !== null) && (invite_object.expiry >= now)) { if ((invite_object.expiry !== null) && (invite_object.expiry < now)) {
return Promise.reject(new Error("expired")); return Promise.reject(new Error("expired"));
} }
else { else {
@ -146,6 +146,11 @@ namespace _espe.service.invite
{ {
const invite_id : _espe.type.invite_id = await _espe.repository.invite.identify(key); const invite_id : _espe.type.invite_id = await _espe.repository.invite.identify(key);
const invite_object : _espe.type.invite_object = await _espe.repository.invite.read(invite_id); const invite_object : _espe.type.invite_object = await _espe.repository.invite.read(invite_id);
const now : int = lib_plankton.base.get_current_timestamp(true);
if ((invite_object.expiry !== null) && (invite_object.expiry < now)) {
return Promise.reject(new Error("expired"));
}
else {
const member_id : _espe.type.member_id = await _espe.service.member.project( const member_id : _espe.type.member_id = await _espe.service.member.project(
{ {
"membership_number": ( "membership_number": (
@ -188,5 +193,6 @@ namespace _espe.service.invite
); );
await _espe.repository.invite.delete_(invite_id); await _espe.repository.invite.delete_(invite_id);
} }
}
} }