@opengis/surveyor 0.0.8 → 0.0.10

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.
Files changed (68) hide show
  1. package/README.md +4 -3
  2. package/dist/chunks/{AppIcon-CO70tpMX.js → AppIcon-Di5F4Bu_.js} +1 -1
  3. package/dist/chunks/{AppealDetailField-DNRGpnyD.js → AppealDetailField-DNpsGpPY.js} +2 -2
  4. package/dist/chunks/{AppealStatusBadge-Cu-UzdzA.js → AppealStatusBadge-MP1qD952.js} +1 -1
  5. package/dist/chunks/{AppealStatusBadge-BlAaNUSK.js → AppealStatusBadge-z77wwkFD.js} +2 -2
  6. package/dist/chunks/{ApplicationHistorySection-Cwq0-Frd.js → ApplicationHistorySection-DIoFZwH6.js} +4 -4
  7. package/dist/chunks/{BaseModal-SQXvRRNW.js → BaseModal-DP_ilBdg.js} +21 -11
  8. package/dist/chunks/{FormFilePicker-DxPQlxgy.js → FormFilePicker-D5fAUE0Z.js} +2 -2
  9. package/dist/chunks/{MapLayerMenu-AUeTqgEp.js → MapLayerMenu-CI5cbLEC.js} +1 -1
  10. package/dist/chunks/{RegistryForm-wG-c8GKf.js → RegistryForm-DbCxZsr0.js} +1 -1
  11. package/dist/chunks/{RegistryFormModal-R_iZYqGE.js → RegistryFormModal-D_KLGj2d.js} +3 -3
  12. package/dist/chunks/{RegistryToolbar-322DKUXi.js → RegistryToolbar-DvbrASlj.js} +6 -6
  13. package/dist/chunks/{SurveyorTeleport-CnSF0Ptl.js → SurveyorTeleport-D6-KXe_5.js} +1 -1
  14. package/dist/chunks/{UserAccessBadge-DyZDv7Oo.js → UserAccessBadge-B5Q1LvNv.js} +1 -1
  15. package/dist/chunks/{UserTypeBadge-LvnMuKGo.js → UserTypeBadge-CuAMctTK.js} +1 -1
  16. package/dist/chunks/{VerifiedBadge-bk0n-rlC.js → VerifiedBadge-D6L7mCdp.js} +2 -2
  17. package/dist/chunks/{card-CWqi1K-x.js → card--XUb1kFK.js} +4 -4
  18. package/dist/chunks/{card-C3y-j2TA.js → card-BrjnXf1N.js} +6 -6
  19. package/dist/chunks/{card-6z-m7UkM.js → card-BsTSF6aL.js} +10 -10
  20. package/dist/chunks/{card-Dlp8_KhV.js → card-CI7ntIHf.js} +5 -5
  21. package/dist/chunks/{card-DWpAv92l.js → card-Cu8QOSIw.js} +4 -4
  22. package/dist/chunks/{card-X9UVFgdR.js → card-ylC5NYbz.js} +241 -208
  23. package/dist/chunks/certificates-BnseQylH.js +209 -0
  24. package/dist/chunks/certificates-aJ-hvaP-.js +236 -0
  25. package/dist/chunks/{create-CAVC1qXJ.js → create-Bi7-j9Ri.js} +413 -413
  26. package/dist/chunks/{forgot-DoG6vXhq.js → forgot-DnixBqdc.js} +2 -2
  27. package/dist/chunks/{login-BWGylcSU.js → login-BWCQdEkv.js} +2 -2
  28. package/dist/chunks/map-CwsVIW79.js +2872 -0
  29. package/dist/chunks/{map-layers-sT-gTiD_.js → map-layers-BLiEYC4C.js} +5 -5
  30. package/dist/chunks/{organizations-ByVE2f0c.js → organizations-mc6FlSwe.js} +6 -6
  31. package/dist/chunks/{profile-CkwMFh82.js → profile-F7mr0poI.js} +3 -3
  32. package/dist/chunks/{registration-3GLgq-ae.js → registration-BRF4985_.js} +2 -2
  33. package/dist/chunks/{requests-BTpLXrNj.js → requests-7pD2ckdx.js} +4 -4
  34. package/dist/chunks/{requests-rWq8ok3C.js → requests-BCJN-CNx.js} +5 -5
  35. package/dist/chunks/{reset-CP9LsLkC.js → reset-OZCgLi6f.js} +2 -2
  36. package/dist/chunks/{useEntityPath-C5Owtidc.js → useEntityPath-8s0Y1tjA.js} +1 -1
  37. package/dist/chunks/{users-U1P6xCP4.js → users-CAEjpaI1.js} +6 -6
  38. package/dist/index.css +1 -1
  39. package/dist/index.js +40 -40
  40. package/migrations/20261016120000_map_layers.sql +156 -156
  41. package/migrations/20261016150000_password_reset.sql +15 -15
  42. package/migrations/20261016180000_settlement_lookup.sql +16 -16
  43. package/package.json +1 -1
  44. package/server/dictionaries/index.ts +17 -17
  45. package/server/dictionaries/surveyor/map_layer_components.ts +11 -11
  46. package/server/dictionaries/surveyor/map_layer_groups.ts +10 -10
  47. package/server/dictionaries/surveyor/map_layer_types.ts +11 -11
  48. package/server/modules/surveyor/route.ts +4 -2
  49. package/server/modules/surveyor/schema.ts +18 -1
  50. package/server/modules/surveyor/services/applicationTile.ts +36 -8
  51. package/server/modules/surveyor/services/createApplication.ts +2 -3
  52. package/server/modules/surveyor/services/mapLayers.ts +61 -61
  53. package/server/modules/surveyor/services/registerSurveyor.ts +3 -4
  54. package/server/modules/surveyor/services/requestPasswordReset.ts +1 -0
  55. package/server/modules/surveyor/services/resetSurveyorPassword.ts +1 -0
  56. package/server/modules/surveyor/services/updateSurveyorAccountStatus.ts +52 -52
  57. package/server/modules/surveyor/services/updateSurveyorStatus.ts +53 -53
  58. package/server/modules/surveyor/utils/certificateStatus.ts +15 -0
  59. package/server/modules/surveyor/utils/mail.ts +49 -20
  60. package/server/modules/surveyor/utils/templates/ds.surveyor_password_reset.pt.hbs +79 -79
  61. package/server/resources/helpers/settlement_lookup.ts +7 -7
  62. package/server/resources/surveyor-admin/certificates.ts +27 -1
  63. package/server/resources/surveyor-admin/map_layers.ts +69 -69
  64. package/server/resources/surveyor-admin/organization_surveyors.ts +31 -31
  65. package/server/resources/surveyor-admin/organizations.ts +61 -61
  66. package/server/resources/surveyor-user/applications.ts +1 -1
  67. package/dist/chunks/certificates-Cwch72-o.js +0 -425
  68. package/dist/chunks/map-UTBxwT7-.js +0 -2776
