@opengis/admin 0.2.101 → 0.2.102
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/{add-page-CIxr0QVt.js → add-page-ng7vx4Nh.js} +1 -1
- package/dist/{admin-interface-DohUSsAx.js → admin-interface-dNCM41Ed.js} +1 -1
- package/dist/{admin-view-hNFc7Wm7.js → admin-view-8fTOFWCP.js} +1 -1
- package/dist/admin.js +1 -1
- package/dist/admin.umd.cjs +48 -48
- package/dist/{card-view-BXGlPipy.js → card-view-LBKjcQpn.js} +1 -1
- package/dist/{edit-page-COqubwSc.js → edit-page-Dl551-GP.js} +1 -1
- package/dist/{import-file-CIA2eGIc.js → import-file-DRlEx3gL.js} +11663 -11636
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/server/routes/notifications/hook/onWidgetSet.js +1 -2
- package/server/routes/widget/controllers/widget.get.js +16 -10
- package/server/routes/widget/controllers/widget.set.js +45 -37
- package/server/routes/widget/hook/onWidgetSet.js +12 -0
- package/server/routes/widget/index.mjs +6 -1
- package/server/routes/widget/controllers/utils/obj2db.js +0 -13
@@ -24,12 +24,14 @@ export default async function widgetGet({
|
|
24
24
|
const sqls = {
|
25
25
|
comment: pg.pk['admin.users']
|
26
26
|
? `select communication_id, entity_id, body, subject, c.cdate, c.uid,
|
27
|
-
${username}, u.login, avatar
|
28
|
-
from crm.communications c
|
27
|
+
${username} as username, u.login, u.avatar
|
28
|
+
from crm.communications c
|
29
|
+
left join admin.users u on u.uid=c.uid
|
30
|
+
where entity_id=$1 order by cdate desc`
|
29
31
|
: 'select communication_id, entity_id, body, subject, cdate, uid from crm.communications where entity_id=$1 order by cdate desc',
|
30
32
|
|
31
33
|
history: `SELECT change_id, entity_id, entity_type, change_type, change_date, a.change_user_id, a.uid, a.cdate, b.json_agg as changes,
|
32
|
-
${username}, u.login
|
34
|
+
${username} as username, u.login, u.avatar
|
33
35
|
FROM log.table_changes a
|
34
36
|
left join admin.users u on a.change_user_id = u.uid
|
35
37
|
left join lateral(
|
@@ -46,21 +48,25 @@ export default async function widgetGet({
|
|
46
48
|
limit 100`,
|
47
49
|
|
48
50
|
checklist: pg.pk['admin.users']
|
49
|
-
? `SELECT checklist_id, entity_id, subject, is_done, done_date, c.uid, c.cdate, ${username}, u.login,
|
50
|
-
|
51
|
+
? `SELECT checklist_id, entity_id, subject, is_done, done_date, c.uid, c.cdate, ${username} as username, u.login, u.avatar
|
52
|
+
FROM crm.checklists c
|
53
|
+
left join admin.users u on u.uid=c.uid
|
54
|
+
where entity_id=$1 order by cdate desc`
|
51
55
|
: 'SELECT checklist_id, entity_id, subject, is_done, done_date, uid, cdate FROM crm.checklists where entity_id=$1 order by cdate desc',
|
52
56
|
|
53
57
|
file: pg.pk['admin.users']
|
54
|
-
? `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
|
55
|
-
${username}, u.login, isverified,
|
56
|
-
|
58
|
+
? `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
|
59
|
+
${username} as username, u.login, isverified, u.avatar, u.uid as author, file_status
|
60
|
+
FROM crm.files c
|
61
|
+
left join admin.users u on u.uid=c.uid
|
57
62
|
where entity_id=$1 and file_status<>3 order by cdate desc`
|
58
63
|
: `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, uid, cdate, file_type, ismain,
|
59
64
|
isverified, uid as author, file_status FROM crm.files c where entity_id=$1 and file_status<>3 order by cdate desc`,
|
60
65
|
gallery: pg.pk['admin.users']
|
61
66
|
? `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
|
62
|
-
${username}, u.login, isverified,
|
63
|
-
|
67
|
+
${username} as username, u.login, u.avatar, isverified, u.avatar, c.uid as author, file_status
|
68
|
+
FROM crm.files c
|
69
|
+
left join admin.users u on u.uid=c.uid
|
64
70
|
where entity_id=$1 and file_status<>3 and ext = any($2) order by cdate desc`
|
65
71
|
: `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, ismain,
|
66
72
|
isverified, uid as author, file_status FROM crm.files c where entity_id=$1 and file_status<>3 and ext = any($2) order by cdate desc`,
|
@@ -8,11 +8,13 @@ import { uploadMultiPart } from '@opengis/fastify-file/utils.js';
|
|
8
8
|
|
9
9
|
const tableList = {
|
10
10
|
comment: 'crm.communications',
|
11
|
+
gallery: 'crm.files',
|
11
12
|
checklist: 'crm.checklists',
|
12
13
|
};
|
13
14
|
const pkList = {
|
14
15
|
comment: 'communication_id',
|
15
16
|
checklist: 'checklist_id',
|
17
|
+
gallery: 'file_id',
|
16
18
|
};
|
17
19
|
|
18
20
|
const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
|
@@ -28,49 +30,55 @@ export default async function widgetSet(req) {
|
|
28
30
|
|
29
31
|
const table = tableList[type];
|
30
32
|
|
33
|
+
// dsadasdad
|
34
|
+
if (['gallery', 'file'].includes(type) && req.headers['content-type'].split(';').shift() === "multipart/form-data") {
|
35
|
+
const file = await uploadMultiPart(req);
|
36
|
+
const extName = path.extname(file.filepath).slice(1).toLowerCase();
|
31
37
|
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
const data = {
|
39
|
+
uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
|
40
|
+
file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
|
41
|
+
ext: extName,
|
42
|
+
size: file?.size,
|
43
|
+
file_status: 1,
|
44
|
+
uid: user?.uid || 1,
|
45
|
+
entity_id: objectid,
|
46
|
+
};
|
35
47
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
ext: extName,
|
40
|
-
size: file?.size,
|
41
|
-
file_status: 1,
|
42
|
-
uid: user?.uid || 1,
|
43
|
-
entity_id: objectid,
|
44
|
-
};
|
48
|
+
if (type === 'gallery' && !galleryExtList.includes(extName.toLowerCase())) {
|
49
|
+
return { message: 'invalid file extension', status: 400 };
|
50
|
+
}
|
45
51
|
|
46
|
-
|
47
|
-
|
48
|
-
|
52
|
+
const { rows = [] } = await dataInsert({
|
53
|
+
table: 'crm.files', data, uid: user?.uid,
|
54
|
+
});
|
55
|
+
return {
|
56
|
+
rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, entity_id: rows[0]?.entity_id,
|
57
|
+
};
|
58
|
+
}
|
59
|
+
const { pk } = await getMeta({ pg, table });
|
60
|
+
if (!pk) return { message: 'table not found', status: 404 };
|
49
61
|
|
50
|
-
|
51
|
-
table: 'crm.files', data, uid: user?.uid,
|
52
|
-
});
|
53
|
-
return {
|
54
|
-
rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, entity_id: rows[0]?.entity_id,
|
55
|
-
};
|
56
|
-
}
|
57
|
-
const { pk } = await getMeta({ pg, table });
|
58
|
-
if (!pk) return { message: 'table not found', status: 404 };
|
62
|
+
const data = { ...body, uid: user?.uid, entity_id: objectid };
|
59
63
|
|
60
|
-
|
64
|
+
await applyHook('onWidgetSet', {
|
65
|
+
link: req.path,
|
66
|
+
id,
|
67
|
+
objectid,
|
68
|
+
session,
|
69
|
+
type,
|
70
|
+
payload: data,
|
71
|
+
});
|
61
72
|
|
62
|
-
|
63
|
-
|
73
|
+
const result = id
|
74
|
+
? await dataUpdate({
|
75
|
+
table, data, id, uid: user?.uid,
|
76
|
+
})
|
77
|
+
: await dataInsert({
|
78
|
+
table, data, uid: user?.uid,
|
64
79
|
});
|
65
|
-
const result = id
|
66
|
-
? await dataUpdate({
|
67
|
-
table, data, id, uid: user?.uid,
|
68
|
-
})
|
69
|
-
: await dataInsert({
|
70
|
-
table, data, uid: user?.uid,
|
71
|
-
});
|
72
80
|
|
73
|
-
|
74
|
-
|
75
|
-
|
81
|
+
return {
|
82
|
+
rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]] || result?.[pkList[type]],
|
83
|
+
};
|
76
84
|
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { pgClients } from '@opengis/fastify-table/utils.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
|
+
}
|
@@ -1,11 +1,16 @@
|
|
1
|
+
import { addHook } from '@opengis/fastify-table/utils.js';
|
2
|
+
|
1
3
|
import widgetDel from './controllers/widget.del.js';
|
2
4
|
import widgetSet from './controllers/widget.set.js';
|
3
5
|
import widgetGet from './controllers/widget.get.js';
|
4
6
|
|
5
|
-
import
|
7
|
+
import onWidgetSet from './hook/onWidgetSet.js';
|
8
|
+
|
9
|
+
import { tableSchema } from './schema.js';
|
6
10
|
|
7
11
|
export default async function route(fastify) {
|
8
12
|
fastify.delete(`/widget/:type/:objectid/:id`, { scheme: tableSchema }, widgetDel);
|
9
13
|
fastify.post(`/widget/:type/:objectid/:id?`, { scheme: tableSchema }, widgetSet);
|
10
14
|
fastify.get(`/widget/:type/:objectid`, { config: { policy: ['public'] }, scheme: tableSchema }, widgetGet);
|
15
|
+
addHook('onWidgetSet', onWidgetSet);
|
11
16
|
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
export default function obj2db(data, nonexistCol) {
|
2
|
-
if (
|
3
|
-
typeof data !== 'object'
|
4
|
-
|| Array.isArray(data)
|
5
|
-
|| !Object.keys(data || {}).length
|
6
|
-
) return { error: 'invalid data type' };
|
7
|
-
|
8
|
-
const columns = Object.keys(data)?.filter((key) => !nonexistCol.includes(key));
|
9
|
-
// const columns = existColumns?.filter((col) => data[col] || data?.[col] === 0);
|
10
|
-
const args = columns?.map((col) => data[col]);
|
11
|
-
|
12
|
-
return { columns, args, error: !columns?.length ? 'nothing to process' : undefined };
|
13
|
-
}
|