@opengis/surveyor 0.0.14 → 0.0.16

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 (48) hide show
  1. package/dist/chunks/AppealStatusBadge-7KruOSVI.js +295 -0
  2. package/dist/chunks/ApplicationGeometryExportModal-DJbnKPm6.js +1245 -0
  3. package/dist/chunks/{BaseModal-SjP521X9.js → BaseModal-BJxKuONh.js} +1 -1
  4. package/dist/chunks/{RegistryFormModal-DhzEpxys.js → RegistryFormModal-BmBsUOF3.js} +1 -1
  5. package/dist/chunks/SurveyorTeleport-Cd6D92mo.js +30 -0
  6. package/dist/chunks/{applications-D6pHAQaK.js → applications-B6GAxopO.js} +16 -19
  7. package/dist/chunks/card-B113dNzv.js +1327 -0
  8. package/dist/chunks/card-COmcUdms.js +639 -0
  9. package/dist/chunks/{card-BBx1zR0E.js → card-Deae73xd.js} +2 -2
  10. package/dist/chunks/{certificates-DtfZTFN9.js → certificates-DHf1zGQs.js} +18 -8
  11. package/dist/chunks/{create-Cgeu7aKO.js → create-BVPqfJOb.js} +10 -10
  12. package/dist/chunks/{map-DkKsEnCM.js → map-BZi4eVl3.js} +893 -897
  13. package/dist/chunks/{map-layers-BmuIMLHa.js → map-layers-CKZK50de.js} +2 -2
  14. package/dist/chunks/{organizations-BO1dIl7v.js → organizations-DYGfYfHS.js} +2 -2
  15. package/dist/chunks/{requests-rWq8ok3C.js → requests-D1ix8U5f.js} +1 -1
  16. package/dist/chunks/requests-v1jHarHb.js +303 -0
  17. package/dist/chunks/{users-DOiQeVwn.js → users-frk3gmmd.js} +1 -1
  18. package/dist/index.css +1 -1
  19. package/dist/index.js +21 -21
  20. package/package.json +1 -1
  21. package/server/modules/surveyor/route.ts +13 -12
  22. package/server/modules/surveyor/services/applicationTile.ts +3 -3
  23. package/server/modules/surveyor/services/cancelApplication.ts +2 -1
  24. package/server/modules/surveyor/services/changeSurveyorPasswordByAdmin.ts +1 -1
  25. package/server/modules/surveyor/services/completeApplication.ts +1 -1
  26. package/server/modules/surveyor/services/identifyApplications.ts +2 -2
  27. package/server/modules/surveyor/services/issueSourceData.ts +1 -1
  28. package/server/modules/surveyor/services/registerSurveyor.ts +1 -1
  29. package/server/modules/surveyor/services/resendRegistration.ts +1 -1
  30. package/server/modules/surveyor/services/searchApplications.ts +2 -2
  31. package/server/modules/surveyor/services/updateSurveyorAccountStatus.ts +1 -1
  32. package/server/modules/surveyor/services/updateSurveyorStatus.ts +1 -1
  33. package/server/modules/surveyor/services/verifyApplication.ts +1 -1
  34. package/server/modules/surveyor/utils/shared.ts +28 -6
  35. package/server/resources/surveyor-admin/application_comments.ts +1 -1
  36. package/server/resources/surveyor-admin/application_status_history.ts +1 -1
  37. package/server/resources/surveyor-admin/applications.ts +12 -11
  38. package/server/resources/surveyor-admin/certificates.ts +26 -26
  39. package/server/resources/surveyor-admin/map_layers.ts +1 -1
  40. package/server/resources/surveyor-admin/organizations.ts +1 -1
  41. package/server/resources/surveyor-admin/surveyors.ts +1 -1
  42. package/server/suggests/index.ts +18 -1
  43. package/dist/chunks/AppealStatusBadge-Ct3EcB4_.js +0 -185
  44. package/dist/chunks/ApplicationHistorySection-D7KPV2cX.js +0 -788
  45. package/dist/chunks/SurveyorTeleport-CnSF0Ptl.js +0 -23
  46. package/dist/chunks/card-Bj4zFzbe.js +0 -1193
  47. package/dist/chunks/card-C-ohjNkC.js +0 -609
  48. package/dist/chunks/requests-BZ2jrt5J.js +0 -234