@@ -1,16 +1,16 @@
1
- -- Settlement lookup labels with the settlement type: "м. Львів", "с. Лисиничі".
2
- CREATE OR REPLACE VIEW surveyor.settlement_lookup AS
3
- SELECT
4
- settlement.katottg,
5
- settlement.level,
6
- concat_ws(' ',
7
- CASE settlement.type
8
- WHEN 201 THEN 'м.'
9
- WHEN 501 THEN 'м.'
10
- WHEN 503 THEN 'смт'
11
- WHEN 504 THEN 'с.'
12
- WHEN 505 THEN 'с-ще'
13
- END,
14
- trim(settlement.name)
15
- ) AS settlement_text
16
- FROM data_address.atu AS settlement;
1
+ -- Settlement lookup labels with the settlement type: "м. Львів", "с. Лисиничі".
2
+ CREATE OR REPLACE VIEW surveyor.settlement_lookup AS
3
+ SELECT
4
+ settlement.katottg,
5
+ settlement.level,
6
+ concat_ws(' ',
7
+ CASE settlement.type
8
+ WHEN 201 THEN 'м.'
9
+ WHEN 501 THEN 'м.'
10
+ WHEN 503 THEN 'смт'
11
+ WHEN 504 THEN 'с.'
12
+ WHEN 505 THEN 'с-ще'
13
+ END,
14
+ trim(settlement.name)
15
+ ) AS settlement_text
16
+ FROM data_address.atu AS settlement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/surveyor",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "author": "Softpro",
6
6
  "description": "Surveyor admin and geodesist cabinet UI for embedded host applications",
