1b85fc9a1308f1305a4525dd93427f7f597ee55c
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

1) namespace services.concept
2) {
3) 	
4) 	/**
5) 	 */
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

6) 	export type type_bloated =
7) 	{
8) 		id : int;
9) 		description : string;
10) 		type :
11) 		{
12) 			id : int;
13) 			value : string;
14) 		};
15) 		tags : Array<
16) 			{
17) 				id : int;
18) 				value : string;
19) 			}
20) 		>;
21) 		expressions : Array<
22) 			{
23) 				id : int;
24) 				language :
25) 				{
26) 					id : int;
27) 					value : string;
28) 				};
29) 				value : string;
30) 			}
31) 		>;
32) 	};
33) 	
34) 	
35) 	/**
36) 	 */
37) 	export type type_exposal =
38) 	{
39) 		id : int;
40) 		description : string;
41) 		type : string;
42) 		tags : Array<string>;
43) 		expressions : {[language : string] : Array<string>};
44) 	};
45) 	
46) 	
47) 	/**
48) 	 */
49) 	function parse_tags(
50) 		tags_raw : string
51) 	) : Array<string>
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

52) 	{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

53) 		return (
54) 			(tags_raw === null)
55) 			? []
56) 			: tags_raw.split(",")
57) 		);
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

58) 	}
59) 	
60) 	
61) 	/**
62) 	 */
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

63) 	function parse_expressions
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

64) 	(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

65) 		expressions_raw : string
66) 	) : {[language : string] : Array<string>}
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

67) 	{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

68) 		let result : {[language : string] : Array<string>} = {};
69) 		const parts : Array<string> = expressions_raw.split(",");
70) 		parts.forEach
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

71) 		(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

72) 			(part) =>
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

73) 			{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

74) 				const [language, value] : Array<string> = part.split(":", 2);
75) 				if (! result.hasOwnProperty(language)) result[language] = [];
76) 				result[language].push(value);
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

77) 			}
78) 		);
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

79) 		return result;
80) 	}
81) 	
82) 	
83) 	/**
84) 	 */
85) 	export async function bloat
86) 	(
87) 		concept_id : int
88) 	) : Promise<type_bloated>
89) 	{
90) 		const concept_entity : entities.concept = await repositories.concept.read(concept_id);
91) 		const type_value : string = (await repositories.type.read(concept_entity.type_id))["value"];
92) 		let result : type_bloated =
93) 		{
94) 			"id": concept_id,
95) 			"description": concept_entity.description,
96) 			"type":
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

97) 			{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

98) 				"id": concept_entity.type_id,
99) 				"value": type_value,
100) 			},
101) 			"tags": [],
102) 			"expressions": [],
103) 		};
104) 		for await (const tag_id of concept_entity.tags)
105) 		{
106) 			const tag_value : string = (await repositories.tag.read(tag_id))["value"];
107) 			result.tags.push({"id": tag_id, "value": tag_value});
108) 		}
109) 		for await (const expression_id of concept_entity.expressions)
110) 		{
111) 			const expression_row : type_row = await repositories.expression.read(expression_id);
112) 			const language_id : int = expression_row["language_id"];
113) 			const language_row : type_row = (await repositories.language.read(expression_row["language_id"]));
114) 			result.expressions.push
115) 			(
116) 				{
117) 					"id": expression_id,
118) 					"language":
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

119) 					{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

120) 						"id": language_id,
121) 						"value": language_row["value"]
122) 					},
123) 					"value": expression_row["value"]
124) 				}
125) 			);
126) 		}
127) 		return Promise.resolve<type_bloated>(result);
128) 	}
129) 	
130) 	
131) 	/**
132) 	 */
133) 	export async function expose
134) 	(
135) 		concept_id : int
136) 	) : Promise<type_exposal>
137) 	{
138) 		const bloated : type_bloated = await bloat(concept_id);
139) 		return Promise.resolve<type_exposal>
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

