@opengis/fastify-table 2.5.37 → 2.5.38
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/server/plugins/crud/funcs/validateData.d.ts +2 -1
- package/dist/server/plugins/crud/funcs/validateData.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/validateData.js +5 -2
- package/dist/server/plugins/usercls/index.d.ts +4 -8
- package/dist/server/plugins/usercls/index.d.ts.map +1 -1
- package/dist/server/plugins/usercls/index.js +45 -29
- package/dist/server/routes/crud/controllers/update.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateData.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/crud/funcs/validateData.ts"],"names":[],"mappings":"AAmJA,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,IAAS,EACT,MAAW,
|
|
1
|
+
{"version":3,"file":"validateData.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/crud/funcs/validateData.ts"],"names":[],"mappings":"AAmJA,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,IAAS,EACT,MAAW,EACX,MAAc,GACf,EAAE;IACD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,OASA"}
|
|
@@ -120,10 +120,13 @@ function checkBody({ body = {}, arr = [], idx }) {
|
|
|
120
120
|
}
|
|
121
121
|
return { message: "ok" };
|
|
122
122
|
}
|
|
123
|
-
export default function validateData({ body = {}, schema = {}, }) {
|
|
123
|
+
export default function validateData({ body = {}, schema = {}, update = false, }) {
|
|
124
|
+
const arr = Object.keys(schema).map((key) => ({ ...schema[key], key }));
|
|
124
125
|
const res = checkBody({
|
|
125
126
|
body,
|
|
126
|
-
arr:
|
|
127
|
+
arr: update
|
|
128
|
+
? arr.filter((el) => Object.keys(body || {}).includes(el.key))
|
|
129
|
+
: arr,
|
|
127
130
|
});
|
|
128
131
|
return res;
|
|
129
132
|
}
|
|
@@ -17,18 +17,14 @@ export declare function deleteUserCls({ name, code }: {
|
|
|
17
17
|
name: string;
|
|
18
18
|
code?: string;
|
|
19
19
|
}, pg?: any): Promise<string>;
|
|
20
|
-
|
|
20
|
+
type UserClsPayload = {
|
|
21
21
|
name: string;
|
|
22
22
|
alias?: string[];
|
|
23
23
|
description?: string;
|
|
24
24
|
data: string | Record<string, any>[];
|
|
25
|
-
}
|
|
26
|
-
export declare function
|
|
27
|
-
|
|
28
|
-
description?: string;
|
|
29
|
-
alias?: string[];
|
|
30
|
-
data: string | Record<string, any>[];
|
|
31
|
-
}, pg?: any): Promise<string>;
|
|
25
|
+
};
|
|
26
|
+
export declare function addUserCls({ name, alias, data, description }: UserClsPayload, pg?: any): Promise<string>;
|
|
27
|
+
export declare function editUserCls({ name, alias, description, data }: UserClsPayload, pg?: any): Promise<string>;
|
|
32
28
|
export declare function getUserClsList({ name, search, sql, custom, }: {
|
|
33
29
|
name?: string;
|
|
34
30
|
search?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/usercls/index.ts"],"names":[],"mappings":"AAMA,wBAAsB,YAAY,CAChC,EACE,IAAI,EACJ,WAAW,EACX,KAAK,EACL,KAAK,EACL,GAAG,EACH,IAAS,GACV,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE;QACJ,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,EAAE,CAAC;CACL,EACD,EAAE,MAAmB,mBA8EtB;AAED,wBAAsB,aAAa,CACjC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAC/C,EAAE,MAAmB,mBAgBtB;AAED,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/usercls/index.ts"],"names":[],"mappings":"AAMA,wBAAsB,YAAY,CAChC,EACE,IAAI,EACJ,WAAW,EACX,KAAK,EACL,KAAK,EACL,GAAG,EACH,IAAS,GACV,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE;QACJ,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,EAAE,CAAC;CACL,EACD,EAAE,MAAmB,mBA8EtB;AAED,wBAAsB,aAAa,CACjC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAC/C,EAAE,MAAmB,mBAgBtB;AAED,KAAK,cAAc,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;CACtC,CAAC;AAmDF,wBAAsB,UAAU,CAC9B,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,cAAc,EAClD,EAAE,MAAmB,mBActB;AAED,wBAAsB,WAAW,CAC/B,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,cAAc,EAClD,EAAE,MAAmB,mBAmBtB;AAED,wBAAsB,cAAc,CAClC,EACE,IAAI,EACJ,MAAM,EACN,GAAG,EACH,MAAM,GACP,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,MAAM,CAAC,EAAE,MAAM,CAAC;CAEjB,EACD,EAAE,MAAmB,gBA0DtB;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAmB;;;;;UAuBnE;;AAED,wBAAoB"}
|
|
@@ -73,7 +73,8 @@ export async function deleteUserCls({ name, code }, pg = pgClients.client) {
|
|
|
73
73
|
await pg.query(`delete from admin.user_cls where ((name=$1 and parent is null) or parent=$1) and ${code ? "code=$2" : "true"}`, [name, code].filter(Boolean));
|
|
74
74
|
return "ok";
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
/** Запис класифікатора в межах уже відкритої транзакції (client — з pg.connect()) */
|
|
77
|
+
async function insertUserCls({ name, alias, data, description }, client) {
|
|
77
78
|
const type = typeof data === "string" ? "sql" : "json";
|
|
78
79
|
if (type === "json" && data && !Array.isArray(data)) {
|
|
79
80
|
throw new Error("param data must be an array");
|
|
@@ -84,33 +85,36 @@ export async function addUserCls({ name, alias, data, description, }, pg = pgCli
|
|
|
84
85
|
!data.find((item) => item.id && item.text)) {
|
|
85
86
|
throw new Error("param data must have items");
|
|
86
87
|
}
|
|
88
|
+
if (type === "sql") {
|
|
89
|
+
throw ForbiddenError("access restricted: creation of custom selects is not allowed");
|
|
90
|
+
await dataInsert({
|
|
91
|
+
pg: client,
|
|
92
|
+
table: "admin.user_cls",
|
|
93
|
+
data: { name, alias, description, type, data },
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
else if (type === "json") {
|
|
97
|
+
await dataInsert({
|
|
98
|
+
pg: client,
|
|
99
|
+
table: "admin.user_cls",
|
|
100
|
+
data: { name, alias, description, type },
|
|
101
|
+
});
|
|
102
|
+
if (Array.isArray(data) && data.length) {
|
|
103
|
+
await Promise.all(data.map(async (item) => {
|
|
104
|
+
await dataInsert({
|
|
105
|
+
pg: client,
|
|
106
|
+
table: "admin.user_cls",
|
|
107
|
+
data: { ...item, code: item.id, name: item.text, parent: name },
|
|
108
|
+
});
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export async function addUserCls({ name, alias, data, description }, pg = pgClients.client) {
|
|
87
114
|
const client = await pg.connect();
|
|
88
115
|
try {
|
|
89
116
|
await client.query("begin");
|
|
90
|
-
|
|
91
|
-
throw ForbiddenError("access restricted: creation of custom selects is not allowed");
|
|
92
|
-
await dataInsert({
|
|
93
|
-
pg: client,
|
|
94
|
-
table: "admin.user_cls",
|
|
95
|
-
data: { name, alias, description, type, data },
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
else if (type === "json") {
|
|
99
|
-
await dataInsert({
|
|
100
|
-
pg: client,
|
|
101
|
-
table: "admin.user_cls",
|
|
102
|
-
data: { name, alias, description, type },
|
|
103
|
-
});
|
|
104
|
-
if (Array.isArray(data) && data.length) {
|
|
105
|
-
await Promise.all(data.map(async (item) => {
|
|
106
|
-
await dataInsert({
|
|
107
|
-
pg: client,
|
|
108
|
-
table: "admin.user_cls",
|
|
109
|
-
data: { ...item, code: item.id, name: item.text, parent: name },
|
|
110
|
-
});
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
117
|
+
await insertUserCls({ name, alias, data, description }, client);
|
|
114
118
|
await client.query("commit");
|
|
115
119
|
return "ok";
|
|
116
120
|
}
|
|
@@ -122,10 +126,22 @@ export async function addUserCls({ name, alias, data, description, }, pg = pgCli
|
|
|
122
126
|
client.release();
|
|
123
127
|
}
|
|
124
128
|
}
|
|
125
|
-
export async function editUserCls({ name, alias, description, data
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
export async function editUserCls({ name, alias, description, data }, pg = pgClients.client) {
|
|
130
|
+
const client = await pg.connect();
|
|
131
|
+
try {
|
|
132
|
+
await client.query("begin");
|
|
133
|
+
await deleteUserCls({ name }, client);
|
|
134
|
+
await insertUserCls({ name, alias, description, data }, client);
|
|
135
|
+
await client.query("commit");
|
|
136
|
+
return "ok";
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
await client.query("rollback");
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
client.release();
|
|
144
|
+
}
|
|
129
145
|
}
|
|
130
146
|
export async function getUserClsList({ name, search, sql, custom, }, pg = pgClients.client) {
|
|
131
147
|
const args = [];
|
|
@@ -101,7 +101,7 @@ export default async function update(req, reply) {
|
|
|
101
101
|
logger.file("injection/xss", { msg: xssCheck.error, table }, req);
|
|
102
102
|
throw ConflictError("Дані не пройшли валідацію. Приберіть некоректні дані та спробуйте ще раз");
|
|
103
103
|
}
|
|
104
|
-
const fieldCheck = validateData({ body, schema });
|
|
104
|
+
const fieldCheck = validateData({ body, schema, update: true });
|
|
105
105
|
if (fieldCheck.error) {
|
|
106
106
|
logger.file("injection/formdata", {
|
|
107
107
|
table,
|