@opengis/fastify-table 2.5.44 → 2.5.47

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/functions.d.ts +1 -0
  2. package/dist/functions.d.ts.map +1 -1
  3. package/dist/functions.js +122 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +4 -1
  6. package/dist/server/migrations/dictionaries.sql +79 -0
  7. package/dist/server/plugins/crud/funcs/dataDelete.d.ts +2 -1
  8. package/dist/server/plugins/crud/funcs/dataDelete.d.ts.map +1 -1
  9. package/dist/server/plugins/crud/funcs/dataDelete.js +2 -2
  10. package/dist/server/plugins/file/utils/inspectContent.d.ts +1 -1
  11. package/dist/server/plugins/file/utils/inspectContent.d.ts.map +1 -1
  12. package/dist/server/plugins/file/utils/inspectContent.js +23 -7
  13. package/dist/server/plugins/policy/funcs/checkXSS.d.ts.map +1 -1
  14. package/dist/server/plugins/policy/funcs/checkXSS.js +1 -0
  15. package/dist/server/plugins/upload/s3.d.ts.map +1 -1
  16. package/dist/server/plugins/upload/s3.js +8 -0
  17. package/dist/server/routes/crud/controllers/insert.d.ts +1 -2
  18. package/dist/server/routes/crud/controllers/insert.d.ts.map +1 -1
  19. package/dist/server/routes/crud/controllers/insert.js +1 -1
  20. package/dist/server/routes/crud/controllers/update.js +1 -1
  21. package/dist/server/routes/dictionaries/dictionaries.route.d.ts +2 -0
  22. package/dist/server/routes/dictionaries/dictionaries.route.d.ts.map +1 -0
  23. package/dist/server/routes/dictionaries/dictionaries.route.js +134 -0
  24. package/dist/server/routes/dictionaries/dictionaries.schema.d.ts +190 -0
  25. package/dist/server/routes/dictionaries/dictionaries.schema.d.ts.map +1 -0
  26. package/dist/server/routes/dictionaries/dictionaries.schema.js +86 -0
  27. package/dist/server/routes/dictionaries/functions/create.dictionary.d.ts +10 -0
  28. package/dist/server/routes/dictionaries/functions/create.dictionary.d.ts.map +1 -0
  29. package/dist/server/routes/dictionaries/functions/create.dictionary.item.d.ts +13 -0
  30. package/dist/server/routes/dictionaries/functions/create.dictionary.item.d.ts.map +1 -0
  31. package/dist/server/routes/dictionaries/functions/create.dictionary.item.js +57 -0
  32. package/dist/server/routes/dictionaries/functions/create.dictionary.js +76 -0
  33. package/dist/server/routes/dictionaries/functions/delete.dictionary.d.ts +9 -0
  34. package/dist/server/routes/dictionaries/functions/delete.dictionary.d.ts.map +1 -0
  35. package/dist/server/routes/dictionaries/functions/delete.dictionary.item.d.ts +11 -0
  36. package/dist/server/routes/dictionaries/functions/delete.dictionary.item.d.ts.map +1 -0
  37. package/dist/server/routes/dictionaries/functions/delete.dictionary.item.js +32 -0
  38. package/dist/server/routes/dictionaries/functions/delete.dictionary.js +28 -0
  39. package/dist/server/routes/dictionaries/functions/read.dictionaries.d.ts +5 -0
  40. package/dist/server/routes/dictionaries/functions/read.dictionaries.d.ts.map +1 -0
  41. package/dist/server/routes/dictionaries/functions/read.dictionaries.js +27 -0
  42. package/dist/server/routes/dictionaries/functions/update.dictionary.d.ts +10 -0
  43. package/dist/server/routes/dictionaries/functions/update.dictionary.d.ts.map +1 -0
  44. package/dist/server/routes/dictionaries/functions/update.dictionary.item.d.ts +13 -0
  45. package/dist/server/routes/dictionaries/functions/update.dictionary.item.d.ts.map +1 -0
  46. package/dist/server/routes/dictionaries/functions/update.dictionary.item.js +48 -0
  47. package/dist/server/routes/dictionaries/functions/update.dictionary.js +51 -0
  48. package/package.json +1 -1
