@opengis/fastify-table 1.4.82 → 1.4.84
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/index.js +30 -9
- package/package.json +2 -2
- package/server/helpers/core/token.js +18 -18
- package/server/plugins/cron/funcs/addCron.js +52 -52
- package/server/plugins/crud/funcs/dataDelete.js +2 -2
- package/server/plugins/crud/funcs/getOpt.js +14 -14
- package/server/plugins/crud/funcs/utils/getFolder.js +11 -11
- package/server/plugins/logger/errorStatus.js +19 -19
- package/server/plugins/pg/funcs/init.js +2 -2
- package/server/plugins/redis/client.js +8 -8
- package/server/plugins/redis/funcs/redisClients.js +3 -3
- package/server/plugins/sqlite/funcs/getSqlite.js +8 -3
- package/server/plugins/sqlite/funcs/init.js +1 -1
- package/server/plugins/sqlite/sqliteClients.js +8 -3
- package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/server/plugins/table/funcs/getTemplates.js +19 -19
- package/server/plugins/table/funcs/gisIRColumn.js +82 -82
- package/server/plugins/table/funcs/loadTemplate.js +1 -1
- package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
- package/server/plugins/table/funcs/userTemplateDir.js +1 -1
- package/server/plugins/util/funcs/unflattenObject.js +4 -1
- package/server/routes/crud/controllers/deleteCrud.js +35 -9
- package/server/routes/table/controllers/search.js +74 -74
- package/server/routes/table/controllers/tableData.js +2 -2
- package/server/routes/table/functions/getData.js +6 -6
- package/server/routes/widget/controllers/widget.del.js +89 -89
- package/server/routes/widget/hook/onWidgetSet.js +13 -13
- package/server/routes/widget/index.mjs +38 -38
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import config from '../../../../config.js';
|
|
2
|
-
import isFileExists from '../../../plugins/file/isFileExists.js';
|
|
3
|
-
import logChanges from '../../../plugins/crud/funcs/utils/logChanges.js';
|
|
4
|
-
import pgClients from '../../../plugins/pg/pgClients.js';
|
|
5
|
-
|
|
6
|
-
const isAdmin = (req) => process.env.NODE_ENV === 'admin'
|
|
7
|
-
|| config.admin
|
|
8
|
-
|| req?.hostname?.split?.(':')?.shift?.() === config.adminDomain
|
|
9
|
-
|| req?.hostname?.startsWith?.('admin');
|
|
10
|
-
|
|
11
|
-
async function checkAccess(pg, objectid, id) {
|
|
12
|
-
const { uid, filepath } = await pg.query('select uid, file_path as filepath from crm.files where entity_id=$1 and file_id=$2', [objectid, id])
|
|
13
|
-
.then(el => el.rows?.[0] || {});
|
|
14
|
-
return { uid, exists: filepath ? await isFileExists(filepath) : null };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Дістає CRM дані для vue хешує ідентифікатори, підтягує селекти
|
|
19
|
-
*
|
|
20
|
-
* @method DELETE
|
|
21
|
-
* @summary CRM дані для обраного віджета.
|
|
22
|
-
* @priority 2
|
|
23
|
-
* @tag table
|
|
24
|
-
* @type api
|
|
25
|
-
* @requires setTokenById
|
|
26
|
-
* @requires getSelect
|
|
27
|
-
* @param {String} id Ідентифікатор для хешування
|
|
28
|
-
* @param {Any} sql Використовується для повернення sql запиту
|
|
29
|
-
* @param {String} type Тип для хешування даних
|
|
30
|
-
* @errors 400, 500
|
|
31
|
-
* @returns {Number} status Номер помилки
|
|
32
|
-
* @returns {String|Object} error Опис помилки
|
|
33
|
-
* @returns {String|Object} message Повідомлення про успішне виконання або об'єкт з параметрами
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
export default async function widgetDel(req, reply) {
|
|
37
|
-
const {
|
|
38
|
-
pg = pgClients.client, params = {}, user = {},
|
|
39
|
-
} = req;
|
|
40
|
-
|
|
41
|
-
if (!user?.uid) {
|
|
42
|
-
return reply.status(401).send('access restricted: user not authorized');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const { type, objectid, id } = params;
|
|
46
|
-
|
|
47
|
-
if (!objectid) {
|
|
48
|
-
return reply.status(400).send('not enough params: id');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// force delete db entry if file not exists
|
|
52
|
-
const { exists, uid } = ['file', 'gallery'].includes(type) ? await checkAccess(pg, objectid, id) : {};
|
|
53
|
-
|
|
54
|
-
if (exists && !isAdmin(req) && uid && user?.uid !== uid) {
|
|
55
|
-
return reply.status(403).send('access restricted: file exists, not an author');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const sqls = {
|
|
59
|
-
comment: `delete from crm.communications where entity_id=$1 and ${isAdmin(req) ? '$2=$2' : 'uid=$2'} and communication_id=$3`,
|
|
60
|
-
checklist: `delete from crm.checklists where entity_id=$1 and ${isAdmin(req) ? '$2=$2' : 'uid=$2'} and checklist_id=$3`,
|
|
61
|
-
file: `update crm.files set file_status=3 where entity_id=$1 and ${!exists || isAdmin(req) ? '$2=$2' : 'uid=$2'} and file_id=$3 returning uploaded_name`,
|
|
62
|
-
gallery: `update crm.files set file_status=3 where entity_id=$1 and ${!exists || isAdmin(req) ? '$2=$2' : 'uid=$2'} and file_id=$3 returning uploaded_name`,
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const sql = sqls[type];
|
|
66
|
-
const table = {
|
|
67
|
-
comment: 'crm.communications',
|
|
68
|
-
checklist: 'crm.checklists',
|
|
69
|
-
file: 'crm.files',
|
|
70
|
-
gallery: 'crm.files',
|
|
71
|
-
}[type];
|
|
72
|
-
|
|
73
|
-
if (!sql) {
|
|
74
|
-
return reply.status(400).send('invalid widget type');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const { rows = [] } = await pg.query(sql, [objectid, user.uid, id]);
|
|
78
|
-
|
|
79
|
-
await logChanges({
|
|
80
|
-
pg,
|
|
81
|
-
table,
|
|
82
|
-
id,
|
|
83
|
-
data: rows[0],
|
|
84
|
-
uid: user?.uid,
|
|
85
|
-
type: 'DELETE',
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
return reply.status(200).send({ data: { id }, user: { uid: user.uid, name: user.user_name } });
|
|
89
|
-
}
|
|
1
|
+
import config from '../../../../config.js';
|
|
2
|
+
import isFileExists from '../../../plugins/file/isFileExists.js';
|
|
3
|
+
import logChanges from '../../../plugins/crud/funcs/utils/logChanges.js';
|
|
4
|
+
import pgClients from '../../../plugins/pg/pgClients.js';
|
|
5
|
+
|
|
6
|
+
const isAdmin = (req) => process.env.NODE_ENV === 'admin'
|
|
7
|
+
|| config.admin
|
|
8
|
+
|| req?.hostname?.split?.(':')?.shift?.() === config.adminDomain
|
|
9
|
+
|| req?.hostname?.startsWith?.('admin');
|
|
10
|
+
|
|
11
|
+
async function checkAccess(pg, objectid, id) {
|
|
12
|
+
const { uid, filepath } = await pg.query('select uid, file_path as filepath from crm.files where entity_id=$1 and file_id=$2', [objectid, id])
|
|
13
|
+
.then(el => el.rows?.[0] || {});
|
|
14
|
+
return { uid, exists: filepath ? await isFileExists(filepath) : null };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Дістає CRM дані для vue хешує ідентифікатори, підтягує селекти
|
|
19
|
+
*
|
|
20
|
+
* @method DELETE
|
|
21
|
+
* @summary CRM дані для обраного віджета.
|
|
22
|
+
* @priority 2
|
|
23
|
+
* @tag table
|
|
24
|
+
* @type api
|
|
25
|
+
* @requires setTokenById
|
|
26
|
+
* @requires getSelect
|
|
27
|
+
* @param {String} id Ідентифікатор для хешування
|
|
28
|
+
* @param {Any} sql Використовується для повернення sql запиту
|
|
29
|
+
* @param {String} type Тип для хешування даних
|
|
30
|
+
* @errors 400, 500
|
|
31
|
+
* @returns {Number} status Номер помилки
|
|
32
|
+
* @returns {String|Object} error Опис помилки
|
|
33
|
+
* @returns {String|Object} message Повідомлення про успішне виконання або об'єкт з параметрами
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export default async function widgetDel(req, reply) {
|
|
37
|
+
const {
|
|
38
|
+
pg = pgClients.client, params = {}, user = {},
|
|
39
|
+
} = req;
|
|
40
|
+
|
|
41
|
+
if (!user?.uid) {
|
|
42
|
+
return reply.status(401).send('access restricted: user not authorized');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { type, objectid, id } = params;
|
|
46
|
+
|
|
47
|
+
if (!objectid) {
|
|
48
|
+
return reply.status(400).send('not enough params: id');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// force delete db entry if file not exists
|
|
52
|
+
const { exists, uid } = ['file', 'gallery'].includes(type) ? await checkAccess(pg, objectid, id) : {};
|
|
53
|
+
|
|
54
|
+
if (exists && !isAdmin(req) && uid && user?.uid !== uid) {
|
|
55
|
+
return reply.status(403).send('access restricted: file exists, not an author');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const sqls = {
|
|
59
|
+
comment: `delete from crm.communications where entity_id=$1 and ${isAdmin(req) ? '$2=$2' : 'uid=$2'} and communication_id=$3`,
|
|
60
|
+
checklist: `delete from crm.checklists where entity_id=$1 and ${isAdmin(req) ? '$2=$2' : 'uid=$2'} and checklist_id=$3`,
|
|
61
|
+
file: `update crm.files set file_status=3 where entity_id=$1 and ${!exists || isAdmin(req) ? '$2=$2' : 'uid=$2'} and file_id=$3 returning uploaded_name`,
|
|
62
|
+
gallery: `update crm.files set file_status=3 where entity_id=$1 and ${!exists || isAdmin(req) ? '$2=$2' : 'uid=$2'} and file_id=$3 returning uploaded_name`,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const sql = sqls[type];
|
|
66
|
+
const table = {
|
|
67
|
+
comment: 'crm.communications',
|
|
68
|
+
checklist: 'crm.checklists',
|
|
69
|
+
file: 'crm.files',
|
|
70
|
+
gallery: 'crm.files',
|
|
71
|
+
}[type];
|
|
72
|
+
|
|
73
|
+
if (!sql) {
|
|
74
|
+
return reply.status(400).send('invalid widget type');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const { rows = [] } = await pg.query(sql, [objectid, user.uid, id]);
|
|
78
|
+
|
|
79
|
+
await logChanges({
|
|
80
|
+
pg,
|
|
81
|
+
table,
|
|
82
|
+
id,
|
|
83
|
+
data: rows[0],
|
|
84
|
+
uid: user?.uid,
|
|
85
|
+
type: 'DELETE',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return reply.status(200).send({ data: { id }, user: { uid: user.uid, name: user.user_name } });
|
|
89
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import pgClients from '../../../plugins/pg/pgClients.js';
|
|
2
|
-
|
|
3
|
-
export default async function onWidgetSet({
|
|
4
|
-
pg = pgClients.client, id, objectid, type, payload = {},
|
|
5
|
-
}) {
|
|
6
|
-
if (!id || !objectid || type !== 'gallery') {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
if (payload?.ismain) {
|
|
10
|
-
await pg.query('update crm.files set ismain=false where entity_id=$1 and file_id<>$2', [objectid, id]);
|
|
11
|
-
}
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
1
|
+
import pgClients from '../../../plugins/pg/pgClients.js';
|
|
2
|
+
|
|
3
|
+
export default async function onWidgetSet({
|
|
4
|
+
pg = pgClients.client, id, objectid, type, payload = {},
|
|
5
|
+
}) {
|
|
6
|
+
if (!id || !objectid || type !== 'gallery') {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
if (payload?.ismain) {
|
|
10
|
+
await pg.query('update crm.files set ismain=false where entity_id=$1 and file_id<>$2', [objectid, id]);
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import addHook from '../../plugins/hook/funcs/addHook.js';
|
|
2
|
-
|
|
3
|
-
import widgetDel from './controllers/widget.del.js';
|
|
4
|
-
import widgetSet from './controllers/widget.set.js';
|
|
5
|
-
import widgetGet from './controllers/widget.get.js';
|
|
6
|
-
import fileEdit from './controllers/file.edit.js';
|
|
7
|
-
|
|
8
|
-
import onWidgetSet from './hook/onWidgetSet.js';
|
|
9
|
-
|
|
10
|
-
const tableSchema = {
|
|
11
|
-
params: {
|
|
12
|
-
type: 'object',
|
|
13
|
-
properties: {
|
|
14
|
-
// type: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
15
|
-
objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
16
|
-
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
querystring: {
|
|
20
|
-
type: 'object',
|
|
21
|
-
properties: {
|
|
22
|
-
debug: { type: 'string', pattern: '^(\\d+)$' },
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
addHook('onWidgetSet', onWidgetSet);
|
|
28
|
-
|
|
29
|
-
const policy = ['site'];
|
|
30
|
-
const params = { config: { policy }, schema: tableSchema };
|
|
31
|
-
|
|
32
|
-
export default async function route(app, config = {}) {
|
|
33
|
-
const { prefix = '/api' } = config;
|
|
34
|
-
app.delete(`${prefix}/widget/:type/:objectid/:id`, params, widgetDel);
|
|
35
|
-
app.post(`${prefix}/widget/:type/:objectid/:id?`, params, widgetSet);
|
|
36
|
-
app.put(`${prefix}/file-edit/:id`, params, fileEdit);
|
|
37
|
-
app.get(`${prefix}/widget/:type/:objectid`, { config: { policy: ['public'] }, schema: tableSchema }, widgetGet);
|
|
38
|
-
}
|
|
1
|
+
import addHook from '../../plugins/hook/funcs/addHook.js';
|
|
2
|
+
|
|
3
|
+
import widgetDel from './controllers/widget.del.js';
|
|
4
|
+
import widgetSet from './controllers/widget.set.js';
|
|
5
|
+
import widgetGet from './controllers/widget.get.js';
|
|
6
|
+
import fileEdit from './controllers/file.edit.js';
|
|
7
|
+
|
|
8
|
+
import onWidgetSet from './hook/onWidgetSet.js';
|
|
9
|
+
|
|
10
|
+
const tableSchema = {
|
|
11
|
+
params: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
// type: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
15
|
+
objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
16
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
querystring: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
debug: { type: 'string', pattern: '^(\\d+)$' },
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
addHook('onWidgetSet', onWidgetSet);
|
|
28
|
+
|
|
29
|
+
const policy = ['site'];
|
|
30
|
+
const params = { config: { policy }, schema: tableSchema };
|
|
31
|
+
|
|
32
|
+
export default async function route(app, config = {}) {
|
|
33
|
+
const { prefix = '/api' } = config;
|
|
34
|
+
app.delete(`${prefix}/widget/:type/:objectid/:id`, params, widgetDel);
|
|
35
|
+
app.post(`${prefix}/widget/:type/:objectid/:id?`, params, widgetSet);
|
|
36
|
+
app.put(`${prefix}/file-edit/:id`, params, fileEdit);
|
|
37
|
+
app.get(`${prefix}/widget/:type/:objectid`, { config: { policy: ['public'] }, schema: tableSchema }, widgetGet);
|
|
38
|
+
}
|