git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
bc0937f
Branches
Tags
develop-client_server
master
typescript
fs-words.git
source
services
concept.ts
[mod] logic
Christian Fraß
commited
bc0937f
at 2021-03-03 01:35:40
concept.ts
Blame
History
Raw
namespace services.concept { /** */ export function get ( concept_id : int ) : Promise<entities.concept> { return repositories.concept.read(concept_id); } /** */ export async function suck ( concept_thing : any ) : Promise<int> { const type_id : int = await services.type.give(concept_thing["type"]); const concept_id : int = await repositories.concept_core.create ( { "type_id": type_id, "description": concept_thing["description"], } ); await concept_thing["tags"].map ( async (tag_value) => { const tag_id : int = await services.tag.give(tag_value); const concept_tag_id : int = await repositories.concept_tags.create ( { "concept_id": concept_id, "tag_id": tag_id, } ); return concept_tag_id; } ); await Object.keys(concept_thing["translations"]).map ( async (language_value) => { const language_id : int = await services.language.give(language_value); const concept_translation_ids = await concept_thing["translations"][language_value].map ( async (translation_value) => { const concept_translation_id : int = await repositories.concept_translations.create ( { "concept_id": concept_id, "language_id": language_id, "value": translation_value, } ); } ); } ); return concept_id; } /** */ function parse_tags( tags_raw : string ) : Array<string> { return ( (tags_raw === null) ? [] : tags_raw.split(",") ); } /** */ function parse_translations ( translations_raw : string ) : Array<{id : int; language : string; value : string;}> { let result : Array<{id : int; language : string; value : string;}> = []; const parts : Array<string> = translations_raw.split(",") parts.forEach ( (part) => { const [id, language, value] : Array<string> = part.split(":", 3); result.push({"id": parseInt(id), "language": language, "value": value}); } ); return result; } /** */ export function get_translations ( language_from : string, language_to : string, part : string ) : Promise<Array<type_row>> { return repositories.concept.get_translations ( language_from, language_to, part ); } /** */ export async function export_ ( ) : Promise<Array<{id : int; type : string; description : string; tags : Array<string>; translations : Array<{id : int; language : string; value : string;}>;}>> { return ( repositories.concept.export() .then ( rows => Promise.resolve ( rows.map ( (row) => ( { "id": row["id"], "type": row["type"], "description": row["description"], "tags": parse_tags(row["tags"]), "translations": parse_translations(row["translations"]), } ) ) ) ) ) } /** */ export function search ( part : string ) : Promise<Array<{id : int; type : string; description : string; tags : Array<string>; translations : Array<{id : int; language : string; value : string;}>;}>> { return ( repositories.concept.search(part) .then ( rows => Promise.resolve ( rows.map ( (row) => ( { "id": row["id"], "type": row["type"], "description": row["description"], "tags": parse_tags(row["tags"]), "translations": parse_translations(row["translations"]), } ) ) ) ) ) } }