@@ -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"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ *
3
+ * @param {String} id Item ID, optional
4
+ * @param {String} code Dictionary code (filename)
5
+ * @param {String} body.code Item code
6
+ */
7
+ export default function createDictionaryItem({ id, code, body, uid, }: {
8
+ id: string;
9
+ code: string;
10
+ body: Record<string, any>;
11
+ uid: string;
12
+ }, pg?: any): Promise<any>;
13
+ //# sourceMappingURL=create.dictionary.item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.dictionary.item.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/create.dictionary.item.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AAEH,wBAA8B,oBAAoB,CAChD,EACE,EAAE,EACF,IAAI,EACJ,IAAI,EACJ,GAAG,GACJ,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBA2DtB"}
@@ -0,0 +1,57 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataInsert from "../../../plugins/crud/funcs/dataInsert.js";
3
+ import { BadRequestError, NotFoundError } from "../../../../errors.js";
4
+ import updateDictionary from "./update.dictionary.js";
5
+ /**
6
+ *
7
+ * @param {String} id Item ID, optional
8
+ * @param {String} code Dictionary code (filename)
9
+ * @param {String} body.code Item code
10
+ */
11
+ export default async function createDictionaryItem({ id, code, body, uid, }, pg = pgClients.client) {
12
+ if (!pg) {
13
+ throw new Error("empty pg");
14
+ }
15
+ if (!code) {
16
+ throw BadRequestError("not enough params: code");
17
+ }
18
+ if (!body) {
19
+ throw BadRequestError("not enough params: body");
20
+ }
21
+ if (!body.code) {
22
+ throw BadRequestError("not enough body params: code");
23
+ }
24
+ if (!body.name) {
25
+ throw BadRequestError("not enough body params: name");
26
+ }
27
+ const { system, id: dictionaryId } = await pg
28
+ .query("select id from admin.dictionaries where code=$1", [code])
29
+ .then((r) => ({ system: r.rows?.[0]?.system, id: r.rows?.[0]?.id }));
30
+ if (!dictionaryId) {
31
+ throw NotFoundError("dictionary not found");
32
+ }
33
+ // make custom
34
+ if (system) {
35
+ await updateDictionary({ id: dictionaryId, body: { system: false }, uid }, pg);
36
+ }
37
+ const { data } = await dataInsert({
38
+ id,
39
+ table: "admin.dictionary_items",
40
+ data: {
41
+ code: body.code,
42
+ dictionary_id: dictionaryId,
43
+ name: body.name,
44
+ description: body.description,
45
+ color: body.color,
46
+ icon: body.icon,
47
+ parent_id: body.parent_id,
48
+ sort_order: body.sort,
49
+ metadata: body.metadata,
50
+ system: false,
51
+ active: body.active === false ? false : true,
52
+ },
53
+ pg,
54
+ uid,
55
+ });
56
+ return data;
57
+ }
@@ -0,0 +1,76 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataInsert from "../../../plugins/crud/funcs/dataInsert.js";
3
+ import deleteDictionary from "./delete.dictionary.js";
4
+ import { BadRequestError } from "../../../../errors.js";
5
+ /**
6
+ *
7
+ * @param {String} id Dictionary ID, optional
8
+ */
9
+ export default async function createDictionary({ id, body, uid, }, pg = pgClients.client) {
10
+ if (!pg) {
11
+ throw new Error("empty pg");
12
+ }
13
+ if (!body) {
14
+ throw BadRequestError("not enough params: body");
15
+ }
16
+ if (!body?.values?.length) {
17
+ // throw BadRequestError("not enough body params: values");
18
+ }
19
+ const client = await pg.connect();
20
+ try {
21
+ const systemDictionaryId = await pg
22
+ .query("select id from admin.dictionaries where system and id = $1", [id])
23
+ .then((r) => r.rows?.[0]?.id);
24
+ await client.query("begin");
25
+ if (systemDictionaryId) {
26
+ await deleteDictionary({ id: systemDictionaryId, uid }, client);
27
+ }
28
+ const { data } = (await dataInsert({
29
+ id,
30
+ table: "admin.dictionaries",
31
+ data: {
32
+ code: body.code,
33
+ name: body.name,
34
+ module: body.module,
35
+ description: body.description,
36
+ source: "custom",
37
+ system: false,
38
+ editable: body.editable === false ? false : true,
39
+ },
40
+ pg: client,
41
+ uid,
42
+ })) || {};
43
+ if (!data) {
44
+ throw new Error("dictionary insert error");
45
+ }
46
+ const values = await Promise.all((body.values || []).map(async (el) => {
47
+ return dataInsert({
48
+ table: "admin.dictionary_items",
49
+ data: {
50
+ dictionary_id: id,
51
+ code: el.code,
52
+ name: el.name,
53
+ description: el.description,
54
+ color: el.color,
55
+ icon: el.icon,
56
+ parent_id: el.parent_id,
57
+ sort_order: el.sort_order,
58
+ metadata: el.metadata,
59
+ system: false,
60
+ active: el.active === false ? false : true,
61
+ },
62
+ pg: client,
63
+ uid,
64
+ }).then((r) => r.data);
65
+ }));
66
+ await client.query("commit");
67
+ return { ...data, values };
68
+ }
69
+ catch (err) {
70
+ await client.query("rollback");
71
+ throw err;
72
+ }
73
+ finally {
74
+ client.release();
75
+ }
76
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @param {String} id Dictionary ID
4
+ */
5
+ export default function deleteDictionary({ id, uid, }: {
6
+ id: string;
7
+ uid: string;
8
+ }, pg?: any): Promise<any>;
9
+ //# sourceMappingURL=delete.dictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete.dictionary.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/delete.dictionary.ts"],"names":[],"mappings":"AAKA;;;GAGG;AAEH,wBAA8B,gBAAgB,CAC5C,EACE,EAAE,EACF,GAAG,GACJ,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBA6BtB"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * @param {String} id Item ID
4
+ * @param {String} code Dictionary code (filename)
5
+ */
6
+ export default function deleteDictionaryItem({ id, code, uid, }: {
7
+ id: string;
8
+ code: string;
9
+ uid: string;
10
+ }, pg?: any): Promise<any>;
11
+ //# sourceMappingURL=delete.dictionary.item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete.dictionary.item.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/delete.dictionary.item.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AAEH,wBAA8B,oBAAoB,CAChD,EACE,EAAE,EACF,IAAI,EACJ,GAAG,GACJ,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBAiCtB"}
@@ -0,0 +1,32 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataDelete from "../../../plugins/crud/funcs/dataDelete.js";
3
+ import { BadRequestError, NotFoundError } from "../../../../errors.js";
4
+ /**
5
+ *
6
+ * @param {String} id Item ID
7
+ * @param {String} code Dictionary code (filename)
8
+ */
9
+ export default async function deleteDictionaryItem({ id, code, uid, }, pg = pgClients.client) {
10
+ if (!pg) {
11
+ throw new Error("empty pg");
12
+ }
13
+ if (!id) {
14
+ throw BadRequestError("not enough params: id");
15
+ }
16
+ if (!code) {
17
+ throw BadRequestError("not enough params: code");
18
+ }
19
+ const itemId = await pg
20
+ .query("select id from admin.dictionary_items where dictionary_id in (select id from admin.dictionaries where $1 in (id,code) ) and $2 in (id,code)", [code, id])
21
+ .then((r) => r.rows?.[0]?.id);
22
+ if (!itemId) {
23
+ throw NotFoundError("dictionary item not found");
24
+ }
25
+ const item = await dataDelete({
26
+ id: itemId,
27
+ table: "admin.dictionary_items",
28
+ pg,
29
+ uid,
30
+ });
31
+ return item;
32
+ }
@@ -0,0 +1,28 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataDelete from "../../../plugins/crud/funcs/dataDelete.js";
3
+ import { BadRequestError, NotFoundError } from "../../../../errors.js";
4
+ /**
5
+ *
6
+ * @param {String} id Dictionary ID
7
+ */
8
+ export default async function deleteDictionary({ id, uid, }, pg = pgClients.client) {
9
+ if (!pg) {
10
+ throw new Error("empty pg");
11
+ }
12
+ if (!id) {
13
+ throw BadRequestError("not enough params: id");
14
+ }
15
+ const values = await pg
16
+ .query("delete from admin.dictionary_items where dictionary_id=$1 returning id,code,name,color,icon", [id])
17
+ .then((r) => r.rowCount || 0);
18
+ const row = await dataDelete({
19
+ table: "admin.dictionaries",
20
+ id,
21
+ uid,
22
+ pg,
23
+ });
24
+ if (!row) {
25
+ throw NotFoundError("dictionary not found");
26
+ }
27
+ return { ...row, values };
28
+ }
@@ -0,0 +1,5 @@
1
+ export default function readDictionaries({ code, values, }: {
2
+ code: string;
3
+ values?: boolean;
4
+ }, pg?: any): Promise<any>;
5
+ //# sourceMappingURL=read.dictionaries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.dictionaries.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/read.dictionaries.ts"],"names":[],"mappings":"AAIA,wBAA8B,gBAAgB,CAC5C,EACE,IAAI,EACJ,MAAc,GACf,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,EACD,EAAE,MAAmB,gBAqCtB"}
@@ -0,0 +1,27 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import { NotFoundError } from "../../../../errors.js";
3
+ export default async function readDictionaries({ code, values = false, }, pg = pgClients.client) {
4
+ if (!pg) {
5
+ throw new Error("empty pg");
6
+ }
7
+ if (!code) {
8
+ const rows = await pg
9
+ .query("select code,name,module,source from admin.dictionaries")
10
+ .then((r) => r.rows || []);
11
+ return { total: rows.length, rows };
12
+ }
13
+ // code is unique
14
+ const rows = await pg
15
+ .query("select id, code, name, module, description, source, editable, system from admin.dictionaries where $1 in (code, id) limit 1", [code])
16
+ .then((r) => r.rows || []);
17
+ if (!rows.length) {
18
+ throw NotFoundError("dictionary not found");
19
+ }
20
+ const items = await pg
21
+ .query("select code, name, description, color, icon, sort_order as sort, parent_id, active, system, metadata from admin.dictionary_items where dictionary_id=$1", [rows[0].id])
22
+ .then((r) => r.rows || []);
23
+ if (values) {
24
+ return items;
25
+ }
26
+ return { ...rows[0], values: items };
27
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @param {String} id Dictionary ID
4
+ */
5
+ export default function updateDictionary({ id, body, uid, }: {
6
+ id: string;
7
+ body: Record<string, any>;
8
+ uid: string;
9
+ }, pg?: any): Promise<any>;
10
+ //# sourceMappingURL=update.dictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.dictionary.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/update.dictionary.ts"],"names":[],"mappings":"AAIA;;;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,gBAyDtB"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ *
3
+ * @param {String} id Item ID
4
+ * @param {String} code Dictionary code (filename)
5
+ * @param {String} body.code Item code
6
+ */
7
+ export default function updateDictionaryItem({ id, code, body, uid, }: {
8
+ id: string;
9
+ code: string;
10
+ body: Record<string, any>;
11
+ uid: string;
12
+ }, pg?: any): Promise<any>;
13
+ //# sourceMappingURL=update.dictionary.item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.dictionary.item.d.ts","sourceRoot":"","sources":["../../../../../server/routes/dictionaries/functions/update.dictionary.item.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AAEH,wBAA8B,oBAAoB,CAChD,EACE,EAAE,EACF,IAAI,EACJ,IAAI,EACJ,GAAG,GACJ,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBAiDtB"}
@@ -0,0 +1,48 @@
1
+ import pgClients from "../../../plugins/pg/pgClients.js";
2
+ import dataUpdate from "../../../plugins/crud/funcs/dataUpdate.js";
3
+ import updateDictionary from "./update.dictionary.js";
4
+ import { BadRequestError, NotFoundError } from "../../../../errors.js";
5
+ /**
6
+ *
7
+ * @param {String} id Item ID
8
+ * @param {String} code Dictionary code (filename)
9
+ * @param {String} body.code Item code
10
+ */
11
+ export default async function updateDictionaryItem({ id, code, body, uid, }, pg = pgClients.client) {
12
+ if (!pg) {
13
+ throw new Error("empty pg");
14
+ }
15
+ if (!code) {
16
+ throw BadRequestError("not enough params: code");
17
+ }
18
+ if (!body) {
19
+ throw BadRequestError("not enough params: body");
20
+ }
21
+ const { system, id: dictionaryId } = await pg
22
+ .query("select id from admin.dictionaries where $1 in (id,code)", [code])
23
+ .then((r) => ({ system: r.rows?.[0]?.system, id: r.rows?.[0]?.id }));
24
+ if (!dictionaryId) {
25
+ throw NotFoundError("dictionary not found");
26
+ }
27
+ const itemId = await pg
28
+ .query("select id from admin.dictionary_items where $1 in (id,code)", [id])
29
+ .then((r) => r.rows?.[0]?.id);
30
+ if (!itemId) {
31
+ throw NotFoundError("dictionary item not found");
32
+ }
33
+ // make custom
34
+ if (system) {
35
+ await updateDictionary({ id: dictionaryId, body: { system: false }, uid }, pg);
36
+ }
37
+ const row = await dataUpdate({
38
+ id: itemId,
39
+ table: "admin.dictionary_items",
40
+ data: {
41
+ ...body,
42
+ sort_order: body.sort,
43
+ },
44
+ pg,
45
+ uid,
46
+ });
47
+ return row;
48
+ }