@opengis/fastify-table 1.3.57 → 1.3.59
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
CHANGED
|
@@ -44,7 +44,7 @@ export default async function dataUpdate({
|
|
|
44
44
|
const types = columns.reduce((acc, { name, dataTypeID }) => ({ ...acc, [name]: pg.pgType?.[dataTypeID] }), {});
|
|
45
45
|
|
|
46
46
|
const filterData = Object.keys(data)
|
|
47
|
-
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && !['editor_date', 'editor_id'].includes(el)));
|
|
47
|
+
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && !['editor_date', 'editor_id', 'updated_by', 'updated_at'].includes(el)));
|
|
48
48
|
|
|
49
49
|
const systemColumns = [['editor_date', 'now()'], ['updated_at', 'now()'], uid ? ['editor_id', `'${uid.replace(/'/g, "''")}'`] : null, uid ? ['updated_by', `'${uid.replace(/'/g, "''")}'`] : null].filter((el) => el && names.includes(el[0])).map((el) => `${el[0]} = ${el[1]}`).join(',');
|
|
50
50
|
|
|
@@ -50,7 +50,7 @@ export default async function tableAPI(req) {
|
|
|
50
50
|
const formData = await getTemplate('form', formName) || {};
|
|
51
51
|
const schema = formData?.schema || formData || {};
|
|
52
52
|
// skip DataTable from another table
|
|
53
|
-
const extraKeys = Object.keys(schema).filter((key) => schema[key]?.
|
|
53
|
+
const extraKeys = Object.keys(schema).filter((key) => schema[key]?.table && schema[key]?.parent_id && Object.hasOwn(schema[key], 'colModel'));
|
|
54
54
|
// skip non-existing columns
|
|
55
55
|
const columnList = dbColumns.map((el) => el.name || el).join(',');
|
|
56
56
|
|
|
@@ -62,7 +62,14 @@ export default async function tableAPI(req) {
|
|
|
62
62
|
const geom = dbColumns.find((el) => el.name === 'geom' && pg.pgType[el.dataTypeID] === 'geometry') ? ',st_asgeojson(geom)::json as geom' : '';
|
|
63
63
|
const q = `select "${pk}" as id, ${cols || '*'} ${geom} from ${tableName} t where ${where.join(' and ') || 'true'} limit 1`;
|
|
64
64
|
|
|
65
|
-
if (query?.sql === '1')
|
|
65
|
+
if (query?.sql === '1') {
|
|
66
|
+
const extraQ = extraKeys?.map((key) => {
|
|
67
|
+
const { colModel, table: extraTable, parent_id: parentId } = schema[key];
|
|
68
|
+
const colModel1 = Array.isArray(colModel) ? colModel : Object.values(colModel || {});
|
|
69
|
+
return colModel1.length ? `/*${key}*/ select ${parentId} as parent, ${colModel1.map((col) => col.name || col.key).join(',')} from ${extraTable} a where ${parentId}::text=$1` : null;
|
|
70
|
+
}).filter(el => el).join(';');
|
|
71
|
+
return `${q};${extraQ || ''}`.replace(/\$1/g, `'${id}'`);
|
|
72
|
+
}
|
|
66
73
|
|
|
67
74
|
const data = await pg.query(q.replace(/{{uid}}/, user?.uid), [id]).then(el => el.rows[0]);
|
|
68
75
|
if (!data) return { message: 'not found', status: 404 };
|
|
@@ -74,9 +81,10 @@ export default async function tableAPI(req) {
|
|
|
74
81
|
if (extraKeys?.length) {
|
|
75
82
|
await Promise.all(extraKeys?.map(async (key) => {
|
|
76
83
|
const { colModel, table: extraTable, parent_id: parentId } = schema[key];
|
|
77
|
-
const
|
|
84
|
+
const colModel1 = Array.isArray(colModel) ? colModel : Object.values(colModel || {});
|
|
85
|
+
const q1 = `select ${parentId} as parent, ${colModel1.map((col) => col.name || col.key).join(',')} from ${extraTable} a where ${parentId}=$1`;
|
|
78
86
|
// console.log(tableName, formName, q1);
|
|
79
|
-
const { rows: extraRows } = await pg.query(q1, [
|
|
87
|
+
const { rows: extraRows } = await pg.query(q1, [id]);
|
|
80
88
|
Object.assign(data, { [key]: extraRows });
|
|
81
89
|
}));
|
|
82
90
|
}
|