140) 		(
141) 			{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

142) 				"id": bloated.id,
143) 				"description": bloated.description,
144) 				"type": bloated.type.value,
145) 				"tags": bloated.tags.map(tag_entry => tag_entry.value),
146) 				"expressions": (
147) 					() =>
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

148) 					{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

149) 						let expressions : {[language : string] : Array<string>} = {};
150) 						bloated.expressions.forEach
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

151) 						(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

152) 							expression_entry =>
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

153) 							{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

154) 								const language : string = expression_entry.language.value;
155) 								if (! expressions.hasOwnProperty(language))
156) 								{
157) 									expressions[language] = [];
158) 								}
159) 								expressions[language].push(expression_entry.value);
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

160) 							}
161) 						);
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

162) 						return expressions;
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

163) 					}
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

164) 				) (),
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

165) 			}
166) 		);
167) 	}
168) 	
169) 	
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

170) 	/**
171) 	 */
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

172) 	export async function export_
173) 	(
174) 	) : Promise<Array<type_exposal>>
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

175) 	{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

176) 		const rows : Array<type_row> = await repositories.concept.export();
177) 		return Promise.resolve<Array<type_exposal>>
178) 		(
179) 			rows.map
180) 			(
181) 				(row) => (
182) 					{
183) 						"id": row["id"],
184) 						"type": row["type"],
185) 						"description": row["description"],
186) 						"tags": parse_tags(row["tags"]),
187) 						"expressions": parse_expressions(row["expressions"]),
188) 					}
189) 				)
190) 			)
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

191) 		);
192) 	}
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

193) 
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

194) 	
195) 	/**
196) 	 */
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

197) 	export async function search
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

198) 	(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

199) 		part : string
200) 	) : Promise<Array<type_exposal>>
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

201) 	{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

202) 		const concept_ids : Array<int> = await repositories.concept.search(part);
203) 		let result : Array<type_exposal> = [];
204) 		for await (const concept_id of concept_ids)
205) 		{
206) 			result.push(await expose(concept_id));
207) 		}
208) 		return Promise.resolve<Array<type_exposal>>(result);
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

209) 	}
210) 	
211) 	
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

212) 	/**
213) 	 */
214) 	export function get_translations
215) 	(
216) 		language_from : string,
217) 		language_to : string,
218) 		part : string
219) 	) : Promise<Array<type_row>>
220) 	{
221) 		return repositories.concept.get_translations
222) 		(
223) 			language_from,
224) 			language_to,
225) 			part
226) 		);
227) 	}
228) 	
229) 	
230) 	/**
231) 	 */
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

232) 	export async function suck
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

233) 	(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

234) 		concept_thing : any
235) 	) : Promise<int>
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

236) 	{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

237) 		const type_id : int = await services.type.give(concept_thing["type"]);
238) 		const concept_id : int = await repositories.concept_core.create
239) 		(
240) 			{
241) 				"type_id": type_id,
242) 				"description": concept_thing["description"],
243) 			}
244) 		);
245) 		for await (const tag_value of concept_thing["tags"])
246) 		{
247) 			const tag_id : int = await services.tag.give(tag_value);
248) 			const concept_tag_id : int = await repositories.concept_tags.create
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

249) 			(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

250) 				{
251) 					"concept_id": concept_id,
252) 					"tag_id": tag_id,
253) 				}
254) 			);
255) 		}
256) 		for await (const [language_value, expression_values] of Object.entries(concept_thing["expressions"]))
257) 		{
258) 			const language_id : int = await services.language.give(language_value);
259) 			for await (const expression_value of <Array<string>>(expression_values))
260) 			{
261) 				const expression_id : int = await services.expression.give(language_id, expression_value);
262) 				const concept_expression_id : int = await repositories.concept_expressions.create
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

263) 				(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

264) 					{
265) 						"concept_id": concept_id,
266) 						"expression_id": expression_id,
267) 					}
268) 				);
269) 			}
270) 		}
271) 		return concept_id;