@galadrim/galadmin 0.1.215 → 0.1.216

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.
@@ -224,6 +224,7 @@ export type TableView = {
224
224
  export type Subview = {
225
225
  label: string;
226
226
  filters: string;
227
+ having?: string;
227
228
  orderBy?: string;
228
229
  notificationBadge?: {
229
230
  query: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galadrim/galadmin",
3
- "version": "0.1.215",
3
+ "version": "0.1.216",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/src/api.ts CHANGED
@@ -63,7 +63,7 @@ export default (db, config, user) => {
63
63
  queryString += ")"
64
64
  }
65
65
  const limit = params.allRecords ? 999999 : parseInt(params.limit)
66
- const query = params.customQuery || ("SELECT " + (params.selectExpression || "*") + " FROM ?? " + (params.join || "") + queryString + " " + (params.groupBy ? "GROUP BY " + params.groupBy : "") + (params.orderBy || params.primaryId ? " ORDER BY " + (params.orderBy || `${params.table}.${params.primaryId}`) : "") + " LIMIT ? OFFSET ?")
66
+ const query = params.customQuery || ("SELECT " + (params.selectExpression || "*") + " FROM ?? " + (params.join || "") + queryString + " " + (params.groupBy ? "GROUP BY " + params.groupBy : "") + (params.having ? " HAVING " + params.having : "") + (params.orderBy || params.primaryId ? " ORDER BY " + (params.orderBy || `${params.table}.${params.primaryId}`) : "") + " LIMIT ? OFFSET ?")
67
67
  const queryParams = [params.table, limit, Math.max((params.page - 1) * limit, 0)]
68
68
  const { err, rows } = await db.query(query, queryParams)
69
69
  if (err) {
@@ -201,16 +201,18 @@ export default (db, config, user) => {
201
201
  app.post('/records', async function (req, res, next) {
202
202
  const view = config.views[req.body.viewIndex];
203
203
  const isDesc = req.body.isDesc === null ? view.isDesc : req.body.isDesc
204
- const orderBy = req.body.orderBy || (view.subviews && req.body.subviewIndex !== undefined ? view.subviews[req.body.subviewIndex]?.orderBy : null) || view.orderBy
204
+ const subview = view.subviews && req.body.subviewIndex !== undefined ? view.subviews[req.body.subviewIndex] : null
205
+ const orderBy = req.body.orderBy || subview?.orderBy || view.orderBy
205
206
  const { rows: records, queryString, input, error } = await getRecords({
206
207
  table: view.tableName,
207
208
  page: req.body.page,
208
209
  filters: sqlAnd([
209
210
  view.filters,
210
- view.subviews && req.body.subviewIndex !== undefined ? view.subviews[req.body.subviewIndex].filters : null,
211
+ subview?.filters,
211
212
  ...req.body.filters,
212
213
  view.filtersFromUser ? view.filtersFromUser(user.userId, user.role) : null
213
214
  ]),
215
+ having: subview?.having,
214
216
  customQuery: view.customQuery,
215
217
  join: view.join,
216
218
  selectExpression: view.selectExpression,
@@ -322,11 +324,13 @@ export default (db, config, user) => {
322
324
  const view = config.views[req.body.viewIndex];
323
325
  const orderBy = req.body.orderBy || view.orderBy;
324
326
  const isDesc = req.body.isDesc === null ? view.isDesc : req.body.isDesc;
327
+ const subview = view.subviews && req.body.subviewIndex !== undefined ? view.subviews[req.body.subviewIndex] : null
325
328
  const { rows: records, error } = await getRecords({
326
329
  table: view.tableName,
327
330
  page: 1,
328
331
  allRecords: true,
329
- filters: sqlAnd([view.filters, view.subviews && req.body.subviewIndex !== undefined ? view.subviews[req.body.subviewIndex].filters : null].concat(req.body.filters)),
332
+ filters: sqlAnd([view.filters, subview?.filters, req.body.filters]),
333
+ having: subview?.having,
330
334
  customQuery: view.customQuery,
331
335
  join: view.join,
332
336
  selectExpression: view.selectExpression,
@@ -273,6 +273,7 @@ export type TableView = {
273
273
  export type Subview = {
274
274
  label: string;
275
275
  filters: string;
276
+ having?: string;
276
277
  orderBy?: string;
277
278
  notificationBadge?: {
278
279
  query: string;