@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,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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import pgClients from "../../../plugins/pg/pgClients.js";
|
|
2
|
+
import dataInsert from "../../../plugins/crud/funcs/dataInsert.js";
|
|
3
|
+
import dataUpdate from "../../../plugins/crud/funcs/dataUpdate.js";
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {String} id Dictionary ID
|
|
7
|
+
*/
|
|
8
|
+
export default async function updateDictionary({ id, body, uid, }, pg = pgClients.client) {
|
|
9
|
+
if (!pg) {
|
|
10
|
+
throw new Error("empty pg");
|
|
11
|
+
}
|
|
12
|
+
if (!id) {
|
|
13
|
+
throw new Error("not enough params: id");
|
|
14
|
+
}
|
|
15
|
+
if (!body) {
|
|
16
|
+
throw new Error("not enough params: body");
|
|
17
|
+
}
|
|
18
|
+
const row = await dataUpdate({
|
|
19
|
+
id,
|
|
20
|
+
table: "admin.dictionaries",
|
|
21
|
+
data: body,
|
|
22
|
+
pg,
|
|
23
|
+
uid,
|
|
24
|
+
});
|
|
25
|
+
if (body.values?.length) {
|
|
26
|
+
const client = await pg.connect();
|
|
27
|
+
try {
|
|
28
|
+
await client.query("begin");
|
|
29
|
+
await client.query("delete from admin.dictionary_items where dictionary_id = $1", [id]);
|
|
30
|
+
const values = await Promise.all(body.values.map(async (item) => dataInsert({
|
|
31
|
+
table: "admin.dictionary_items",
|
|
32
|
+
data: {
|
|
33
|
+
...item,
|
|
34
|
+
dictionary_id: id,
|
|
35
|
+
},
|
|
36
|
+
pg: client,
|
|
37
|
+
uid,
|
|
38
|
+
}).then((r) => r.data)));
|
|
39
|
+
await client.query("commit");
|
|
40
|
+
return { ...row, values };
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
await client.query("rollback");
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
client.release();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return row;
|
|
51
|
+
}
|
|
@@ -3,13 +3,13 @@ const resizeSchema = {
|
|
|
3
3
|
type: "object",
|
|
4
4
|
properties: {
|
|
5
5
|
filepath: { type: "string" },
|
|
6
|
-
quality: { type: "
|
|
6
|
+
quality: { type: "integer", exclusiveMinimum: 0, maximum: 100 },
|
|
7
7
|
size: {
|
|
8
8
|
type: "string",
|
|
9
9
|
pattern: "^((\\d{1,4})x(\\d{1,4})|(\\d{1,4})x|x(\\d{1,4}))$",
|
|
10
10
|
},
|
|
11
|
-
w: { type: "
|
|
12
|
-
h: { type: "
|
|
11
|
+
w: { type: "integer", minimum: 1, maximum: 2048 },
|
|
12
|
+
h: { type: "integer", minimum: 1, maximum: 2048 },
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
15
|
};
|
|
@@ -17,9 +17,9 @@ const exportSchema = {
|
|
|
17
17
|
querystring: {
|
|
18
18
|
type: "object",
|
|
19
19
|
properties: {
|
|
20
|
-
limit: { type: "
|
|
21
|
-
batchLimit: { type: "
|
|
22
|
-
page: { type: "
|
|
20
|
+
limit: { type: "integer", minimum: 1 },
|
|
21
|
+
batchLimit: { type: "integer", minimum: 1 },
|
|
22
|
+
page: { type: "integer", minimum: 1 },
|
|
23
23
|
key: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
|
|
24
24
|
},
|
|
25
25
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FastifyReply } from "fastify";
|
|
2
2
|
import type { ExtendedPG } from "../../../types/core.js";
|
|
3
|
-
export default function dataAPI({ pg, params, table, id, headers, query, user, contextQuery, searchColumn, sufix, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, isExport, }: {
|
|
3
|
+
export default function dataAPI({ pg, params, table, id, headers, query, user, contextQuery, searchColumn, sufix, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, isExport, called: isCalled, }: {
|
|
4
4
|
pg?: ExtendedPG;
|
|
5
5
|
params?: {
|
|
6
6
|
id?: string;
|
|
@@ -20,5 +20,6 @@ export default function dataAPI({ pg, params, table, id, headers, query, user, c
|
|
|
20
20
|
accessQuery?: string;
|
|
21
21
|
columns?: string[];
|
|
22
22
|
isExport?: boolean;
|
|
23
|
-
|
|
23
|
+
called?: boolean;
|
|
24
|
+
}, _?: FastifyReply, called1?: any): Promise<any>;
|
|
24
25
|
//# sourceMappingURL=getData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/functions/getData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/functions/getData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAuFzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,KAAK,EACL,EAAE,EACF,OAAY,EACZ,KAAU,EACV,IAAS,EACT,YAAY,EACZ,YAAY,EACZ,KAAY,EACZ,UAAU,EACV,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,YAAY,EACrB,QAAgB,EAChB,MAAM,EAAE,QAAQ,GACjB,EAAE;IACD,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,MAAM,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,EACD,CAAC,CAAC,EAAE,YAAY,EAChB,OAAO,CAAC,EAAE,GAAG,gBAo5Bd"}
|
|
@@ -25,19 +25,6 @@ const components = {
|
|
|
25
25
|
"vs-widget-file": "select 'vs-widget-file' as component, count(*) from crm.files where entity_id=$1 and file_status<>3",
|
|
26
26
|
"vs-widget-comments": "select 'vs-widget-comments' as component, count(*) from crm.communications where entity_id=$1",
|
|
27
27
|
};
|
|
28
|
-
const mockReply = {
|
|
29
|
-
response: {},
|
|
30
|
-
// redirect: (txt) => txt,
|
|
31
|
-
redirect: (txt) => Object.assign(mockReply.response, {
|
|
32
|
-
body: txt,
|
|
33
|
-
statusCode: mockReply.response.statusCode || 200,
|
|
34
|
-
}),
|
|
35
|
-
status: (statusCode) => {
|
|
36
|
-
Object.assign(mockReply.response, { status: statusCode });
|
|
37
|
-
return mockReply;
|
|
38
|
-
},
|
|
39
|
-
send: (txt) => Object.assign(mockReply.response, txt),
|
|
40
|
-
};
|
|
41
28
|
function getOrder({ queryOrder, queryDesc, defaultOrder, columnList, cols, sqlColumns, iscalled = false, }) {
|
|
42
29
|
if (iscalled && queryOrder) {
|
|
43
30
|
return `order by ${queryOrder}`;
|
|
@@ -59,7 +46,8 @@ function getOrder({ queryOrder, queryDesc, defaultOrder, columnList, cols, sqlCo
|
|
|
59
46
|
const checkInline = {};
|
|
60
47
|
const maxLimit = 100;
|
|
61
48
|
const defaultLimit = 20;
|
|
62
|
-
export default async function dataAPI({ pg = pgClients.client, params, table, id, headers = {}, query = {}, user = {}, contextQuery, searchColumn, sufix = true, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, isExport = false, },
|
|
49
|
+
export default async function dataAPI({ pg = pgClients.client, params, table, id, headers = {}, query = {}, user = {}, contextQuery, searchColumn, sufix = true, filterList, actions: actionsParam, accessQuery: accessQueryParam, columns: columnsParam, isExport = false, called: isCalled, }, _, called1) {
|
|
50
|
+
const called = called1 || isCalled;
|
|
63
51
|
const time = Date.now();
|
|
64
52
|
const timeArr = [Date.now()];
|
|
65
53
|
const { uid } = user;
|
|
@@ -134,7 +134,7 @@ declare const searchSchema: {
|
|
|
134
134
|
};
|
|
135
135
|
sql: {
|
|
136
136
|
type: string;
|
|
137
|
-
|
|
137
|
+
enum: number[];
|
|
138
138
|
};
|
|
139
139
|
};
|
|
140
140
|
};
|
|
@@ -170,14 +170,15 @@ declare const suggestSchema: {
|
|
|
170
170
|
};
|
|
171
171
|
sql: {
|
|
172
172
|
type: string;
|
|
173
|
+
enum: number[];
|
|
173
174
|
};
|
|
174
175
|
count: {
|
|
175
176
|
type: string;
|
|
177
|
+
enum: number[];
|
|
176
178
|
};
|
|
177
179
|
json: {
|
|
178
180
|
type: string;
|
|
179
|
-
|
|
180
|
-
maximum: number;
|
|
181
|
+
enum: number[];
|
|
181
182
|
};
|
|
182
183
|
};
|
|
183
184
|
};
|
|
@@ -223,7 +224,7 @@ declare const cardTabDataSchema: {
|
|
|
223
224
|
properties: {
|
|
224
225
|
sql: {
|
|
225
226
|
type: string;
|
|
226
|
-
|
|
227
|
+
enum: number[];
|
|
227
228
|
};
|
|
228
229
|
};
|
|
229
230
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/table/schema.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBpB,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BhB,CAAC;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAajB,CAAC;AAEF,QAAA,MAAM,aAAa
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/table/schema.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBpB,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BhB,CAAC;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAajB,CAAC;AAEF,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsBlB,CAAC;AAEF,QAAA,MAAM,UAAU;;;;;;;;;;;;;;CAQf,CAAC;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;CAOjB,CAAC;AAEF,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;CAatB,CAAC;AAEF,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;CAQtB,CAAC;AAEF,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,UAAU,EACV,YAAY,EACZ,iBAAiB,GAClB,CAAC"}
|
|
@@ -2,8 +2,8 @@ const tableDataSchema = {
|
|
|
2
2
|
type: "object",
|
|
3
3
|
properties: {
|
|
4
4
|
querystring: {
|
|
5
|
-
limit: { type: "
|
|
6
|
-
page: { type: "
|
|
5
|
+
limit: { type: "integer", minimum: 1 },
|
|
6
|
+
page: { type: "integer", minimum: 1 },
|
|
7
7
|
// filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
|
|
8
8
|
// search: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
|
|
9
9
|
order: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
|
|
@@ -13,7 +13,7 @@ const tableDataSchema = {
|
|
|
13
13
|
bbox: { type: "string", pattern: "^([\\d\\s,.-]+)$" },
|
|
14
14
|
polyline: { type: "string", pattern: "^([\\d\\w|@{}~_`]+)$" },
|
|
15
15
|
// key: { type: 'string', pattern: '^([\\d\\w_]+)$' },
|
|
16
|
-
sql: { type: "
|
|
16
|
+
sql: { type: "integer" },
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
params: {
|
|
@@ -28,8 +28,8 @@ const tableSchema = {
|
|
|
28
28
|
querystring: {
|
|
29
29
|
type: "object",
|
|
30
30
|
properties: {
|
|
31
|
-
limit: { type: "
|
|
32
|
-
page: { type: "
|
|
31
|
+
limit: { type: "integer", minimum: 1 },
|
|
32
|
+
page: { type: "integer", minimum: 1 },
|
|
33
33
|
// filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
|
|
34
34
|
// search: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
|
|
35
35
|
order: { type: "string", pattern: "^$|^[\\d\\w_.-]+$" },
|
|
@@ -40,7 +40,7 @@ const tableSchema = {
|
|
|
40
40
|
// polyline: { type: 'string', pattern: '^([\\d\\w\\|@\\/\\{\\}~_`]+)$' },
|
|
41
41
|
key: { type: "string", pattern: "^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$" },
|
|
42
42
|
uid: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
|
|
43
|
-
sql: { type: "
|
|
43
|
+
sql: { type: "integer" },
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
params: {
|
|
@@ -55,13 +55,13 @@ const searchSchema = {
|
|
|
55
55
|
querystring: {
|
|
56
56
|
type: "object",
|
|
57
57
|
properties: {
|
|
58
|
-
page: { type: "
|
|
59
|
-
limit: { type: "
|
|
58
|
+
page: { type: "integer", minimum: 1 },
|
|
59
|
+
limit: { type: "integer", minimum: 1 },
|
|
60
60
|
order: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
|
|
61
61
|
desc: { type: "string", pattern: "^(\\d+)$" },
|
|
62
62
|
key: { type: "string", pattern: "^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$" },
|
|
63
63
|
table: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
|
|
64
|
-
sql: { type: "
|
|
64
|
+
sql: { type: "integer", enum: [1] },
|
|
65
65
|
},
|
|
66
66
|
},
|
|
67
67
|
};
|
|
@@ -76,9 +76,9 @@ const suggestSchema = {
|
|
|
76
76
|
name: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
|
|
77
77
|
key: { type: "string", pattern: "^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$" },
|
|
78
78
|
val: { type: "string", pattern: "([\\d\\w]+)$" },
|
|
79
|
-
sql: { type: "
|
|
80
|
-
count: { type: "
|
|
81
|
-
json: { type: "
|
|
79
|
+
sql: { type: "integer", enum: [1] },
|
|
80
|
+
count: { type: "integer", enum: [1] },
|
|
81
|
+
json: { type: "integer", enum: [1] }, // dummy schema param to avoid crash caused by frontend calls w/ useless json param
|
|
82
82
|
},
|
|
83
83
|
},
|
|
84
84
|
params: {
|
|
@@ -109,7 +109,7 @@ const cardTabDataSchema = {
|
|
|
109
109
|
querystring: {
|
|
110
110
|
type: "object",
|
|
111
111
|
properties: {
|
|
112
|
-
sql: { type: "
|
|
112
|
+
sql: { type: "integer", enum: [1] },
|
|
113
113
|
},
|
|
114
114
|
},
|
|
115
115
|
params: {
|