@opengis/surveyor 0.0.0-stage → 0.0.2
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/CHANGELOG.md +42 -0
- package/README.md +188 -3
- package/dist/chunks/AppIcon-CIR6y5uE.js +85 -0
- package/dist/chunks/AppealDetailField-CI-1qhs3.js +58 -0
- package/dist/chunks/AppealStatusBadge-CSXnfarR.js +132 -0
- package/dist/chunks/AppealStatusBadge-DYBe9hqP.js +171 -0
- package/dist/chunks/ApplicationHistorySection-C0wwhwA4.js +769 -0
- package/dist/chunks/BaseModal-C7PVYz0m.js +85 -0
- package/dist/chunks/FormFilePicker-C3XQw50i.js +76 -0
- package/dist/chunks/MapLayerMenu-DjYCxEc3.js +145 -0
- package/dist/chunks/RegistryForm-CEUqFmsF.js +99 -0
- package/dist/chunks/RegistryFormModal-DfY4z_7r.js +85 -0
- package/dist/chunks/RegistryToolbar-BV4mYVAc.js +452 -0
- package/dist/chunks/UserAccessBadge-D8JfgGfN.js +44 -0
- package/dist/chunks/UserTypeBadge-YIwwoCho.js +188 -0
- package/dist/chunks/VerifiedBadge-Bba8WnuB.js +34 -0
- package/dist/chunks/_plugin-vue_export-helper-B3ysoDQm.js +8 -0
- package/dist/chunks/account-types-Br7gx_D_.js +35 -0
- package/dist/chunks/account_types-DLL1w122.js +25 -0
- package/dist/chunks/appealMapLayers-CQMK3rrz.js +115 -0
- package/dist/chunks/application_status-BhNGiY2I.js +45 -0
- package/dist/chunks/applications-BB9JRcgl.js +132 -0
- package/dist/chunks/buildSchema-CccjX9TJ.js +37 -0
- package/dist/chunks/card-B-ftozcq.js +739 -0
- package/dist/chunks/card-BctFHFZe.js +538 -0
- package/dist/chunks/card-CKD1N0QD.js +330 -0
- package/dist/chunks/card-CiNZxAd5.js +297 -0
- package/dist/chunks/card-DUtDfwMk.js +607 -0
- package/dist/chunks/card-fL26_Gvc.js +1189 -0
- package/dist/chunks/certificates-BSd1i0un.js +424 -0
- package/dist/chunks/create-DxMC_IL1.js +1033 -0
- package/dist/chunks/filterQuery-CvfZrkTC.js +99 -0
- package/dist/chunks/form-Bh6i5n1U.js +315 -0
- package/dist/chunks/form-DDjELqZ9.js +89 -0
- package/dist/chunks/geometry-DyhIVRcw.js +67 -0
- package/dist/chunks/map-Z57iMvFb.js +2763 -0
- package/dist/chunks/map-layers-DnmkOEld.js +400 -0
- package/dist/chunks/mapLayersApi-CWoQ2be-.js +251 -0
- package/dist/chunks/organizations-BO1_JETm.js +476 -0
- package/dist/chunks/organizations-BbYipLwk.js +14 -0
- package/dist/chunks/profile-ByahbF4B.js +164 -0
- package/dist/chunks/profile-Dwwn_4Pr.js +243 -0
- package/dist/chunks/requests-BCin936Z.js +232 -0
- package/dist/chunks/requests-CFv5wwAN.js +530 -0
- package/dist/chunks/resendSurveyorRegistration-BHTTVIw1.js +27 -0
- package/dist/chunks/resources-2e8RFqWR.js +129 -0
- package/dist/chunks/rolldown-runtime-Dy4uBu1J.js +11 -0
- package/dist/chunks/surveyorAccount-C7UiiIYg.js +78 -0
- package/dist/chunks/users-DtTYsgMb.js +291 -0
- package/dist/chunks/work_types-Hwme-FEX.js +34 -0
- package/dist/index.css +3 -0
- package/dist/index.js +336 -0
- package/migrations/20260924120000_surveyor_schema.sql +450 -0
- package/migrations/20261008170000_address_lookup.sql +20 -0
- package/migrations/20261016120000_map_layers.sql +156 -0
- package/migrations/20261016150000_password_reset.sql +15 -0
- package/migrations/20261016170000_address_lookup_format.sql +37 -0
- package/migrations/20261016180000_settlement_lookup.sql +16 -0
- package/migrations/20261019170000_actor_lookup.sql +15 -0
- package/package.json +86 -6
- package/plugin.d.ts +15 -0
- package/plugin.js +8 -0
- package/server/app.ts +51 -0
- package/server/dictionaries/index.ts +17 -0
- package/server/dictionaries/surveyor/account_types.ts +12 -0
- package/server/dictionaries/surveyor/application_status.ts +16 -0
- package/server/dictionaries/surveyor/map_layer_components.ts +11 -0
- package/server/dictionaries/surveyor/map_layer_groups.ts +10 -0
- package/server/dictionaries/surveyor/map_layer_types.ts +11 -0
- package/server/dictionaries/surveyor/work_types.ts +15 -0
- package/server/dictionaries/surveyor/yes_no.ts +11 -0
- package/server/fastify.d.ts +12 -0
- package/server/index.ts +23 -0
- package/server/modules/surveyor/route.ts +410 -0
- package/server/modules/surveyor/schema.ts +439 -0
- package/server/modules/surveyor/services/applicationTile.ts +53 -0
- package/server/modules/surveyor/services/cancelApplication.ts +74 -0
- package/server/modules/surveyor/services/changeSurveyorPassword.ts +52 -0
- package/server/modules/surveyor/services/changeSurveyorPasswordByAdmin.ts +41 -0
- package/server/modules/surveyor/services/completeApplication.ts +46 -0
- package/server/modules/surveyor/services/completeSurveyorRegistration.ts +48 -0
- package/server/modules/surveyor/services/createApplication.ts +169 -0
- package/server/modules/surveyor/services/geometryExport.ts +34 -0
- package/server/modules/surveyor/services/geometryImport.ts +66 -0
- package/server/modules/surveyor/services/getSurveyorUser.ts +56 -0
- package/server/modules/surveyor/services/identifyApplications.ts +82 -0
- package/server/modules/surveyor/services/issueSourceData.ts +55 -0
- package/server/modules/surveyor/services/loginSurveyor.ts +67 -0
- package/server/modules/surveyor/services/mapLayers.ts +61 -0
- package/server/modules/surveyor/services/rasterExport.ts +15 -0
- package/server/modules/surveyor/services/registerSurveyor.ts +161 -0
- package/server/modules/surveyor/services/requestPasswordReset.ts +49 -0
- package/server/modules/surveyor/services/resendRegistration.ts +42 -0
- package/server/modules/surveyor/services/resetSurveyorPassword.ts +53 -0
- package/server/modules/surveyor/services/searchApplications.ts +63 -0
- package/server/modules/surveyor/services/submitSurvey.ts +70 -0
- package/server/modules/surveyor/services/updateSurveyorAccountStatus.ts +52 -0
- package/server/modules/surveyor/services/updateSurveyorStatus.ts +53 -0
- package/server/modules/surveyor/services/vectorExport.ts +86 -0
- package/server/modules/surveyor/services/verifyApplication.ts +59 -0
- package/server/modules/surveyor/utils/accessibleApplication.ts +37 -0
- package/server/modules/surveyor/utils/application.ts +68 -0
- package/server/modules/surveyor/utils/export.ts +39 -0
- package/server/modules/surveyor/utils/firstBoundary.ts +48 -0
- package/server/modules/surveyor/utils/mail.ts +161 -0
- package/server/modules/surveyor/utils/permissions.ts +29 -0
- package/server/modules/surveyor/utils/registration.ts +33 -0
- package/server/modules/surveyor/utils/shared.ts +305 -0
- package/server/modules/surveyor/utils/templates/ds.surveyor_admin_password.pt.hbs +79 -0
- package/server/modules/surveyor/utils/templates/ds.surveyor_password_reset.pt.hbs +79 -0
- package/server/modules/surveyor/utils/templates/ds.surveyor_registration.pt.hbs +80 -0
- package/server/modules/surveyor/utils/templates/ds.surveyor_send_mail.pt.hbs +79 -0
- package/server/modules/surveyor/utils/vectorLayer.ts +41 -0
- package/server/plugins/convertVector.ts +74 -0
- package/server/plugins/proto/convertVector.proto +21 -0
- package/server/plugins/swagger.ts +54 -0
- package/server/plugins/vite.dev.ts +52 -0
- package/server/plugins/vite.prod.ts +55 -0
- package/server/resources/helpers/actor_lookup.ts +5 -0
- package/server/resources/helpers/address_lookup.ts +8 -0
- package/server/resources/helpers/settlement_lookup.ts +7 -0
- package/server/resources/helpers/user_lookup.ts +5 -0
- package/server/resources/index.ts +30 -0
- package/server/resources/surveyor-admin/application_comments.ts +24 -0
- package/server/resources/surveyor-admin/application_status_history.ts +46 -0
- package/server/resources/surveyor-admin/applications.ts +125 -0
- package/server/resources/surveyor-admin/certificates.ts +87 -0
- package/server/resources/surveyor-admin/map_layers.ts +69 -0
- package/server/resources/surveyor-admin/organization_surveyors.ts +32 -0
- package/server/resources/surveyor-admin/organizations.ts +61 -0
- package/server/resources/surveyor-admin/surveyors.ts +71 -0
- package/server/resources/surveyor-user/application_status_history.ts +52 -0
- package/server/resources/surveyor-user/applications.ts +131 -0
- package/server/resources/surveyor-user/certificates.ts +67 -0
- package/server/resources/surveyor-user/organizations.ts +40 -0
- package/server/resources/surveyor-user/surveyors.ts +69 -0
- package/server/suggests/index.ts +17 -0
- package/server/tsconfig.json +3 -0
- package/surveyor-types.d.ts +30 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import statuses from "../../dictionaries/surveyor/application_status.js";
|
|
2
|
+
import workTypes from "../../dictionaries/surveyor/work_types.js";
|
|
3
|
+
import mapLayerComponentDictionary from "../../dictionaries/surveyor/map_layer_components.js";
|
|
4
|
+
import applications from "../../resources/surveyor-user/applications.js";
|
|
5
|
+
|
|
6
|
+
/** Схеми параметрів та відповідей Business API Surveyor для Fastify. */
|
|
7
|
+
const identifier = { type: "string", minLength: 1, pattern: "\\S" };
|
|
8
|
+
const nonBlank = { type: "string", minLength: 1, pattern: "\\S" };
|
|
9
|
+
const filePath = { type: "string", minLength: 1, pattern: "^[^/\\\\][^\\r\\n]*$" };
|
|
10
|
+
const password = { type: "string", minLength: 8, maxLength: 256 };
|
|
11
|
+
const applicationStatus = statuses.items.map((item) => item.code);
|
|
12
|
+
const exportOptions = {
|
|
13
|
+
format: { type: "string", enum: ["geoJson", "geojson"] },
|
|
14
|
+
srid: { type: "integer", minimum: 1, maximum: 2147483647 },
|
|
15
|
+
crs: { type: "string", pattern: "^EPSG:[1-9][0-9]*$" },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const applicationParams = {
|
|
19
|
+
type: "object",
|
|
20
|
+
required: ["applicationId"],
|
|
21
|
+
properties: { applicationId: identifier },
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
};
|
|
24
|
+
const surveyorParams = {
|
|
25
|
+
type: "object",
|
|
26
|
+
required: ["surveyorId"],
|
|
27
|
+
properties: { surveyorId: identifier },
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
};
|
|
30
|
+
const registrationParams = {
|
|
31
|
+
type: "object",
|
|
32
|
+
required: ["token"],
|
|
33
|
+
properties: {
|
|
34
|
+
token: { type: "string", minLength: 32, maxLength: 256, pattern: "^[A-Za-z0-9_-]+$" },
|
|
35
|
+
},
|
|
36
|
+
additionalProperties: false,
|
|
37
|
+
};
|
|
38
|
+
const fileBody = {
|
|
39
|
+
type: "object",
|
|
40
|
+
required: ["file_path"],
|
|
41
|
+
properties: {
|
|
42
|
+
file_path: filePath,
|
|
43
|
+
note: { type: "string" },
|
|
44
|
+
},
|
|
45
|
+
additionalProperties: false,
|
|
46
|
+
};
|
|
47
|
+
const passwordBody = {
|
|
48
|
+
type: "object",
|
|
49
|
+
required: ["password", "password_confirmation"],
|
|
50
|
+
properties: { password, password_confirmation: password },
|
|
51
|
+
additionalProperties: false,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const mapLayerComponents = mapLayerComponentDictionary.items.map((item) => item.code);
|
|
55
|
+
const nullableInteger = { type: "integer", nullable: true };
|
|
56
|
+
const nullableObject = { type: "object", nullable: true, additionalProperties: true };
|
|
57
|
+
const mapLayer = {
|
|
58
|
+
type: "object",
|
|
59
|
+
required: [
|
|
60
|
+
"code",
|
|
61
|
+
"name",
|
|
62
|
+
"layer_group",
|
|
63
|
+
"layer_type",
|
|
64
|
+
"tiles",
|
|
65
|
+
"scheme",
|
|
66
|
+
"opacity",
|
|
67
|
+
"components",
|
|
68
|
+
"is_default",
|
|
69
|
+
"has_filters",
|
|
70
|
+
],
|
|
71
|
+
properties: {
|
|
72
|
+
code: nonBlank,
|
|
73
|
+
name: { type: "string" },
|
|
74
|
+
layer_group: { type: "string", enum: ["base", "overlay"] },
|
|
75
|
+
layer_type: { type: "string", enum: ["raster", "vector", "applications"] },
|
|
76
|
+
tiles: { type: "array", items: { type: "string" } },
|
|
77
|
+
scheme: { type: "string", enum: ["xyz", "tms"] },
|
|
78
|
+
source_layer: { type: "string", nullable: true },
|
|
79
|
+
attribution: { type: "string", nullable: true },
|
|
80
|
+
minzoom: nullableInteger,
|
|
81
|
+
maxzoom: nullableInteger,
|
|
82
|
+
opacity: { type: "number", minimum: 0, maximum: 1 },
|
|
83
|
+
style: nullableObject,
|
|
84
|
+
legend: nullableObject,
|
|
85
|
+
preview: { type: "string", nullable: true },
|
|
86
|
+
components: { type: "array", items: { type: "string", enum: mapLayerComponents } },
|
|
87
|
+
is_default: { type: "boolean" },
|
|
88
|
+
has_filters: { type: "boolean" },
|
|
89
|
+
},
|
|
90
|
+
additionalProperties: false,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const surveyorSchemas = {
|
|
94
|
+
applicationParams,
|
|
95
|
+
surveyorParams,
|
|
96
|
+
registrationParams,
|
|
97
|
+
|
|
98
|
+
surveyorUser: {
|
|
99
|
+
type: "object",
|
|
100
|
+
required: [
|
|
101
|
+
"surveyor_id", "certificate_id", "first_name", "last_name", "middle_name",
|
|
102
|
+
"email", "phone", "enabled", "organizations",
|
|
103
|
+
],
|
|
104
|
+
properties: {
|
|
105
|
+
surveyor_id: identifier,
|
|
106
|
+
certificate_id: identifier,
|
|
107
|
+
first_name: { type: "string" },
|
|
108
|
+
last_name: { type: "string" },
|
|
109
|
+
middle_name: { type: "string", nullable: true },
|
|
110
|
+
email: { type: "string" },
|
|
111
|
+
phone: { type: "string", nullable: true },
|
|
112
|
+
enabled: { type: "boolean" },
|
|
113
|
+
organizations: {
|
|
114
|
+
type: "array",
|
|
115
|
+
items: {
|
|
116
|
+
type: "object",
|
|
117
|
+
required: ["org_id", "name", "legal_address", "phone", "email", "scan_path"],
|
|
118
|
+
properties: {
|
|
119
|
+
org_id: identifier,
|
|
120
|
+
name: { type: "string" },
|
|
121
|
+
legal_address: { type: "string", nullable: true },
|
|
122
|
+
phone: { type: "string" },
|
|
123
|
+
email: { type: "string" },
|
|
124
|
+
scan_path: { type: "string", nullable: true },
|
|
125
|
+
},
|
|
126
|
+
additionalProperties: false,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
additionalProperties: false,
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
createApplication: {
|
|
134
|
+
type: "object",
|
|
135
|
+
required: ["organization_id", "work_type", "settlement_id", "is_found_address_id", "geom"],
|
|
136
|
+
properties: {
|
|
137
|
+
organization_id: identifier,
|
|
138
|
+
work_type: { type: "string", enum: workTypes.items.map((item) => item.code) },
|
|
139
|
+
description: { type: "string" },
|
|
140
|
+
execution_basis: { type: "string" },
|
|
141
|
+
settlement_id: nonBlank,
|
|
142
|
+
is_found_address_id: { type: "boolean" },
|
|
143
|
+
address_id: nonBlank,
|
|
144
|
+
location: { type: "string" },
|
|
145
|
+
geom: {
|
|
146
|
+
type: "object",
|
|
147
|
+
required: ["type", "coordinates"],
|
|
148
|
+
properties: {
|
|
149
|
+
type: { const: "Polygon" },
|
|
150
|
+
coordinates: {
|
|
151
|
+
type: "array",
|
|
152
|
+
minItems: 1,
|
|
153
|
+
items: {
|
|
154
|
+
type: "array",
|
|
155
|
+
minItems: 4,
|
|
156
|
+
items: {
|
|
157
|
+
type: "array",
|
|
158
|
+
minItems: 2,
|
|
159
|
+
maxItems: 2,
|
|
160
|
+
items: { type: "number" },
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
additionalProperties: false,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
allOf: [
|
|
169
|
+
{
|
|
170
|
+
if: { properties: { is_found_address_id: { const: true } } },
|
|
171
|
+
then: { required: ["address_id"] },
|
|
172
|
+
else: { not: { required: ["address_id"] } },
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
additionalProperties: false,
|
|
176
|
+
},
|
|
177
|
+
cancelApplication: {
|
|
178
|
+
type: "object",
|
|
179
|
+
required: ["reason"],
|
|
180
|
+
properties: { reason: nonBlank },
|
|
181
|
+
additionalProperties: false,
|
|
182
|
+
},
|
|
183
|
+
fileBody,
|
|
184
|
+
verifyApplication: {
|
|
185
|
+
type: "object",
|
|
186
|
+
required: ["status"],
|
|
187
|
+
properties: {
|
|
188
|
+
status: {
|
|
189
|
+
type: "string",
|
|
190
|
+
enum: applicationStatus.filter((code) => code === "verified" || code === "dataIssued"),
|
|
191
|
+
},
|
|
192
|
+
file_path: filePath,
|
|
193
|
+
note_4_file_corrected_geodetic_survey: nonBlank,
|
|
194
|
+
},
|
|
195
|
+
allOf: [
|
|
196
|
+
{
|
|
197
|
+
if: { properties: { status: { const: "dataIssued" } } },
|
|
198
|
+
then: { required: ["note_4_file_corrected_geodetic_survey"] },
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
additionalProperties: false,
|
|
202
|
+
},
|
|
203
|
+
geometryImport: {
|
|
204
|
+
type: "object",
|
|
205
|
+
required: ["file", "filename"],
|
|
206
|
+
properties: {
|
|
207
|
+
file: { type: "string", minLength: 1 },
|
|
208
|
+
filename: nonBlank,
|
|
209
|
+
encoding: { type: "string", minLength: 1, maxLength: 64, pattern: "\\S" },
|
|
210
|
+
},
|
|
211
|
+
additionalProperties: false,
|
|
212
|
+
},
|
|
213
|
+
geometryExport: {
|
|
214
|
+
type: "object",
|
|
215
|
+
properties: exportOptions,
|
|
216
|
+
additionalProperties: false,
|
|
217
|
+
},
|
|
218
|
+
vectorExport: {
|
|
219
|
+
type: "object",
|
|
220
|
+
required: ["layer_id"],
|
|
221
|
+
properties: {
|
|
222
|
+
...exportOptions,
|
|
223
|
+
layer_id: nonBlank,
|
|
224
|
+
buffer: { type: "number", minimum: 0 },
|
|
225
|
+
},
|
|
226
|
+
additionalProperties: false,
|
|
227
|
+
},
|
|
228
|
+
rasterExport: {
|
|
229
|
+
type: "object",
|
|
230
|
+
required: ["format"],
|
|
231
|
+
properties: {
|
|
232
|
+
format: { const: "geotiff" },
|
|
233
|
+
crs: { type: "string", pattern: "^EPSG:[0-9]+$" },
|
|
234
|
+
},
|
|
235
|
+
additionalProperties: false,
|
|
236
|
+
},
|
|
237
|
+
registerSurveyor: {
|
|
238
|
+
type: "object",
|
|
239
|
+
required: ["organization_id", "certificate_id", "email"],
|
|
240
|
+
properties: {
|
|
241
|
+
organization_id: identifier,
|
|
242
|
+
certificate_id: identifier,
|
|
243
|
+
email: { type: "string", minLength: 3, pattern: "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$" },
|
|
244
|
+
phone: { type: "string" },
|
|
245
|
+
},
|
|
246
|
+
additionalProperties: false,
|
|
247
|
+
},
|
|
248
|
+
loginSurveyor: {
|
|
249
|
+
type: "object",
|
|
250
|
+
required: ["email", "password"],
|
|
251
|
+
properties: {
|
|
252
|
+
email: {
|
|
253
|
+
type: "string",
|
|
254
|
+
minLength: 3,
|
|
255
|
+
maxLength: 320,
|
|
256
|
+
pattern: "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$",
|
|
257
|
+
},
|
|
258
|
+
password: { type: "string", minLength: 1, maxLength: 256 },
|
|
259
|
+
},
|
|
260
|
+
additionalProperties: false,
|
|
261
|
+
},
|
|
262
|
+
passwordBody,
|
|
263
|
+
passwordResetRequest: {
|
|
264
|
+
type: "object",
|
|
265
|
+
required: ["email"],
|
|
266
|
+
properties: {
|
|
267
|
+
email: {
|
|
268
|
+
type: "string",
|
|
269
|
+
minLength: 3,
|
|
270
|
+
maxLength: 320,
|
|
271
|
+
pattern: "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$",
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
additionalProperties: false,
|
|
275
|
+
},
|
|
276
|
+
surveyorStatus: {
|
|
277
|
+
type: "object",
|
|
278
|
+
required: ["org_id", "enabled"],
|
|
279
|
+
properties: { org_id: identifier, enabled: { type: "boolean" } },
|
|
280
|
+
additionalProperties: false,
|
|
281
|
+
},
|
|
282
|
+
surveyorAccountStatus: {
|
|
283
|
+
type: "object",
|
|
284
|
+
required: ["enabled"],
|
|
285
|
+
properties: { enabled: { type: "boolean" } },
|
|
286
|
+
additionalProperties: false,
|
|
287
|
+
},
|
|
288
|
+
orgParams: {
|
|
289
|
+
type: "object",
|
|
290
|
+
required: ["orgId"],
|
|
291
|
+
properties: { orgId: identifier },
|
|
292
|
+
additionalProperties: false,
|
|
293
|
+
},
|
|
294
|
+
membershipParams: {
|
|
295
|
+
type: "object",
|
|
296
|
+
required: ["orgId", "surveyorId"],
|
|
297
|
+
properties: { orgId: identifier, surveyorId: identifier },
|
|
298
|
+
additionalProperties: false,
|
|
299
|
+
},
|
|
300
|
+
linkSurveyor: {
|
|
301
|
+
type: "object",
|
|
302
|
+
required: ["surveyor_id"],
|
|
303
|
+
properties: { surveyor_id: identifier },
|
|
304
|
+
additionalProperties: false,
|
|
305
|
+
},
|
|
306
|
+
membershipBody: {
|
|
307
|
+
type: "object",
|
|
308
|
+
required: ["enabled"],
|
|
309
|
+
properties: { enabled: { type: "boolean" } },
|
|
310
|
+
additionalProperties: false,
|
|
311
|
+
},
|
|
312
|
+
changePasswordParams: {
|
|
313
|
+
type: "object",
|
|
314
|
+
required: ["id"],
|
|
315
|
+
properties: { id: identifier },
|
|
316
|
+
additionalProperties: false,
|
|
317
|
+
},
|
|
318
|
+
applicationIdentify: {
|
|
319
|
+
type: "object",
|
|
320
|
+
required: ["lng", "lat"],
|
|
321
|
+
properties: {
|
|
322
|
+
lng: { type: "number", minimum: -180, maximum: 180 },
|
|
323
|
+
lat: { type: "number", minimum: -90, maximum: 90 },
|
|
324
|
+
page: { type: "integer", minimum: 1, maximum: 2147483647, default: 1 },
|
|
325
|
+
limit: { type: "integer", minimum: 1, maximum: 100, default: 20 },
|
|
326
|
+
filter: { type: "string", enum: applicationStatus },
|
|
327
|
+
statuses: { type: "string", minLength: 1, maxLength: 512 },
|
|
328
|
+
},
|
|
329
|
+
additionalProperties: false,
|
|
330
|
+
},
|
|
331
|
+
applicationIdentifyResult: {
|
|
332
|
+
type: "object",
|
|
333
|
+
required: ["total", "page", "count", "data"],
|
|
334
|
+
properties: {
|
|
335
|
+
total: { type: "integer", minimum: 0 },
|
|
336
|
+
page: { type: "integer", minimum: 1 },
|
|
337
|
+
count: { type: "integer", minimum: 0 },
|
|
338
|
+
data: {
|
|
339
|
+
type: "array",
|
|
340
|
+
items: {
|
|
341
|
+
type: "object",
|
|
342
|
+
required: Object.keys(applications.fields),
|
|
343
|
+
properties: Object.fromEntries(Object.entries(applications.fields).flatMap(([name, field]) => [
|
|
344
|
+
[name, field.type === "geometry"
|
|
345
|
+
? { type: "object", additionalProperties: true }
|
|
346
|
+
: {
|
|
347
|
+
type: field.type === "number" || field.type === "boolean" ? field.type : "string",
|
|
348
|
+
nullable: true,
|
|
349
|
+
}],
|
|
350
|
+
...("dictionary" in field || "lookup" in field
|
|
351
|
+
? [[`${name}_data`, { type: "object", nullable: true, additionalProperties: true }]]
|
|
352
|
+
: []),
|
|
353
|
+
])),
|
|
354
|
+
additionalProperties: false,
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
additionalProperties: false,
|
|
359
|
+
},
|
|
360
|
+
applicationSearch: {
|
|
361
|
+
type: "object",
|
|
362
|
+
required: ["search"],
|
|
363
|
+
properties: {
|
|
364
|
+
search: { ...nonBlank, maxLength: 256 },
|
|
365
|
+
page: { type: "integer", minimum: 1, maximum: 2147483647, default: 1 },
|
|
366
|
+
limit: { type: "integer", minimum: 1, maximum: 100, default: 20 },
|
|
367
|
+
filter: { type: "string", enum: applicationStatus },
|
|
368
|
+
},
|
|
369
|
+
additionalProperties: false,
|
|
370
|
+
},
|
|
371
|
+
applicationSearchResult: {
|
|
372
|
+
type: "object",
|
|
373
|
+
required: ["total", "page", "count", "data"],
|
|
374
|
+
properties: {
|
|
375
|
+
total: { type: "integer", minimum: 0 },
|
|
376
|
+
page: { type: "integer", minimum: 1 },
|
|
377
|
+
count: { type: "integer", minimum: 0 },
|
|
378
|
+
data: {
|
|
379
|
+
type: "array",
|
|
380
|
+
items: {
|
|
381
|
+
type: "object",
|
|
382
|
+
required: ["id", "number", "address", "geometry"],
|
|
383
|
+
properties: {
|
|
384
|
+
id: identifier,
|
|
385
|
+
number: { type: "string", nullable: true },
|
|
386
|
+
address: { type: "string" },
|
|
387
|
+
geometry: {
|
|
388
|
+
type: "object",
|
|
389
|
+
required: ["type", "coordinates"],
|
|
390
|
+
properties: {
|
|
391
|
+
type: { type: "string", enum: ["Polygon"] },
|
|
392
|
+
coordinates: {
|
|
393
|
+
type: "array",
|
|
394
|
+
items: {
|
|
395
|
+
type: "array",
|
|
396
|
+
items: { type: "array", items: { type: "number" } },
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
additionalProperties: false,
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
additionalProperties: false,
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
additionalProperties: false,
|
|
408
|
+
},
|
|
409
|
+
tileParams: {
|
|
410
|
+
type: "object",
|
|
411
|
+
required: ["z", "x", "y"],
|
|
412
|
+
properties: {
|
|
413
|
+
z: { type: "integer", minimum: 0, maximum: 22 },
|
|
414
|
+
x: { type: "integer", minimum: 0 },
|
|
415
|
+
y: { type: "integer", minimum: 0 },
|
|
416
|
+
},
|
|
417
|
+
additionalProperties: false,
|
|
418
|
+
},
|
|
419
|
+
tileQuery: {
|
|
420
|
+
type: "object",
|
|
421
|
+
properties: { filter: { type: "string", enum: applicationStatus } },
|
|
422
|
+
additionalProperties: false,
|
|
423
|
+
},
|
|
424
|
+
mapLayersQuery: {
|
|
425
|
+
type: "object",
|
|
426
|
+
properties: { component: { type: "string", enum: mapLayerComponents } },
|
|
427
|
+
additionalProperties: false,
|
|
428
|
+
},
|
|
429
|
+
mapLayersResult: {
|
|
430
|
+
type: "object",
|
|
431
|
+
required: ["default_base", "base", "overlays"],
|
|
432
|
+
properties: {
|
|
433
|
+
default_base: { type: "string", nullable: true },
|
|
434
|
+
base: { type: "array", items: mapLayer },
|
|
435
|
+
overlays: { type: "array", items: mapLayer },
|
|
436
|
+
},
|
|
437
|
+
additionalProperties: false,
|
|
438
|
+
},
|
|
439
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AppContext, User } from "@opengis/fcore";
|
|
2
|
+
import { BadRequestError } from "@opengis/fcore";
|
|
3
|
+
import { actor, surveyorForUser } from "../utils/shared.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Будує векторний тайл заявок, доступних користувачу, з необов'язковим фільтром статусу.
|
|
7
|
+
* @param params Координати тайла, фільтр, користувач і контекст FCore.
|
|
8
|
+
* @returns Вміст тайла у форматі MVT.
|
|
9
|
+
*/
|
|
10
|
+
export async function applicationTile(
|
|
11
|
+
{ z, x, y, filter, user, ctx }: {
|
|
12
|
+
z: number;
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
filter: string | undefined;
|
|
16
|
+
user: User | undefined;
|
|
17
|
+
ctx: AppContext;
|
|
18
|
+
}
|
|
19
|
+
): Promise<Buffer> {
|
|
20
|
+
actor(user);
|
|
21
|
+
if (x >= 2 ** z || y >= 2 ** z) {
|
|
22
|
+
throw new BadRequestError("Invalid tile coordinates");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const surveyorId = user?.type === "admin" ? null : await surveyorForUser({ db: ctx.pg, user });
|
|
26
|
+
const result = await ctx.pg.query<{ tile: Buffer }>(
|
|
27
|
+
`WITH bounds AS (
|
|
28
|
+
SELECT ST_TileEnvelope($1, $2, $3) AS box
|
|
29
|
+
), features AS (
|
|
30
|
+
SELECT a.app_id::text AS id,
|
|
31
|
+
a.status::text AS status,
|
|
32
|
+
a.number,
|
|
33
|
+
ST_AsMVTGeom(ST_Transform(a.geom, 3857), bounds.box) AS geom
|
|
34
|
+
FROM surveyor.applications AS a
|
|
35
|
+
CROSS JOIN bounds
|
|
36
|
+
WHERE ST_Intersects(ST_Transform(a.geom, 3857), bounds.box)
|
|
37
|
+
AND (
|
|
38
|
+
$4::text IS NULL OR EXISTS (
|
|
39
|
+
SELECT 1
|
|
40
|
+
FROM surveyor.organization_surveyors AS os
|
|
41
|
+
WHERE os.org_id = a.org_id
|
|
42
|
+
AND os.surveyor_id = $4
|
|
43
|
+
AND os.enabled = true
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
AND ($5::text IS NULL OR a.status::text = $5)
|
|
47
|
+
)
|
|
48
|
+
SELECT ST_AsMVT(features, 'applications', 4096, 'geom') AS tile
|
|
49
|
+
FROM features`,
|
|
50
|
+
[z, x, y, surveyorId, filter ?? null]
|
|
51
|
+
);
|
|
52
|
+
return result.rows[0]?.tile ?? Buffer.alloc(0);
|
|
53
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { AppContext, User } from "@opengis/fcore";
|
|
2
|
+
import { ConflictError, ForbiddenError, NotFoundError } from "@opengis/fcore";
|
|
3
|
+
import {
|
|
4
|
+
actor,
|
|
5
|
+
assertStatus,
|
|
6
|
+
audit,
|
|
7
|
+
history,
|
|
8
|
+
readApplication,
|
|
9
|
+
releaseReservesForParent,
|
|
10
|
+
surveyorForUser,
|
|
11
|
+
type Db,
|
|
12
|
+
} from "../utils/shared.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Скасовує власну заявку геодезиста зі статусом `awaitingData` і переглядає резерви.
|
|
16
|
+
* @param params Заявка, причина скасування, геодезист і контекст FCore.
|
|
17
|
+
* @returns Новий статус і перелік заявок, знятих із резерву.
|
|
18
|
+
*/
|
|
19
|
+
export async function cancelApplication({
|
|
20
|
+
id,
|
|
21
|
+
reason,
|
|
22
|
+
user,
|
|
23
|
+
ctx,
|
|
24
|
+
}: {
|
|
25
|
+
id: string;
|
|
26
|
+
reason: string;
|
|
27
|
+
user: User | undefined;
|
|
28
|
+
ctx: AppContext;
|
|
29
|
+
}) {
|
|
30
|
+
const uid = actor(user);
|
|
31
|
+
if (user?.type === "admin") {
|
|
32
|
+
throw new ForbiddenError("Administrator cannot cancel an application");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const text = reason.trim();
|
|
36
|
+
const result = await ctx.pg.transaction(async (db: Db) => {
|
|
37
|
+
// Узгоджує скасування та звільнення резервів із паралельним створенням заявок.
|
|
38
|
+
await db.query("SELECT pg_advisory_xact_lock(85437120)");
|
|
39
|
+
const surveyorId = await surveyorForUser({ db, user });
|
|
40
|
+
const updated = await db.query<{ app_id: string }>(
|
|
41
|
+
`UPDATE surveyor.applications
|
|
42
|
+
SET status = 'cancelled',
|
|
43
|
+
cancel_reason = $2,
|
|
44
|
+
cancelled_at = now(),
|
|
45
|
+
cancelled_by = $3,
|
|
46
|
+
updated_by = $3,
|
|
47
|
+
updated_at = now()
|
|
48
|
+
WHERE app_id = $1
|
|
49
|
+
AND status = 'awaitingData'
|
|
50
|
+
AND surveyor_id = $4
|
|
51
|
+
RETURNING app_id`,
|
|
52
|
+
[id, text, uid, surveyorId]
|
|
53
|
+
);
|
|
54
|
+
if (!updated.rows[0]) {
|
|
55
|
+
const app = await readApplication({ db, id });
|
|
56
|
+
assertStatus({ app, status: "awaitingData" });
|
|
57
|
+
if (app.surveyor_id !== surveyorId) {
|
|
58
|
+
throw new NotFoundError("Application not found");
|
|
59
|
+
}
|
|
60
|
+
throw new ConflictError("Application changed concurrently");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
await history({ db, appId: id, from: "awaitingData", to: "cancelled", by: uid, reason: text });
|
|
64
|
+
|
|
65
|
+
const released = await releaseReservesForParent({ db, parentId: id, uid });
|
|
66
|
+
return { id, status: "cancelled", released };
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await audit({ ctx, action: "cancel", appId: id, uid });
|
|
70
|
+
for (const released of result.released) {
|
|
71
|
+
await audit({ ctx, action: "releaseReserve", appId: released, uid });
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AppContext, User } from "@opengis/fcore";
|
|
2
|
+
import { ForbiddenError, hashPassword } from "@opengis/fcore";
|
|
3
|
+
import { actor } from "../utils/shared.js";
|
|
4
|
+
import { checkPassword } from "../utils/registration.js";
|
|
5
|
+
import { sendPasswordChangedEmail } from "../utils/mail.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Змінює пароль власного профілю геодезиста та повідомляє його листом.
|
|
9
|
+
* @param params Геодезист, новий пароль, підтвердження і контекст FCore.
|
|
10
|
+
* @returns Ознака успішної зміни пароля.
|
|
11
|
+
*/
|
|
12
|
+
export async function changeSurveyorPassword(
|
|
13
|
+
{ id, password, confirmation, user, ctx }: {
|
|
14
|
+
id: string;
|
|
15
|
+
password: string;
|
|
16
|
+
confirmation: string;
|
|
17
|
+
user: User | undefined;
|
|
18
|
+
ctx: AppContext;
|
|
19
|
+
}
|
|
20
|
+
) {
|
|
21
|
+
const uid = actor(user);
|
|
22
|
+
if (user?.type !== "regular") {
|
|
23
|
+
throw new ForbiddenError("Own active surveyor profile required");
|
|
24
|
+
}
|
|
25
|
+
const validPassword = checkPassword({ password, confirmation });
|
|
26
|
+
const passwordHash = await hashPassword(validPassword);
|
|
27
|
+
const surveyor = await ctx.pg.query<{ surveyor_id: string; email: string }>(
|
|
28
|
+
`UPDATE surveyor.surveyors
|
|
29
|
+
SET password_hash = $2,
|
|
30
|
+
password_changed_at = now(),
|
|
31
|
+
updated_by = $3,
|
|
32
|
+
updated_at = now()
|
|
33
|
+
WHERE surveyor_id = $1
|
|
34
|
+
AND surveyor_id::text = $3
|
|
35
|
+
AND enabled = true
|
|
36
|
+
AND registered_at IS NOT NULL
|
|
37
|
+
RETURNING surveyor_id, email`,
|
|
38
|
+
[id, passwordHash, uid]
|
|
39
|
+
);
|
|
40
|
+
if (!surveyor.rows[0]) {
|
|
41
|
+
throw new ForbiddenError("Own active surveyor profile required");
|
|
42
|
+
}
|
|
43
|
+
await ctx.audit.write({
|
|
44
|
+
module: "surveyor",
|
|
45
|
+
resource: "surveyors",
|
|
46
|
+
resourceId: id,
|
|
47
|
+
action: "changePassword",
|
|
48
|
+
userId: uid,
|
|
49
|
+
});
|
|
50
|
+
await sendPasswordChangedEmail({ email: surveyor.rows[0].email });
|
|
51
|
+
return { success: true };
|
|
52
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import type { AppContext, User } from "@opengis/fcore";
|
|
3
|
+
import { NotFoundError, hashPassword } from "@opengis/fcore";
|
|
4
|
+
import { admin } from "../utils/shared.js";
|
|
5
|
+
import { sendAdminPasswordChangedEmail } from "../utils/mail.js";
|
|
6
|
+
|
|
7
|
+
/** Змінює пароль зареєстрованого геодезиста адміністратором та повідомляє його листом. */
|
|
8
|
+
export async function changeSurveyorPasswordByAdmin(
|
|
9
|
+
{ id, user, ctx }: {
|
|
10
|
+
id: string;
|
|
11
|
+
user: User | undefined;
|
|
12
|
+
ctx: AppContext;
|
|
13
|
+
}
|
|
14
|
+
) {
|
|
15
|
+
const uid = admin(user);
|
|
16
|
+
const password = randomBytes(16).toString("hex");
|
|
17
|
+
const passwordHash = await hashPassword(password);
|
|
18
|
+
const surveyor = await ctx.pg.query<{ surveyor_id: string; email: string }>(
|
|
19
|
+
`UPDATE surveyor.surveyors
|
|
20
|
+
SET password_hash = $2,
|
|
21
|
+
password_changed_at = now(),
|
|
22
|
+
updated_by = $3,
|
|
23
|
+
updated_at = now()
|
|
24
|
+
WHERE surveyor_id = $1
|
|
25
|
+
AND registered_at IS NOT NULL
|
|
26
|
+
RETURNING surveyor_id, email`,
|
|
27
|
+
[id, passwordHash, uid]
|
|
28
|
+
);
|
|
29
|
+
if (!surveyor.rows[0]) {
|
|
30
|
+
throw new NotFoundError("Registered surveyor not found");
|
|
31
|
+
}
|
|
32
|
+
await ctx.audit.write({
|
|
33
|
+
module: "surveyor",
|
|
34
|
+
resource: "surveyors",
|
|
35
|
+
resourceId: id,
|
|
36
|
+
action: "changePasswordByAdmin",
|
|
37
|
+
userId: uid,
|
|
38
|
+
});
|
|
39
|
+
await sendAdminPasswordChangedEmail({ email: surveyor.rows[0].email, password });
|
|
40
|
+
return { success: true };
|
|
41
|
+
}
|