@opengis/admin 0.4.15 → 0.4.17
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-CLQKORAq.js → add-page-D3JHk421.js} +1 -1
- package/dist/{admin-interface-CpLDRPag.js → admin-interface-Bh0X1WRG.js} +229 -210
- package/dist/{admin-view-B2qQ1IHJ.js → admin-view-BaFEZfOb.js} +1 -1
- package/dist/admin.js +1 -1
- package/dist/admin.umd.cjs +1 -1
- package/dist/{card-view-Cj5WEg5z.js → card-view-B6lmjnUp.js} +1 -1
- package/dist/{edit-page-r6I6Vi6E.js → edit-page-BRMI75iP.js} +1 -1
- package/dist/{import-file-q1gVGP28.js → import-file-DanTkH8S.js} +7 -7
- package/dist/{profile-page-DRdrE5zR.js → profile-page-Cvt3Wmr6.js} +1 -1
- package/package.json +3 -2
- package/server/routes/widget/controllers/file.edit.js +0 -51
- package/server/routes/widget/controllers/widget.del.js +0 -79
- package/server/routes/widget/controllers/widget.get.js +0 -136
- package/server/routes/widget/controllers/widget.set.js +0 -99
- package/server/routes/widget/hook/onWidgetSet.js +0 -12
- package/server/routes/widget/index.mjs +0 -20
- package/server/routes/widget/schema.js +0 -13
@@ -1,4 +1,4 @@
|
|
1
|
-
import { _ as $, f as d, u as k, s as V } from "./import-file-
|
1
|
+
import { _ as $, f as d, u as k, s as V } from "./import-file-DanTkH8S.js";
|
2
2
|
import { resolveComponent as j, createElementBlock as g, openBlock as p, createElementVNode as m, createCommentVNode as b, normalizeClass as x, normalizeStyle as y, createBlock as E } from "vue";
|
3
3
|
const O = {
|
4
4
|
data() {
|
@@ -3725,27 +3725,27 @@ const rM = [
|
|
3725
3725
|
{
|
3726
3726
|
name: "edit",
|
3727
3727
|
path: "/edit",
|
3728
|
-
component: () => import("./edit-page-
|
3728
|
+
component: () => import("./edit-page-BRMI75iP.js")
|
3729
3729
|
},
|
3730
3730
|
{
|
3731
3731
|
name: "add",
|
3732
3732
|
path: "/add",
|
3733
|
-
component: () => import("./add-page-
|
3733
|
+
component: () => import("./add-page-D3JHk421.js")
|
3734
3734
|
},
|
3735
3735
|
{
|
3736
3736
|
path: "/profile",
|
3737
3737
|
name: "profile",
|
3738
|
-
component: () => import("./profile-page-
|
3738
|
+
component: () => import("./profile-page-Cvt3Wmr6.js")
|
3739
3739
|
},
|
3740
3740
|
{
|
3741
3741
|
name: "card-view",
|
3742
3742
|
path: "/card",
|
3743
|
-
component: () => import("./card-view-
|
3743
|
+
component: () => import("./card-view-B6lmjnUp.js"),
|
3744
3744
|
children: [
|
3745
3745
|
{
|
3746
3746
|
name: "table",
|
3747
3747
|
path: ":table",
|
3748
|
-
component: () => import("./card-view-
|
3748
|
+
component: () => import("./card-view-B6lmjnUp.js"),
|
3749
3749
|
children: [
|
3750
3750
|
{
|
3751
3751
|
name: "card",
|
@@ -3806,14 +3806,14 @@ const cM = /* @__PURE__ */ gt(sM, [["render", lM]]), uM = (t) => {
|
|
3806
3806
|
{
|
3807
3807
|
path: "/",
|
3808
3808
|
name: "home",
|
3809
|
-
component: () => import("./admin-view-
|
3809
|
+
component: () => import("./admin-view-BaFEZfOb.js"),
|
3810
3810
|
children: [
|
3811
3811
|
...t,
|
3812
3812
|
...e,
|
3813
3813
|
// { path: '/', redirect: '/home' },
|
3814
3814
|
{
|
3815
3815
|
path: "/:catchAll(.*)",
|
3816
|
-
component: () => import("./admin-interface-
|
3816
|
+
component: () => import("./admin-interface-Bh0X1WRG.js")
|
3817
3817
|
}
|
3818
3818
|
]
|
3819
3819
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { _ as n, f as m } from "./import-file-
|
1
|
+
import { _ as n, f as m } from "./import-file-DanTkH8S.js";
|
2
2
|
import { u as p } from "./user-B_2kh6ic.js";
|
3
3
|
import { resolveComponent as f, createElementBlock as d, openBlock as u, createElementVNode as o, createBlock as h, createCommentVNode as b } from "vue";
|
4
4
|
const x = {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@opengis/admin",
|
3
|
-
"version": "0.4.
|
3
|
+
"version": "0.4.17",
|
4
4
|
"description": "This project Softpro Admin",
|
5
5
|
"main": "dist/admin.js",
|
6
6
|
"type": "module",
|
@@ -25,6 +25,7 @@
|
|
25
25
|
"prod": "cross-env NODE_ENV=production npm run start",
|
26
26
|
"debug": "node --watch-path=server server",
|
27
27
|
"start": "node server",
|
28
|
+
"start-env": "node --env-file=.env server",
|
28
29
|
"docs:i": "npm install --prefix ./docs",
|
29
30
|
"docs:dev": "npm run --prefix ./docs docs:dev",
|
30
31
|
"docs:build": "npm run --prefix ./docs docs:build",
|
@@ -51,7 +52,7 @@
|
|
51
52
|
"@opengis/fastify-auth": "1.1.x",
|
52
53
|
"@opengis/fastify-table": "1.4.x",
|
53
54
|
"@opengis/v3-core": "^0.3.213",
|
54
|
-
"@opengis/v3-filter": "
|
55
|
+
"@opengis/v3-filter": "0.1.30",
|
55
56
|
"@turf/turf": "^7.1.0",
|
56
57
|
"@vitejs/plugin-vue": "^5.0.4",
|
57
58
|
"@vueuse/core": "^13.0.0",
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import path from 'node:path';
|
2
|
-
|
3
|
-
import { dataUpdate, pgClients, uploadMultiPart } from '@opengis/fastify-table/utils.js';
|
4
|
-
|
5
|
-
export default async function widgetSet(req, reply) {
|
6
|
-
const { pg = pgClients.client, headers = {}, user = {}, params = {} } = req;
|
7
|
-
|
8
|
-
if (!params?.id) {
|
9
|
-
return reply.status(400).send('not enough params: id');
|
10
|
-
}
|
11
|
-
|
12
|
-
if (!pg.pk?.['crm.files']) {
|
13
|
-
return reply.status(404).send('table not found');
|
14
|
-
}
|
15
|
-
|
16
|
-
if (headers['content-type']?.split?.(';')?.shift?.() !== 'multipart/form-data') {
|
17
|
-
return reply.status(400).send('invalid payload content type');
|
18
|
-
}
|
19
|
-
|
20
|
-
const file = await uploadMultiPart(req);
|
21
|
-
const extName = path.extname(file.filepath).slice(1).toLowerCase();
|
22
|
-
|
23
|
-
const data = {
|
24
|
-
uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
|
25
|
-
file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
|
26
|
-
ext: extName,
|
27
|
-
size: file?.size,
|
28
|
-
file_status: 1,
|
29
|
-
uid: user?.uid || 1,
|
30
|
-
};
|
31
|
-
|
32
|
-
const result = await dataUpdate({
|
33
|
-
pg,
|
34
|
-
table: 'crm.files',
|
35
|
-
id: params.id,
|
36
|
-
data,
|
37
|
-
uid: user?.uid,
|
38
|
-
});
|
39
|
-
|
40
|
-
if (!result?.file_id) {
|
41
|
-
return reply.status(404).send('file not found');
|
42
|
-
}
|
43
|
-
|
44
|
-
return reply.status(200).send({
|
45
|
-
rowCount: 1,
|
46
|
-
data: result,
|
47
|
-
command: 'UPLOAD',
|
48
|
-
id: result?.file_id,
|
49
|
-
entity_id: result?.entity_id,
|
50
|
-
});
|
51
|
-
}
|
@@ -1,79 +0,0 @@
|
|
1
|
-
import { pgClients, logChanges, isFileExists } from "@opengis/fastify-table/utils.js";
|
2
|
-
|
3
|
-
import { isAdmin } from "../../../../utils.js";
|
4
|
-
|
5
|
-
async function checkAccess(pg, objectid, id) {
|
6
|
-
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])
|
7
|
-
.then(el => el.rows?.[0] || {});
|
8
|
-
return { uid, exists: filepath ? await isFileExists(filepath) : null };
|
9
|
-
}
|
10
|
-
|
11
|
-
/**
|
12
|
-
* Дістає CRM дані для vue хешує ідентифікатори, підтягує селекти
|
13
|
-
*
|
14
|
-
* @method DELETE
|
15
|
-
* @summary CRM дані для обраного віджета.
|
16
|
-
* @priority 2
|
17
|
-
* @tag table
|
18
|
-
* @type api
|
19
|
-
* @requires setTokenById
|
20
|
-
* @requires getSelect
|
21
|
-
* @param {String} id Ідентифікатор для хешування
|
22
|
-
* @param {Any} sql Використовується для повернення sql запиту
|
23
|
-
* @param {String} type Тип для хешування даних
|
24
|
-
* @errors 400, 500
|
25
|
-
* @returns {Number} status Номер помилки
|
26
|
-
* @returns {String|Object} error Опис помилки
|
27
|
-
* @returns {String|Object} message Повідомлення про успішне виконання або об'єкт з параметрами
|
28
|
-
*/
|
29
|
-
|
30
|
-
export default async function widgetDel(req, reply) {
|
31
|
-
const {
|
32
|
-
pg = pgClients.client, params = {}, user = {},
|
33
|
-
} = req;
|
34
|
-
|
35
|
-
if (!user?.uid) {
|
36
|
-
return reply.status(401).send('access restricted: user not authorized');
|
37
|
-
}
|
38
|
-
|
39
|
-
const { type, objectid, id } = params;
|
40
|
-
|
41
|
-
if (!objectid) {
|
42
|
-
return reply.status(400).send('not enough params: id');
|
43
|
-
}
|
44
|
-
|
45
|
-
// force delete db entry if file not exists
|
46
|
-
const { exists, uid } = ['file', 'gallery'].includes(type) ? await checkAccess(pg, objectid, id) : {};
|
47
|
-
|
48
|
-
if (exists && !isAdmin(req) && uid && user?.uid !== uid) {
|
49
|
-
return reply.status(403).send('access restricted: file exists, not an author');
|
50
|
-
}
|
51
|
-
|
52
|
-
const sqls = {
|
53
|
-
comment: `delete from crm.communications where entity_id=$1 and ${isAdmin(req) ? '$2=$2' : 'uid=$2'} and communication_id=$3`,
|
54
|
-
checklist: `delete from crm.checklists where entity_id=$1 and ${isAdmin(req) ? '$2=$2' : 'uid=$2'} and checklist_id=$3`,
|
55
|
-
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`,
|
56
|
-
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`,
|
57
|
-
};
|
58
|
-
|
59
|
-
const sql = sqls[type];
|
60
|
-
const table = {
|
61
|
-
comment: 'crm.communications',
|
62
|
-
checklist: 'crm.checklists',
|
63
|
-
file: 'crm.files',
|
64
|
-
gallery: 'crm.files',
|
65
|
-
}[type];
|
66
|
-
|
67
|
-
if (!sql) {
|
68
|
-
return reply.status(400).send('invalid widget type');
|
69
|
-
}
|
70
|
-
|
71
|
-
const { rows = [] } = await pg.query(sql, [objectid, user.uid, id]);
|
72
|
-
|
73
|
-
await logChanges({
|
74
|
-
pg, table, id, data: rows[0], uid: user?.uid, type: 'DELETE',
|
75
|
-
});
|
76
|
-
|
77
|
-
return { data: { id }, user: { uid: user.uid, name: user.user_name } };
|
78
|
-
|
79
|
-
}
|
@@ -1,136 +0,0 @@
|
|
1
|
-
import { getMeta, getToken, pgClients } from '@opengis/fastify-table/utils.js';
|
2
|
-
|
3
|
-
const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
|
4
|
-
const username = `coalesce(u.sur_name,'')||coalesce(' '||u.user_name,'') ||coalesce(' '||u.father_name,'')`;
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Дістає CRM для widget
|
8
|
-
*
|
9
|
-
*/
|
10
|
-
|
11
|
-
export default async function widgetGet({
|
12
|
-
pg = pgClients.client, user = {}, params = {}, query = {}, unittest,
|
13
|
-
}, reply) {
|
14
|
-
const param = user?.uid ? await getToken({
|
15
|
-
token: params.objectid, mode: 'w', uid: user.uid,
|
16
|
-
}) : null;
|
17
|
-
|
18
|
-
const objectid = param ? JSON.parse(param)?.id : params.objectid;
|
19
|
-
|
20
|
-
if (!objectid) {
|
21
|
-
return reply.status(400).send('not enough params: id');
|
22
|
-
}
|
23
|
-
|
24
|
-
const sqls = {
|
25
|
-
comment: pg.pk['admin.users']
|
26
|
-
? `select communication_id, entity_id, body, subject, c.cdate, c.uid,
|
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`
|
31
|
-
: 'select communication_id, entity_id, body, subject, cdate, uid from crm.communications where entity_id=$1 order by cdate desc',
|
32
|
-
|
33
|
-
history: `select * from (
|
34
|
-
SELECT change_id, entity_id, entity_type, change_type, change_date, a.change_user_id, a.uid, a.cdate, b.json_agg as changes,
|
35
|
-
${username} as username, u.login, u.avatar
|
36
|
-
FROM log.table_changes a
|
37
|
-
left join admin.users u on a.change_user_id = u.uid
|
38
|
-
left join lateral(
|
39
|
-
select json_agg(row_to_json(q)) from (
|
40
|
-
select change_data_id, entity_key, value_new, value_old from log.table_changes_data
|
41
|
-
where change_id=a.change_id
|
42
|
-
)q
|
43
|
-
)b on 1=1
|
44
|
-
where b.json_agg is not null and (entity_id=$1 or entity_id in (
|
45
|
-
select communication_id as comments from crm.communications where entity_id=$1
|
46
|
-
union all select checklist_id from crm.checklists where entity_id=$1)
|
47
|
-
)
|
48
|
-
|
49
|
-
union all
|
50
|
-
select change_id, entity_id, entity_type, change_type, change_date, a.change_user_id, a.uid, a.cdate, b.json_agg as changes,
|
51
|
-
${username} as username, u.login, u.avatar
|
52
|
-
FROM log.table_changes a
|
53
|
-
left join admin.users u on a.change_user_id = u.uid
|
54
|
-
left join lateral(
|
55
|
-
select json_agg(o) from (
|
56
|
-
select json_object_agg(entity_key, coalesce(value_new, value_old)) as o from log.table_changes_data
|
57
|
-
where change_id=a.change_id and entity_key not in ('uid', 'file_status', 'editor_id', 'cdate', 'editor_date', 'entity_id')
|
58
|
-
)q
|
59
|
-
)b on 1=1
|
60
|
-
where a.change_type in ('INSERT', 'DELETE') and a.entity_id in (select file_id from crm.files where entity_id=$1)
|
61
|
-
limit 100
|
62
|
-
|
63
|
-
)q order by cdate desc limit 100`,
|
64
|
-
|
65
|
-
checklist: pg.pk['admin.users']
|
66
|
-
? `SELECT checklist_id, entity_id, subject, is_done, done_date, c.uid, c.cdate, ${username} as username, u.login, u.avatar
|
67
|
-
FROM crm.checklists c
|
68
|
-
left join admin.users u on u.uid=c.uid
|
69
|
-
where entity_id=$1 order by cdate desc`
|
70
|
-
: 'SELECT checklist_id, entity_id, subject, is_done, done_date, uid, cdate FROM crm.checklists where entity_id=$1 order by cdate desc',
|
71
|
-
|
72
|
-
file: pg.pk['admin.users']
|
73
|
-
? `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
|
74
|
-
${username} as username, u.login, isverified, u.avatar, u.uid as author, file_status
|
75
|
-
FROM crm.files c
|
76
|
-
left join admin.users u on u.uid=c.uid
|
77
|
-
where entity_id=$1 and file_status<>3 order by cdate desc`
|
78
|
-
: `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, uid, cdate, file_type, ismain,
|
79
|
-
isverified, uid as author, file_status FROM crm.files c where entity_id=$1 and file_status<>3 order by cdate desc`,
|
80
|
-
gallery: pg.pk['admin.users']
|
81
|
-
? `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, c.ismain,
|
82
|
-
${username} as username, u.login, u.avatar, isverified, u.avatar, c.uid as author, file_status
|
83
|
-
FROM crm.files c
|
84
|
-
left join admin.users u on u.uid=c.uid
|
85
|
-
where entity_id=$1 and file_status<>3 and ext = any($2) order by cdate desc`
|
86
|
-
: `SELECT file_id, entity_id, entity_type, file_path, uploaded_name, ext, size, c.uid, c.cdate, file_type, ismain,
|
87
|
-
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`,
|
88
|
-
|
89
|
-
};
|
90
|
-
|
91
|
-
const q = sqls[params.type];
|
92
|
-
|
93
|
-
if (!q) {
|
94
|
-
return reply.status(400).send('invalid widget type');
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
/* data */
|
99
|
-
const time = [Date.now()];
|
100
|
-
const { rows = [] } = await pg.query(q, [objectid, params.type === 'gallery' ? galleryExtList : null].filter((el) => el));
|
101
|
-
rows.forEach(row => Object.assign(row, { username: row.username?.trim?.() || row.login }));
|
102
|
-
time.push(Date.now());
|
103
|
-
|
104
|
-
/* Object info */
|
105
|
-
const { tableName } = pg.pk['log.table_changes'] ? await pg.query(
|
106
|
-
'select entity_type as "tableName" from log.table_changes where entity_id=$1 limit 1',
|
107
|
-
[objectid]
|
108
|
-
).then(el => el.rows?.[0] || {}) : {};
|
109
|
-
|
110
|
-
const { pk, columns = [] } = await getMeta({ pg, table: tableName });
|
111
|
-
|
112
|
-
const authorIdColumn = columns.find(col => ['uid', 'created_by'].includes(col.name))?.name;
|
113
|
-
|
114
|
-
if (!pk && params.type === 'history' && !unittest) {
|
115
|
-
return reply.status(404).send('log table not found');
|
116
|
-
}
|
117
|
-
|
118
|
-
const q1 = `select ${username} as author, u.login, a.cdate, a.editor_date from ${tableName} a
|
119
|
-
left join admin.users u on a.${authorIdColumn}=u.uid where a.${pk}=$1 limit 1`;
|
120
|
-
|
121
|
-
const data = pg.pk['admin.users'] && pk && tableName ? await pg.query(q, [objectid, params.type === 'gallery' ? galleryExtList : null].filter((el) => el)).then(el => el.rows?.[0] || {}) : {};
|
122
|
-
|
123
|
-
if (query.debug && user?.user_type === 'admin') {
|
124
|
-
return {
|
125
|
-
q, type: params.type, q1, id: objectid, data,
|
126
|
-
};
|
127
|
-
}
|
128
|
-
|
129
|
-
return {
|
130
|
-
time: { data: time[1] - time[0] },
|
131
|
-
rows,
|
132
|
-
user: { uid: user?.uid, name: user?.user_name },
|
133
|
-
data: { author: data?.author, cdate: data?.cdate, edate: data?.editor_date },
|
134
|
-
objectid: params.objectid,
|
135
|
-
};
|
136
|
-
}
|
@@ -1,99 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
|
3
|
-
import {
|
4
|
-
getMeta, dataInsert, dataUpdate, applyHook, uploadMultiPart,
|
5
|
-
} from '@opengis/fastify-table/utils.js';
|
6
|
-
|
7
|
-
const tableList = {
|
8
|
-
comment: 'crm.communications',
|
9
|
-
gallery: 'crm.files',
|
10
|
-
checklist: 'crm.checklists',
|
11
|
-
};
|
12
|
-
const pkList = {
|
13
|
-
comment: 'communication_id',
|
14
|
-
checklist: 'checklist_id',
|
15
|
-
gallery: 'file_id',
|
16
|
-
};
|
17
|
-
|
18
|
-
const galleryExtList = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'mp4', 'mov', 'avi'];
|
19
|
-
|
20
|
-
export default async function widgetSet(req, reply) {
|
21
|
-
const {
|
22
|
-
pg, params = {}, session = {}, headers = {}, body = {}, user = {}, unittest,
|
23
|
-
} = req;
|
24
|
-
const { type, id, objectid } = params;
|
25
|
-
|
26
|
-
if (!['comment', 'checklist', 'file', 'gallery'].includes(type)) {
|
27
|
-
return reply.status(400).send('param type not valid');
|
28
|
-
}
|
29
|
-
|
30
|
-
if (!objectid) {
|
31
|
-
return reply.status(400).send('not enough params: id');
|
32
|
-
}
|
33
|
-
|
34
|
-
const table = tableList[type];
|
35
|
-
|
36
|
-
// dsadasdad
|
37
|
-
if (['gallery', 'file'].includes(type) && headers['content-type']?.split?.(';')?.shift?.() === "multipart/form-data") {
|
38
|
-
const file = await uploadMultiPart(req);
|
39
|
-
const extName = path.extname(file.filepath).slice(1).toLowerCase();
|
40
|
-
|
41
|
-
const data = {
|
42
|
-
uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
|
43
|
-
file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
|
44
|
-
ext: extName,
|
45
|
-
size: file?.size,
|
46
|
-
file_status: 1,
|
47
|
-
uid: user?.uid || 1,
|
48
|
-
entity_id: objectid,
|
49
|
-
};
|
50
|
-
|
51
|
-
if (type === 'gallery' && !galleryExtList.includes(extName.toLowerCase())) {
|
52
|
-
return reply.status(400).send('invalid file extension');
|
53
|
-
}
|
54
|
-
|
55
|
-
const { rows = [] } = await dataInsert({
|
56
|
-
pg, table: 'crm.files', data, uid: user?.uid,
|
57
|
-
});
|
58
|
-
|
59
|
-
if (type === 'gallery') {
|
60
|
-
await pg.query(`update crm.files set ismain=true
|
61
|
-
where entity_id=$1
|
62
|
-
and file_id=$2
|
63
|
-
and (select count(*) = 0 from crm.files where entity_id=$1 and ismain)`, [objectid, rows[0]?.file_id]);
|
64
|
-
}
|
65
|
-
|
66
|
-
return {
|
67
|
-
rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, entity_id: rows[0]?.entity_id,
|
68
|
-
};
|
69
|
-
}
|
70
|
-
const { pk } = await getMeta({ pg, table });
|
71
|
-
|
72
|
-
if (!pk) {
|
73
|
-
return reply.status(404).send('table not found');
|
74
|
-
}
|
75
|
-
|
76
|
-
const data = { ...body, uid: user?.uid, entity_id: objectid };
|
77
|
-
|
78
|
-
await applyHook('onWidgetSet', {
|
79
|
-
pg,
|
80
|
-
link: req.path,
|
81
|
-
id,
|
82
|
-
objectid,
|
83
|
-
session,
|
84
|
-
type,
|
85
|
-
payload: data,
|
86
|
-
});
|
87
|
-
|
88
|
-
const result = id
|
89
|
-
? await dataUpdate({
|
90
|
-
pg, table, data, id, uid: user?.uid,
|
91
|
-
})
|
92
|
-
: await dataInsert({
|
93
|
-
pg, table, data, uid: user?.uid,
|
94
|
-
});
|
95
|
-
|
96
|
-
return {
|
97
|
-
rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]] || result?.[pkList[type]],
|
98
|
-
};
|
99
|
-
}
|
@@ -1,12 +0,0 @@
|
|
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,20 +0,0 @@
|
|
1
|
-
import { addHook } from '@opengis/fastify-table/utils.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
|
-
import { tableSchema } from './schema.js';
|
11
|
-
|
12
|
-
const policy = ['site'];
|
13
|
-
|
14
|
-
export default async function route(fastify) {
|
15
|
-
fastify.delete(`/widget/:type/:objectid/:id`, { config: { policy }, scheme: tableSchema }, widgetDel);
|
16
|
-
fastify.post(`/widget/:type/:objectid/:id?`, { config: { policy }, scheme: tableSchema }, widgetSet);
|
17
|
-
fastify.put(`/file-edit/:id`, { config: { policy }, scheme: tableSchema }, fileEdit);
|
18
|
-
fastify.get(`/widget/:type/:objectid`, { config: { policy: ['public'] }, scheme: tableSchema }, widgetGet);
|
19
|
-
addHook('onWidgetSet', onWidgetSet);
|
20
|
-
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
const tableSchema = {
|
2
|
-
params: {
|
3
|
-
// type: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
4
|
-
objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
5
|
-
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
6
|
-
},
|
7
|
-
querystring: {
|
8
|
-
debug: { type: 'string', pattern: '^(\\d+)$' },
|
9
|
-
},
|
10
|
-
};
|
11
|
-
|
12
|
-
export default null;
|
13
|
-
export { tableSchema }
|