package/dist/index.js CHANGED
@@ -43,16 +43,16 @@ function z(e, t, n, r, i, a) {
43
43
  return O(), v("div", {
44
44
  id: r.hostProvidesRoot ? void 0 : r.SURVEYOR_ROOT_ID,
45
45
  class: T(["surveyor-embed w-full min-w-0", n.fill ? "flex max-w-none h-[calc(100vh-40px)] min-h-[calc(100vh-40px)] max-h-[calc(100vh-40px)] flex-col" : "mx-auto max-w-[1280px]"])
46
- }, [n.card ? (O(), v("div", {
46
+ }, [r.hostProvidesRoot ? _("", !0) : (O(), v("div", {
47
47
  key: 0,
48
+ id: r.SURVEYOR_PORTAL_ID
49
+ }, null, 8, R)), n.card ? (O(), v("div", {
50
+ key: 1,
48
51
  class: T(["w-full rounded-xl bg-white p-4 shadow-sm sm:p-5", n.fill ? "min-h-0 flex-1" : ""])
49
52
  }, [A(e.$slots, "default", {}, void 0, !0)], 2)) : (O(), v("div", {
50
- key: 1,
51
- class: T(["min-h-0 w-full flex-1 flex flex-col", n.fill ? "h-full min-h-0" : ""])
52
- }, [A(e.$slots, "default", {}, void 0, !0)], 2)), r.hostProvidesRoot ? _("", !0) : (O(), v("div", {
53
53
  key: 2,
54
- id: r.SURVEYOR_PORTAL_ID
55
- }, null, 8, R))], 10, L);
54
+ class: T(["min-h-0 w-full flex-1 flex flex-col", n.fill ? "h-full min-h-0" : ""])
55
+ }, [A(e.$slots, "default", {}, void 0, !0)], 2))], 10, L);
56
56
  }
