[task-388]
This commit is contained in:
parent
e552560887
commit
6c548272fe
|
|
@ -23,25 +23,37 @@ namespace _zeitbild.repository.calendar
|
|||
|
||||
/**
|
||||
*/
|
||||
const hue_scaling : int = 0xFFFF;
|
||||
type type_core_row = {
|
||||
name : string;
|
||||
hue : int;
|
||||
access_public : boolean;
|
||||
access_level_default : int;
|
||||
resource_id : int;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
type type_access_attributed_row = {
|
||||
// calendar_id : int;
|
||||
user_id : int;
|
||||
level : int;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
type type_dispersal = {
|
||||
core_row : Record<
|
||||
string,
|
||||
any
|
||||
>;
|
||||
access_attributed_rows : Array<
|
||||
Record<
|
||||
string,
|
||||
any
|
||||
>
|
||||
>;
|
||||
core_row : type_core_row;
|
||||
access_attributed_rows : Array<type_access_attributed_row>;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
const hue_scaling : int = 0xFFFF;
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
var _core_store : (
|
||||
|
|
@ -195,11 +207,11 @@ namespace _zeitbild.repository.calendar
|
|||
) : _zeitbild.type_calendar_object
|
||||
{
|
||||
return {
|
||||
"name": dispersal.core_row["name"],
|
||||
"hue": (dispersal.core_row["hue"] / hue_scaling),
|
||||
"name": dispersal.core_row.name,
|
||||
"hue": (dispersal.core_row.hue / hue_scaling),
|
||||
"access": {
|
||||
"public": dispersal.core_row["access_public"],
|
||||
"default_level": decode_access_level(dispersal.core_row["access_level_default"]),
|
||||
"public": dispersal.core_row.access_public,
|
||||
"default_level": decode_access_level(dispersal.core_row.access_level_default),
|
||||
"attributed": lib_plankton.map.hashmap.implementation_map(
|
||||
lib_plankton.map.hashmap.make<_zeitbild.type_user_id, _zeitbild.enum_access_level>(
|
||||
x => x.toFixed(0),
|
||||
|
|
@ -209,8 +221,10 @@ namespace _zeitbild.repository.calendar
|
|||
.map(
|
||||
(access_attributed_row) => ({
|
||||
// "calendar_id": access_attributed_row["calendar_id"],
|
||||
"key": access_attributed_row["preview"]["user_id"],
|
||||
"value": decode_access_level(access_attributed_row["preview"]["level"]),
|
||||
// "key": access_attributed_row["preview"]["user_id"],
|
||||
"key": access_attributed_row.user_id,
|
||||
// "value": decode_access_level(access_attributed_row["preview"]["level"]),
|
||||
"value": decode_access_level(access_attributed_row.level),
|
||||
})
|
||||
)
|
||||
),
|
||||
|
|
@ -218,7 +232,7 @@ namespace _zeitbild.repository.calendar
|
|||
)
|
||||
),
|
||||
},
|
||||
"resource_id": dispersal.core_row["resource_id"],
|
||||
"resource_id": dispersal.core_row.resource_id,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +247,9 @@ namespace _zeitbild.repository.calendar
|
|||
return (
|
||||
get_core_store().read(id)
|
||||
.then(
|
||||
(core_row) => (
|
||||
(core_row_raw) => {
|
||||
const core_row : type_core_row = (core_row_raw as type_core_row);
|
||||
return (
|
||||
get_access_attributed_chest().search(
|
||||
{
|
||||
"expression": "(calendar_id = $calendar_id)",
|
||||
|
|
@ -243,10 +259,21 @@ namespace _zeitbild.repository.calendar
|
|||
}
|
||||
)
|
||||
.then(
|
||||
(access_attributed_rows) => Promise.resolve<type_dispersal>(
|
||||
(hits) => Promise.resolve<type_dispersal>(
|
||||
{
|
||||
"core_row": core_row,
|
||||
"access_attributed_rows": access_attributed_rows,
|
||||
"access_attributed_rows": (
|
||||
hits
|
||||
.map(
|
||||
hit => (
|
||||
{
|
||||
// "calendar_id": null,
|
||||
"user_id": hit.preview.user_id,
|
||||
"level": hit.preview.level,
|
||||
}
|
||||
)
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
@ -255,7 +282,8 @@ namespace _zeitbild.repository.calendar
|
|||
decode(dispersal)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -347,17 +375,24 @@ namespace _zeitbild.repository.calendar
|
|||
|
||||
/**
|
||||
* @todo remove events from resource?
|
||||
* @todo remove resource
|
||||
*/
|
||||
export async function delete_(
|
||||
calendar_id : _zeitbild.type_calendar_id
|
||||
) : Promise<void>
|
||||
)
|
||||
: Promise<void>
|
||||
{
|
||||
await lib_plankton.cache.clear(_zeitbild.cache_regular);
|
||||
const core_store = get_core_store();
|
||||
const access_attributed_chest = get_access_attributed_chest();
|
||||
// attributed access
|
||||
{
|
||||
const hits : Array<Record<string, any>> = await access_attributed_chest.search(
|
||||
const hits : Array<
|
||||
{
|
||||
key : Array<any>;
|
||||
preview : Record<string, any>;
|
||||
}
|
||||
> = await access_attributed_chest.search(
|
||||
{
|
||||
"expression": "(calendar_id = $calendar_id)",
|
||||
"arguments": {
|
||||
|
|
@ -365,9 +400,10 @@ namespace _zeitbild.repository.calendar
|
|||
}
|
||||
}
|
||||
);
|
||||
for await (const hit of hits) {
|
||||
for (const hit of hits)
|
||||
{
|
||||
await access_attributed_chest.delete(
|
||||
[calendar_id, hit["user_id"]]
|
||||
hit.key
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,22 @@ along with »zeitbild«. If not, see <http://www.gnu.org/licenses/>.
|
|||
namespace _zeitbild.repository.resource
|
||||
{
|
||||
|
||||
/**
|
||||
*/
|
||||
type type_row = {
|
||||
kind : string;
|
||||
sub_id : int;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
type type_preview = {
|
||||
kind : string;
|
||||
sub_id : int;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
type type_local_resource_event_stuff = {
|
||||
|
|
@ -81,10 +97,10 @@ namespace _zeitbild.repository.resource
|
|||
|
|
||||
lib_plankton.storage.type_store<
|
||||
_zeitbild.type_resource_id,
|
||||
Record<string, any>,
|
||||
/*type_row*/Record<string, any>,
|
||||
{},
|
||||
lib_plankton.storage.type_sql_table_autokey_search_term,
|
||||
Record<string, any>
|
||||
/*type_preview*/Record<string, any>
|
||||
>
|
||||
) = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,22 @@ along with »zeitbild«. If not, see <http://www.gnu.org/licenses/>.
|
|||
namespace _zeitbild.repository.user
|
||||
{
|
||||
|
||||
/**
|
||||
*/
|
||||
type type_row = {
|
||||
name : string;
|
||||
email_address : (null | string);
|
||||
dav_token : (null | string);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
type type_preview = {
|
||||
name : string;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
var _store : (
|
||||
|
|
@ -28,10 +44,10 @@ namespace _zeitbild.repository.user
|
|||
|
|
||||
lib_plankton.storage.type_store<
|
||||
_zeitbild.type_user_id,
|
||||
Record<string, any>,
|
||||
/*type_row*/Record<string, any>,
|
||||
{},
|
||||
lib_plankton.storage.type_sql_table_autokey_search_term,
|
||||
Record<string, any>
|
||||
/*type_preview*/Record<string, any>
|
||||
>
|
||||
) = null;
|
||||
|
||||
|
|
@ -39,15 +55,17 @@ namespace _zeitbild.repository.user
|
|||
/**
|
||||
*/
|
||||
function get_store(
|
||||
) : lib_plankton.storage.type_store<
|
||||
)
|
||||
: lib_plankton.storage.type_store<
|
||||
_zeitbild.type_user_id,
|
||||
Record<string, any>,
|
||||
/*type_row*/Record<string, any>,
|
||||
{},
|
||||
lib_plankton.storage.type_sql_table_autokey_search_term,
|
||||
Record<string, any>
|
||||
/*type_preview*/Record<string, any>
|
||||
>
|
||||
{
|
||||
if (_store === null) {
|
||||
if (_store === null)
|
||||
{
|
||||
_store = lib_plankton.storage.sql_table_autokey_store(
|
||||
{
|
||||
"database_implementation": _zeitbild.database.get_implementation(),
|
||||
|
|
@ -56,7 +74,8 @@ namespace _zeitbild.repository.user
|
|||
}
|
||||
);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
return _store;
|
||||
|
|
@ -67,7 +86,8 @@ namespace _zeitbild.repository.user
|
|||
*/
|
||||
function encode(
|
||||
user_object : _zeitbild.type_user_object
|
||||
) : Record<string, any>
|
||||
)
|
||||
: type_row
|
||||
{
|
||||
return {
|
||||
"name": user_object.name,
|
||||
|
|
@ -80,13 +100,14 @@ namespace _zeitbild.repository.user
|
|||
/**
|
||||
*/
|
||||
function decode(
|
||||
row : Record<string, any>
|
||||
) : _zeitbild.type_user_object
|
||||
row : type_row
|
||||
)
|
||||
: _zeitbild.type_user_object
|
||||
{
|
||||
return {
|
||||
"name": row["name"],
|
||||
"email_address": row["email_address"],
|
||||
"dav_token": row["dav_token"],
|
||||
"name": row.name,
|
||||
"email_address": row.email_address,
|
||||
"dav_token": row.dav_token,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +115,8 @@ namespace _zeitbild.repository.user
|
|||
/**
|
||||
*/
|
||||
export async function list(
|
||||
) : Promise<
|
||||
)
|
||||
: Promise<
|
||||
Array<
|
||||
{
|
||||
id : _zeitbild.type_user_id;
|
||||
|
|
@ -103,7 +125,7 @@ namespace _zeitbild.repository.user
|
|||
>
|
||||
>
|
||||
{
|
||||
const hits : Array<{key : int; preview : Record<string, any>;}> = await get_store().search({"expression": "TRUE", "arguments": {}});
|
||||
const hits : Array<{key : int; preview : /*type_preview*/Record<string, any>;}> = await get_store().search({"expression": "TRUE", "arguments": {}});
|
||||
return Promise.resolve(
|
||||
hits
|
||||
.map(
|
||||
|
|
@ -120,9 +142,10 @@ namespace _zeitbild.repository.user
|
|||
*/
|
||||
export async function read(
|
||||
user_id : _zeitbild.type_user_id
|
||||
) : Promise<_zeitbild.type_user_object>
|
||||
)
|
||||
: Promise<_zeitbild.type_user_object>
|
||||
{
|
||||
const row : Record<string, any> = await get_store().read(user_id);
|
||||
const row : type_row = ((await get_store().read(user_id)) as type_row);
|
||||
const user_object : _zeitbild.type_user_object = decode(row);
|
||||
return Promise.resolve<_zeitbild.type_user_object>(user_object);
|
||||
}
|
||||
|
|
@ -132,9 +155,10 @@ namespace _zeitbild.repository.user
|
|||
*/
|
||||
export async function create(
|
||||
user_object : _zeitbild.type_user_object
|
||||
) : Promise<_zeitbild.type_user_id>
|
||||
)
|
||||
: Promise<_zeitbild.type_user_id>
|
||||
{
|
||||
const row : Record<string, any> = encode(user_object);
|
||||
const row : type_row = encode(user_object);
|
||||
const user_id : _zeitbild.type_user_id = await get_store().create(row);
|
||||
return Promise.resolve<_zeitbild.type_user_id>(user_id);
|
||||
}
|
||||
|
|
@ -145,10 +169,11 @@ namespace _zeitbild.repository.user
|
|||
export async function update(
|
||||
user_id : _zeitbild.type_user_id,
|
||||
user_object : _zeitbild.type_user_object
|
||||
) : Promise<void>
|
||||
)
|
||||
: Promise<void>
|
||||
{
|
||||
const dispersal : Record<string, any> = encode(user_object);
|
||||
await get_store().update(user_id, dispersal);
|
||||
const row : type_row = encode(user_object);
|
||||
await get_store().update(user_id, row);
|
||||
return Promise.resolve<void>(undefined);
|
||||
}
|
||||
|
||||
|
|
@ -157,9 +182,10 @@ namespace _zeitbild.repository.user
|
|||
*/
|
||||
export async function identify(
|
||||
name : string
|
||||
) : Promise<_zeitbild.type_user_id>
|
||||
)
|
||||
: Promise<_zeitbild.type_user_id>
|
||||
{
|
||||
const hits : Array<{key : _zeitbild.type_user_id; preview : any;}> = await get_store().search(
|
||||
const hits : Array<{key : _zeitbild.type_user_id; preview : /*type_preview*/Record<string, any>;}> = await get_store().search(
|
||||
{
|
||||
"expression": "(name = $name)",
|
||||
"arguments": {
|
||||
|
|
@ -167,10 +193,12 @@ namespace _zeitbild.repository.user
|
|||
}
|
||||
}
|
||||
);
|
||||
if (hits.length <= 0) {
|
||||
if (hits.length <= 0)
|
||||
{
|
||||
return Promise.reject<_zeitbild.type_user_id>(new Error("not found"));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return Promise.resolve<_zeitbild.type_user_id>(hits[0].key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue