@opengis/fastify-table 1.0.89 → 1.0.91
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/deleteCrud.js +4 -1
- package/crud/controllers/insert.js +6 -2
- package/crud/controllers/update.js +5 -3
- package/crud/funcs/dataDelete.js +19 -15
- package/crud/funcs/dataInsert.js +7 -1
- package/crud/funcs/dataUpdate.js +7 -2
- package/crud/funcs/utils/logChanges.js +71 -0
- package/crud/index.js +36 -36
- package/package.json +1 -1
- package/server/migrations/log.sql +63 -26
- package/table/controllers/table.js +4 -1
- package/test/api/widget.test.js +117 -114
- package/test/funcs/crud.test.js +122 -76
- package/util/controllers/logger.file.js +90 -0
- package/util/controllers/properties.add.js +57 -51
- package/util/controllers/utils/checkUserAccess.js +19 -0
- package/util/controllers/utils/getRootDir.js +21 -0
- package/util/index.js +23 -21
- package/widget/controllers/widget.get.js +5 -3
- package/widget/controllers/widget.set.js +9 -3
- package/widget/index.js +40 -40
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @summary check user access to logger interface - per admin user type or user group
|
|
4
|
+
* @returns {Object} message, status
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export default async function checkUserAccess({
|
|
8
|
+
user = {}, pg,
|
|
9
|
+
}) {
|
|
10
|
+
const { count = '0' } = pg.pk?.['admin.access']
|
|
11
|
+
? await pg.query(`select count(*) from admin.access
|
|
12
|
+
where user_uid=$1 and route_id='logger'`, [user.uid]).then((res) => res.rows[0] || {})
|
|
13
|
+
: {};
|
|
14
|
+
|
|
15
|
+
if (!['admin', 'superadmin']?.includes(user.user_type) && count === '0') {
|
|
16
|
+
return { message: 'access restricted', status: 403 };
|
|
17
|
+
}
|
|
18
|
+
return { message: 'access granted', status: 200 };
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
|
|
4
|
+
export default function getRootDir(config) {
|
|
5
|
+
// absolute / relative path
|
|
6
|
+
if (config.log?.dir) {
|
|
7
|
+
return config.log.dir.startsWith('/') || config.log.dir.includes(':')
|
|
8
|
+
? config.log.dir
|
|
9
|
+
: path.join(process.cwd(), config.log.dir);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// windows debug support
|
|
13
|
+
const customLogDir = process.cwd().includes(':') ? 'c:/data/local' : '/data/local';
|
|
14
|
+
// docker default path
|
|
15
|
+
if (existsSync(customLogDir)) {
|
|
16
|
+
return path.join(customLogDir, config.folder || '', 'log');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// non-docker default path
|
|
20
|
+
return path.join(config.root || '/data/local', config.folder || '', 'log');
|
|
21
|
+
}
|
package/util/index.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import getExtraProperties from './controllers/properties.get.js';
|
|
2
|
-
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
-
import nextId from './controllers/next.id.js';
|
|
4
|
-
import statusMonitor from './controllers/status.monitor.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
fastify.get(`${prefix}/
|
|
17
|
-
fastify.get(`${prefix}/
|
|
18
|
-
fastify.
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import getExtraProperties from './controllers/properties.get.js';
|
|
2
|
+
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
+
import nextId from './controllers/next.id.js';
|
|
4
|
+
import statusMonitor from './controllers/status.monitor.js';
|
|
5
|
+
import loggerFile from './controllers/logger.file.js';
|
|
6
|
+
|
|
7
|
+
const propertiesSchema = {
|
|
8
|
+
params: {
|
|
9
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
async function plugin(fastify, config = {}) {
|
|
14
|
+
const prefix = config.prefix || '/api';
|
|
15
|
+
|
|
16
|
+
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
17
|
+
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
18
|
+
fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
|
|
19
|
+
fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
|
|
20
|
+
fastify.get('/logger-file/*', { config: { policy: ['log'] } }, loggerFile);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default plugin;
|
|
@@ -29,9 +29,11 @@ export default async function widgetGet({
|
|
|
29
29
|
from crm.communications c left join admin.users u on u.uid=c.uid where entity_id=$1 order by cdate desc`
|
|
30
30
|
: 'select communication_id, entity_id, body, subject, cdate, uid from crm.communications where entity_id=$1 order by cdate desc',
|
|
31
31
|
|
|
32
|
-
history: `SELECT
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
history: `SELECT b.change_data_id, change_id, entity_id, entity_type, change_type, change_date, uid, cdate, b.entity_key, b.value_new, b.value_old FROM log.table_changes a
|
|
33
|
+
left join lateral(
|
|
34
|
+
select change_data_id, entity_key, value_new, value_old from log.table_changes_data where change_id=a.change_id
|
|
35
|
+
)b on 1=1
|
|
36
|
+
where entity_id=$1 and b.change_data_id is not null order by cdate desc limit 100`,
|
|
35
37
|
|
|
36
38
|
checklist: pg.pk['admin.users']
|
|
37
39
|
? `SELECT checklist_id, entity_id, subject, is_done, done_date, c.uid, c.cdate, coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username,
|
|
@@ -45,7 +45,9 @@ export default async function widgetSet(req) {
|
|
|
45
45
|
return { message: 'invalid file extension', status: 400 };
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const { rows = [] } = await dataInsert({
|
|
48
|
+
const { rows = [] } = await dataInsert({
|
|
49
|
+
table: 'crm.files', data, uid: user?.uid,
|
|
50
|
+
});
|
|
49
51
|
return {
|
|
50
52
|
rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, entity_id: rows[0]?.entity_id,
|
|
51
53
|
};
|
|
@@ -56,8 +58,12 @@ export default async function widgetSet(req) {
|
|
|
56
58
|
const data = { ...body, uid: user?.uid, entity_id: objectid };
|
|
57
59
|
|
|
58
60
|
const result = id
|
|
59
|
-
? await dataUpdate({
|
|
60
|
-
|
|
61
|
+
? await dataUpdate({
|
|
62
|
+
table, data, id, uid: user?.uid,
|
|
63
|
+
})
|
|
64
|
+
: await dataInsert({
|
|
65
|
+
table, data, uid: user?.uid,
|
|
66
|
+
});
|
|
61
67
|
|
|
62
68
|
return {
|
|
63
69
|
rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]] || result?.[pkList[type]],
|
package/widget/index.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
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
|
-
const tableSchema = {
|
|
6
|
-
params: {
|
|
7
|
-
// type: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
8
|
-
objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
9
|
-
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
10
|
-
},
|
|
11
|
-
querystring: {
|
|
12
|
-
debug: { type: 'string', pattern: '^(\\d+)$' },
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
async function route(fastify, opt) {
|
|
17
|
-
const prefix = opt.prefix || '/api';
|
|
18
|
-
fastify.route({
|
|
19
|
-
method: 'DELETE',
|
|
20
|
-
url: `${prefix}/widget/:type/:objectid/:id`,
|
|
21
|
-
schema: tableSchema,
|
|
22
|
-
handler: widgetDel,
|
|
23
|
-
});
|
|
24
|
-
fastify.route({
|
|
25
|
-
method: 'POST',
|
|
26
|
-
path: `${prefix}/widget/:type/:objectid/:id?`,
|
|
27
|
-
schema: tableSchema,
|
|
28
|
-
handler: widgetSet,
|
|
29
|
-
});
|
|
30
|
-
fastify.route({
|
|
31
|
-
method: 'GET',
|
|
32
|
-
path: `${prefix}/widget/:type/:objectid`,
|
|
33
|
-
config: {
|
|
34
|
-
policy: ['public'],
|
|
35
|
-
},
|
|
36
|
-
schema: tableSchema,
|
|
37
|
-
handler: widgetGet,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
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
|
+
const tableSchema = {
|
|
6
|
+
params: {
|
|
7
|
+
// type: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
8
|
+
objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
9
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
10
|
+
},
|
|
11
|
+
querystring: {
|
|
12
|
+
debug: { type: 'string', pattern: '^(\\d+)$' },
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
async function route(fastify, opt) {
|
|
17
|
+
const prefix = opt.prefix || '/api';
|
|
18
|
+
fastify.route({
|
|
19
|
+
method: 'DELETE',
|
|
20
|
+
url: `${prefix}/widget/:type/:objectid/:id`,
|
|
21
|
+
schema: tableSchema,
|
|
22
|
+
handler: widgetDel,
|
|
23
|
+
});
|
|
24
|
+
fastify.route({
|
|
25
|
+
method: 'POST',
|
|
26
|
+
path: `${prefix}/widget/:type/:objectid/:id?`,
|
|
27
|
+
schema: tableSchema,
|
|
28
|
+
handler: widgetSet,
|
|
29
|
+
});
|
|
30
|
+
fastify.route({
|
|
31
|
+
method: 'GET',
|
|
32
|
+
path: `${prefix}/widget/:type/:objectid`,
|
|
33
|
+
config: {
|
|
34
|
+
policy: ['public'],
|
|
35
|
+
},
|
|
36
|
+
schema: tableSchema,
|
|
37
|
+
handler: widgetGet,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export default route;
|