text-to-map 1.0.7 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/clear-all.js +21 -4
- package/dist/bin/init-db.d.ts +1 -0
- package/dist/bin/init-db.js +18 -0
- package/dist/bin/parse-ordinance.js +56 -42
- package/dist/bin/schools.js +1 -1
- package/dist/db/address-points.d.ts +13 -13
- package/dist/db/address-points.js +93 -77
- package/dist/db/db.d.ts +19 -10
- package/dist/db/db.js +124 -50
- package/dist/db/founders.d.ts +7 -7
- package/dist/db/founders.js +187 -135
- package/dist/db/meta.d.ts +3 -4
- package/dist/db/meta.js +23 -16
- package/dist/db/migrations/20230704125715_initial.d.ts +3 -0
- package/dist/db/migrations/20230704125715_initial.js +251 -0
- package/dist/db/regions.d.ts +5 -5
- package/dist/db/regions.js +40 -28
- package/dist/db/schools.d.ts +3 -2
- package/dist/db/schools.js +30 -14
- package/dist/db/street-sync.d.ts +4 -4
- package/dist/db/street-sync.js +26 -17
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -2
- package/dist/open-data-sync/address-points.d.ts +0 -1
- package/dist/open-data-sync/address-points.js +35 -25
- package/dist/open-data-sync/regions.js +13 -5
- package/dist/open-data-sync/schools.js +19 -15
- package/dist/open-data-sync/streets.js +46 -33
- package/dist/street-markdown/municipality.d.ts +2 -2
- package/dist/street-markdown/municipality.js +46 -14
- package/dist/street-markdown/smd-line-parser.d.ts +1 -1
- package/dist/street-markdown/smd-line-parser.js +21 -8
- package/dist/street-markdown/smd.d.ts +8 -5
- package/dist/street-markdown/smd.js +100 -86
- package/dist/street-markdown/token-definition.js +6 -6
- package/dist/street-markdown/types.d.ts +8 -3
- package/dist/utils/helpers.d.ts +0 -1
- package/dist/utils/helpers.js +1 -8
- package/package.json +9 -5
package/dist/db/founders.js
CHANGED
|
@@ -1,39 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
4
10
|
import distance from "@turf/distance";
|
|
11
|
+
import { wholeLineError } from "../street-markdown/smd";
|
|
12
|
+
import { extractMunicipalityName, findClosestString, sanitizeMunicipalityName, } from "../utils/helpers";
|
|
13
|
+
import { getKnexDb, insertAutoincrementRow, insertMultipleRows } from "./db";
|
|
14
|
+
import { MunicipalityType, } from "./types";
|
|
5
15
|
const cityTypeCode = 261;
|
|
6
16
|
const cityDistrictTypeCode = 263;
|
|
7
|
-
export const insertFounders = (founders) => {
|
|
8
|
-
|
|
9
|
-
const selectCityStatement = db.prepare(`SELECT c.name, c.code FROM school s
|
|
10
|
-
JOIN school_location l ON s.izo = l.school_izo
|
|
11
|
-
JOIN address_point a ON l.address_point_id = a.id
|
|
12
|
-
JOIN city c ON a.city_code = c.code
|
|
13
|
-
WHERE s.izo = ?
|
|
14
|
-
LIMIT 1`);
|
|
15
|
-
const selectDistrictStatement = db.prepare(`SELECT d.name, d.code FROM school s
|
|
16
|
-
JOIN school_location l ON s.izo = l.school_izo
|
|
17
|
-
JOIN address_point a ON l.address_point_id = a.id
|
|
18
|
-
JOIN city_district d ON a.city_district_code = d.code
|
|
19
|
-
WHERE s.izo = ?
|
|
20
|
-
LIMIT 1`);
|
|
17
|
+
export const insertFounders = (founders) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
21
19
|
let insertedFounders = 0;
|
|
22
20
|
const schoolFounderConnectionData = [];
|
|
23
|
-
|
|
24
|
-
var _a;
|
|
21
|
+
for (const founder of founders) {
|
|
25
22
|
if (founder.municipalityType !== MunicipalityType.City &&
|
|
26
23
|
founder.municipalityType !== MunicipalityType.District) {
|
|
27
|
-
|
|
24
|
+
continue;
|
|
28
25
|
}
|
|
29
26
|
const extractedMunicipalityName = extractMunicipalityName(founder);
|
|
30
27
|
// check if the extracted municipality name is the same as in all the schools' locations
|
|
31
28
|
let differingSchools = [];
|
|
32
29
|
let municipalityCode = -1;
|
|
33
|
-
founder.schools
|
|
34
|
-
const result = (founder.municipalityType === MunicipalityType.City
|
|
35
|
-
?
|
|
36
|
-
:
|
|
30
|
+
for (const school of founder.schools) {
|
|
31
|
+
const result = yield (founder.municipalityType === MunicipalityType.City
|
|
32
|
+
? getCityOfSchool(school.izo)
|
|
33
|
+
: getDistrictOfSchool(school.izo));
|
|
37
34
|
if (!result) {
|
|
38
35
|
console.log(`izo: ${school.izo}, extracted: ${extractedMunicipalityName}, RUIAN: UNDEFINED`);
|
|
39
36
|
differingSchools.push(school);
|
|
@@ -47,8 +44,8 @@ export const insertFounders = (founders) => {
|
|
|
47
44
|
// store municipalityCode even if the names don't match, we will use it later
|
|
48
45
|
municipalityCode = parseInt(code);
|
|
49
46
|
}
|
|
50
|
-
}
|
|
51
|
-
municipalityCode = fixFounderProblems(founder, municipalityCode, differingSchools, extractedMunicipalityName);
|
|
47
|
+
}
|
|
48
|
+
municipalityCode = yield fixFounderProblems(founder, municipalityCode, differingSchools, extractedMunicipalityName);
|
|
52
49
|
const cityDistrictCode = founder.municipalityType === MunicipalityType.District
|
|
53
50
|
? municipalityCode.toString()
|
|
54
51
|
: null;
|
|
@@ -57,46 +54,80 @@ export const insertFounders = (founders) => {
|
|
|
57
54
|
cityCode = (_a = municipalityCode === null || municipalityCode === void 0 ? void 0 : municipalityCode.toString()) !== null && _a !== void 0 ? _a : null;
|
|
58
55
|
}
|
|
59
56
|
else {
|
|
60
|
-
cityCode = getCityCodeByDistrictCode(municipalityCode)
|
|
57
|
+
cityCode = yield getCityCodeByDistrictCode(municipalityCode);
|
|
61
58
|
}
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
const existing = yield getKnexDb()
|
|
60
|
+
.select("*")
|
|
61
|
+
.from("founder")
|
|
62
|
+
.where({
|
|
63
|
+
name: sanitizeMunicipalityName(founder.name),
|
|
64
|
+
ico: founder.ico,
|
|
65
|
+
});
|
|
66
|
+
if (existing.length === 0) {
|
|
67
|
+
const founderId = yield insertAutoincrementRow([
|
|
68
|
+
sanitizeMunicipalityName(founder.name),
|
|
69
|
+
sanitizeMunicipalityName(extractedMunicipalityName),
|
|
70
|
+
founder.ico,
|
|
71
|
+
String(founder.originalType),
|
|
72
|
+
cityCode,
|
|
73
|
+
cityDistrictCode,
|
|
74
|
+
], "founder", [
|
|
75
|
+
"name",
|
|
76
|
+
"short_name",
|
|
77
|
+
"ico",
|
|
78
|
+
"founder_type_code",
|
|
79
|
+
"city_code",
|
|
80
|
+
"city_district_code",
|
|
81
|
+
]);
|
|
73
82
|
insertedFounders++;
|
|
74
83
|
founder.schools.forEach((school) => {
|
|
75
84
|
schoolFounderConnectionData.push([school.izo, founderId]);
|
|
76
85
|
});
|
|
77
86
|
}
|
|
78
|
-
}
|
|
79
|
-
const insertedConnections = insertMultipleRows(schoolFounderConnectionData, "school_founder", ["school_izo", "founder_id"]);
|
|
87
|
+
}
|
|
88
|
+
const insertedConnections = yield insertMultipleRows(schoolFounderConnectionData, "school_founder", ["school_izo", "founder_id"]);
|
|
80
89
|
return insertedFounders + insertedConnections;
|
|
81
|
-
};
|
|
82
|
-
const
|
|
90
|
+
});
|
|
91
|
+
const getCityOfSchool = (izo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
return yield getKnexDb()
|
|
93
|
+
.select("c.name", "c.code")
|
|
94
|
+
.from("school as s")
|
|
95
|
+
.join("school_location as l", "s.izo", "l.school_izo")
|
|
96
|
+
.join("address_point as a", "l.address_point_id", "a.id")
|
|
97
|
+
.join("city as c", "a.city_code", "c.code")
|
|
98
|
+
.where("s.izo", izo)
|
|
99
|
+
.limit(1)
|
|
100
|
+
.first();
|
|
101
|
+
});
|
|
102
|
+
const getDistrictOfSchool = (izo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
return yield getKnexDb()
|
|
104
|
+
.select("d.name", "d.code")
|
|
105
|
+
.from("school as s")
|
|
106
|
+
.join("school_location as l", "s.izo", "l.school_izo")
|
|
107
|
+
.join("address_point as a", "l.address_point_id", "a.id")
|
|
108
|
+
.join("city_district as d", "a.city_district_code", "d.code")
|
|
109
|
+
.where("s.izo", izo)
|
|
110
|
+
.limit(1)
|
|
111
|
+
.first();
|
|
112
|
+
});
|
|
113
|
+
const fixFounderProblems = (founder, municipalityCode, differingSchools, extractedMunicipalityName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
114
|
if (differingSchools.length === 0 ||
|
|
84
115
|
differingSchools.length < founder.schools.length) {
|
|
85
116
|
return municipalityCode;
|
|
86
117
|
}
|
|
87
118
|
// either the school does not have a position (invalid RUIAN or missing building)
|
|
88
119
|
// or the school is not in the same municipality as the founder
|
|
89
|
-
const db = getDb();
|
|
90
120
|
// find all cities and their position with the same name as municipalityName
|
|
91
|
-
const municipalities = findMunicipalitiesAndPositionsByNameAndType(extractedMunicipalityName, founder.municipalityType);
|
|
121
|
+
const municipalities = yield findMunicipalitiesAndPositionsByNameAndType(extractedMunicipalityName, founder.municipalityType);
|
|
92
122
|
// get one school position (if there are more schools, they should be close to each other)
|
|
93
|
-
const schoolPosition =
|
|
94
|
-
.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.
|
|
123
|
+
const schoolPosition = yield getKnexDb()
|
|
124
|
+
.select("address_point.wgs84_latitude", "address_point.wgs84_longitude")
|
|
125
|
+
.from("school")
|
|
126
|
+
.join("school_location", "school.izo", "school_location.school_izo")
|
|
127
|
+
.join("address_point", "school_location.address_point_id", "address_point.id")
|
|
128
|
+
.whereIn("school.izo", differingSchools.map((school) => school.izo))
|
|
129
|
+
.limit(1)
|
|
130
|
+
.first();
|
|
100
131
|
if (schoolPosition) {
|
|
101
132
|
if (municipalities.length === 0) {
|
|
102
133
|
if (municipalityCode === -1) {
|
|
@@ -141,91 +172,107 @@ const fixFounderProblems = (founder, municipalityCode, differingSchools, extract
|
|
|
141
172
|
return null;
|
|
142
173
|
}
|
|
143
174
|
}
|
|
144
|
-
};
|
|
145
|
-
const getCityCodeByDistrictCode = (districtCode) => {
|
|
146
|
-
|
|
147
|
-
const result =
|
|
148
|
-
.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
const findMunicipalitiesAndPositionsByNameAndType = (name, type) => {
|
|
161
|
-
const db = getDb();
|
|
175
|
+
});
|
|
176
|
+
const getCityCodeByDistrictCode = (districtCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
177
|
+
var _b;
|
|
178
|
+
const result = yield getKnexDb()
|
|
179
|
+
.first("city.code")
|
|
180
|
+
.from("city_district")
|
|
181
|
+
.join("city", "city_district.city_code", "city.code")
|
|
182
|
+
.where("city_district.code", districtCode)
|
|
183
|
+
.limit(1);
|
|
184
|
+
return (_b = result === null || result === void 0 ? void 0 : result.code) !== null && _b !== void 0 ? _b : null;
|
|
185
|
+
});
|
|
186
|
+
const findMunicipalitiesAndPositionsByNameAndType = (name, type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
187
|
+
const knex = getKnexDb();
|
|
162
188
|
return (type === MunicipalityType.City
|
|
163
|
-
?
|
|
164
|
-
.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
.
|
|
169
|
-
:
|
|
170
|
-
.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
.
|
|
189
|
+
? yield knex
|
|
190
|
+
.select("city.name", "city.code", "address_point.wgs84_latitude", "address_point.wgs84_longitude")
|
|
191
|
+
.from("city")
|
|
192
|
+
.join("address_point", "city.code", "address_point.city_code")
|
|
193
|
+
.where("city.name", name)
|
|
194
|
+
.groupBy("city.code")
|
|
195
|
+
: yield knex
|
|
196
|
+
.select("city_district.name", "city_district.code", "address_point.wgs84_latitude", "address_point.wgs84_longitude")
|
|
197
|
+
.from("city_district")
|
|
198
|
+
.join("address_point", "city_district.code", "address_point.city_district_code")
|
|
199
|
+
.where("city_district.name", name)
|
|
200
|
+
.groupBy("city_district.code")).map((row) => ({
|
|
175
201
|
code: row.code,
|
|
176
202
|
type,
|
|
177
203
|
lat: row.wgs84_latitude,
|
|
178
204
|
lng: row.wgs84_longitude,
|
|
179
205
|
}));
|
|
206
|
+
});
|
|
207
|
+
const extractFounderName = (line) => {
|
|
208
|
+
if (line[0] === "#") {
|
|
209
|
+
return line.substring(1).trim();
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
return line.trim();
|
|
213
|
+
}
|
|
180
214
|
};
|
|
181
|
-
export const findFounder = (
|
|
215
|
+
export const findFounder = (nameWithHashtag) => __awaiter(void 0, void 0, void 0, function* () {
|
|
182
216
|
const errors = [];
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
217
|
+
const name = extractFounderName(nameWithHashtag);
|
|
218
|
+
const result = yield getKnexDb()
|
|
219
|
+
.select("f.id", "f.name", "f.ico", "f.founder_type_code", "f.city_code", "f.city_district_code")
|
|
220
|
+
.from("founder as f")
|
|
221
|
+
.leftJoin("city as c", "c.code", "f.city_code")
|
|
222
|
+
.leftJoin("city_district as d", "d.code", "f.city_district_code")
|
|
223
|
+
.where("f.name", name)
|
|
224
|
+
.orWhere("c.name", name)
|
|
225
|
+
.orWhere("d.name", name)
|
|
226
|
+
.first();
|
|
189
227
|
if (result) {
|
|
190
|
-
return { founder: resultToFounder(result), errors };
|
|
228
|
+
return { founder: yield resultToFounder(result), errors };
|
|
191
229
|
}
|
|
192
230
|
else {
|
|
193
|
-
const allFounderNames = getAllFounderNames();
|
|
231
|
+
const allFounderNames = yield getAllFounderNames();
|
|
194
232
|
const namesList = allFounderNames
|
|
195
233
|
.map((row) => row.founderName)
|
|
196
234
|
.concat(allFounderNames.map((row) => row.municipalityName));
|
|
197
235
|
const bestMatch = findClosestString(name, namesList);
|
|
198
236
|
const bestMatchRow = allFounderNames.find((foundersNames) => foundersNames.founderName === bestMatch ||
|
|
199
237
|
foundersNames.municipalityName === bestMatch);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
238
|
+
if (!bestMatchRow) {
|
|
239
|
+
errors.push(wholeLineError(`Nenašli jsme žádné zřizovatele, nejspíš jste zapomněli inicializovat databázi.`, nameWithHashtag));
|
|
240
|
+
return {
|
|
241
|
+
founder: null,
|
|
242
|
+
errors,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
errors.push(wholeLineError(`Zřizovatel '${name}' neexistuje, mysleli jste '${bestMatch}'?`, nameWithHashtag));
|
|
246
|
+
const founder = yield getKnexDb()
|
|
247
|
+
.select("id", "name", "ico", "founder_type_code", "city_code", "city_district_code")
|
|
248
|
+
.from("founder")
|
|
249
|
+
.where("id", bestMatchRow.id)
|
|
250
|
+
.first();
|
|
203
251
|
return {
|
|
204
|
-
founder: resultToFounder(
|
|
252
|
+
founder: yield resultToFounder(founder),
|
|
205
253
|
errors,
|
|
206
254
|
};
|
|
207
255
|
}
|
|
208
|
-
};
|
|
256
|
+
});
|
|
209
257
|
let cachedCityCode = null;
|
|
210
258
|
let cityCodeFounder = null;
|
|
211
|
-
export const getFounderCityCode = (founder) => {
|
|
212
|
-
const db = getDb();
|
|
259
|
+
export const getFounderCityCode = (founder) => __awaiter(void 0, void 0, void 0, function* () {
|
|
213
260
|
if (founder.municipalityType === MunicipalityType.District) {
|
|
214
261
|
if (cityCodeFounder !== founder) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
262
|
+
cityCodeFounder = founder;
|
|
263
|
+
cachedCityCode = yield getKnexDb()
|
|
264
|
+
.pluck("city_code")
|
|
265
|
+
.from("city_district")
|
|
266
|
+
.where("code", founder.cityOrDistrictCode)
|
|
267
|
+
.first();
|
|
221
268
|
}
|
|
222
269
|
return cachedCityCode;
|
|
223
270
|
}
|
|
224
271
|
else {
|
|
225
272
|
return founder.cityOrDistrictCode;
|
|
226
273
|
}
|
|
227
|
-
};
|
|
228
|
-
const resultToFounder = (result) => {
|
|
274
|
+
});
|
|
275
|
+
const resultToFounder = (result) => __awaiter(void 0, void 0, void 0, function* () {
|
|
229
276
|
return {
|
|
230
277
|
name: result.name,
|
|
231
278
|
ico: result.ico,
|
|
@@ -236,16 +283,17 @@ const resultToFounder = (result) => {
|
|
|
236
283
|
cityOrDistrictCode: result.founder_type_code === cityTypeCode
|
|
237
284
|
? result.city_code
|
|
238
285
|
: result.city_district_code,
|
|
239
|
-
schools: getSchoolsByFounderId(parseInt(result.id)),
|
|
286
|
+
schools: yield getSchoolsByFounderId(parseInt(result.id)),
|
|
240
287
|
};
|
|
241
|
-
};
|
|
242
|
-
const getSchoolsByFounderId = (founderId) => {
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
288
|
+
});
|
|
289
|
+
const getSchoolsByFounderId = (founderId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
290
|
+
const result = yield getKnexDb()
|
|
291
|
+
.select("s.izo", "s.redizo", "s.name", "s.capacity", "sl.address_point_id")
|
|
292
|
+
.from("school as s")
|
|
293
|
+
.join("school_founder as sf", "s.izo", "sf.school_izo")
|
|
294
|
+
.join("school_location as sl", "s.izo", "sl.school_izo")
|
|
295
|
+
.where("sf.founder_id", founderId);
|
|
296
|
+
return result.map((row) => ({
|
|
249
297
|
izo: String(row.izo),
|
|
250
298
|
redizo: String(row.redizo),
|
|
251
299
|
name: String(row.name),
|
|
@@ -256,45 +304,49 @@ const getSchoolsByFounderId = (founderId) => {
|
|
|
256
304
|
},
|
|
257
305
|
],
|
|
258
306
|
}));
|
|
259
|
-
};
|
|
260
|
-
const getAllFounderNames = () => {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
307
|
+
});
|
|
308
|
+
const getAllFounderNames = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
309
|
+
const result = yield getKnexDb()
|
|
310
|
+
.select("f.id", "f.name as founder_name", "c.name as city_name", "d.name as city_district_name")
|
|
311
|
+
.from("founder as f")
|
|
312
|
+
.leftJoin("city as c", "c.code", "f.city_code")
|
|
313
|
+
.leftJoin("city_district as d", "d.code", "f.city_district_code");
|
|
266
314
|
return result.map((row) => ({
|
|
267
315
|
id: parseInt(row.id),
|
|
268
316
|
founderName: String(row.founder_name),
|
|
269
317
|
municipalityName: String(row.city_name ? row.city_name : row.city_district_name),
|
|
270
318
|
}));
|
|
271
|
-
};
|
|
272
|
-
export const findMunicipalityByNameAndType = (name, type) => {
|
|
319
|
+
});
|
|
320
|
+
export const findMunicipalityByNameAndType = (name, type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
273
321
|
const errors = [];
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
322
|
+
const result = yield getKnexDb()
|
|
323
|
+
.first("code")
|
|
324
|
+
.from(type === MunicipalityType.City ? "city" : "city_district")
|
|
325
|
+
.where("name", name);
|
|
277
326
|
if (result) {
|
|
278
327
|
return { municipality: { code: result.code, type }, errors };
|
|
279
328
|
}
|
|
280
329
|
else {
|
|
281
|
-
const allNames = getAllMunicipalityNames(type);
|
|
330
|
+
const allNames = yield getAllMunicipalityNames(type);
|
|
282
331
|
const namesList = allNames.map((row) => row.name);
|
|
283
332
|
const bestMatch = findClosestString(name, namesList);
|
|
284
333
|
const bestMatchRow = allNames.find((municipality) => municipality.name === bestMatch);
|
|
285
|
-
errors.push(
|
|
334
|
+
errors.push({
|
|
335
|
+
message: `Obec ani městská část '${name}' neexistuje, mysleli jste '${bestMatch}'?`,
|
|
336
|
+
startOffset: 0,
|
|
337
|
+
endOffset: 0,
|
|
338
|
+
});
|
|
286
339
|
return {
|
|
287
340
|
municipality: { code: bestMatchRow.code, type },
|
|
288
341
|
errors,
|
|
289
342
|
};
|
|
290
343
|
}
|
|
291
|
-
};
|
|
292
|
-
const getAllMunicipalityNames = (type) => {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return result.map((row) => ({
|
|
344
|
+
});
|
|
345
|
+
const getAllMunicipalityNames = (type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
346
|
+
return (yield getKnexDb()
|
|
347
|
+
.select("name", "code")
|
|
348
|
+
.from(type === MunicipalityType.City ? "city" : "city_district")).map((row) => ({
|
|
297
349
|
name: row.name,
|
|
298
350
|
code: row.code,
|
|
299
351
|
}));
|
|
300
|
-
};
|
|
352
|
+
});
|
package/dist/db/meta.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const setMetaValue: (key: string, value: any) => import("better-sqlite3").RunResult;
|
|
1
|
+
export declare const getMetaValue: (key: string) => Promise<string | undefined>;
|
|
2
|
+
export declare const setMetaValue: (key: string, value: any) => Promise<void>;
|
|
4
3
|
export declare const setCurrentDatetimeMetaValue: (key: string) => void;
|
|
5
|
-
export declare const getDatetimeMetaValue: (key: string) => Date | undefined
|
|
4
|
+
export declare const getDatetimeMetaValue: (key: string) => Promise<Date | undefined>;
|
package/dist/db/meta.js
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
6
9
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
import { getKnexDb } from "./db";
|
|
11
|
+
export const getMetaValue = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const knex = getKnexDb();
|
|
13
|
+
const result = yield knex.pluck("value").from("meta").where({ key });
|
|
14
|
+
return result.length > 0 ? result[0] : undefined;
|
|
15
|
+
});
|
|
16
|
+
export const setMetaValue = (key, value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const knex = getKnexDb();
|
|
18
|
+
if ((yield getMetaValue(key)) === undefined) {
|
|
19
|
+
yield knex.from("meta").insert({ key, value });
|
|
12
20
|
}
|
|
13
21
|
else {
|
|
14
|
-
|
|
15
|
-
return statement.run(value.toString(), key);
|
|
22
|
+
yield knex.from("meta").update({ value }).where({ key });
|
|
16
23
|
}
|
|
17
|
-
};
|
|
24
|
+
});
|
|
18
25
|
export const setCurrentDatetimeMetaValue = (key) => {
|
|
19
26
|
setMetaValue(key, new Date().toISOString());
|
|
20
27
|
};
|
|
21
|
-
export const getDatetimeMetaValue = (key) => {
|
|
22
|
-
const value = getMetaValue(key);
|
|
28
|
+
export const getDatetimeMetaValue = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const value = yield getMetaValue(key);
|
|
23
30
|
if (value === undefined) {
|
|
24
31
|
return undefined;
|
|
25
32
|
}
|
|
26
33
|
return new Date(value);
|
|
27
|
-
};
|
|
34
|
+
});
|