@opengis/fastify-table 1.4.26 → 1.4.27

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.4.26",
3
+ "version": "1.4.27",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -51,8 +51,8 @@
51
51
  "uglify-js": "3.19.3"
52
52
  },
53
53
  "devDependencies": {
54
- "eslint": "8.49.0",
55
- "eslint-config-airbnb": "19.0.4"
54
+ "eslint": "^8.49.0",
55
+ "eslint-config-airbnb": "^19.0.4"
56
56
  },
57
57
  "author": "Softpro",
58
58
  "license": "ISC"
@@ -17,6 +17,14 @@ const checkInline = {};
17
17
  const maxLimit = 100;
18
18
  const defaultLimit = 20;
19
19
 
20
+ function getOrder(query, columnList, orderColumn, loadTable, orderDir, called) {
21
+ if (query?.order && called) { return `order by ${query.order}`; }
22
+ if (typeof orderColumn === 'string' && Array.isArray(columnList) && columnList.includes(orderColumn)) {
23
+ return `order by ${orderColumn} ${query?.desc || orderDir === 'desc' ? 'desc' : ''} nulls last`;
24
+ }
25
+ return `order by ${(loadTable?.order || 'true::boolean')} nulls last`;
26
+ }
27
+
20
28
  export default async function dataAPI(req, reply, called) {
21
29
  const {
22
30
  pg = pgClients.client, params, headers = {}, query = {}, user = {}, contextQuery, sufix = true,
@@ -166,9 +174,8 @@ export default async function dataAPI(req, reply, called) {
166
174
  // id, query, filter
167
175
  const [orderColumn, orderDir] = (query.order || loadTable?.order || '').split(/[- ]/);
168
176
 
169
- const order = query.order && columnList.includes(orderColumn) && orderColumn?.length
170
- ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''} nulls last`
171
- : `order by ${(loadTable?.order || 'true::boolean')} nulls last`;
177
+ const order = getOrder(query, columnList, orderColumn, loadTable, orderDir, called);
178
+
172
179
  const search = loadTable?.meta?.search && query.search
173
180
  ? `(${loadTable?.meta?.search?.split(',')?.map(el => `${el} ilike '%${query.search.replace(/%/g, '\\%').replace(/'/g, "''")}%'`).join(' or ')})`
174
181
  : null;