@opengis/fastify-table 1.3.16 → 1.3.18

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.3.16",
3
+ "version": "1.3.18",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -25,6 +25,7 @@ export default async function dataAPI(req, reply, called) {
25
25
  const hookData = await applyHook('preData', {
26
26
  pg, table: params?.table, id: params?.id, user,
27
27
  });
28
+
28
29
  if (hookData?.message && hookData?.status) {
29
30
  return { message: hookData?.message, status: hookData?.status };
30
31
  }
@@ -49,7 +50,9 @@ export default async function dataAPI(req, reply, called) {
49
50
 
50
51
  if (query.sql === '0') return loadTable;
51
52
 
52
- if (!loadTable && !(tokenData?.table && pg.pk?.[tokenData?.table]) && !(called && pg.pk?.[params?.table])) { return { message: 'template not found', status: 404 }; }
53
+ if (!loadTable && !(tokenData?.table && pg.pk?.[tokenData?.table]) && !(called && pg.pk?.[params?.table])) {
54
+ return { message: 'template not found', status: 404 };
55
+ }
53
56
 
54
57
  const id = tokenData?.id || hookData?.id || params?.id;
55
58
  const { actions = [], query: accessQuery } = await getAccess({ table: tokenData?.table || hookData?.table || params.table, id, user }, pg) || {};
@@ -100,6 +103,7 @@ export default async function dataAPI(req, reply, called) {
100
103
  }
101
104
 
102
105
  const checkFilter = [query.filter, query.search, query.state, query.custom].filter((el) => el).length;
106
+
103
107
  const fData = checkFilter ? await getFilterSQL({
104
108
  pg,
105
109
  table: loadTable ? params.table : table,
@@ -110,18 +114,20 @@ export default async function dataAPI(req, reply, called) {
110
114
  uid,
111
115
  json: 1,
112
116
  }) : {};
113
- timeArr.push(Date.now())
114
- const keyQuery = query.key && (loadTable?.key || tokenData?.key) && !(hookData?.id || tokenData?.id || params.id) ? `${loadTable?.key || tokenData?.key}=$1` : null;
117
+
118
+ timeArr.push(Date.now());
119
+
120
+ const keyQuery = query.key && (loadTable?.key || tokenData?.key) && !(tokenData?.id || hookData?.id || params.id) ? `${loadTable?.key || tokenData?.key}=$1` : null;
115
121
 
116
122
  const limit = called ? (query.limit || 20) : Math.min(maxLimit, +(query.limit || 20));
117
123
 
118
- const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
124
+ const offset = query.page && query.page > 0 && !(tokenData?.id || hookData?.id || params.id) ? ` offset ${(query.page - 1) * limit}` : '';
119
125
  // id, query, filter
120
126
  const [orderColumn, orderDir] = (query.order || loadTable?.order || '').split(/[- ]/);
121
127
 
122
128
  const order = query.order && columnList.includes(orderColumn) && orderColumn?.length
123
- ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}`
124
- : `order by ${(loadTable?.order || 'true::boolean')}`;
129
+ ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''} nulls last`
130
+ : `order by ${(loadTable?.order || 'true::boolean')} nulls last`;
125
131
  const search = loadTable?.meta?.search && query.search
126
132
  ? `(${loadTable?.meta?.search?.split(',')?.map(el => `${el} ilike '%${query.search.replace(/%/g, '\\%').replace(/'/g, "''")}%'`).join(' or ')})`
127
133
  : null;
@@ -142,7 +148,7 @@ export default async function dataAPI(req, reply, called) {
142
148
 
143
149
  ${params.id ? cardSqlTable : ''}
144
150
  where ${where.join(' and ') || 'true'}
145
- ${order} ${offset} limit ${limit}`
151
+ ${order} ${offset} limit ${limit}`
146
152
  .replace(/{{uid}}/g, uid);
147
153
 
148
154
  // if (user?.user_type === 'superadmin') console.log(q);