@opengis/surveyor 0.0.10 → 0.0.11

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 (56) hide show
  1. package/dist/chunks/{AppIcon-Di5F4Bu_.js → AppIcon-CCLzEE-_.js} +1 -1
  2. package/dist/chunks/{AppealDetailField-DNpsGpPY.js → AppealDetailField-CI-1qhs3.js} +2 -2
  3. package/dist/chunks/{AppealStatusBadge-z77wwkFD.js → AppealStatusBadge-CzzI6x8I.js} +2 -2
  4. package/dist/chunks/{AppealStatusBadge-MP1qD952.js → AppealStatusBadge-DYBe9hqP.js} +1 -1
  5. package/dist/chunks/{ApplicationHistorySection-DIoFZwH6.js → ApplicationHistorySection-CPCU_DXH.js} +4 -4
  6. package/dist/chunks/{BaseModal-DP_ilBdg.js → BaseModal-DnwqlJhc.js} +2 -2
  7. package/dist/chunks/{FormFilePicker-D5fAUE0Z.js → FormFilePicker-Dss6pGmO.js} +2 -2
  8. package/dist/chunks/{MapLayerMenu-CI5cbLEC.js → MapLayerMenu-DjYCxEc3.js} +1 -1
  9. package/dist/chunks/{RegistryForm-DbCxZsr0.js → RegistryForm-CEUqFmsF.js} +1 -1
  10. package/dist/chunks/{RegistryFormModal-D_KLGj2d.js → RegistryFormModal-C-Z4MMHi.js} +3 -3
  11. package/dist/chunks/{RegistryToolbar-DvbrASlj.js → RegistryToolbar-CI1MRqzw.js} +6 -6
  12. package/dist/chunks/{SurveyorTeleport-D6-KXe_5.js → SurveyorTeleport-BLEO6we9.js} +1 -1
  13. package/dist/chunks/{UserAccessBadge-B5Q1LvNv.js → UserAccessBadge-D8JfgGfN.js} +1 -1
  14. package/dist/chunks/{UserTypeBadge-CuAMctTK.js → UserTypeBadge-YIwwoCho.js} +1 -1
  15. package/dist/chunks/{VerifiedBadge-D6L7mCdp.js → VerifiedBadge-B__Vs_ce.js} +2 -2
  16. package/dist/chunks/{card-ylC5NYbz.js → card-BElHsAFl.js} +10 -10
  17. package/dist/chunks/{card-Cu8QOSIw.js → card-CU2THiBT.js} +4 -4
  18. package/dist/chunks/{card-BsTSF6aL.js → card-CUDo4kUH.js} +10 -10
  19. package/dist/chunks/{card-CI7ntIHf.js → card-DL7yHB1C.js} +5 -5
  20. package/dist/chunks/{card--XUb1kFK.js → card-UG1mWhcg.js} +4 -4
  21. package/dist/chunks/{card-BrjnXf1N.js → card-sDIYR6YI.js} +6 -6
  22. package/dist/chunks/{certificates-aJ-hvaP-.js → certificates-DKi9CSfc.js} +5 -5
  23. package/dist/chunks/{create-Bi7-j9Ri.js → create-DVZv77Uw.js} +9 -9
  24. package/dist/chunks/{forgot-DnixBqdc.js → forgot-BVzXMKGA.js} +2 -2
  25. package/dist/chunks/{login-BWCQdEkv.js → login-BCib_dtl.js} +2 -2
  26. package/dist/chunks/{map-CwsVIW79.js → map-CNX1_COE.js} +10 -10
  27. package/dist/chunks/{map-layers-BLiEYC4C.js → map-layers-CCJ7G7ZK.js} +5 -5
  28. package/dist/chunks/{organizations-mc6FlSwe.js → organizations-BuMFRKjw.js} +6 -6
  29. package/dist/chunks/{profile-F7mr0poI.js → profile-BI_RIHN1.js} +3 -3
  30. package/dist/chunks/{registration-BRF4985_.js → registration-6nn7GgDS.js} +2 -2
  31. package/dist/chunks/{requests-7pD2ckdx.js → requests-DQRmDemb.js} +4 -4
  32. package/dist/chunks/{requests-BCJN-CNx.js → requests-Dh5jxF06.js} +5 -5
  33. package/dist/chunks/{reset-OZCgLi6f.js → reset-D2uXDfB6.js} +2 -2
  34. package/dist/chunks/{useEntityPath-8s0Y1tjA.js → useEntityPath-n7hCq8zh.js} +1 -1
  35. package/dist/chunks/{users-CAEjpaI1.js → users-LbXn1F2y.js} +6 -6
  36. package/dist/index.css +1 -1
  37. package/dist/index.js +40 -40
  38. package/migrations/20261016120000_map_layers.sql +156 -156
  39. package/migrations/20261016150000_password_reset.sql +15 -15
  40. package/migrations/20261016180000_settlement_lookup.sql +16 -16
  41. package/package.json +1 -1
  42. package/server/dictionaries/index.ts +17 -17
  43. package/server/dictionaries/surveyor/map_layer_components.ts +11 -11
  44. package/server/dictionaries/surveyor/map_layer_groups.ts +10 -10
  45. package/server/dictionaries/surveyor/map_layer_types.ts +11 -11
  46. package/server/modules/surveyor/services/changeSurveyorPasswordByAdmin.ts +41 -41
  47. package/server/modules/surveyor/services/mapLayers.ts +61 -61
  48. package/server/modules/surveyor/services/updateSurveyorAccountStatus.ts +52 -52
  49. package/server/modules/surveyor/services/updateSurveyorStatus.ts +53 -53
  50. package/server/modules/surveyor/utils/templates/ds.surveyor_admin_password.pt.hbs +79 -79
  51. package/server/modules/surveyor/utils/templates/ds.surveyor_password_reset.pt.hbs +79 -79
  52. package/server/plugins/convertVector.ts +1 -1
  53. package/server/resources/helpers/settlement_lookup.ts +7 -7
  54. package/server/resources/surveyor-admin/map_layers.ts +69 -69
  55. package/server/resources/surveyor-admin/organization_surveyors.ts +31 -31
  56. package/server/resources/surveyor-admin/organizations.ts +61 -61
