@opengis/fastify-table 2.0.122 → 2.0.123
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.
|
@@ -121,24 +121,25 @@ export async function editUserCls({ name, alias, description, data, }, pg = pgCl
|
|
|
121
121
|
return "ok";
|
|
122
122
|
}
|
|
123
123
|
export async function getUserClsList({ name, search, sql }, pg = pgClients.client) {
|
|
124
|
-
const args = name ? [name.split(",")] : [search];
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
const args = name ? [name.split(",")] : [search].filter(Boolean);
|
|
125
|
+
const subQuery = search ? `name ilike '%'||$1||'%'` : "true";
|
|
126
|
+
const where = (name ? "name=any($1::text[])" : null) ||
|
|
127
|
+
(search
|
|
128
|
+
? `( ${subQuery} or name in (select parent from admin.user_cls where ${subQuery}) )`
|
|
129
|
+
: "1=1");
|
|
130
|
+
const q = `select true as custom, name, type, description, alias, (select count(*) filter(where ${subQuery}) from admin.user_cls where parent=t.name limit 1) as count
|
|
131
|
+
from admin.user_cls t where parent is null and ${where}
|
|
130
132
|
union all
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
order by name`;
|
|
133
|
+
select false as custom, name, type, null as description, null as alias, (select count(*) filter(where ${subQuery}) from admin.cls where parent=t.name limit 1) as count
|
|
134
|
+
from admin.cls t where parent is null and ${where}
|
|
135
|
+
order by name`;
|
|
135
136
|
if (sql)
|
|
136
137
|
return q;
|
|
137
|
-
const
|
|
138
|
-
const customRows =
|
|
138
|
+
const rows = await pg.query(q, args).then((el) => el.rows || []);
|
|
139
|
+
const customRows = rows.filter((row) => row.custom);
|
|
139
140
|
const customClsNames = customRows.map((row) => row.name);
|
|
140
|
-
const
|
|
141
|
-
return
|
|
141
|
+
const filteredRows = rows.filter((row) => !customClsNames.includes(row.name));
|
|
142
|
+
return customRows.concat(filteredRows);
|
|
142
143
|
}
|
|
143
144
|
export async function getUserCls(name, pg = pgClients.client) {
|
|
144
145
|
const { type, data, description, alias } = await pg
|