git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
9815a42
Branches
Tags
develop-client_server
master
typescript
fs-words.git
source
services
concept.ts
[add] typescript logic
Christian Fraß
commited
9815a42
at 2021-03-03 00:27:18
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; } /** */ 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 : {[language : string] : Array<string>}}>> { const parse_tags = function (tags_raw : string) : Array<string> { return ( (tags_raw === null) ? [] : tags_raw.split(",") ); }; const parse_translations = function (translations_raw : string) : {[language : string] : Array<string>} { let result : {[language : string] : Array<string>} = {}; const parts : Array<string> = translations_raw.split(",") parts.forEach ( (part) => { const [language, value] : Array<string> = part.split(":", 2); if (! result.hasOwnProperty(language)) result[language] = []; result[language].push(value); } ); return result; }; const rows : Array<type_row> = await repositories.concept.export(); return Promise.resolve<any>( rows.map ( (row) => ( { "id": row["id"], "type": row["type"], "description": row["description"], "tags": parse_tags(row["tags"]), "translations": parse_translations(row["translations"]), }) ) ) } }