backend/source/api/actions/member_project.ts

100 lines
2.6 KiB
TypeScript
Raw Normal View History

2024-05-20 21:56:48 +02:00
/*
Espe | Ein schlichtes Werkzeug zur Mitglieder-Verwaltung | Backend
Copyright (C) 2024 Christian Fraß
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see
<https://www.gnu.org/licenses/>.
*/
2024-04-22 10:22:18 +02:00
namespace _espe.api
2024-04-22 10:02:34 +02:00
{
/**
*/
2024-04-29 22:40:52 +02:00
export function register_member_project(
2024-04-22 10:02:34 +02:00
rest_subject : lib_plankton.rest.type_rest
) : void
{
2024-05-15 08:38:58 +02:00
register<
2024-04-29 22:40:52 +02:00
{
membership_number : string;
name_real_value : string;
email_address_private : (null | string);
},
_espe.type.member_id
2024-04-29 20:48:20 +02:00
>(
2024-04-22 10:02:34 +02:00
rest_subject,
lib_plankton.http.enum_method.post,
2024-05-15 08:38:58 +02:00
"/member/project",
2024-04-22 10:02:34 +02:00
{
"description": "erstellt ein neues Mitglied und gibt die erzeugte ID aus",
"input_schema": () => ({
"type": "object",
"nullable": false,
"additionalProperties": false,
"properties": {
2024-04-29 20:48:20 +02:00
"membership_number": {
2024-04-22 10:02:34 +02:00
"type": "string",
"nullable": false,
2024-05-21 19:58:00 +02:00
"description": "Mitgliedsnummer"
2024-04-22 10:02:34 +02:00
},
2024-04-29 20:48:20 +02:00
"name_real_value": {
2024-04-22 10:02:34 +02:00
"type": "string",
2024-04-29 20:48:20 +02:00
"nullable": false,
2024-05-21 19:58:00 +02:00
"description": "Klarname"
2024-04-22 10:02:34 +02:00
},
2024-04-29 22:40:52 +02:00
"email_address_private": {
2024-04-22 10:02:34 +02:00
"type": "string",
"nullable": true,
2024-05-21 19:58:00 +02:00
"description": "private E-Mail-Adresse"
2024-04-22 10:02:34 +02:00
},
},
"required": [
2024-04-29 20:48:20 +02:00
"membership_number",
"name_real_value",
2024-04-22 10:02:34 +02:00
]
}),
"output_schema": () => ({
2024-04-29 20:48:20 +02:00
"type": "number",
2024-04-22 10:02:34 +02:00
"nullable": false,
}),
"restriction": restriction_logged_in,
"execution": async ({"input": input}) => {
2024-05-27 17:32:42 +02:00
if (input === null) {
return Promise.reject(new Error("impossible"));
}
else {
const member_id : _espe.type.member_id = await _espe.service.member.project(
{
"membership_number": input.membership_number,
"name_real_value": input.name_real_value,
2024-05-27 18:12:15 +02:00
"email_address_private": (
("email_address_private" in input)
? (
(input.email_address_private !== "")
? input.email_address_private
: null
)
: null
),
2024-05-27 17:32:42 +02:00
}
);
return Promise.resolve({
"status_code": 201,
"data": member_id
});
}
2024-04-22 10:02:34 +02:00
}
}
);
}
}