57
57
  var B = /*#__PURE__*/ r(I, [
58
58
  ["render", z],
@@ -63,7 +63,7 @@ var B = /*#__PURE__*/ r(I, [
63
63
  setup(e, { expose: t }) {
64
64
  t();
65
65
  let n = {
66
- MapPage: S(() => import("./chunks/map-DkKsEnCM.js")),
66
+ MapPage: S(() => import("./chunks/map-BZi4eVl3.js")),
67
67
  SurveyorEmbedShell: B
68
68
  };
69
69
  return Object.defineProperty(n, "__isScriptSetup", {
@@ -139,8 +139,8 @@ var K = /*#__PURE__*/ r(W, [["render", G], ["__file", "C:/softpro/surveyor/src/w
139
139
  setup(e, { expose: t }) {
140
140
  t();
141
141
  let n = {
142
- Index: S(() => import("./chunks/requests-BZ2jrt5J.js")),
143
- Card: S(() => import("./chunks/card-Bj4zFzbe.js")),
142
+ Index: S(() => import("./chunks/requests-v1jHarHb.js")),
143
+ Card: S(() => import("./chunks/card-B113dNzv.js")),
144
144
  BaseEntityWrapper: K,
145
145
  SurveyorEmbedShell: B
146
146
  };
@@ -167,8 +167,8 @@ var ue = /*#__PURE__*/ r(ce, [["render", le], ["__file", "C:/softpro/surveyor/sr
167
167
  setup(e, { expose: t }) {
168
168
  t();
169
169
  let n = {
170
- Index: S(() => import("./chunks/organizations-BO1dIl7v.js")),
171
- Card: S(() => import("./chunks/card-BBx1zR0E.js")),
170
+ Index: S(() => import("./chunks/organizations-DYGfYfHS.js")),
171
+ Card: S(() => import("./chunks/card-Deae73xd.js")),
172
172
  BaseEntityWrapper: K,
173
173
  SurveyorEmbedShell: B
174
174
  };
@@ -195,7 +195,7 @@ var pe = /*#__PURE__*/ r(de, [["render", fe], ["__file", "C:/softpro/surveyor/sr
195
195
  setup(e, { expose: t }) {
196
196
  t();
197
197
  let n = {
198
- Index: S(() => import("./chunks/certificates-DtfZTFN9.js")),
198
+ Index: S(() => import("./chunks/certificates-DHf1zGQs.js")),
199
199
  Card: S(() => import("./chunks/card-_YyJbLNI.js")),
200
200
  BaseEntityWrapper: K,
201
201
  SurveyorEmbedShell: B
@@ -223,7 +223,7 @@ var ge = /*#__PURE__*/ r(me, [["render", he], ["__file", "C:/softpro/surveyor/sr
223
223
  setup(e, { expose: t }) {
224
224
  t();
225
225
  let n = {
226
- Index: S(() => import("./chunks/users-DOiQeVwn.js")),
226
+ Index: S(() => import("./chunks/users-frk3gmmd.js")),
227
227
  Card: S(() => import("./chunks/card-VnUCFC7v.js")),
228
228
  BaseEntityWrapper: K,
229
229
  SurveyorEmbedShell: B
@@ -251,7 +251,7 @@ var ye = /*#__PURE__*/ r(_e, [["render", ve], ["__file", "C:/softpro/surveyor/sr
251
251
  setup(e, { expose: t }) {
252
252
  t();
253
253
  let n = {
254
- Index: S(() => import("./chunks/map-layers-BmuIMLHa.js")),
254
+ Index: S(() => import("./chunks/map-layers-CKZK50de.js")),
255
255
  Card: S(() => import("./chunks/card-DEJs9IIP.js")),
256
256
  BaseEntityWrapper: K,
257
257
  SurveyorEmbedShell: B
@@ -279,9 +279,9 @@ var Se = /*#__PURE__*/ r(be, [["render", xe], ["__file", "C:/softpro/surveyor/sr
279
279
  setup(e, { expose: t }) {
280
280
  t();
281
281
  let n = {
282
- Index: S(() => import("./chunks/requests-rWq8ok3C.js")),
283
- Create: S(() => import("./chunks/create-Cgeu7aKO.js")),
284
- Card: S(() => import("./chunks/card-C-ohjNkC.js")),
282
+ Index: S(() => import("./chunks/requests-D1ix8U5f.js")),
283
+ Create: S(() => import("./chunks/create-BVPqfJOb.js")),
284
+ Card: S(() => import("./chunks/card-COmcUdms.js")),
285
285
  BaseEntityWrapper: K,
286
286
  SurveyorEmbedShell: B
287
287
  };
@@ -353,7 +353,7 @@ function Me(e, t, n, r, i, a) {
353
353
  return O(), v("div", {
354
354
  id: r.SURVEYOR_ROOT_ID,
355
355
  class: "surveyor-root min-h-screen bg-slate-50 text-slate-800 antialiased"
356
- }, [A(e.$slots, "default"), y("div", { id: r.SURVEYOR_PORTAL_ID }, null, 8, je)], 8, Ae);
356
+ }, [y("div", { id: r.SURVEYOR_PORTAL_ID }, null, 8, je), A(e.$slots, "default")], 8, Ae);
357
357
  }
358
358
  var q = /*#__PURE__*/ r(ke, [["render", Me], ["__file", "C:/softpro/surveyor/shared/surveyor/SurveyorRoot.vue"]]), Ne = /*@__PURE__*/ C({
359
359
  __name: "Cabinet",
@@ -674,7 +674,7 @@ var X = [
674
674
  {
675
675
  path: "requests",
676
676
  name: "requests",
677
- component: () => import("./chunks/requests-rWq8ok3C.js"),
677
+ component: () => import("./chunks/requests-D1ix8U5f.js"),
678
678
  meta: {
679
679
  title: "Звернення",
680
680
  label: "Звернення на видачу та прийом матеріалів",
@@ -684,7 +684,7 @@ var X = [
684
684
  {
685
685
  path: "requests/new",
686
686
  name: "request-create",
687
- component: () => import("./chunks/create-Cgeu7aKO.js"),
687
+ component: () => import("./chunks/create-BVPqfJOb.js"),
688
688
  meta: {
689
689
  title: "Нове звернення",
690
690
  section: "requests"
@@ -693,7 +693,7 @@ var X = [
693
693
  {
694
694
  path: "requests/:number",
695
695
  name: "request-detail",
696
- component: () => import("./chunks/card-C-ohjNkC.js"),
696
+ component: () => import("./chunks/card-COmcUdms.js"),
697
697
  meta: {
698
698
  title: "Звернення",
699
699
  section: "requests"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/surveyor",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "type": "module",
5
5
  "author": "Softpro",
6
6
  "description": "Surveyor admin and geodesist cabinet UI for embedded host applications",
@@ -43,11 +43,12 @@ const user: FastifySchema = {
43
43
  access: "user",
44
44
  permissions: [],
45
45
  };
46
- const administrator: FastifySchema = {
46
+ /** Службовий маршрут: адміністратор або користувач із правом `resource:action`. */
47
+ const staff = (permission: string): FastifySchema => ({
47
48
  tags: ["surveyor"],
48
- access: "admin",
49
- permissions: [],
50
- };
49
+ access: "user",
50
+ permissions: [permission],
51
+ });
51
52
  const publicRoute: FastifySchema = {
52
53
  tags: ["surveyor"],
53
54
  access: "public",
@@ -102,7 +103,7 @@ export function createSurveyorRoutes(ctx: AppContext): FastifyPluginAsync {
102
103
  "/api/surveyor/applications/:applicationId/upload-source-data",
103
104
  {
104
105
  schema: {
105
- ...administrator,
106
+ ...staff("applications:update"),
106
107
  params: surveyorSchemas.applicationParams,
107
108
  body: surveyorSchemas.fileBody,
108
109
  },
@@ -136,7 +137,7 @@ export function createSurveyorRoutes(ctx: AppContext): FastifyPluginAsync {
136
137
  "/api/surveyor/applications/:applicationId/verify",
137
138
  {
138
139
  schema: {
139
- ...administrator,
140
+ ...staff("applications:update"),
140
141
  params: surveyorSchemas.applicationParams,
141
142
  body: surveyorSchemas.verifyApplication,
142
143
  },
@@ -151,7 +152,7 @@ export function createSurveyorRoutes(ctx: AppContext): FastifyPluginAsync {
151
152
  );
152
153
  app.post<ApplicationRoute>(
153
154
  "/api/surveyor/applications/:applicationId/complete",
154
- { schema: { ...administrator, params: surveyorSchemas.applicationParams } },
155
+ { schema: { ...staff("applications:update"), params: surveyorSchemas.applicationParams } },
155
156
  async (req) => completeApplication({ id: req.params.applicationId, user: req.user, ctx })
156
157
  );
157
158
 
@@ -223,7 +224,7 @@ export function createSurveyorRoutes(ctx: AppContext): FastifyPluginAsync {
223
224
  );
224
225
  app.post<{ Body: RegisterInput }>(
225
226
  "/api/surveyor/surveyors",
226
- { schema: { ...administrator, body: surveyorSchemas.registerSurveyor } },
227
+ { schema: { ...staff("surveyors:create"), body: surveyorSchemas.registerSurveyor } },
227
228
  async (req) => registerSurveyor({ input: req.body, user: req.user, ctx })
228
229
  );
229
230
  app.post<RegistrationRoute & { Body: PasswordInput }>(
@@ -296,7 +297,7 @@ export function createSurveyorRoutes(ctx: AppContext): FastifyPluginAsync {
296
297
  "/api/surveyor/surveyors/:surveyorId/password",
297
298
  {
298
299
  schema: {
299
- ...administrator,
300
+ ...staff("surveyors:update"),
300
301
  summary: "Зміна пароля геодезиста адміністратором",
301
302
  params: surveyorSchemas.surveyorParams,
302
303
  },
@@ -309,14 +310,14 @@ export function createSurveyorRoutes(ctx: AppContext): FastifyPluginAsync {
309
310
  );
310
311
  app.post<SurveyorRoute>(
311
312
  "/api/surveyor/surveyors/:surveyorId/registration/resend",
312
- { schema: { ...administrator, params: surveyorSchemas.surveyorParams } },
313
+ { schema: { ...staff("surveyors:update"), params: surveyorSchemas.surveyorParams } },
313
314
  async (req) => resendRegistration({ id: req.params.surveyorId, user: req.user, ctx })
314
315
  );
315
316
  app.put<SurveyorRoute & { Body: SurveyorStatusInput }>(
316
317
  "/api/surveyor/surveyors/:surveyorId/status",
317
318
  {
318
319
  schema: {
319
- ...administrator,
320
+ ...staff("surveyors:update"),
320
321
  summary: "Увімкнення або вимкнення доступу геодезиста до організації",
321
322
  params: surveyorSchemas.surveyorParams,
322
323
  body: surveyorSchemas.surveyorStatus,
@@ -333,7 +334,7 @@ export function createSurveyorRoutes(ctx: AppContext): FastifyPluginAsync {
333
334
  "/api/surveyor/surveyors/:surveyorId/account-status",
334
335
  {
335
336
  schema: {
336
- ...administrator,
337
+ ...staff("surveyors:update"),
337
338
  summary: "Повне блокування або розблокування облікового запису геодезиста",
338
339
  params: surveyorSchemas.surveyorParams,
339
340
  body: surveyorSchemas.surveyorAccountStatus,
@@ -1,6 +1,6 @@
1
1
  import type { AppContext, User } from "@opengis/fcore";
2
2
  import { BadRequestError, buildFilters } from "@opengis/fcore";
3
- import { actor, surveyorForUser } from "../utils/shared.js";
3
+ import { actor, isStaff, surveyorForUser } from "../utils/shared.js";
4
4
 
5
5
  export type ApplicationTileQuery = {
6
6
  filter?: Record<string, unknown>;
@@ -27,14 +27,14 @@ export async function applicationTile(
27
27
  throw new BadRequestError("Invalid tile coordinates");
28
28
  }
29
29
 
30
- const resource = ctx.resource.get(user?.type === "admin" ? "applications" : "public_applications");
30
+ const resource = ctx.resource.get(isStaff(user) ? "applications" : "public_applications");
31
31
 
32
32
  const filters = buildFilters(resource, filter, 6);
33
33
  const scopeFilter = scope === "active"
34
34
  ? "AND a.status IN ('awaitingData', 'dataIssued', 'reserve', 'underReview', 'verified')"
35
35
  : "";
36
36
 
37
- const surveyorId = user?.type === "admin" ? null : await surveyorForUser({ db: ctx.pg, user });
37
+ const surveyorId = isStaff(user) ? null : await surveyorForUser({ db: ctx.pg, user });
38
38
 
39
39
  const result = await ctx.pg.query<{ tile: Buffer }>(
40
40
  `WITH bounds AS (
@@ -5,6 +5,7 @@ import {
5
5
  assertStatus,
6
6
  audit,
7
7
  history,
8
+ isStaff,
8
9
  readApplication,
9
10
  releaseReservesForParent,
10
11
  surveyorForUser,
@@ -28,7 +29,7 @@ export async function cancelApplication({
28
29
  ctx: AppContext;
29
30
  }) {
30
31
  const uid = actor(user);
31
- if (user?.type === "admin") {
32
+ if (isStaff(user)) {
32
33
  throw new ForbiddenError("Administrator cannot cancel an application");
33
34
  }
34
35
 
@@ -12,7 +12,7 @@ export async function changeSurveyorPasswordByAdmin(
12
12
  ctx: AppContext;
13
13
  }
14
14
  ) {
15
- const uid = admin(user);
15
+ const uid = admin(user, "surveyors:update");
16
16
  const password = randomBytes(16).toString("hex");
17
17
  const passwordHash = await hashPassword(password);
18
18
  const surveyor = await ctx.pg.query<{ surveyor_id: string; email: string }>(
@@ -16,7 +16,7 @@ import {
16
16
  export async function completeApplication(
17
17
  { id, user, ctx }: { id: string; user: User | undefined; ctx: AppContext }
18
18
  ) {
19
- const uid = admin(user);
19
+ const uid = admin(user, "applications:update");
20
20
  const result = await ctx.pg.transaction(async (db: Db) => {
21
21
  // Узгоджує завершення та звільнення резервів із паралельним створенням заявок.
22
22
  await db.query("SELECT pg_advisory_xact_lock(85437120)");
@@ -1,7 +1,7 @@
1
1
  import type { AppContext, User } from "@opengis/fcore";
2
2
  import { BadRequestError } from "@opengis/fcore";
3
3
  import applicationStatus from "../../../dictionaries/surveyor/application_status.js";
4
- import { actor, surveyorForUser, type Status } from "../utils/shared.js";
4
+ import { actor, isStaff, surveyorForUser, type Status } from "../utils/shared.js";
5
5
 
6
6
  const statusCodes = new Set(applicationStatus.items.map((item) => item.code));
7
7
 
@@ -38,7 +38,7 @@ export async function identifyApplications({
38
38
  const page = input.page ?? 1;
39
39
  const limit = input.limit ?? 10;
40
40
 
41
- const isAdmin = user?.type === "admin";
41
+ const isAdmin = isStaff(user);
42
42
  if (!isAdmin) await surveyorForUser({ db: ctx.pg, user });
43
43
 
44
44
  const resourceName = isAdmin ? "applications" : "public_applications";
@@ -22,7 +22,7 @@ export async function issueSourceData(
22
22
  ctx: AppContext;
23
23
  }
24
24
  ) {
25
- const uid = admin(user);
25
+ const uid = admin(user, "applications:update");
26
26
  const file = await attachedFile({ ctx, appId: id, filePath: input.file_path });
27
27
  const result = await ctx.pg.transaction(async (db: Db) => {
28
28
  const updated = await db.query<{ app_id: string }>(
@@ -21,7 +21,7 @@ export type RegisterInput = {
21
21
  export async function registerSurveyor(
22
22
  { input, user, ctx }: { input: RegisterInput; user: User | undefined; ctx: AppContext }
23
23
  ) {
24
- const uid = admin(user);
24
+ const uid = admin(user, "surveyors:create");
25
25
  const orgId = input.organization_id;
26
26
  const certId = input.certificate_id;
27
27
  const email = input.email.toLowerCase();
@@ -12,7 +12,7 @@ import { sendActivationEmail } from "../utils/mail.js";
12
12
  export async function resendRegistration(
13
13
  { id, user, ctx }: { id: string; user: User | undefined; ctx: AppContext }
14
14
  ) {
15
- const uid = admin(user);
15
+ const uid = admin(user, "surveyors:update");
16
16
  const rawToken = token();
17
17
  const result = await ctx.pg.query<{ email: string }>(
18
18
  `UPDATE surveyor.surveyors
@@ -1,5 +1,5 @@
1
1
  import type { AppContext, User } from "@opengis/fcore";
2
- import { actor, surveyorForUser, type Status } from "../utils/shared.js";
2
+ import { actor, isStaff, surveyorForUser, type Status } from "../utils/shared.js";
3
3
 
4
4
  export type ApplicationSearchInput = {
5
5
  search: string;
@@ -25,7 +25,7 @@ export async function searchApplications(
25
25
  const page = input.page ?? 1;
26
26
  const limit = input.limit ?? 20;
27
27
 
28
- const surveyorId = user?.type === "admin" ? null : await surveyorForUser({ db: ctx.pg, user });
28
+ const surveyorId = isStaff(user) ? null : await surveyorForUser({ db: ctx.pg, user });
29
29
  const pattern = `%${search.replace(/[\\%_]/g, "\\$&")}%`;
30
30
 
31
31
  const fromWhere = `FROM surveyor.applications AS a
@@ -16,7 +16,7 @@ export async function updateSurveyorAccountStatus(
16
16
  ctx: AppContext;
17
17
  }
18
18
  ) {
19
- const uid = admin(user);
19
+ const uid = admin(user, "surveyors:update");
20
20
  if (typeof input.enabled !== "boolean") {
21
21
  throw new BadRequestError("Enabled must be a boolean");
22
22
  }
@@ -16,7 +16,7 @@ export async function updateSurveyorStatus(
16
16
  ctx: AppContext;
17
17
  }
18
18
  ) {
19
- const uid = admin(user);
19
+ const uid = admin(user, "surveyors:update");
20
20
  if (typeof input.enabled !== "boolean") {
21
21
  throw new BadRequestError("Enabled must be a boolean");
22
22
  }
@@ -22,7 +22,7 @@ export async function verifyApplication(
22
22
  ctx: AppContext;
23
23
  }
24
24
  ) {
25
- const uid = admin(user);
25
+ const uid = admin(user, "applications:update");
26
26
  const file = input.file_path
27
27
  ? await attachedFile({ ctx, appId: id, filePath: input.file_path })
28
28
  : null;
@@ -39,15 +39,37 @@ export function actor(user: User | undefined): string {
39
39
  return user.id;
40
40
  }
41
41
 
42
+ /** Право, що відкриває адмінський (службовий) режим кабінету. */
43
+ export const STAFF_PERMISSION = "applications:read";
44
+
45
+ /**
46
+ * Чи має користувач право: адміністратор має всі, інші — лише видані (`resource:action`).
47
+ * @param user Користувач із запиту.
48
+ * @param permission Право у форматі `resource:action`.
49
+ */
50
+ export function hasPermission(user: User | undefined, permission: string): boolean {
51
+ return user?.type === "admin" || Boolean(user?.permissions?.includes(permission));
52
+ }
53
+
54
+ /**
55
+ * Чи працює користувач у службовому режимі (адміністратор або працівник з правами),
56
+ * а не як геодезист.
57
+ * @param user Користувач із запиту.
58
+ */
59
+ export function isStaff(user: User | undefined): boolean {
60
+ return hasPermission(user, STAFF_PERMISSION);
61
+ }
62
+
42
63
  /**
43
- * Перевіряє права адміністратора та повертає його ідентифікатор.
64
+ * Перевіряє службове право та повертає ідентифікатор користувача.
44
65
  * @param user Користувач із запиту.
45
- * @returns Ідентифікатор адміністратора.
66
+ * @param permission Потрібне право у форматі `resource:action`.
67
+ * @returns Ідентифікатор користувача.
46
68
  */
47
- export function admin(user: User | undefined): string {
69
+ export function admin(user: User | undefined, permission: string): string {
48
70
  const id = actor(user);
49
- if (user?.type !== "admin") {
50
- throw new ForbiddenError("Administrator access required");
71
+ if (!hasPermission(user, permission)) {
72
+ throw new ForbiddenError(`Missing permission: ${permission}`);
51
73
  }
52
74
  return id;
53
75
  }
@@ -127,7 +149,7 @@ export async function surveyorForUser(
127
149
  export async function canReadApplication(
128
150
  { db, app, user }: { db: Db; app: Application; user: User | undefined }
129
151
  ): Promise<void> {
130
- if (user?.type === "admin") {
152
+ if (isStaff(user)) {
131
153
  return;
132
154
  }
133
155
  const surveyorId = await surveyorForUser({ db, user });
@@ -9,7 +9,7 @@ export default {
9
9
  title: "Коментарі заявок",
10
10
  table: "admin.notes",
11
11
  key: "note_id",
12
- access: "admin",
12
+ access: "user",
13
13
  operations: [],
14
14
  fields: {
15
15
  note_id: { type: "text", read: true, write: false },
@@ -12,7 +12,7 @@ export default {
12
12
  title: "Історія статусів заявок",
13
13
  table: "surveyor.application_status_history",
14
14
  key: "history_id",
15
- access: "admin",
15
+ access: "user",
16
16
  operations: ["read"],
17
17
  fields: {
18
18
  history_id: { type: "text", write: false },
@@ -10,7 +10,8 @@ const applicationStatusCodes = applicationStatus.items.map(({ code }) => code);
10
10
  const workTypeCodes = workTypes.items.map(({ code }) => code);
11
11
 
12
12
  // Status changes, area checks, and file workflow belong to Business API services.
13
- // Generic update is limited to replacing already issued source data (file_output).
13
+ // Generic update covers descriptive fields and replacing issued source data (file_output);
14
+ // workflow fields (status, files, signature, area/geom, dates) stay read-only.
14
15
  export default {
15
16
  version: 1,
16
17
  name: "applications",
@@ -18,7 +19,7 @@ export default {
18
19
  title: "Заявки на геодезичні роботи",
19
20
  table: "surveyor.applications",
20
21
  key: "app_id",
21
- access: "admin",
22
+ access: "user",
22
23
  operations: ["read", "update"],
23
24
  searchable: ["number", "location", "description"],
24
25
  capabilities: ["notes", "files"],
@@ -55,30 +56,30 @@ export default {
55
56
  },
56
57
  work_type: {
57
58
  type: "string",
58
- write: false,
59
+ write: true,
59
60
  filterable: true,
60
61
  dictionary: workTypes.code,
61
62
  enum: workTypeCodes,
62
63
  },
63
- description: { type: "text", write: false, searchable: true },
64
- execution_basis: { type: "text", write: false },
64
+ description: { type: "text", write: true, searchable: true },
65
+ execution_basis: { type: "text", write: true },
65
66
  settlement_id: {
66
67
  type: "string",
67
- write: false,
68
+ write: true,
68
69
  filterable: true,
69
70
  lookup: settlementLookup,
70
71
  },
71
- is_found_address_id: { type: "boolean", write: false, filterable: true, dictionary: "yes-no" },
72
- address_id: { type: "string", write: false, filterable: true, lookup: addressLookup },
73
- location: { type: "text", write: false, searchable: true },
72
+ is_found_address_id: { type: "boolean", write: true, filterable: true, dictionary: "yes-no" },
73
+ address_id: { type: "string", write: true, filterable: true, lookup: addressLookup },
74
+ location: { type: "text", write: true, searchable: true },
74
75
  area: { type: "number", write: false, sortable: true },
75
76
  geom: { type: "geometry", write: false },
76
77
  file_output: { type: "file", write: true },
77
78
  file_geodetic_survey: { type: "file", write: false },
78
79
  file_corrected_geodetic_survey: { type: "file", write: false },
79
80
  note_4_file_corrected_geodetic_survey: { type: "text", write: false },
80
- notes: { type: "text", write: false },
81
- signature: { type: "text", write: false },
81
+ notes: { type: "text", write: true },
82
+ signature: { type: "text", write: true },
82
83
  cancel_reason: { type: "text", write: false },
83
84
  source_data_issued_at: { type: "timestamp", write: false, sortable: true },
84
85
  survey_uploaded_at: { type: "timestamp", write: false, sortable: true },
@@ -5,7 +5,7 @@ import { certificateStatusSql } from "../../modules/surveyor/utils/certificateSt
5
5
 
6
6
  const accountTypeCodes = accountTypes.items.map(({ code }) => code);
7
7
 
8
- // Certificates are imported from the external registry, so Resource API only reads them.
8
+ // Сертифікати імпортуються із зовнішнього реєстру, але адміністратор може додавати та редагувати їх вручну.
9
9
  export default {
10
10
  version: 1,
11
11
  name: "certificates",
@@ -26,8 +26,8 @@ export default {
26
26
  "account_phone",
27
27
  "account_registered_at",
28
28
  ],
29
- access: "admin",
30
- operations: ["read"],
29
+ access: "user",
30
+ operations: ["read", "create", "update"],
31
31
  searchable: ["surveyor_name", "last_name", "first_name", "number_certificate"],
32
32
  fields: {
33
33
  certificate_id: {
@@ -43,51 +43,51 @@ export default {
43
43
  },
44
44
  certificate_type: {
45
45
  type: "string",
46
- write: false,
46
+ write: true,
47
47
  filterable: true,
48
48
  dictionary: accountTypes.code,
49
49
  enum: accountTypeCodes,
50
50
  },
51
51
  surveyor_name: {
52
52
  type: "string",
53
- write: false,
53
+ write: true,
54
54
  searchable: true,
55
55
  },
56
- last_name: { type: "string", write: false, searchable: true },
57
- first_name: { type: "string", write: false, searchable: true },
58
- middle_name: { type: "string", write: false },
59
- surveyor_phone: { type: "string", write: false },
60
- surveyor_email: { type: "string", write: false },
56
+ last_name: { type: "string", write: true, searchable: true },
57
+ first_name: { type: "string", write: true, searchable: true },
58
+ middle_name: { type: "string", write: true },
59
+ surveyor_phone: { type: "string", write: true },
60
+ surveyor_email: { type: "string", write: true },
61
61
  date_certificate: {
62
62
  type: "date",
63
- write: false,
63
+ write: true,
64
64
  filterable: true,
65
65
  sortable: true,
66
66
  },
67
- number_certificate: { type: "string", write: false, searchable: true },
68
- name_school: { type: "text", write: false },
69
- date_protocol: { type: "date", write: false },
70
- number_protocol: { type: "string", write: false },
71
- certificate_increase: { type: "text", write: false },
72
- certificate_stopping: { type: "text", write: false },
73
- certificate_suspension: { type: "date", write: false },
74
- certificate_renewal: { type: "text", write: false },
75
- work_place: { type: "text", write: false },
76
- economic_activity: { type: "text", write: false },
67
+ number_certificate: { type: "string", write: true, searchable: true },
68
+ name_school: { type: "text", write: true },
69
+ date_protocol: { type: "date", write: true },
70
+ number_protocol: { type: "string", write: true },
71
+ certificate_increase: { type: "text", write: true },
72
+ certificate_stopping: { type: "text", write: true },
73
+ certificate_suspension: { type: "date", write: true },
74
+ certificate_renewal: { type: "text", write: true },
75
+ work_place: { type: "text", write: true },
76
+ economic_activity: { type: "text", write: true },
77
77
  created_by: { type: "string", write: false, lookup: userLookup },
78
78
  created_at: { type: "timestamp", write: false, sortable: true },
79
79
  updated_by: { type: "string", write: false, lookup: userLookup },
80
80
  updated_at: { type: "timestamp", write: false, sortable: true },
81
81
  is_membership: {
82
82
  type: "boolean",
83
- write: false,
83
+ write: true,
84
84
  filterable: true,
85
85
  dictionary: "yes-no",
86
86
  },
87
- membership: { type: "text", write: false },
88
- last_qualification_date: { type: "date", write: false },
89
- isvalid: { type: "boolean", write: false, filterable: true },
90
- qualification_level: { type: "string", write: false },
87
+ membership: { type: "text", write: true },
88
+ last_qualification_date: { type: "date", write: true },
89
+ isvalid: { type: "boolean", write: true, filterable: true },
90
+ qualification_level: { type: "string", write: true },
91
91
  },
92
92
  // Колонки мають префікс account_, щоб не конфліктувати з полями сертифіката.
93
93
  // scope "item" не додає join до основного списку сертифікатів.
@@ -14,7 +14,7 @@ export default {
14
14
  key: "layer_id",
15
15
  display: ["name"],
16
16
  displayFields: ["code", "layer_group", "layer_type"],
17
- access: "admin",
17
+ access: "user",
18
18
  operations: ["read", "create", "update", "delete"],
19
19
  searchable: ["name", "code"],
20
20
  fields: {
@@ -9,7 +9,7 @@ export default {
9
9
  table: "surveyor.organizations",
10
10
  key: "org_id",
11
11
  display: ["name"],
12
- access: "admin",
12
+ access: "user",
13
13
  operations: ["read", "create", "update", "delete"],
14
14
  searchable: ["name", "email", "phone"],
15
15
  capabilities: ["notes", "files"],
@@ -10,7 +10,7 @@ export default {
10
10
  title: "Геодезисти",
11
11
  table: "surveyor.surveyors",
12
12
  key: "surveyor_id",
13
- access: "admin",
13
+ access: "user",
14
14
  operations: ["read", "update"],
15
15
  searchable: ["first_name", "last_name", "email", "phone"],
16
16
  fields: {