@@ -1,17 +1,17 @@
1
- import applicationStatus from "./surveyor/application_status.js";
2
- import workTypes from "./surveyor/work_types.js";
3
- import accountTypes from "./surveyor/account_types.js";
4
- import yesNo from "./surveyor/yes_no.js";
5
- import mapLayerGroups from "./surveyor/map_layer_groups.js";
6
- import mapLayerTypes from "./surveyor/map_layer_types.js";
7
- import mapLayerComponents from "./surveyor/map_layer_components.js";
8
-
9
- export default [
10
- applicationStatus,
11
- workTypes,
12
- accountTypes,
13
- yesNo,
14
- mapLayerGroups,
15
- mapLayerTypes,
16
- mapLayerComponents,
17
- ];
1
+ import applicationStatus from "./surveyor/application_status.js";
2
+ import workTypes from "./surveyor/work_types.js";
3
+ import accountTypes from "./surveyor/account_types.js";
4
+ import yesNo from "./surveyor/yes_no.js";
5
+ import mapLayerGroups from "./surveyor/map_layer_groups.js";
6
+ import mapLayerTypes from "./surveyor/map_layer_types.js";
7
+ import mapLayerComponents from "./surveyor/map_layer_components.js";
8
+
9
+ export default [
10
+ applicationStatus,
11
+ workTypes,
12
+ accountTypes,
13
+ yesNo,
14
+ mapLayerGroups,
15
+ mapLayerTypes,
16
+ mapLayerComponents,
17
+ ];
@@ -1,11 +1,11 @@
1
- import type { DictionaryDefinition } from "@opengis/fcore";
2
-
3
- export default {
4
- code: "map-layer-components",
5
- name: "Компоненти карти",
6
- items: [
7
- { code: "map", name: "Карта" },
8
- { code: "application-form", name: "Форма окреслення геометрії заявки" },
9
- { code: "application-card", name: "Картка заявки" },
10
- ],
11
- } satisfies DictionaryDefinition;
1
+ import type { DictionaryDefinition } from "@opengis/fcore";
2
+
3
+ export default {
4
+ code: "map-layer-components",
5
+ name: "Компоненти карти",
6
+ items: [
7
+ { code: "map", name: "Карта" },
8
+ { code: "application-form", name: "Форма окреслення геометрії заявки" },
9
+ { code: "application-card", name: "Картка заявки" },
10
+ ],
11
+ } satisfies DictionaryDefinition;
@@ -1,10 +1,10 @@
1
- import type { DictionaryDefinition } from "@opengis/fcore";
2
-
3
- export default {
4
- code: "map-layer-groups",
5
- name: "Групи шарів карти",
6
- items: [
7
- { code: "base", name: "Базовий шар" },
8
- { code: "overlay", name: "Додатковий шар" },
9
- ],
10
- } satisfies DictionaryDefinition;
1
+ import type { DictionaryDefinition } from "@opengis/fcore";
2
+
3
+ export default {
4
+ code: "map-layer-groups",
5
+ name: "Групи шарів карти",
6
+ items: [
7
+ { code: "base", name: "Базовий шар" },
8
+ { code: "overlay", name: "Додатковий шар" },
9
+ ],
10
+ } satisfies DictionaryDefinition;
@@ -1,11 +1,11 @@
1
- import type { DictionaryDefinition } from "@opengis/fcore";
2
-
3
- export default {
4
- code: "map-layer-types",
5
- name: "Типи шарів карти",
6
- items: [
7
- { code: "raster", name: "Растрові тайли" },
8
- { code: "vector", name: "Векторні тайли" },
9
- { code: "applications", name: "Заявки" },
10
- ],
11
- } satisfies DictionaryDefinition;
1
+ import type { DictionaryDefinition } from "@opengis/fcore";
2
+
3
+ export default {
4
+ code: "map-layer-types",
5
+ name: "Типи шарів карти",
6
+ items: [
7
+ { code: "raster", name: "Растрові тайли" },
8
+ { code: "vector", name: "Векторні тайли" },
9
+ { code: "applications", name: "Заявки" },
10
+ ],
11
+ } satisfies DictionaryDefinition;
@@ -20,7 +20,7 @@ import {
20
20
  updateSurveyorAccountStatus,
21
21
  type SurveyorAccountStatusInput,
22
22
  } from "./services/updateSurveyorAccountStatus.js";
