714b5b0a962115fe16ec65d616035e41c74e2c30
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) 	 */
Christian Fraß [add] api

Christian Fraß authored 3 years ago

49) 	function parse_tags
50) 	(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

51) 		tags_raw : string
52) 	) : Array<string>
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

53) 	{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

65) 	(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

68) 	{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

72) 		(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

74) 			{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

80) 		return result;
81) 	}
82) 	
83) 	
Christian Fraß [add] api

Christian Fraß authored 3 years ago

84) 	/**
85) 	 */
86) 	export function add
87) 	(
88) 		concept_entity : entities.concept
89) 	) : Promise<int>
90) 	{
91) 		return repositories.concept.create(concept_entity);
92) 	}
93) 	
94) 	
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

95) 	/**
96) 	 */
97) 	export async function bloat
98) 	(
99) 		concept_id : int
100) 	) : Promise<type_bloated>
101) 	{
102) 		const concept_entity : entities.concept = await repositories.concept.read(concept_id);
103) 		const type_value : string = (await repositories.type.read(concept_entity.type_id))["value"];
104) 		let result : type_bloated =
105) 		{
106) 			"id": concept_id,
107) 			"description": concept_entity.description,
108) 			"type":
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

109) 			{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

110) 				"id": concept_entity.type_id,
111) 				"value": type_value,
112) 			},
113) 			"tags": [],
114) 			"expressions": [],
115) 		};
Christian Fraß [add] api

Christian Fraß authored 3 years ago

116) 		for await (const tag_id of concept_entity.tag_ids)
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

117) 		{
118) 			const tag_value : string = (await repositories.tag.read(tag_id))["value"];
119) 			result.tags.push({"id": tag_id, "value": tag_value});
120) 		}
Christian Fraß [add] api

Christian Fraß authored 3 years ago

121) 		for await (const expression_id of concept_entity.expression_ids)
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

122) 		{
123) 			const expression_row : type_row = await repositories.expression.read(expression_id);
124) 			const language_id : int = expression_row["language_id"];
125) 			const language_row : type_row = (await repositories.language.read(expression_row["language_id"]));
126) 			result.expressions.push
127) 			(
128) 				{
129) 					"id": expression_id,
130) 					"language":
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

131) 					{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

132) 						"id": language_id,
133) 						"value": language_row["value"]
134) 					},
135) 					"value": expression_row["value"]
136) 				}
137) 			);
138) 		}
139) 		return Promise.resolve<type_bloated>(result);
140) 	}
141) 	
142) 	
143) 	/**
144) 	 */
145) 	export async function expose
146) 	(
147) 		concept_id : int
148) 	) : Promise<type_exposal>
149) 	{
150) 		const bloated : type_bloated = await bloat(concept_id);
151) 		return Promise.resolve<type_exposal>
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

152) 		(
153) 			{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

154) 				"id": bloated.id,
155) 				"description": bloated.description,
156) 				"type": bloated.type.value,
157) 				"tags": bloated.tags.map(tag_entry => tag_entry.value),
158) 				"expressions": (
159) 					() =>
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

160) 					{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

163) 						(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

165) 							{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

166) 								const language : string = expression_entry.language.value;
167) 								if (! expressions.hasOwnProperty(language))
168) 								{
169) 									expressions[language] = [];
170) 								}
171) 								expressions[language].push(expression_entry.value);
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

172) 							}
173) 						);
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

175) 					}
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

177) 			}
178) 		);
179) 	}
180) 	
181) 	
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

182) 	/**
183) 	 */
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

184) 	export async function export_
185) 	(
186) 	) : Promise<Array<type_exposal>>
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

187) 	{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

188) 		const rows : Array<type_row> = await repositories.concept.export();
189) 		return Promise.resolve<Array<type_exposal>>
190) 		(
191) 			rows.map
192) 			(
193) 				(row) => (
194) 					{
195) 						"id": row["id"],
196) 						"type": row["type"],
197) 						"description": row["description"],
198) 						"tags": parse_tags(row["tags"]),
199) 						"expressions": parse_expressions(row["expressions"]),
200) 					}
201) 				)
202) 			)
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

203) 		);
204) 	}
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

205) 
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

206) 	
207) 	/**
208) 	 */
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

210) 	(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

213) 	{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

214) 		const concept_ids : Array<int> = await repositories.concept.search(part);
215) 		let result : Array<type_exposal> = [];
216) 		for await (const concept_id of concept_ids)
217) 		{
218) 			result.push(await expose(concept_id));
219) 		}
220) 		return Promise.resolve<Array<type_exposal>>(result);
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

221) 	}
222) 	
223) 	
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

224) 	/**
225) 	 */
226) 	export function get_translations
227) 	(
228) 		language_from : string,
229) 		language_to : string,
230) 		part : string
231) 	) : Promise<Array<type_row>>
232) 	{
233) 		return repositories.concept.get_translations
234) 		(
235) 			language_from,
236) 			language_to,
237) 			part
238) 		);
239) 	}
240) 	
241) 	
242) 	/**
243) 	 */
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

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

Christian Fraß authored 3 years ago

245) 	(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

246) 		concept_thing : any
247) 	) : Promise<int>
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

248) 	{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

249) 		const type_id : int = await services.type.give(concept_thing["type"]);
250) 		const concept_id : int = await repositories.concept_core.create
251) 		(
252) 			{
253) 				"type_id": type_id,
254) 				"description": concept_thing["description"],
255) 			}
256) 		);
257) 		for await (const tag_value of concept_thing["tags"])
258) 		{
259) 			const tag_id : int = await services.tag.give(tag_value);
260) 			const concept_tag_id : int = await repositories.concept_tags.create
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

261) 			(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

262) 				{
263) 					"concept_id": concept_id,
264) 					"tag_id": tag_id,
265) 				}
266) 			);
267) 		}
268) 		for await (const [language_value, expression_values] of Object.entries(concept_thing["expressions"]))
269) 		{
270) 			const language_id : int = await services.language.give(language_value);
271) 			for await (const expression_value of <Array<string>>(expression_values))
272) 			{
273) 				const expression_id : int = await services.expression.give(language_id, expression_value);
274) 				const concept_expression_id : int = await repositories.concept_expressions.create
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

275) 				(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

276) 					{
277) 						"concept_id": concept_id,
278) 						"expression_id": expression_id,
279) 					}
280) 				);
281) 			}
282) 		}
283) 		return concept_id;