## Tasks - [192](https://vikunja.ramsch.sx/tasks/192) ## Zugehörige MRs - [datamodel](misc/zeitbild-datamodel#1) - [frontend-dali](misc/zeitbild-frontend-dali#1) Reviewed-on: misc/zeitbild-backend#1 Co-authored-by: Fenris Wolf <fenris@folksprak.org> Co-committed-by: Fenris Wolf <fenris@folksprak.org>
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
namespace _zeitbild.api
|
|
{
|
|
|
|
/**
|
|
*/
|
|
export function register_user_dav_token(
|
|
rest_subject : lib_plankton.rest_http.type_rest
|
|
) : void
|
|
{
|
|
register<
|
|
// string,
|
|
null,
|
|
null
|
|
>(
|
|
rest_subject,
|
|
lib_plankton.http.enum_method.patch,
|
|
"/user_dav_token",
|
|
{
|
|
"description": "setzt/überschreibt den DAV-Token eines Nutzers",
|
|
/*
|
|
"input_schema": () => ({
|
|
"nullable": false,
|
|
"type": "string"
|
|
}),
|
|
*/
|
|
"input_schema": () => ({
|
|
"nullable": true,
|
|
}),
|
|
"output_schema": () => ({
|
|
"nullable": true
|
|
}),
|
|
"restriction": restriction_logged_in,
|
|
"execution": async (stuff) => {
|
|
const session : {key : string; value : lib_plankton.session.type_session;} = await session_from_stuff(stuff);
|
|
const user_id : _zeitbild.type_user_id = await _zeitbild.service.user.identify(session.value.name);
|
|
// TODO: outsource to user service?
|
|
const user_object : _zeitbild.type_user_object = await _zeitbild.service.user.get(user_id);
|
|
// user_object.dav_token = stuff.input;
|
|
user_object.dav_token = lib_plankton.random.generate_string({"length": 12});
|
|
await _zeitbild.service.user.change(user_id, user_object);
|
|
return Promise.resolve(
|
|
{
|
|
"status_code": 200,
|
|
"data": null,
|
|
}
|
|
);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|
|
|