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