@opengis/fastify-table 1.0.26 → 1.0.28
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/Changelog.md +8 -0
- package/crud/controllers/insert.js +29 -29
- package/crud/controllers/update.js +31 -31
- package/crud/funcs/dataInsert.js +1 -1
- package/crud/funcs/dataUpdate.js +7 -3
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/setOpt.js +16 -16
- package/crud/index.js +29 -29
- package/dblist/controllers/createItem.js +32 -17
- package/dblist/controllers/deleteItem.js +14 -12
- package/dblist/controllers/readItems.js +10 -8
- package/dblist/controllers/setItem.js +21 -0
- package/dblist/controllers/updateItem.js +25 -22
- package/dblist/controllers/utils/checkItem.js +24 -9
- package/dblist/controllers/utils/formatData.js +7 -0
- package/dblist/index.js +49 -40
- package/helper.js +28 -28
- package/index.js +41 -41
- package/notification/controllers/userNotifications.js +19 -19
- package/notification/funcs/addNotification.js +8 -8
- package/notification/index.js +19 -19
- package/package.json +1 -1
- package/pg/funcs/getPG.js +1 -1
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +74 -74
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/getRedis.js +1 -1
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/crm.sql +57 -57
- package/server/migrations/log.sql +41 -41
- package/server/migrations/notifications.sql +14 -14
- package/server/templates/form/test.dataset.form.json +411 -411
- package/server/templates/select/test.storage.data.json +2 -2
- package/server/templates/table/test.dataset.table.json +24 -24
- package/table/controllers/data.js +57 -57
- package/table/controllers/filter.js +32 -32
- package/table/controllers/form.js +10 -10
- package/table/controllers/suggest.js +60 -60
- package/table/controllers/utils/getSelect.js +20 -20
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate.js +28 -28
- package/table/funcs/getFilterSQL/index.js +75 -75
- package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/metaFormat/getSelectVal.js +20 -20
- package/table/funcs/metaFormat/index.js +26 -26
- package/table/index.js +42 -42
- package/test/api/crud.test.js +56 -56
- package/test/api/crud.xss.test.js +71 -71
- package/test/api/dblist.test.js +47 -47
- package/test/api/notification.test.js +37 -37
- package/test/api/table.test.js +57 -57
- package/test/api/widget.test.js +39 -39
- package/test/funcs/notification.test.js +31 -31
- package/test/widget.test.js +39 -39
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +40 -40
- package/widget/controllers/widget.get.js +74 -74
- package/widget/controllers/widget.set.js +45 -45
- package/widget/index.js +29 -29
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import getToken from '../../crud/funcs/getToken.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import historyFormat from './utils/historyFormat.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Дістає CRM для widget
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export default async function widgetGet({
|
|
11
|
-
pg, session = {}, params = {}, query = {},
|
|
12
|
-
}) {
|
|
13
|
-
const { user = {} } = session.passport || {};
|
|
14
|
-
|
|
15
|
-
const param = user?.uid ? await getToken({
|
|
16
|
-
token: params.objectid, mode: 'w', uid: user.uid,
|
|
17
|
-
}) : null;
|
|
18
|
-
|
|
19
|
-
const objectid = param ? JSON.parse(param)?.id : params.objectid;
|
|
20
|
-
|
|
21
|
-
if (!['comment', 'history', 'file', 'checklist'].includes(params.type)) return { error: 'param type not valid', status: 400 };
|
|
22
|
-
if (!objectid) return { error: 'id required', status: 400 };
|
|
23
|
-
|
|
24
|
-
const sql = {
|
|
25
|
-
comment: `select body,c.cdate, comment_id,object_id,c.uid, coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username,avatar
|
|
26
|
-
from crm.comment c left join admin.users u on u.uid=c.uid where object_id=$1 order by cdate desc`,
|
|
27
|
-
|
|
28
|
-
history: `SELECT object_id, table_name, change_key, change_date, json_old, json_new, date_old,
|
|
29
|
-
date_new, number_old, number_new, bool_old, bool_new, text_old,
|
|
30
|
-
text_new, uid, cdate FROM log.table_change where object_id=$1 order by cdate desc, change_key limit 100`,
|
|
31
|
-
|
|
32
|
-
checklist: `SELECT checklist_id, title, is_done, done_date, c.uid, c.cdate, coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username,
|
|
33
|
-
avatar FROM crm.checklist c left join admin.users u on u.uid=c.uid where object_id=$1 order by cdate desc`,
|
|
34
|
-
|
|
35
|
-
file: `SELECT file_id, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
|
|
36
|
-
coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username, isverified,
|
|
37
|
-
avatar, c.uid as author, file_status FROM crm.file c left join admin.users u on u.uid=c.uid
|
|
38
|
-
where object_id=$1 and file_status<>3 order by cdate desc`,
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
try {
|
|
42
|
-
/* data */
|
|
43
|
-
const time = [Date.now()];
|
|
44
|
-
const { rows } = await pg.query(sql[params.type], [objectid]);
|
|
45
|
-
time.push(Date.now());
|
|
46
|
-
|
|
47
|
-
/* Object info */
|
|
48
|
-
const { tableName } = await pg.one('select table_name as "tableName" from log.table_change where object_id=$1 limit 1', [objectid]);
|
|
49
|
-
const { pk } = await getMeta({ table: tableName });
|
|
50
|
-
|
|
51
|
-
const q = `select coalesce(b.user_name,'')||coalesce(' '||b.sur_name,'') as author, a.cdate, a.editor_date from ${tableName} a left join admin.users b on a.uid=b.uid where a.${pk}=$1 limit 1`;
|
|
52
|
-
const data = pk ? await pg.one(q, [objectid]) : {};
|
|
53
|
-
|
|
54
|
-
if (query.debug && user?.user_type === 'admin') {
|
|
55
|
-
return {
|
|
56
|
-
sql, type: params.type, q, id: objectid, data,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
time.push(Date.now());
|
|
61
|
-
return {
|
|
62
|
-
time: { data: time[1] - time[0], format: time[2] - time[1] },
|
|
63
|
-
rows: params.type === 'history' ? await historyFormat(rows, tableName, pg) : rows,
|
|
64
|
-
user: { uid: user?.uid, name: user?.user_name },
|
|
65
|
-
data: { author: data?.author, cdate: data?.cdate, edate: data?.editor_date },
|
|
66
|
-
objectid: params.objectid,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
// 'history', 'file', 'checklist'
|
|
71
|
-
/* 'document', 'image' - Макс на клиенте */
|
|
72
|
-
return { message: err.toString(), status: 500 };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
1
|
+
import getToken from '../../crud/funcs/getToken.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import historyFormat from './utils/historyFormat.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Дістає CRM для widget
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export default async function widgetGet({
|
|
11
|
+
pg, session = {}, params = {}, query = {},
|
|
12
|
+
}) {
|
|
13
|
+
const { user = {} } = session.passport || {};
|
|
14
|
+
|
|
15
|
+
const param = user?.uid ? await getToken({
|
|
16
|
+
token: params.objectid, mode: 'w', uid: user.uid,
|
|
17
|
+
}) : null;
|
|
18
|
+
|
|
19
|
+
const objectid = param ? JSON.parse(param)?.id : params.objectid;
|
|
20
|
+
|
|
21
|
+
if (!['comment', 'history', 'file', 'checklist'].includes(params.type)) return { error: 'param type not valid', status: 400 };
|
|
22
|
+
if (!objectid) return { error: 'id required', status: 400 };
|
|
23
|
+
|
|
24
|
+
const sql = {
|
|
25
|
+
comment: `select body,c.cdate, comment_id,object_id,c.uid, coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username,avatar
|
|
26
|
+
from crm.comment c left join admin.users u on u.uid=c.uid where object_id=$1 order by cdate desc`,
|
|
27
|
+
|
|
28
|
+
history: `SELECT object_id, table_name, change_key, change_date, json_old, json_new, date_old,
|
|
29
|
+
date_new, number_old, number_new, bool_old, bool_new, text_old,
|
|
30
|
+
text_new, uid, cdate FROM log.table_change where object_id=$1 order by cdate desc, change_key limit 100`,
|
|
31
|
+
|
|
32
|
+
checklist: `SELECT checklist_id, title, is_done, done_date, c.uid, c.cdate, coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username,
|
|
33
|
+
avatar FROM crm.checklist c left join admin.users u on u.uid=c.uid where object_id=$1 order by cdate desc`,
|
|
34
|
+
|
|
35
|
+
file: `SELECT file_id, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
|
|
36
|
+
coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username, isverified,
|
|
37
|
+
avatar, c.uid as author, file_status FROM crm.file c left join admin.users u on u.uid=c.uid
|
|
38
|
+
where object_id=$1 and file_status<>3 order by cdate desc`,
|
|
39
|
+
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
/* data */
|
|
43
|
+
const time = [Date.now()];
|
|
44
|
+
const { rows } = await pg.query(sql[params.type], [objectid]);
|
|
45
|
+
time.push(Date.now());
|
|
46
|
+
|
|
47
|
+
/* Object info */
|
|
48
|
+
const { tableName } = await pg.one('select table_name as "tableName" from log.table_change where object_id=$1 limit 1', [objectid]);
|
|
49
|
+
const { pk } = await getMeta({ table: tableName });
|
|
50
|
+
|
|
51
|
+
const q = `select coalesce(b.user_name,'')||coalesce(' '||b.sur_name,'') as author, a.cdate, a.editor_date from ${tableName} a left join admin.users b on a.uid=b.uid where a.${pk}=$1 limit 1`;
|
|
52
|
+
const data = pk ? await pg.one(q, [objectid]) : {};
|
|
53
|
+
|
|
54
|
+
if (query.debug && user?.user_type === 'admin') {
|
|
55
|
+
return {
|
|
56
|
+
sql, type: params.type, q, id: objectid, data,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
time.push(Date.now());
|
|
61
|
+
return {
|
|
62
|
+
time: { data: time[1] - time[0], format: time[2] - time[1] },
|
|
63
|
+
rows: params.type === 'history' ? await historyFormat(rows, tableName, pg) : rows,
|
|
64
|
+
user: { uid: user?.uid, name: user?.user_name },
|
|
65
|
+
data: { author: data?.author, cdate: data?.cdate, edate: data?.editor_date },
|
|
66
|
+
objectid: params.objectid,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
// 'history', 'file', 'checklist'
|
|
71
|
+
/* 'document', 'image' - Макс на клиенте */
|
|
72
|
+
return { message: err.toString(), status: 500 };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import obj2db from './utils/obj2db.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
|
|
4
|
-
const tableList = {
|
|
5
|
-
comment: 'crm.comment',
|
|
6
|
-
checklist: 'crm.checklist',
|
|
7
|
-
};
|
|
8
|
-
const pkList = {
|
|
9
|
-
comment: 'comment_id',
|
|
10
|
-
checklist: 'checklist_id',
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default async function widgetSet({
|
|
14
|
-
pg, params = {}, session = {}, body = {},
|
|
15
|
-
}) {
|
|
16
|
-
const { user = {} } = session.passport || {};
|
|
17
|
-
const { type, id, objectid } = params;
|
|
18
|
-
if (!['comment', 'checklist'].includes(type)) return { error: 'param type not valid', status: 400 };
|
|
19
|
-
if (!objectid) return { error: 'id required', status: 400 };
|
|
20
|
-
|
|
21
|
-
const table = tableList[type];
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
const { pk, columns: metaColumns } = await getMeta({ pg, table });
|
|
25
|
-
if (!pk) return { error: 'table not found', status: 404 };
|
|
26
|
-
|
|
27
|
-
const columnList = metaColumns.map((col) => col.name);
|
|
28
|
-
const nonexistCol = Object.keys(body).filter((key) => !columnList.includes(key));
|
|
29
|
-
const { columns, args } = obj2db({ ...body, uid: user?.uid, object_id: objectid }, nonexistCol);
|
|
30
|
-
|
|
31
|
-
const query = id
|
|
32
|
-
? `UPDATE ${table} SET ${columns?.map((key, index) => `"${key}"=$${++index}`).join(',')} WHERE ${pkList[type]} = '${id}' `
|
|
33
|
-
: `INSERT INTO ${table} (${columns?.join(',')}) VALUES (${columns?.map((el, index) => `$${++index}`).join(',')}) returning *;`;
|
|
34
|
-
|
|
35
|
-
// console.log(query, args);
|
|
36
|
-
const result = await pg.query(query, args);
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]],
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
return { error: err.toString(), status: 500 };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
import obj2db from './utils/obj2db.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
|
|
4
|
+
const tableList = {
|
|
5
|
+
comment: 'crm.comment',
|
|
6
|
+
checklist: 'crm.checklist',
|
|
7
|
+
};
|
|
8
|
+
const pkList = {
|
|
9
|
+
comment: 'comment_id',
|
|
10
|
+
checklist: 'checklist_id',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default async function widgetSet({
|
|
14
|
+
pg, params = {}, session = {}, body = {},
|
|
15
|
+
}) {
|
|
16
|
+
const { user = {} } = session.passport || {};
|
|
17
|
+
const { type, id, objectid } = params;
|
|
18
|
+
if (!['comment', 'checklist'].includes(type)) return { error: 'param type not valid', status: 400 };
|
|
19
|
+
if (!objectid) return { error: 'id required', status: 400 };
|
|
20
|
+
|
|
21
|
+
const table = tableList[type];
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const { pk, columns: metaColumns } = await getMeta({ pg, table });
|
|
25
|
+
if (!pk) return { error: 'table not found', status: 404 };
|
|
26
|
+
|
|
27
|
+
const columnList = metaColumns.map((col) => col.name);
|
|
28
|
+
const nonexistCol = Object.keys(body).filter((key) => !columnList.includes(key));
|
|
29
|
+
const { columns, args } = obj2db({ ...body, uid: user?.uid, object_id: objectid }, nonexistCol);
|
|
30
|
+
|
|
31
|
+
const query = id
|
|
32
|
+
? `UPDATE ${table} SET ${columns?.map((key, index) => `"${key}"=$${++index}`).join(',')} WHERE ${pkList[type]} = '${id}' `
|
|
33
|
+
: `INSERT INTO ${table} (${columns?.join(',')}) VALUES (${columns?.map((el, index) => `$${++index}`).join(',')}) returning *;`;
|
|
34
|
+
|
|
35
|
+
// console.log(query, args);
|
|
36
|
+
const result = await pg.query(query, args);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
return { error: err.toString(), status: 500 };
|
|
44
|
+
}
|
|
45
|
+
}
|
package/widget/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import widgetDel from './controllers/widget.del.js';
|
|
2
|
-
import widgetSet from './controllers/widget.set.js';
|
|
3
|
-
import widgetGet from './controllers/widget.get.js';
|
|
4
|
-
|
|
5
|
-
async function route(fastify, opt) {
|
|
6
|
-
const prefix = opt.prefix || '/api';
|
|
7
|
-
fastify.route({
|
|
8
|
-
method: 'DELETE',
|
|
9
|
-
url: `${prefix}/widget/:type/:objectid/:id`,
|
|
10
|
-
schema: {},
|
|
11
|
-
handler: widgetDel,
|
|
12
|
-
});
|
|
13
|
-
fastify.route({
|
|
14
|
-
method: 'POST',
|
|
15
|
-
path: `${prefix}/widget/:type/:objectid/:id?`,
|
|
16
|
-
schema: {},
|
|
17
|
-
handler: widgetSet,
|
|
18
|
-
});
|
|
19
|
-
fastify.route({
|
|
20
|
-
method: 'GET',
|
|
21
|
-
path: `${prefix}/widget/:type/:objectid`,
|
|
22
|
-
config: {
|
|
23
|
-
policy: ['public'],
|
|
24
|
-
},
|
|
25
|
-
schema: {},
|
|
26
|
-
handler: widgetGet,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
export default route;
|
|
1
|
+
import widgetDel from './controllers/widget.del.js';
|
|
2
|
+
import widgetSet from './controllers/widget.set.js';
|
|
3
|
+
import widgetGet from './controllers/widget.get.js';
|
|
4
|
+
|
|
5
|
+
async function route(fastify, opt) {
|
|
6
|
+
const prefix = opt.prefix || '/api';
|
|
7
|
+
fastify.route({
|
|
8
|
+
method: 'DELETE',
|
|
9
|
+
url: `${prefix}/widget/:type/:objectid/:id`,
|
|
10
|
+
schema: {},
|
|
11
|
+
handler: widgetDel,
|
|
12
|
+
});
|
|
13
|
+
fastify.route({
|
|
14
|
+
method: 'POST',
|
|
15
|
+
path: `${prefix}/widget/:type/:objectid/:id?`,
|
|
16
|
+
schema: {},
|
|
17
|
+
handler: widgetSet,
|
|
18
|
+
});
|
|
19
|
+
fastify.route({
|
|
20
|
+
method: 'GET',
|
|
21
|
+
path: `${prefix}/widget/:type/:objectid`,
|
|
22
|
+
config: {
|
|
23
|
+
policy: ['public'],
|
|
24
|
+
},
|
|
25
|
+
schema: {},
|
|
26
|
+
handler: widgetGet,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export default route;
|