23
- import { applicationTile } from "./services/applicationTile.js";
23
+ import { applicationTile, type ApplicationTileQuery } from "./services/applicationTile.js";
24
24
  import { searchApplications, type ApplicationSearchInput } from "./services/searchApplications.js";
25
25
  import { identifyApplications, type ApplicationIdentifyInput } from "./services/identifyApplications.js";
26
26
  import { mapLayers, type MapLayersInput } from "./services/mapLayers.js";
@@ -384,7 +384,7 @@ export function createSurveyorRoutes(ctx: AppContext): FastifyPluginAsync {
384
384
  },
385
385
  async (req) => mapLayers({ input: req.query, user: req.user, ctx })
386
386
  );
387
- app.get<{ Params: { z: string; x: string; y: string }; Querystring: { filter?: string } }>(
387
+ app.get<{ Params: { z: string; x: string; y: string }; Querystring: ApplicationTileQuery }>(
388
388
  "/api/surveyor/vtile/applications/:z/:x/:y",
389
389
  {
390
390
  schema: {
@@ -400,6 +400,8 @@ export function createSurveyorRoutes(ctx: AppContext): FastifyPluginAsync {
400
400
  x: Number(x),
401
401
  y: Number(y),
402
402
  filter: req.query.filter,
403
+ year: req.query.year,
404
+ scope: req.query.scope,
403
405
  user: req.user,
404
406
  ctx,
405
407
  });
@@ -419,7 +419,24 @@ export const surveyorSchemas = {
419
419
  },
420
420
  tileQuery: {
421
421
  type: "object",
422
- properties: { filter: { type: "string", enum: applicationStatus } },
422
+ properties: {
423
+ filter: {
424
+ type: "object",
425
+ additionalProperties: true,
426
+ description: "Фільтри FCore, наприклад filter[created_at][gte]=2026-01-01",
427
+ },
428
+ year: {
429
+ type: "string",
430
+ pattern: "^(all|[1-9][0-9]{3}(,[1-9][0-9]{3})*)$",
431
+ description: "Роки створення заявок через кому або all; за замовчуванням поточний рік",
432
+ },
433
+ scope: {
434
+ type: "string",
435
+ enum: ["all", "active"],
436
+ default: "all",
437
+ description: "all — усі статуси; active — awaitingData, dataIssued, reserve, underReview, verified",
438
+ },
439
+ },
423
440
  additionalProperties: false,
424
441
  },
425
442
  mapLayersQuery: {
@@ -1,18 +1,23 @@
1
1
  import type { AppContext, User } from "@opengis/fcore";
2
- import { BadRequestError } from "@opengis/fcore";
2
+ import { BadRequestError, buildFilters } from "@opengis/fcore";
3
3
  import { actor, surveyorForUser } from "../utils/shared.js";
4
4
 
5
+ export type ApplicationTileQuery = {
6
+ filter?: Record<string, unknown>;
7
+ year?: string;
8
+ scope?: "all" | "active";
9
+ };
10
+
5
11
  /**
6
- * Будує векторний тайл заявок, доступних користувачу, з необов'язковим фільтром статусу.
7
- * @param params Координати тайла, фільтр, користувач і контекст FCore.
12
+ * Будує векторний тайл доступних заявок із фільтрами ресурсу та роками створення.
13
+ * @param params Координати тайла, фільтри, роки, користувач і контекст FCore.
8
14
  * @returns Вміст тайла у форматі MVT.
9
15
  */
10
16
  export async function applicationTile(
11
- { z, x, y, filter, user, ctx }: {
17
+ { z, x, y, filter, year = String(new Date().getFullYear()), scope = "all", user, ctx }: ApplicationTileQuery & {
12
18
  z: number;
13
19
  x: number;
14
20
  y: number;
15
- filter: string | undefined;
16
21
  user: User | undefined;
17
22
  ctx: AppContext;
18
23
  }
@@ -22,16 +27,32 @@ export async function applicationTile(
22
27
  throw new BadRequestError("Invalid tile coordinates");
23
28
  }
24
29
 
30
+ const resource = ctx.resource.get(user?.type === "admin" ? "applications" : "public_applications");
31
+
32
+ const filters = buildFilters(resource, filter, 6);
33
+ const scopeFilter = scope === "active"
34
+ ? "AND a.status IN ('awaitingData', 'dataIssued', 'reserve', 'underReview', 'verified')"
35
+ : "";
36
+
25
37
  const surveyorId = user?.type === "admin" ? null : await surveyorForUser({ db: ctx.pg, user });
38
+
26
39
  const result = await ctx.pg.query<{ tile: Buffer }>(
27
40
  `WITH bounds AS (
28
41
  SELECT ST_TileEnvelope($1, $2, $3) AS box
42
+ ), filtered_applications AS (
43
+ SELECT * FROM surveyor.applications ${filters.sql}
29
44
  ), features AS (
30
45
  SELECT a.app_id::text AS id,
31
46
  a.status::text AS status,
32
47
  a.number,
48
+ a.work_type::text AS work_type,
49
+ organization.name AS organization,
50
+ a.area::double precision AS area,
51
+ concat_ws(', ', NULLIF(address.address_text, ''), NULLIF(a.location, '')) AS address,
33
52
  ST_AsMVTGeom(ST_Transform(a.geom, 3857), bounds.box) AS geom
34
- FROM surveyor.applications AS a
53
+ FROM filtered_applications AS a
54
+ LEFT JOIN surveyor.organizations AS organization ON organization.org_id = a.org_id
55
+ LEFT JOIN surveyor.address_lookup AS address ON address.addr_id = a.address_id
35
56
  CROSS JOIN bounds
36
57
  WHERE ST_Intersects(ST_Transform(a.geom, 3857), bounds.box)
37
58
  AND (
@@ -43,11 +64,18 @@ export async function applicationTile(
43
64
  AND os.enabled = true
44
65
  )
45
66
  )
46
- AND ($5::text IS NULL OR a.status::text = $5)
67
+ AND ($5::text = 'all' OR EXISTS (
68
+ SELECT 1
69
+ FROM unnest(string_to_array(NULLIF($5::text, 'all'), ',')::integer[]) AS selected_year(year)
70
+ WHERE a.created_at >= make_date(selected_year.year, 1, 1)
71
+ AND a.created_at < make_date(selected_year.year + 1, 1, 1)
72
+ ))
73
+ ${scopeFilter}
47
74
  )
48
75
  SELECT ST_AsMVT(features, 'applications', 4096, 'geom') AS tile
49
76
  FROM features`,
50
- [z, x, y, surveyorId, filter ?? null]
77
+ [z, x, y, surveyorId, year, ...filters.values]
51
78
  );
79
+
52
80
  return result.rows[0]?.tile ?? Buffer.alloc(0);
53
81
  }
@@ -8,6 +8,7 @@ import {
8
8
  type Db,
9
9
  } from "../utils/shared.js";
10
10
  import { limit, polygon, type CreateInput } from "../utils/application.js";
11
+ import { certificateStatusSql } from "../utils/certificateStatus.js";
11
12
 
12
13
  /**
13
14
  * Створює заявку після перевірки сертифіката, членства, адреси, площі та перетинів.
@@ -36,9 +37,7 @@ export async function createApplication(
36
37
  WHERE s.surveyor_id = $1
37
38
  AND os.org_id = $2
38
39
  AND os.enabled = true
39
- AND c.certificate_stopping IS NULL
40
- AND c.certificate_suspension IS NULL
41
- AND c.isvalid IS NOT FALSE`,
40
+ AND ${certificateStatusSql("c")} = 'valid'`,
42
41
  [surveyorId, orgId]
43
42
  );
44
43
  if (!profile.rowCount) {
@@ -1,61 +1,61 @@
1
- import type { AppContext, User } from "@opengis/fcore";
2
- import { actor } from "../utils/shared.js";
3
-
4
- export type MapLayerComponent = "map" | "application-form" | "application-card";
5
-
6
- export type MapLayersInput = { component?: MapLayerComponent };
7
-
8
- export type MapLayer = {
9
- code: string;
10
- name: string;
11
- layer_group: "base" | "overlay";
12
- layer_type: "raster" | "vector" | "applications";
13
- tiles: string[];
14
- scheme: "xyz" | "tms";
15
- source_layer: string | null;
16
- attribution: string | null;
17
- minzoom: number | null;
18
- maxzoom: number | null;
19
- opacity: number;
20
- style: Record<string, unknown> | null;
21
- legend: Record<string, unknown> | null;
22
- preview: string | null;
23
- components: MapLayerComponent[];
24
- is_default: boolean;
25
- has_filters: boolean;
26
- };
27
-
28
- export type MapLayersResult = {
29
- default_base: string | null;
30
- base: MapLayer[];
31
- overlays: MapLayer[];
32
- };
33
-
34
- /**
35
- * Повертає увімкнені шари панелі карти, згруповані на базові та додаткові у порядку відображення.
36
- * Додаткові шари йдуть від верхнього до нижнього: перший у списку малюється поверх.
37
- * Якщо передано `component`, повертаються лише шари, налаштовані для цього компонента.
38
- */
39
- export async function mapLayers(
40
- { input, user, ctx }: { input: MapLayersInput; user: User | undefined; ctx: AppContext }
41
- ): Promise<MapLayersResult> {
42
- actor(user);
43
-
44
- const { rows }: { rows: MapLayer[] } = await ctx.pg.query(
45
- `SELECT code, name, layer_group, layer_type, tiles, scheme, source_layer, attribution,
46
- minzoom, maxzoom, opacity::float AS opacity, style, legend, preview, components,
47
- is_default, has_filters
48
- FROM surveyor.map_layers
49
- WHERE enabled
50
- AND ($1::text IS NULL OR components @> ARRAY[$1::text])
51
- ORDER BY layer_group, sort_order, name`,
52
- [input.component ?? null]
53
- );
54
-
55
- const base = rows.filter((layer) => layer.layer_group === "base");
56
- const overlays = rows.filter((layer) => layer.layer_group === "overlay");
57
- // Підложку вимкнути не можна, тому без явного значення активна перша.
58
- const defaultBase = base.find((layer) => layer.is_default) ?? base[0];
59
-
60
- return { default_base: defaultBase?.code ?? null, base, overlays };
61
- }
1
+ import type { AppContext, User } from "@opengis/fcore";
2
+ import { actor } from "../utils/shared.js";
3
+
4
+ export type MapLayerComponent = "map" | "application-form" | "application-card";
5
+
6
+ export type MapLayersInput = { component?: MapLayerComponent };
7
+
8
+ export type MapLayer = {
9
+ code: string;
10
+ name: string;
11
+ layer_group: "base" | "overlay";
12
+ layer_type: "raster" | "vector" | "applications";
13
+ tiles: string[];
14
+ scheme: "xyz" | "tms";
15
+ source_layer: string | null;
16
+ attribution: string | null;
17
+ minzoom: number | null;
18
+ maxzoom: number | null;
19
+ opacity: number;
20
+ style: Record<string, unknown> | null;
21
+ legend: Record<string, unknown> | null;
22
+ preview: string | null;
23
+ components: MapLayerComponent[];
24
+ is_default: boolean;
25
+ has_filters: boolean;
26
+ };
27
+
28
+ export type MapLayersResult = {
29
+ default_base: string | null;
30
+ base: MapLayer[];
31
+ overlays: MapLayer[];
32
+ };
33
+
34
+ /**
35
+ * Повертає увімкнені шари панелі карти, згруповані на базові та додаткові у порядку відображення.
36
+ * Додаткові шари йдуть від верхнього до нижнього: перший у списку малюється поверх.
37
+ * Якщо передано `component`, повертаються лише шари, налаштовані для цього компонента.
38
+ */
39
+ export async function mapLayers(
40
+ { input, user, ctx }: { input: MapLayersInput; user: User | undefined; ctx: AppContext }
41
+ ): Promise<MapLayersResult> {
42
+ actor(user);
43
+
44
+ const { rows }: { rows: MapLayer[] } = await ctx.pg.query(
45
+ `SELECT code, name, layer_group, layer_type, tiles, scheme, source_layer, attribution,
46
+ minzoom, maxzoom, opacity::float AS opacity, style, legend, preview, components,
47
+ is_default, has_filters
48
+ FROM surveyor.map_layers
49
+ WHERE enabled
50
+ AND ($1::text IS NULL OR components @> ARRAY[$1::text])
51
+ ORDER BY layer_group, sort_order, name`,
52
+ [input.component ?? null]
53
+ );
54
+
55
+ const base = rows.filter((layer) => layer.layer_group === "base");
56
+ const overlays = rows.filter((layer) => layer.layer_group === "overlay");
57
+ // Підложку вимкнути не можна, тому без явного значення активна перша.
58
+ const defaultBase = base.find((layer) => layer.is_default) ?? base[0];
59
+
60
+ return { default_base: defaultBase?.code ?? null, base, overlays };
61
+ }
@@ -3,6 +3,7 @@ import { ConflictError, NotFoundError } from "@opengis/fcore";
3
3
  import { admin, type Db } from "../utils/shared.js";
4
4
  import { token, tokenHash } from "../utils/registration.js";
5
5
  import { sendActivationEmail } from "../utils/mail.js";
6
+ import { certificateStatusSql } from "../utils/certificateStatus.js";
6
7
 
7
8
  export type RegisterInput = {
8
9
  organization_id: string;
@@ -38,11 +39,9 @@ export async function registerSurveyor(
38
39
  middle_name: string | null;
39
40
  }>(
40
41
  `SELECT first_name, last_name, middle_name
41
- FROM surveyor.certificates
42
+ FROM surveyor.certificates AS c
42
43
  WHERE certificate_id = $1
43
- AND certificate_stopping IS NULL
44
- AND certificate_suspension IS NULL
45
- AND isvalid IS NOT FALSE`,
44
+ AND ${certificateStatusSql("c")} = 'valid'`,
46
45
  [certId]
47
46
  );
48
47
  if (!cert.rows[0]) {
@@ -38,6 +38,7 @@ export async function requestPasswordReset(
38
38
  await sendPasswordResetEmail({ email: surveyor.email, token: rawToken });
39
39
  } catch (err) {
40
40
  ctx.logger.error({ err, surveyorId: surveyor.surveyor_id }, "Failed to send password reset email");
41
+ throw err;
41
42
  }
42
43
  await ctx.audit.write({
43
44
  module: "surveyor",
@@ -48,6 +48,7 @@ export async function resetSurveyorPassword(
48
48
  await sendPasswordChangedEmail({ email: surveyor.email });
49
49
  } catch (err) {
50
50
  ctx.logger.error({ err, surveyorId: surveyor.surveyor_id }, "Failed to send password changed email");
51
+ throw err;
51
52
  }
52
53
  return { success: true };
53
54
  }
@@ -1,52 +1,52 @@
1
- import type { AppContext, User } from "@opengis/fcore";
2
- import { BadRequestError, NotFoundError } from "@opengis/fcore";
3
- import { admin } from "../utils/shared.js";
4
-
5
- export type SurveyorAccountStatusInput = { enabled: boolean };
6
-
7
- /**
8
- * Повністю блокує або розблоковує обліковий запис геодезиста (`surveyors.enabled`)
9
- * та записує автора і значення зміни в аудит FCore. Членство в організаціях не змінюється.
10
- */
11
- export async function updateSurveyorAccountStatus(
12
- { id, input, user, ctx }: {
13
- id: string;
14
- input: SurveyorAccountStatusInput;
15
- user: User | undefined;
16
- ctx: AppContext;
17
- }
18
- ) {
19
- const uid = admin(user);
20
- if (typeof input.enabled !== "boolean") {
21
- throw new BadRequestError("Enabled must be a boolean");
22
- }
23
-
24
- const updated = await ctx.pg.query<{ surveyor_id: string }>(
25
- `UPDATE surveyor.surveyors
26
- SET enabled = $2, updated_by = $3, updated_at = now()
27
- WHERE surveyor_id = $1 AND enabled <> $2
28
- RETURNING surveyor_id`,
29
- [id, input.enabled, uid]
30
- );
31
-
32
- if (!updated.rows[0]) {
33
- const existing = await ctx.pg.query(
34
- "SELECT 1 FROM surveyor.surveyors WHERE surveyor_id = $1",
35
- [id]
36
- );
37
- if (!existing.rowCount) {
38
- throw new NotFoundError("Surveyor not found");
39
- }
40
- } else {
41
- await ctx.audit.write({
42
- module: "surveyor",
43
- resource: "surveyors",
44
- resourceId: id,
45
- action: input.enabled ? "unblock" : "block",
46
- userId: uid,
47
- fields: ["enabled"],
48
- changes: [{ field: "enabled", oldValue: !input.enabled, newValue: input.enabled }],
49
- });
50
- }
51
- return { id, enabled: input.enabled };
52
- }
1
+ import type { AppContext, User } from "@opengis/fcore";
2
+ import { BadRequestError, NotFoundError } from "@opengis/fcore";
3
+ import { admin } from "../utils/shared.js";
4
+
5
+ export type SurveyorAccountStatusInput = { enabled: boolean };
6
+
7
+ /**
8
+ * Повністю блокує або розблоковує обліковий запис геодезиста (`surveyors.enabled`)
9
+ * та записує автора і значення зміни в аудит FCore. Членство в організаціях не змінюється.
10
+ */
11
+ export async function updateSurveyorAccountStatus(
12
+ { id, input, user, ctx }: {
13
+ id: string;
14
+ input: SurveyorAccountStatusInput;
15
+ user: User | undefined;
16
+ ctx: AppContext;
17
+ }
18
+ ) {
19
+ const uid = admin(user);
20
+ if (typeof input.enabled !== "boolean") {
21
+ throw new BadRequestError("Enabled must be a boolean");
22
+ }
23
+
24
+ const updated = await ctx.pg.query<{ surveyor_id: string }>(
25
+ `UPDATE surveyor.surveyors
26
+ SET enabled = $2, updated_by = $3, updated_at = now()
27
+ WHERE surveyor_id = $1 AND enabled <> $2
28
+ RETURNING surveyor_id`,
29
+ [id, input.enabled, uid]
30
+ );
31
+
32
+ if (!updated.rows[0]) {
33
+ const existing = await ctx.pg.query(
34
+ "SELECT 1 FROM surveyor.surveyors WHERE surveyor_id = $1",
35
+ [id]
36
+ );
37
+ if (!existing.rowCount) {
38
+ throw new NotFoundError("Surveyor not found");
39
+ }
40
+ } else {
41
+ await ctx.audit.write({
42
+ module: "surveyor",
43
+ resource: "surveyors",
44
+ resourceId: id,
45
+ action: input.enabled ? "unblock" : "block",
46
+ userId: uid,
47
+ fields: ["enabled"],
48
+ changes: [{ field: "enabled", oldValue: !input.enabled, newValue: input.enabled }],
49
+ });
50
+ }
51
+ return { id, enabled: input.enabled };
52
+ }