@opengis/fastify-table 1.4.63 → 1.4.65
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/package.json +61 -61
- package/server/helpers/core/token.js +18 -18
- package/server/plugins/cron/funcs/addCron.js +52 -52
- 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/index.js +3 -3
- package/server/plugins/redis/client.js +8 -8
- package/server/plugins/redis/funcs/redisClients.js +3 -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/routes/table/controllers/form.js +42 -42
- package/server/routes/table/controllers/search.js +74 -74
- package/server/routes/table/functions/getData.js +5 -4
- package/server/routes/widget/controllers/widget.del.js +89 -89
- package/server/routes/widget/controllers/widget.set.js +106 -106
- package/server/routes/widget/hook/onWidgetSet.js +13 -13
- package/server/routes/widget/index.mjs +38 -38
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import getMeta from '../../../plugins/pg/funcs/getMeta.js';
|
|
4
|
-
import dataInsert from '../../../plugins/crud/funcs/dataInsert.js';
|
|
5
|
-
import dataUpdate from '../../../plugins/crud/funcs/dataUpdate.js';
|
|
6
|
-
import applyHook from '../../../plugins/hook/funcs/applyHook.js';
|
|
7
|
-
import uploadMultiPart from '../../../plugins/file/uploadMultiPart.js';
|
|
8
|
-
|
|
9
|
-
const tableList = {
|
|
10
|
-
comment: 'crm.communications',
|
|
11
|
-
gallery: 'crm.files',
|
|
12
|
-
file: 'crm.files',
|
|
13
|
-
checklist: 'crm.checklists',
|
|
14
|
-
};
|
|
15
|
-
const pkList = {
|
|
16
|
-
comment: 'communication_id',
|
|
17
|
-
checklist: 'checklist_id',
|
|
18
|
-
file: 'file_id',
|
|
19
|
-
gallery: 'file_id',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
|
|
23
|
-
|
|
24
|
-
export default async function widgetSet(req, reply) {
|
|
25
|
-
const {
|
|
26
|
-
pg, params = {}, session = {}, headers = {}, body = {}, user = {},
|
|
27
|
-
} = req;
|
|
28
|
-
const { type, id, objectid } = params;
|
|
29
|
-
|
|
30
|
-
if (!['comment', 'checklist', 'file', 'gallery'].includes(type)) {
|
|
31
|
-
return reply.status(400).send('param type not valid');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!objectid) {
|
|
35
|
-
return reply.status(400).send('not enough params: id');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const table = tableList[type];
|
|
39
|
-
|
|
40
|
-
// dsadasdad
|
|
41
|
-
if (['gallery', 'file'].includes(type) && headers['content-type']?.split?.(';')?.shift?.() === 'multipart/form-data') {
|
|
42
|
-
const file = await uploadMultiPart(req);
|
|
43
|
-
const extName = path.extname(file.filepath).slice(1).toLowerCase();
|
|
44
|
-
|
|
45
|
-
const data = {
|
|
46
|
-
uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
|
|
47
|
-
file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
|
|
48
|
-
ext: extName,
|
|
49
|
-
size: file?.size,
|
|
50
|
-
file_status: 1,
|
|
51
|
-
uid: user?.uid || 1,
|
|
52
|
-
entity_id: objectid,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
if (type === 'gallery' && !galleryExtList.includes(extName.toLowerCase())) {
|
|
56
|
-
return reply.status(400).send('invalid file extension');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const { rows = [] } = await dataInsert({
|
|
60
|
-
pg, table: 'crm.files', data, uid: user?.uid,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
if (type === 'gallery') {
|
|
64
|
-
await pg.query(`update crm.files set ismain=true
|
|
65
|
-
where entity_id=$1
|
|
66
|
-
and file_id=$2
|
|
67
|
-
and (select count(*) = 0 from crm.files where entity_id=$1 and ismain)`, [objectid, rows[0]?.file_id]);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, entity_id: rows[0]?.entity_id,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
const { pk } = await getMeta({ pg, table });
|
|
75
|
-
|
|
76
|
-
if (!pk) {
|
|
77
|
-
return reply.status(404).send('table not found');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const data = { ...body, uid: user?.uid, entity_id: objectid };
|
|
81
|
-
|
|
82
|
-
await applyHook('onWidgetSet', {
|
|
83
|
-
pg,
|
|
84
|
-
link: req.path,
|
|
85
|
-
id,
|
|
86
|
-
objectid,
|
|
87
|
-
|
|
88
|
-
type,
|
|
89
|
-
payload: data,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const result = id
|
|
93
|
-
? await dataUpdate({
|
|
94
|
-
pg, table, data, id, uid: user?.uid,
|
|
95
|
-
})
|
|
96
|
-
: await dataInsert({
|
|
97
|
-
pg, table, data, uid: user?.uid,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
return reply.status(200).send({
|
|
101
|
-
rowCount: result.rowCount,
|
|
102
|
-
data: 'ok',
|
|
103
|
-
command: result.command,
|
|
104
|
-
id: result.rows?.[0]?.[pkList[type]] || result?.[pkList[type]],
|
|
105
|
-
});
|
|
106
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import getMeta from '../../../plugins/pg/funcs/getMeta.js';
|
|
4
|
+
import dataInsert from '../../../plugins/crud/funcs/dataInsert.js';
|
|
5
|
+
import dataUpdate from '../../../plugins/crud/funcs/dataUpdate.js';
|
|
6
|
+
import applyHook from '../../../plugins/hook/funcs/applyHook.js';
|
|
7
|
+
import uploadMultiPart from '../../../plugins/file/uploadMultiPart.js';
|
|
8
|
+
|
|
9
|
+
const tableList = {
|
|
10
|
+
comment: 'crm.communications',
|
|
11
|
+
gallery: 'crm.files',
|
|
12
|
+
file: 'crm.files',
|
|
13
|
+
checklist: 'crm.checklists',
|
|
14
|
+
};
|
|
15
|
+
const pkList = {
|
|
16
|
+
comment: 'communication_id',
|
|
17
|
+
checklist: 'checklist_id',
|
|
18
|
+
file: 'file_id',
|
|
19
|
+
gallery: 'file_id',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
|
|
23
|
+
|
|
24
|
+
export default async function widgetSet(req, reply) {
|
|
25
|
+
const {
|
|
26
|
+
pg, params = {}, session = {}, headers = {}, body = {}, user = {},
|
|
27
|
+
} = req;
|
|
28
|
+
const { type, id, objectid } = params;
|
|
29
|
+
|
|
30
|
+
if (!['comment', 'checklist', 'file', 'gallery'].includes(type)) {
|
|
31
|
+
return reply.status(400).send('param type not valid');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!objectid) {
|
|
35
|
+
return reply.status(400).send('not enough params: id');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const table = tableList[type];
|
|
39
|
+
|
|
40
|
+
// dsadasdad
|
|
41
|
+
if (['gallery', 'file'].includes(type) && headers['content-type']?.split?.(';')?.shift?.() === 'multipart/form-data') {
|
|
42
|
+
const file = await uploadMultiPart(req);
|
|
43
|
+
const extName = path.extname(file.filepath).slice(1).toLowerCase();
|
|
44
|
+
|
|
45
|
+
const data = {
|
|
46
|
+
uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
|
|
47
|
+
file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
|
|
48
|
+
ext: extName,
|
|
49
|
+
size: file?.size,
|
|
50
|
+
file_status: 1,
|
|
51
|
+
uid: user?.uid || 1,
|
|
52
|
+
entity_id: objectid,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
if (type === 'gallery' && !galleryExtList.includes(extName.toLowerCase())) {
|
|
56
|
+
return reply.status(400).send('invalid file extension');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { rows = [] } = await dataInsert({
|
|
60
|
+
pg, table: 'crm.files', data, uid: user?.uid,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (type === 'gallery') {
|
|
64
|
+
await pg.query(`update crm.files set ismain=true
|
|
65
|
+
where entity_id=$1
|
|
66
|
+
and file_id=$2
|
|
67
|
+
and (select count(*) = 0 from crm.files where entity_id=$1 and ismain)`, [objectid, rows[0]?.file_id]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, entity_id: rows[0]?.entity_id,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const { pk } = await getMeta({ pg, table });
|
|
75
|
+
|
|
76
|
+
if (!pk) {
|
|
77
|
+
return reply.status(404).send('table not found');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const data = { ...body, uid: user?.uid, entity_id: objectid };
|
|
81
|
+
|
|
82
|
+
await applyHook('onWidgetSet', {
|
|
83
|
+
pg,
|
|
84
|
+
link: req.path,
|
|
85
|
+
id,
|
|
86
|
+
objectid,
|
|
87
|
+
user,
|
|
88
|
+
type,
|
|
89
|
+
payload: data,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const result = id
|
|
93
|
+
? await dataUpdate({
|
|
94
|
+
pg, table, data, id, uid: user?.uid,
|
|
95
|
+
})
|
|
96
|
+
: await dataInsert({
|
|
97
|
+
pg, table, data, uid: user?.uid,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return reply.status(200).send({
|
|
101
|
+
rowCount: result.rowCount,
|
|
102
|
+
data: 'ok',
|
|
103
|
+
command: result.command,
|
|
104
|
+
id: result.rows?.[0]?.[pkList[type]] || result?.[pkList[type]],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
@@ -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
|
+
}
|