153 lines
3.9 KiB
TypeScript
153 lines
3.9 KiB
TypeScript
/*
|
|
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/>.
|
|
*/
|
|
|
|
namespace _espe.api
|
|
{
|
|
|
|
/**
|
|
*/
|
|
export function register_member_project(
|
|
rest_subject : lib_plankton.rest.type_rest
|
|
) : void
|
|
{
|
|
register<
|
|
{
|
|
membership_number : (null | string);
|
|
name_real_value : string;
|
|
email_address_private : (null | string);
|
|
groups ?: Array<string>;
|
|
notification_target_url_template ?: (null | string);
|
|
},
|
|
(
|
|
string
|
|
|
|
|
_espe.type.member_id
|
|
)
|
|
>(
|
|
rest_subject,
|
|
lib_plankton.http.enum_method.post,
|
|
"/member/project",
|
|
{
|
|
"description": "erstellt ein neues Mitglied und gibt die erzeugte ID aus",
|
|
"input_schema": () => ({
|
|
"type": "object",
|
|
"nullable": false,
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"membership_number": {
|
|
"type": "string",
|
|
"nullable": false,
|
|
"description": "Mitgliedsnummer"
|
|
},
|
|
"name_real_value": {
|
|
"type": "string",
|
|
"nullable": false,
|
|
"description": "Klarname"
|
|
},
|
|
"email_address_private": {
|
|
"type": "string",
|
|
"nullable": true,
|
|
"description": "private E-Mail-Adresse"
|
|
},
|
|
"groups": {
|
|
"nullable": false,
|
|
"type": "array",
|
|
"items": {
|
|
"type": "string",
|
|
"nullable": false,
|
|
}
|
|
},
|
|
"notification_target_url_template": {
|
|
"type": "string",
|
|
"nullable": true,
|
|
"description": "Platz-Halter: id"
|
|
},
|
|
},
|
|
"required": [
|
|
"membership_number",
|
|
"name_real_value",
|
|
]
|
|
}),
|
|
"output_schema": () => ({
|
|
"type": "number",
|
|
"nullable": false,
|
|
}),
|
|
"restriction": restriction_logged_in,
|
|
"execution": async ({"input": input}) => {
|
|
if (input === null) {
|
|
return Promise.reject(new Error("impossible"));
|
|
}
|
|
else {
|
|
if (
|
|
(! _espe.conf.get().settings.misc.facultative_membership_number)
|
|
&&
|
|
(
|
|
(input.membership_number === null)
|
|
||
|
|
(input.membership_number === "")
|
|
)
|
|
) {
|
|
return Promise.resolve({
|
|
"status_code": 400,
|
|
"data": "membership number required"
|
|
});
|
|
}
|
|
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,
|
|
"email_address_private": (
|
|
("email_address_private" in input)
|
|
? (
|
|
(input.email_address_private !== "")
|
|
? input.email_address_private
|
|
: null
|
|
)
|
|
: null
|
|
),
|
|
"groups": (input.groups ?? []),
|
|
}
|
|
);
|
|
if (! _espe.conf.get().settings.misc.auto_register) {
|
|
// do nothing
|
|
}
|
|
else {
|
|
// TODO: Werte in Konfiguration auslagern
|
|
await _espe.service.member.register(
|
|
member_id,
|
|
{
|
|
"email_use_veiled_address": false,
|
|
"email_use_nominal_address": false,
|
|
"email_redirect_to_private_address": false,
|
|
"password": null,
|
|
},
|
|
{
|
|
"notification_target_url_template": input.notification_target_url_template,
|
|
}
|
|
);
|
|
}
|
|
return Promise.resolve({
|
|
"status_code": 201,
|
|
"data": member_id
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|