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
repositories
concept.ts
[mod] logic
Christian Fraß
commited
bc0937f
at 2021-03-03 01:35:40
concept.ts
Blame
History
Raw
namespace repositories { /** */ export var concept : ( helpers.repository<int, entities.concept> & { get_translations : (language_from : string, language_to : string, part : string)=>Promise<Array<type_row>>; export : ()=>Promise<Array<type_row>>; search : (part : string)=>Promise<Array<type_row>>; } ) = { "setup": async function () { await repositories.concept_core.setup(); await repositories.concept_tags.setup(); await repositories.concept_translations.setup(); return Promise.resolve<void>(undefined); }, "teardown": async function () { await repositories.concept_translations.teardown(); await repositories.concept_tags.teardown(); await repositories.concept_core.teardown(); return Promise.resolve<void>(undefined); }, "create": async function (concept_entity) { const row_core : type_row = {"type_id": concept_entity.type_id, "description": concept_entity.description}; const concept_id : int = await repositories.concept_core.create(row_core); for await (let tag_id of concept_entity.tags) { const row_tag : type_row = {"concept_id": concept_id, "tag_id": tag_id}; const concept_tag_id : int = await repositories.concept_tags.create(row_tag); } for await (let {"language_id": language_id, "value": value} of concept_entity.translations) { const row_translations : type_row = {"concept_id": concept_id, "language_id": language_id, "value": value}; const concept_translations_id : int = await repositories.concept_translations.create(row_translations); } return Promise.resolve<int>(concept_id); }, "update": function (concept_id, concept_entity) { throw (new Error("not implemented")); }, "delete": async function (concept_id) { await repositories.concept_translations.purge("concept_id", concept_id); await repositories.concept_tags.purge("concept_id", concept_id); await repositories.concept_core.delete(concept_id); return Promise.resolve<void>(undefined); }, "read": async function (concept_id) { const row_core : type_row = await repositories.concept_core.read(concept_id);; const rows_tags : Array<type_row> = await repositories.concept_tags.take("concept_id", concept_id); const rows_translations : Array<type_row> = await repositories.concept_translations.take("concept_id", concept_id); const concept_entity : entities.concept = { "type_id": row_core["type_id"], "description": row_core["description"], "tags": rows_tags.map(row_tag => row_tag["tag_id"]), "translations": rows_translations.map(row_translation => ({"language_id": row_translation["language_id"], "value": row_translation["value"]})), }; return Promise.resolve<entities.concept>(concept_entity); }, "get_translations": function (language_from, language_to, part) { return helpers.database.query_get_named ( "concept.get_translations", { "language_from": language_from, "language_to": language_to, "part": part.replace(new RegExp("-", "g"), "%"), } ); }, "export": function () : Promise<Array<type_row>> { return helpers.database.query_get_named("concept.dump", {"part": null}); }, "search": function (part) : Promise<Array<type_row>> { return helpers.database.query_get_named("concept.dump", {"part": part.replace(new RegExp("-", "g"), "%")}); }, }; }