bc0937fc7190a2c8deb910a37f330ffd30cc04b4
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

1) namespace services.concept
2) {
3) 	
4) 	/**
5) 	 */
6) 	export function get
7) 	(
8) 		concept_id : int
9) 	) : Promise<entities.concept>
10) 	{
11) 		return repositories.concept.read(concept_id);
12) 	}
13) 	
14) 	
15) 	/**
16) 	 */
17) 	export async function suck
18) 	(
19) 		concept_thing : any
20) 	) : Promise<int>
21) 	{
22) 		const type_id : int = await services.type.give(concept_thing["type"]);
23) 		const concept_id : int = await repositories.concept_core.create
24) 		(
25) 			{
26) 				"type_id": type_id,
27) 				"description": concept_thing["description"],
28) 			}
29) 		);
30) 		await concept_thing["tags"].map
31) 		(
32) 			async (tag_value) =>
33) 			{
34) 				const tag_id : int = await services.tag.give(tag_value);
35) 				const concept_tag_id : int = await repositories.concept_tags.create
36) 				(
37) 					{
38) 						"concept_id": concept_id,
39) 						"tag_id": tag_id,
40) 					}
41) 				);
42) 				return concept_tag_id;
43) 			}
44) 		);
45) 		await Object.keys(concept_thing["translations"]).map
46) 		(
47) 			async (language_value) =>
48) 			{
49) 				const language_id : int = await services.language.give(language_value);
50) 				const concept_translation_ids = await concept_thing["translations"][language_value].map
51) 				(
52) 					async (translation_value) =>
53) 					{
54) 						const concept_translation_id : int = await repositories.concept_translations.create
55) 						(
56) 							{
57) 								"concept_id": concept_id,
58) 								"language_id": language_id,
59) 								"value": translation_value,
60) 							}
61) 						);
62) 					}
63) 				);
64) 			}
65) 		);
66) 		return concept_id;
67) 	}
68) 	
69) 	
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

70) 	/**
71) 	 */
72) 	function parse_tags(
73) 		tags_raw : string
74) 	) : Array<string>
75) 	{
76) 		return (
77) 			(tags_raw === null)
78) 			? []
79) 			: tags_raw.split(",")
80) 		);
81) 	}
82) 	
83) 	
84) 	/**
85) 	 */
86) 	function parse_translations
87) 	(
88) 		translations_raw : string
89) 	) : Array<{id : int; language : string; value : string;}>
90) 	{
91) 		let result : Array<{id : int; language : string; value : string;}> = [];
92) 		const parts : Array<string> = translations_raw.split(",")
93) 		parts.forEach
94) 		(
95) 			(part) =>
96) 			{
97) 				const [id, language, value] : Array<string> = part.split(":", 3);
98) 				result.push({"id": parseInt(id), "language": language, "value": value});
99) 			}
100) 		);
101) 		return result;
102) 	}
103) 	
104) 	
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

105) 	/**
106) 	 */
107) 	export function get_translations
108) 	(
109) 		language_from : string,
110) 		language_to : string,
111) 		part : string
112) 	) : Promise<Array<type_row>>
113) 	{
114) 		return repositories.concept.get_translations
115) 		(
116) 			language_from,
117) 			language_to,
118) 			part
119) 		);
120) 	}
121) 	
122) 	
123) 	/**
124) 	 */
125) 	export async function export_
126) 	(
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

127) 	) : Promise<Array<{id : int; type : string; description : string; tags : Array<string>; translations : Array<{id : int; language : string; value : string;}>;}>>
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

128) 	{
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

129) 		return (
130) 			repositories.concept.export()
131) 			.then
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

132) 			(
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

133) 				rows => Promise.resolve
134) 				(
135) 					rows.map
136) 					(
137) 						(row) => (
138) 							{
139) 								"id": row["id"],
140) 								"type": row["type"],
141) 								"description": row["description"],
142) 								"tags": parse_tags(row["tags"]),
143) 								"translations": parse_translations(row["translations"]),
144) 							}
145) 						)
146) 					)
147) 				)
148) 			)
149) 		)
150) 	}
151) 
152) 	
153) 	/**
154) 	 */
155) 	export function search
156) 	(
157) 		part : string
158) 	) : Promise<Array<{id : int; type : string; description : string; tags : Array<string>; translations : Array<{id : int; language : string; value : string;}>;}>>
159) 	{
160) 		return (
161) 			repositories.concept.search(part)
162) 			.then
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

163) 			(
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

164) 				rows => Promise.resolve
165) 				(
166) 					rows.map
167) 					(
168) 						(row) => (
169) 							{
170) 								"id": row["id"],
171) 								"type": row["type"],
172) 								"description": row["description"],
173) 								"tags": parse_tags(row["tags"]),
174) 								"translations": parse_translations(row["translations"]),
175) 							}
176) 						)
177) 					)
178) 				)