@@ -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.10",
3
+ "version": "0.0.11",
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;
@@ -1,41 +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
- }
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
+ }
@@ -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
+ }
@@ -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
+ }
@@ -1,53 +1,53 @@
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 SurveyorStatusInput = { org_id: string; enabled: boolean };
6
-
7
- /**
8
- * Змінює доступ геодезиста до однієї організації (членство в `organization_surveyors`)
9
- * та записує автора і значення зміни в аудит FCore. Обліковий запис геодезиста не змінюється.
10
- */
11
- export async function updateSurveyorStatus(
12
- { id, input, user, ctx }: {
13
- id: string;
14
- input: SurveyorStatusInput;
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.organization_surveyors
26
- SET enabled = $3
27
- WHERE org_id = $1 AND surveyor_id = $2 AND enabled <> $3
28
- RETURNING surveyor_id`,
29
- [input.org_id, id, input.enabled]
30
- );
31
-
32
- if (!updated.rows[0]) {
33
- const existing = await ctx.pg.query(
34
- "SELECT 1 FROM surveyor.organization_surveyors WHERE org_id = $1 AND surveyor_id = $2",
35
- [input.org_id, id]
36
- );
37
- if (!existing.rowCount) {
38
- throw new NotFoundError("Surveyor is not a member of this organization");
39
- }
40
- } else {
41
- await ctx.audit.write({
42
- module: "surveyor",
43
- resource: "surveyors",
44
- resourceId: id,
45
- action: input.enabled ? "enable" : "disable",
46
- userId: uid,
47
- fields: ["enabled"],
48
- changes: [{ field: "enabled", oldValue: !input.enabled, newValue: input.enabled }],
49
- metadata: { org_id: input.org_id },
50
- });
51
- }
52
- return { id, org_id: input.org_id, enabled: input.enabled };
53
- }
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 SurveyorStatusInput = { org_id: string; enabled: boolean };
6
+
7
+ /**
8
+ * Змінює доступ геодезиста до однієї організації (членство в `organization_surveyors`)
9
+ * та записує автора і значення зміни в аудит FCore. Обліковий запис геодезиста не змінюється.
10
+ */
11
+ export async function updateSurveyorStatus(
12
+ { id, input, user, ctx }: {
13
+ id: string;
14
+ input: SurveyorStatusInput;
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.organization_surveyors
26
+ SET enabled = $3
27
+ WHERE org_id = $1 AND surveyor_id = $2 AND enabled <> $3
28
+ RETURNING surveyor_id`,
29
+ [input.org_id, id, input.enabled]
30
+ );
31
+
32
+ if (!updated.rows[0]) {
33
+ const existing = await ctx.pg.query(
34
+ "SELECT 1 FROM surveyor.organization_surveyors WHERE org_id = $1 AND surveyor_id = $2",
35
+ [input.org_id, id]
36
+ );
37
+ if (!existing.rowCount) {
38
+ throw new NotFoundError("Surveyor is not a member of this organization");
39
+ }
40
+ } else {
41
+ await ctx.audit.write({
42
+ module: "surveyor",
43
+ resource: "surveyors",
44
+ resourceId: id,
45
+ action: input.enabled ? "enable" : "disable",
46
+ userId: uid,
47
+ fields: ["enabled"],
48
+ changes: [{ field: "enabled", oldValue: !input.enabled, newValue: input.enabled }],
49
+ metadata: { org_id: input.org_id },
50
+ });
51
+ }
52
+ return { id, org_id: input.org_id, enabled: input.enabled };
53
+ }