@opengis/fastify-table 1.0.29 → 1.0.30
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 +4 -0
- package/package.json +1 -1
- package/widget/controllers/widget.set.js +21 -31
package/Changelog.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
|
|
3
|
-
import obj2db from './utils/obj2db.js';
|
|
4
3
|
import getMeta from '../../pg/funcs/getMeta.js';
|
|
5
4
|
|
|
6
5
|
const tableList = {
|
|
@@ -25,44 +24,35 @@ export default async function widgetSet(req) {
|
|
|
25
24
|
|
|
26
25
|
try {
|
|
27
26
|
if (type === 'file') {
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
'${path.extname(message.name).slice(1).toLowerCase()}',
|
|
41
|
-
${message.result?.size}, 1,
|
|
42
|
-
'${session.passport?.user?.uid || 1}',
|
|
43
|
-
nullif('${objectid}','') ) returning file_id as id`;
|
|
27
|
+
const file = await funcs.uploadMultiPart(req);
|
|
28
|
+
const extName = path.extname(file.filepath).slice(1).toLowerCase();
|
|
29
|
+
|
|
30
|
+
const data = {
|
|
31
|
+
uploaded_name: file?.originalFilename?.toLocaleLowerCase()?.replace(/'/g, '\'\''),
|
|
32
|
+
file_path: file?.relativeFilepath?.replace(/\\/g, '/'),
|
|
33
|
+
ext: extName,
|
|
34
|
+
size: file?.size,
|
|
35
|
+
file_status: 1,
|
|
36
|
+
uid: req.session?.passport?.user?.uid || 1,
|
|
37
|
+
object_id: objectid,
|
|
38
|
+
};
|
|
44
39
|
|
|
45
|
-
const {
|
|
40
|
+
const { rows = [] } = await funcs.dataInsert({ table: 'crm.file', data });
|
|
46
41
|
return {
|
|
47
|
-
rowCount: 1, data: 'ok', command: 'UPLOAD', id, objectid,
|
|
42
|
+
rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, objectid: rows[0]?.object_id,
|
|
48
43
|
};
|
|
49
44
|
}
|
|
50
|
-
const { pk
|
|
51
|
-
if (!pk) return {
|
|
52
|
-
|
|
53
|
-
const columnList = metaColumns.map((col) => col.name);
|
|
54
|
-
const nonexistCol = Object.keys(body).filter((key) => !columnList.includes(key));
|
|
55
|
-
const { columns, args } = obj2db({ ...body, uid: user?.uid, object_id: objectid }, nonexistCol);
|
|
45
|
+
const { pk } = await getMeta({ pg, table });
|
|
46
|
+
if (!pk) return { message: 'table not found', status: 404 };
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
? `UPDATE ${table} SET ${columns?.map((key, index) => `"${key}"=$${++index}`).join(',')} WHERE ${pkList[type]} = '${id}' `
|
|
59
|
-
: `INSERT INTO ${table} (${columns?.join(',')}) VALUES (${columns?.map((el, index) => `$${++index}`).join(',')}) returning *;`;
|
|
48
|
+
const data = { ...body, uid: user?.uid, object_id: objectid };
|
|
60
49
|
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
const result = id
|
|
51
|
+
? await funcs.dataUpdate({ table, data, id })
|
|
52
|
+
: await funcs.dataInsert({ table, data });
|
|
63
53
|
|
|
64
54
|
return {
|
|
65
|
-
rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]],
|
|
55
|
+
rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]] || result?.[pkList[type]],
|
|
66
56
|
};
|
|
67
57
|
}
|
|
68
58
|
catch (err) {
|