@opengis/fastify-table 2.5.43 → 2.5.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/functions.d.ts +1 -0
- package/dist/functions.d.ts.map +1 -1
- package/dist/functions.js +122 -1
- package/dist/helper.d.ts +20 -0
- package/dist/helper.d.ts.map +1 -1
- package/dist/helper.js +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/server/migrations/dictionaries.sql +79 -0
- package/dist/server/plugins/access/funcs/getResources.d.ts +2 -1
- package/dist/server/plugins/access/funcs/getResources.d.ts.map +1 -1
- package/dist/server/plugins/access/funcs/getResources.js +5 -1
- package/dist/server/plugins/crud/funcs/dataDelete.d.ts +2 -1
- package/dist/server/plugins/crud/funcs/dataDelete.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/dataDelete.js +2 -2
- package/dist/server/plugins/crud/funcs/getOpt.d.ts +1 -1
- package/dist/server/plugins/crud/funcs/getOpt.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/getOpt.js +1 -1
- package/dist/server/plugins/crud/funcs/setOpt.d.ts +1 -1
- package/dist/server/plugins/crud/funcs/setOpt.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/setOpt.js +1 -1
- package/dist/server/plugins/crud/funcs/setToken.d.ts +1 -1
- package/dist/server/plugins/crud/funcs/setToken.d.ts.map +1 -1
- package/dist/server/plugins/table/funcs/getData.d.ts +32 -0
- package/dist/server/plugins/table/funcs/getData.d.ts.map +1 -0
- package/dist/server/plugins/table/funcs/getData.js +703 -0
- package/dist/server/plugins/table/funcs/getFilterSQLParametrized/index.d.ts +2 -1
- package/dist/server/plugins/table/funcs/getFilterSQLParametrized/index.d.ts.map +1 -1
- package/dist/server/plugins/table/funcs/getFilterSQLParametrized/index.js +2 -2
- package/dist/server/routes/crud/controllers/insert.d.ts +1 -2
- package/dist/server/routes/crud/controllers/insert.d.ts.map +1 -1
- package/dist/server/routes/crud/controllers/insert.js +1 -1
- package/dist/server/routes/crud/controllers/table.d.ts +1 -2
- package/dist/server/routes/crud/controllers/table.d.ts.map +1 -1
- package/dist/server/routes/crud/controllers/table.js +1 -1
- package/dist/server/routes/crud/controllers/update.js +1 -1
- package/dist/server/routes/crud/crud.route.d.ts +3 -0
- package/dist/server/routes/crud/crud.route.d.ts.map +1 -0
- package/dist/server/routes/crud/crud.route.js +161 -0
- package/dist/server/routes/crud/crud.schema.d.ts +114 -0
- package/dist/server/routes/crud/crud.schema.d.ts.map +1 -0
- package/dist/server/routes/crud/crud.schema.js +64 -0
- package/dist/server/routes/crud/functions/createTableRelation.d.ts +13 -0
- package/dist/server/routes/crud/functions/createTableRelation.d.ts.map +1 -0
- package/dist/server/routes/crud/functions/createTableRelation.js +93 -0
- package/dist/server/routes/crud/functions/deleteTableRelation.d.ts +11 -0
- package/dist/server/routes/crud/functions/deleteTableRelation.d.ts.map +1 -0
- package/dist/server/routes/crud/functions/deleteTableRelation.js +74 -0
- package/dist/server/routes/crud/functions/readTableRelations.d.ts +25 -0
- package/dist/server/routes/crud/functions/readTableRelations.d.ts.map +1 -0
- package/dist/server/routes/crud/functions/readTableRelations.js +76 -0
- package/dist/server/routes/crud/functions/updateTableRelation.d.ts +14 -0
- package/dist/server/routes/crud/functions/updateTableRelation.d.ts.map +1 -0
- package/dist/server/routes/crud/functions/updateTableRelation.js +117 -0
- package/dist/server/routes/dictionaries/dictionaries.route.d.ts +2 -0
- package/dist/server/routes/dictionaries/dictionaries.route.d.ts.map +1 -0
- package/dist/server/routes/dictionaries/dictionaries.route.js +134 -0
- package/dist/server/routes/dictionaries/dictionaries.schema.d.ts +190 -0
- package/dist/server/routes/dictionaries/dictionaries.schema.d.ts.map +1 -0
- package/dist/server/routes/dictionaries/dictionaries.schema.js +86 -0
- package/dist/server/routes/dictionaries/functions/create.dictionary.d.ts +10 -0
- package/dist/server/routes/dictionaries/functions/create.dictionary.d.ts.map +1 -0
- package/dist/server/routes/dictionaries/functions/create.dictionary.item.d.ts +13 -0
- package/dist/server/routes/dictionaries/functions/create.dictionary.item.d.ts.map +1 -0
- package/dist/server/routes/dictionaries/functions/create.dictionary.item.js +57 -0
- package/dist/server/routes/dictionaries/functions/create.dictionary.js +76 -0
- package/dist/server/routes/dictionaries/functions/delete.dictionary.d.ts +9 -0
- package/dist/server/routes/dictionaries/functions/delete.dictionary.d.ts.map +1 -0
- package/dist/server/routes/dictionaries/functions/delete.dictionary.item.d.ts +11 -0
- package/dist/server/routes/dictionaries/functions/delete.dictionary.item.d.ts.map +1 -0
- package/dist/server/routes/dictionaries/functions/delete.dictionary.item.js +32 -0
- package/dist/server/routes/dictionaries/functions/delete.dictionary.js +28 -0
- package/dist/server/routes/dictionaries/functions/read.dictionaries.d.ts +5 -0
- package/dist/server/routes/dictionaries/functions/read.dictionaries.d.ts.map +1 -0
- package/dist/server/routes/dictionaries/functions/read.dictionaries.js +27 -0
- package/dist/server/routes/dictionaries/functions/update.dictionary.d.ts +10 -0
- package/dist/server/routes/dictionaries/functions/update.dictionary.d.ts.map +1 -0
- package/dist/server/routes/dictionaries/functions/update.dictionary.item.d.ts +13 -0
- package/dist/server/routes/dictionaries/functions/update.dictionary.item.d.ts.map +1 -0
- package/dist/server/routes/dictionaries/functions/update.dictionary.item.js +48 -0
- package/dist/server/routes/dictionaries/functions/update.dictionary.js +51 -0
- package/dist/server/routes/file/schema.js +6 -6
- package/dist/server/routes/table/functions/getData.d.ts +3 -2
- package/dist/server/routes/table/functions/getData.d.ts.map +1 -1
- package/dist/server/routes/table/functions/getData.js +2 -14
- package/dist/server/routes/table/schema.d.ts +5 -4
- package/dist/server/routes/table/schema.d.ts.map +1 -1
- package/dist/server/routes/table/schema.js +13 -13
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default function readTableRelations({ table: paramsTable, id, relname, relationId, uid, userType, referer, limit, page, called, }: {
|
|
2
|
+
table: string;
|
|
3
|
+
id: string;
|
|
4
|
+
relname: string;
|
|
5
|
+
relationId?: string;
|
|
6
|
+
uid: string;
|
|
7
|
+
userType?: string;
|
|
8
|
+
referer?: string;
|
|
9
|
+
limit?: number;
|
|
10
|
+
page?: number;
|
|
11
|
+
called?: boolean;
|
|
12
|
+
}, pg?: any): Promise<{
|
|
13
|
+
count: any;
|
|
14
|
+
filtered: any;
|
|
15
|
+
total: any;
|
|
16
|
+
limit: number;
|
|
17
|
+
page: number;
|
|
18
|
+
rows: any;
|
|
19
|
+
schema: any;
|
|
20
|
+
} | {
|
|
21
|
+
id: string;
|
|
22
|
+
data: any;
|
|
23
|
+
schema: any;
|
|
24
|
+
}>;
|
|
25
|
+
//# sourceMappingURL=readTableRelations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readTableRelations.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/functions/readTableRelations.ts"],"names":[],"mappings":"AAcA,wBAA8B,kBAAkB,CAC9C,EACE,KAAK,EAAE,WAAW,EAClB,EAAE,EACF,OAAO,EACP,UAAU,EACV,GAAG,EACH,QAAQ,EACR,OAAO,EACP,KAAU,EACV,IAAQ,EACR,MAAc,GACf,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,EACD,EAAE,MAAmB;;;;;;;;;;;;GAkGtB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// import config from "../../../../config.js";
|
|
2
|
+
import pgClients from "../../../plugins/pg/pgClients.js";
|
|
3
|
+
import getAccess from "../../../plugins/crud/funcs/getAccess.js";
|
|
4
|
+
import getTemplate from "../../../plugins/table/funcs/getTemplate.js";
|
|
5
|
+
import getData from "../../../plugins/table/funcs/getData.js";
|
|
6
|
+
import { resourcesObject } from "../../../plugins/access/funcs/getResources.js";
|
|
7
|
+
import { BadRequestError, ForbiddenError, NotFoundError, } from "../../../../errors.js";
|
|
8
|
+
export default async function readTableRelations({ table: paramsTable, id, relname, relationId, uid, userType, referer, limit = 10, page = 1, called = false, }, pg = pgClients.client) {
|
|
9
|
+
if (!paramsTable) {
|
|
10
|
+
throw BadRequestError("not enough params: table ");
|
|
11
|
+
}
|
|
12
|
+
const resource = resourcesObject[paramsTable]?.table
|
|
13
|
+
? paramsTable
|
|
14
|
+
: undefined;
|
|
15
|
+
const templateName = resourcesObject[paramsTable]?.table || paramsTable;
|
|
16
|
+
const loadTable = await getTemplate("table", templateName);
|
|
17
|
+
if (!loadTable && !(pg.pk?.[templateName] && called)) {
|
|
18
|
+
throw NotFoundError("table not found");
|
|
19
|
+
}
|
|
20
|
+
const { relations = {} } = loadTable || {};
|
|
21
|
+
if (!relations[relname]) {
|
|
22
|
+
throw NotFoundError("table relation not found");
|
|
23
|
+
}
|
|
24
|
+
const { table: relationTable, form: relationForm,
|
|
25
|
+
// localKey = relations[relname]?.localKey,
|
|
26
|
+
foreignKey = relations[relname]?.foreignKey, } = relations[relname]?.resource
|
|
27
|
+
? resourcesObject[relations[relname].resource]
|
|
28
|
+
: relations[relname];
|
|
29
|
+
if (!foreignKey) {
|
|
30
|
+
throw new Error("invalid relation: foreignKey not set");
|
|
31
|
+
}
|
|
32
|
+
// check if user has permission to modify main object/row
|
|
33
|
+
const { actions = [], message: accessMessage } = (await getAccess({
|
|
34
|
+
resource,
|
|
35
|
+
table: templateName,
|
|
36
|
+
form: loadTable?.form,
|
|
37
|
+
id,
|
|
38
|
+
user: { uid, user_type: userType },
|
|
39
|
+
method: "GET",
|
|
40
|
+
}, pg)) || {};
|
|
41
|
+
if (accessMessage) {
|
|
42
|
+
throw ForbiddenError(accessMessage);
|
|
43
|
+
}
|
|
44
|
+
if (!actions.includes("edit") && !called) {
|
|
45
|
+
throw ForbiddenError("access restricted: actions");
|
|
46
|
+
}
|
|
47
|
+
const relationTableTemplate = await getTemplate("table", relationTable);
|
|
48
|
+
const formData = await getTemplate("form", relationTableTemplate?.form || relationForm);
|
|
49
|
+
const schema = formData?.schema || formData || {};
|
|
50
|
+
const { count, filtered, total, rows } = await getData({
|
|
51
|
+
table: relationTable,
|
|
52
|
+
id: relationId,
|
|
53
|
+
page: relationId ? undefined : page,
|
|
54
|
+
limit: relationId ? undefined : limit,
|
|
55
|
+
uid,
|
|
56
|
+
userType,
|
|
57
|
+
referer,
|
|
58
|
+
columns: Object.keys(schema).concat([foreignKey]),
|
|
59
|
+
contextQuery: `${foreignKey}=$1`,
|
|
60
|
+
args: [id],
|
|
61
|
+
called: true,
|
|
62
|
+
}, pg);
|
|
63
|
+
if (relationId) {
|
|
64
|
+
return { id: relationId, data: rows[0], schema };
|
|
65
|
+
}
|
|
66
|
+
const data = {
|
|
67
|
+
count,
|
|
68
|
+
filtered,
|
|
69
|
+
total,
|
|
70
|
+
limit,
|
|
71
|
+
page,
|
|
72
|
+
rows,
|
|
73
|
+
schema,
|
|
74
|
+
};
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default function updateTableRelation({ table: paramsTable, id: paramsId, form: paramsForm, relname, relationId, body, uid, userType, referer, ignoreCheck, called, }: {
|
|
2
|
+
table: string;
|
|
3
|
+
id: string;
|
|
4
|
+
form?: string;
|
|
5
|
+
relname: string;
|
|
6
|
+
relationId: string;
|
|
7
|
+
body: Record<string, any>;
|
|
8
|
+
uid?: string;
|
|
9
|
+
userType?: string;
|
|
10
|
+
referer?: string;
|
|
11
|
+
ignoreCheck?: boolean;
|
|
12
|
+
called?: boolean;
|
|
13
|
+
}, pg?: any): Promise<any>;
|
|
14
|
+
//# sourceMappingURL=updateTableRelation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateTableRelation.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/functions/updateTableRelation.ts"],"names":[],"mappings":"AAqBA,wBAA8B,mBAAmB,CAC/C,EACE,KAAK,EAAE,WAAW,EAClB,EAAE,EAAE,QAAQ,EACZ,IAAI,EAAE,UAAU,EAChB,OAAO,EACP,UAAU,EACV,IAAI,EACJ,GAAG,EACH,QAAQ,EACR,OAAO,EACP,WAAmB,EACnB,MAAc,GACf,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,EACD,EAAE,MAAmB,gBA+JtB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// import config from "../../../../config.js";
|
|
2
|
+
import pgClients from "../../../plugins/pg/pgClients.js";
|
|
3
|
+
import getTemplate from "../../../plugins/table/funcs/getTemplate.js";
|
|
4
|
+
import dataUpdate from "../../../plugins/crud/funcs/dataUpdate.js";
|
|
5
|
+
import getAccess from "../../../plugins/crud/funcs/getAccess.js";
|
|
6
|
+
import checkXSS from "../../../plugins/policy/funcs/checkXSS.js";
|
|
7
|
+
import validateData from "../../../plugins/crud/funcs/validateData.js";
|
|
8
|
+
import logger from "../../../plugins/logger/getLogger.js";
|
|
9
|
+
import { resourcesObject } from "../../../plugins/access/funcs/getResources.js";
|
|
10
|
+
import { BadRequestError, ConflictError, ForbiddenError, NotFoundError, UnauthorizedError, } from "../../../../errors.js";
|
|
11
|
+
export default async function updateTableRelation({ table: paramsTable, id: paramsId, form: paramsForm, relname, relationId, body, uid, userType, referer, ignoreCheck = false, called = false, }, pg = pgClients.client) {
|
|
12
|
+
if (!uid) {
|
|
13
|
+
throw UnauthorizedError("unauthorized");
|
|
14
|
+
}
|
|
15
|
+
if (!relationId) {
|
|
16
|
+
throw BadRequestError("not enough params: relationId");
|
|
17
|
+
}
|
|
18
|
+
const resource = resourcesObject[paramsTable] ? paramsTable : undefined;
|
|
19
|
+
const mainTable = resourcesObject[paramsTable]?.table || paramsTable;
|
|
20
|
+
const id = paramsId;
|
|
21
|
+
const { actions = [], message: accessMessage } = (await getAccess({
|
|
22
|
+
resource,
|
|
23
|
+
table: mainTable,
|
|
24
|
+
form: resourcesObject[paramsTable]?.form || paramsForm,
|
|
25
|
+
id: paramsId,
|
|
26
|
+
user: { uid, user_type: userType },
|
|
27
|
+
method: "PUT",
|
|
28
|
+
}, pg)) || {};
|
|
29
|
+
if (accessMessage && !called) {
|
|
30
|
+
throw ForbiddenError(accessMessage);
|
|
31
|
+
}
|
|
32
|
+
if (!actions.includes("edit") && !called) {
|
|
33
|
+
throw ForbiddenError("access restricted: actions");
|
|
34
|
+
}
|
|
35
|
+
const loadTemplate = await getTemplate("table", mainTable);
|
|
36
|
+
if (!loadTemplate) {
|
|
37
|
+
throw NotFoundError(`table not found: ${mainTable}`);
|
|
38
|
+
}
|
|
39
|
+
const { relations = {} } = loadTemplate || {};
|
|
40
|
+
if (!relations[relname]) {
|
|
41
|
+
throw NotFoundError(`table relation not found: ${relname}`);
|
|
42
|
+
}
|
|
43
|
+
const { table: relationTable, form: relationForm,
|
|
44
|
+
// localKey = relations[relname]?.localKey,
|
|
45
|
+
foreignKey = relations[relname]?.foreignKey, } = relations[relname]?.resource
|
|
46
|
+
? resourcesObject[relations[relname].resource]
|
|
47
|
+
: relations[relname];
|
|
48
|
+
if (!foreignKey) {
|
|
49
|
+
throw new Error("invalid relation: foreignKey not set");
|
|
50
|
+
}
|
|
51
|
+
const pks = await pg
|
|
52
|
+
.query(`
|
|
53
|
+
SELECT
|
|
54
|
+
connamespace::regnamespace::text,
|
|
55
|
+
conrelid::regclass,
|
|
56
|
+
(
|
|
57
|
+
SELECT attname FROM pg_attribute WHERE attrelid = c.conrelid AND attnum = c.conkey[1]
|
|
58
|
+
) as pk
|
|
59
|
+
FROM pg_constraint c
|
|
60
|
+
WHERE contype = 'p'
|
|
61
|
+
AND connamespace::regnamespace::text NOT IN ('sde')`)
|
|
62
|
+
.then((r) => r.rows || []);
|
|
63
|
+
const pkList = pks.reduce((acc, curr) => ({
|
|
64
|
+
...acc,
|
|
65
|
+
[curr.connamespace === "public"
|
|
66
|
+
? `${curr.connamespace}.${curr.conrelid}`
|
|
67
|
+
: curr.conrelid]: curr.pk,
|
|
68
|
+
}), {});
|
|
69
|
+
const relationTableTemplate = await getTemplate("table", relationTable);
|
|
70
|
+
const relationPk = pkList[relationTableTemplate?.table || relationTable];
|
|
71
|
+
if (!relationPk) {
|
|
72
|
+
throw NotFoundError("invalid relation: primary key column not found");
|
|
73
|
+
}
|
|
74
|
+
const existsAndRelated = await pg
|
|
75
|
+
.query(`select 1 from ${relationTableTemplate?.table || relationTable} where ${foreignKey}=$1 and ${relationPk}=$2`, [paramsId, relationId])
|
|
76
|
+
.then((r) => r.rowCount > 0);
|
|
77
|
+
if (!existsAndRelated) {
|
|
78
|
+
throw NotFoundError(`relation row not found: ${relationId}`);
|
|
79
|
+
}
|
|
80
|
+
const formData = await getTemplate("form", relationTableTemplate?.form || relationForm);
|
|
81
|
+
const schema = formData?.schema || formData;
|
|
82
|
+
// skip non-present fields in form schema
|
|
83
|
+
if (!ignoreCheck) {
|
|
84
|
+
Object.keys(body || {})
|
|
85
|
+
.filter((key) => !Object.keys(schema || {}).includes(key))
|
|
86
|
+
.forEach((key) => delete body[key]);
|
|
87
|
+
}
|
|
88
|
+
const xssCheck = checkXSS({ body, schema });
|
|
89
|
+
if (xssCheck.error && formData?.xssCheck !== false) {
|
|
90
|
+
logger.file("injection/xss", {
|
|
91
|
+
msg: xssCheck.error,
|
|
92
|
+
table: relationTable,
|
|
93
|
+
form: relationForm,
|
|
94
|
+
uid,
|
|
95
|
+
});
|
|
96
|
+
throw ConflictError("Дані не пройшли валідацію. Приберіть некоректні дані та спробуйте ще раз");
|
|
97
|
+
}
|
|
98
|
+
const fieldCheck = validateData({ body, schema, update: true });
|
|
99
|
+
if (fieldCheck.error) {
|
|
100
|
+
logger.file("injection/formdata", {
|
|
101
|
+
table: relationTable,
|
|
102
|
+
form: relationForm,
|
|
103
|
+
uid,
|
|
104
|
+
...fieldCheck,
|
|
105
|
+
});
|
|
106
|
+
throw ConflictError("Дані не пройшли валідацію. Приберіть некоректні дані та спробуйте ще раз");
|
|
107
|
+
}
|
|
108
|
+
const res = await dataUpdate({
|
|
109
|
+
pg,
|
|
110
|
+
table: relationTableTemplate?.table || relationTable,
|
|
111
|
+
id: relationId,
|
|
112
|
+
data: body,
|
|
113
|
+
uid,
|
|
114
|
+
referer,
|
|
115
|
+
});
|
|
116
|
+
return res;
|
|
117
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionaries.route.d.ts","sourceRoot":"","sources":["../../../../server/routes/dictionaries/dictionaries.route.ts"],"names":[],"mappings":"AAoBA,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,GAAG,EAAE,GAAG,QAmJrC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import readDictionaries from "./functions/read.dictionaries.js";
|
|
2
|
+
import createDictionary from "./functions/create.dictionary.js";
|
|
3
|
+
import updateDictionary from "./functions/update.dictionary.js";
|
|
4
|
+
import deleteDictionary from "./functions/delete.dictionary.js";
|
|
5
|
+
import createDictionaryItem from "./functions/create.dictionary.item.js";
|
|
6
|
+
import updateDictionaryItem from "./functions/update.dictionary.item.js";
|
|
7
|
+
import deleteDictionaryItem from "./functions/delete.dictionary.item.js";
|
|
8
|
+
import { dictionaryParamsSchema, createDictionaryBodySchema, createDictionaryItemBodySchema, updateDictionaryBodySchema, updateDictionaryItemBodySchema, } from "./dictionaries.schema.js";
|
|
9
|
+
const tags = ["core", "dictionaries"];
|
|
10
|
+
const packageName = "fastify-table";
|
|
11
|
+
export default function route(app) {
|
|
12
|
+
app.route({
|
|
13
|
+
method: "GET",
|
|
14
|
+
url: "/dictionaries/:code?",
|
|
15
|
+
config: { tags, package: packageName, policy: "L0" },
|
|
16
|
+
schema: { params: dictionaryParamsSchema },
|
|
17
|
+
handler: async ({ params, pg }) => {
|
|
18
|
+
const result = await readDictionaries({
|
|
19
|
+
code: params.code,
|
|
20
|
+
}, pg);
|
|
21
|
+
return result;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
app.route({
|
|
25
|
+
method: "GET",
|
|
26
|
+
url: "/dictionaries/:code/values",
|
|
27
|
+
config: { tags, package: packageName, policy: "L0" },
|
|
28
|
+
schema: { params: dictionaryParamsSchema },
|
|
29
|
+
handler: async ({ params, pg }) => {
|
|
30
|
+
const result = await readDictionaries({
|
|
31
|
+
code: params.code,
|
|
32
|
+
values: true,
|
|
33
|
+
}, pg);
|
|
34
|
+
return result;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
app.route({
|
|
38
|
+
method: "POST",
|
|
39
|
+
url: "/dictionaries/:id?",
|
|
40
|
+
config: { tags, package: packageName, policy: "L1" },
|
|
41
|
+
schema: {
|
|
42
|
+
params: dictionaryParamsSchema,
|
|
43
|
+
body: createDictionaryBodySchema,
|
|
44
|
+
},
|
|
45
|
+
handler: async ({ params, body, user, pg }) => {
|
|
46
|
+
const result = await createDictionary({
|
|
47
|
+
id: params.id,
|
|
48
|
+
body,
|
|
49
|
+
uid: user?.uid,
|
|
50
|
+
}, pg);
|
|
51
|
+
return result;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
app.route({
|
|
55
|
+
method: "PUT",
|
|
56
|
+
url: "/dictionaries/:id",
|
|
57
|
+
config: { tags, package: packageName, policy: "L1" },
|
|
58
|
+
schema: {
|
|
59
|
+
params: dictionaryParamsSchema,
|
|
60
|
+
body: updateDictionaryBodySchema,
|
|
61
|
+
},
|
|
62
|
+
handler: async ({ params, user, body, pg }) => {
|
|
63
|
+
const result = await updateDictionary({
|
|
64
|
+
id: params.id,
|
|
65
|
+
body,
|
|
66
|
+
uid: user?.uid,
|
|
67
|
+
}, pg);
|
|
68
|
+
return result;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
app.route({
|
|
72
|
+
method: "DELETE",
|
|
73
|
+
url: "/dictionaries/:id",
|
|
74
|
+
config: { tags, package: packageName, policy: "L1" },
|
|
75
|
+
schema: { params: dictionaryParamsSchema },
|
|
76
|
+
handler: async ({ params, user, pg }) => {
|
|
77
|
+
const result = await deleteDictionary({
|
|
78
|
+
id: params.id,
|
|
79
|
+
uid: user?.uid,
|
|
80
|
+
}, pg);
|
|
81
|
+
return result;
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
app.route({
|
|
85
|
+
method: "POST",
|
|
86
|
+
url: "/dictionaries/:code/values/:id?",
|
|
87
|
+
config: { tags, package: packageName, policy: "L1" },
|
|
88
|
+
schema: {
|
|
89
|
+
params: dictionaryParamsSchema,
|
|
90
|
+
body: createDictionaryItemBodySchema,
|
|
91
|
+
},
|
|
92
|
+
handler: async ({ params, body, user, pg }) => {
|
|
93
|
+
const result = await createDictionaryItem({
|
|
94
|
+
id: params.id,
|
|
95
|
+
code: params.code,
|
|
96
|
+
body,
|
|
97
|
+
uid: user?.uid,
|
|
98
|
+
}, pg);
|
|
99
|
+
return result;
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
app.route({
|
|
103
|
+
method: "PUT",
|
|
104
|
+
url: "/dictionaries/:code/values/:id",
|
|
105
|
+
config: { tags, package: packageName, policy: "L1" },
|
|
106
|
+
schema: {
|
|
107
|
+
params: dictionaryParamsSchema,
|
|
108
|
+
body: updateDictionaryItemBodySchema,
|
|
109
|
+
},
|
|
110
|
+
handler: async ({ params, body, user, pg }) => {
|
|
111
|
+
const result = await updateDictionaryItem({
|
|
112
|
+
id: params.id,
|
|
113
|
+
code: params.code,
|
|
114
|
+
body,
|
|
115
|
+
uid: user?.uid,
|
|
116
|
+
}, pg);
|
|
117
|
+
return result;
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
app.route({
|
|
121
|
+
method: "DELETE",
|
|
122
|
+
url: "/dictionaries/:code/values/:id",
|
|
123
|
+
config: { tags, package: packageName, policy: "L1" },
|
|
124
|
+
schema: { params: dictionaryParamsSchema },
|
|
125
|
+
handler: async ({ params, user, pg }) => {
|
|
126
|
+
const result = await deleteDictionaryItem({
|
|
127
|
+
id: params.id,
|
|
128
|
+
code: params.code,
|
|
129
|
+
uid: user?.uid,
|
|
130
|
+
}, pg);
|
|
131
|
+
return result;
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
declare const _default: null;
|
|
2
|
+
export default _default;
|
|
3
|
+
export declare const dictionaryParamsSchema: {
|
|
4
|
+
type: string;
|
|
5
|
+
properties: {
|
|
6
|
+
code: {
|
|
7
|
+
type: string;
|
|
8
|
+
pattern: string;
|
|
9
|
+
};
|
|
10
|
+
id: {
|
|
11
|
+
type: string;
|
|
12
|
+
pattern: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare const createDictionaryBodySchema: {
|
|
17
|
+
type: string;
|
|
18
|
+
additionalProperties: boolean;
|
|
19
|
+
required: string[];
|
|
20
|
+
properties: {
|
|
21
|
+
code: {
|
|
22
|
+
type: string;
|
|
23
|
+
pattern: string;
|
|
24
|
+
};
|
|
25
|
+
name: {
|
|
26
|
+
type: string;
|
|
27
|
+
pattern: string;
|
|
28
|
+
};
|
|
29
|
+
module: {
|
|
30
|
+
type: string;
|
|
31
|
+
pattern: string;
|
|
32
|
+
};
|
|
33
|
+
description: {
|
|
34
|
+
type: string;
|
|
35
|
+
pattern: string;
|
|
36
|
+
};
|
|
37
|
+
editable: {
|
|
38
|
+
type: string;
|
|
39
|
+
};
|
|
40
|
+
values: {
|
|
41
|
+
type: string;
|
|
42
|
+
minItems: number;
|
|
43
|
+
maxItems: number;
|
|
44
|
+
items: {
|
|
45
|
+
required: string[];
|
|
46
|
+
additionalProperties: boolean;
|
|
47
|
+
properties: {
|
|
48
|
+
code: {
|
|
49
|
+
type: string;
|
|
50
|
+
pattern: string;
|
|
51
|
+
};
|
|
52
|
+
name: {
|
|
53
|
+
type: string;
|
|
54
|
+
pattern: string;
|
|
55
|
+
};
|
|
56
|
+
color: {
|
|
57
|
+
type: string;
|
|
58
|
+
};
|
|
59
|
+
icon: {
|
|
60
|
+
type: string;
|
|
61
|
+
};
|
|
62
|
+
sort: {
|
|
63
|
+
type: string;
|
|
64
|
+
minimum: number;
|
|
65
|
+
default: number;
|
|
66
|
+
};
|
|
67
|
+
metadata: {
|
|
68
|
+
type: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export declare const updateDictionaryBodySchema: {
|
|
76
|
+
type: string;
|
|
77
|
+
additionalProperties: boolean;
|
|
78
|
+
properties: {
|
|
79
|
+
code: {
|
|
80
|
+
type: string;
|
|
81
|
+
pattern: string;
|
|
82
|
+
};
|
|
83
|
+
name: {
|
|
84
|
+
type: string;
|
|
85
|
+
pattern: string;
|
|
86
|
+
};
|
|
87
|
+
module: {
|
|
88
|
+
type: string;
|
|
89
|
+
pattern: string;
|
|
90
|
+
};
|
|
91
|
+
description: {
|
|
92
|
+
type: string;
|
|
93
|
+
pattern: string;
|
|
94
|
+
};
|
|
95
|
+
editable: {
|
|
96
|
+
type: string;
|
|
97
|
+
};
|
|
98
|
+
values: {
|
|
99
|
+
type: string;
|
|
100
|
+
minItems: number;
|
|
101
|
+
maxItems: number;
|
|
102
|
+
items: {
|
|
103
|
+
required: string[];
|
|
104
|
+
additionalProperties: boolean;
|
|
105
|
+
properties: {
|
|
106
|
+
code: {
|
|
107
|
+
type: string;
|
|
108
|
+
pattern: string;
|
|
109
|
+
};
|
|
110
|
+
name: {
|
|
111
|
+
type: string;
|
|
112
|
+
pattern: string;
|
|
113
|
+
};
|
|
114
|
+
color: {
|
|
115
|
+
type: string;
|
|
116
|
+
};
|
|
117
|
+
icon: {
|
|
118
|
+
type: string;
|
|
119
|
+
};
|
|
120
|
+
sort: {
|
|
121
|
+
type: string;
|
|
122
|
+
minimum: number;
|
|
123
|
+
default: number;
|
|
124
|
+
};
|
|
125
|
+
metadata: {
|
|
126
|
+
type: string;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
system: {
|
|
132
|
+
type: string;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
export declare const createDictionaryItemBodySchema: {
|
|
137
|
+
type: string;
|
|
138
|
+
properties: {
|
|
139
|
+
code: {
|
|
140
|
+
type: string;
|
|
141
|
+
pattern: string;
|
|
142
|
+
};
|
|
143
|
+
name: {
|
|
144
|
+
type: string;
|
|
145
|
+
pattern: string;
|
|
146
|
+
};
|
|
147
|
+
color: {
|
|
148
|
+
type: string;
|
|
149
|
+
};
|
|
150
|
+
icon: {
|
|
151
|
+
type: string;
|
|
152
|
+
};
|
|
153
|
+
sort: {
|
|
154
|
+
type: string;
|
|
155
|
+
minimum: number;
|
|
156
|
+
default: number;
|
|
157
|
+
};
|
|
158
|
+
metadata: {
|
|
159
|
+
type: string;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
export declare const updateDictionaryItemBodySchema: {
|
|
164
|
+
type: string;
|
|
165
|
+
properties: {
|
|
166
|
+
code: {
|
|
167
|
+
type: string;
|
|
168
|
+
pattern: string;
|
|
169
|
+
};
|
|
170
|
+
name: {
|
|
171
|
+
type: string;
|
|
172
|
+
pattern: string;
|
|
173
|
+
};
|
|
174
|
+
color: {
|
|
175
|
+
type: string;
|
|
176
|
+
};
|
|
177
|
+
icon: {
|
|
178
|
+
type: string;
|
|
179
|
+
};
|
|
180
|
+
sort: {
|
|
181
|
+
type: string;
|
|
182
|
+
minimum: number;
|
|
183
|
+
default: number;
|
|
184
|
+
};
|
|
185
|
+
metadata: {
|
|
186
|
+
type: string;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=dictionaries.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionaries.schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/dictionaries/dictionaries.schema.ts"],"names":[],"mappings":";AAAA,wBAAoB;AA2CpB,eAAO,MAAM,sBAAsB;;;;;;;;;;;;CAMlC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CActC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBtC,CAAC;AAEF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;CAG1C,CAAC;AAEF,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;CAG1C,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export default null;
|
|
2
|
+
const idSchema = {
|
|
3
|
+
type: "string",
|
|
4
|
+
pattern: "^([\\d\\w_.-]+)$",
|
|
5
|
+
};
|
|
6
|
+
const codeSchema = {
|
|
7
|
+
type: "string",
|
|
8
|
+
pattern: "^([\\d\\w_.-]+)$",
|
|
9
|
+
};
|
|
10
|
+
const nameSchema = {
|
|
11
|
+
type: "string",
|
|
12
|
+
pattern: "^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$",
|
|
13
|
+
};
|
|
14
|
+
const moduleSchema = {
|
|
15
|
+
type: "string",
|
|
16
|
+
pattern: "^([\\d\\w_.-]+)$",
|
|
17
|
+
};
|
|
18
|
+
const descriptionSchema = {
|
|
19
|
+
type: "string",
|
|
20
|
+
pattern: "^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$",
|
|
21
|
+
};
|
|
22
|
+
const itemSchema = {
|
|
23
|
+
code: codeSchema,
|
|
24
|
+
name: nameSchema,
|
|
25
|
+
color: { type: "string" },
|
|
26
|
+
icon: { type: "string" },
|
|
27
|
+
sort: { type: "integer", minimum: 0, default: 0 },
|
|
28
|
+
metadata: { type: "object" },
|
|
29
|
+
};
|
|
30
|
+
const valuesSchema = {
|
|
31
|
+
type: "array",
|
|
32
|
+
minItems: 2,
|
|
33
|
+
maxItems: 100,
|
|
34
|
+
items: {
|
|
35
|
+
required: ["code", "name", "sort"],
|
|
36
|
+
additionalProperties: false,
|
|
37
|
+
properties: itemSchema,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export const dictionaryParamsSchema = {
|
|
41
|
+
type: "object",
|
|
42
|
+
properties: {
|
|
43
|
+
code: codeSchema,
|
|
44
|
+
id: idSchema,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
export const createDictionaryBodySchema = {
|
|
48
|
+
type: "object",
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
required: ["code", "name"],
|
|
51
|
+
properties: {
|
|
52
|
+
code: codeSchema,
|
|
53
|
+
name: nameSchema,
|
|
54
|
+
module: moduleSchema,
|
|
55
|
+
description: descriptionSchema,
|
|
56
|
+
editable: {
|
|
57
|
+
type: "boolean",
|
|
58
|
+
},
|
|
59
|
+
values: valuesSchema,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
export const updateDictionaryBodySchema = {
|
|
63
|
+
type: "object",
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
properties: {
|
|
66
|
+
code: codeSchema,
|
|
67
|
+
name: nameSchema,
|
|
68
|
+
module: moduleSchema,
|
|
69
|
+
description: descriptionSchema,
|
|
70
|
+
editable: {
|
|
71
|
+
type: "boolean",
|
|
72
|
+
},
|
|
73
|
+
values: valuesSchema,
|
|
74
|
+
system: {
|
|
75
|
+
type: "boolean",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
export const createDictionaryItemBodySchema = {
|
|
80
|
+
type: "object",
|
|
81
|
+
properties: itemSchema,
|
|
82
|
+
};
|
|
83
|
+
export const updateDictionaryItemBodySchema = {
|
|
84
|
+
type: "object",
|
|
85
|
+
properties: itemSchema,
|
|
86
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {String} id Dictionary ID, optional
|
|
4
|
+
*/
|
|
5
|
+
export default function createDictionary({ id, body, uid, }: {
|
|
6
|
+
id: string;
|
|
7
|
+
body: Record<string, any>;
|
|
8
|
+
uid: string;
|
|
9
|
+
}, pg?: any): Promise<any>;
|
|
10
|
+
//# sourceMappingURL=create.dictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.dictionary.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/create.dictionary.ts"],"names":[],"mappings":"AAOA;;;GAGG;AAEH,wBAA8B,gBAAgB,CAC5C,EACE,EAAE,EACF,IAAI,EACJ,GAAG,GACJ,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBA8EtB"}
|