@galadrim/galadmin 0.1.215 → 0.1.217
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/dist/api.js +9 -6
- package/dist/api.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +1 -0
- package/package.json +1 -1
- package/src/api.ts +9 -5
- package/src/types/config.ts +1 -0
package/dist/types/config.d.ts
CHANGED
package/package.json
CHANGED
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
|
|
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
|
-
|
|
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,
|
|
@@ -232,7 +234,7 @@ export default (db, config, user) => {
|
|
|
232
234
|
}
|
|
233
235
|
}
|
|
234
236
|
}
|
|
235
|
-
const { err, rows: counts } = await db.query("SELECT COUNT(*) AS count FROM (SELECT 1 FROM ?? " + (view.join || "") + queryString + " " + (view.groupBy ? "GROUP BY " + view.groupBy : "") + ") s", [view.tableName])
|
|
237
|
+
const { err, rows: counts } = await db.query("SELECT COUNT(*) AS count FROM (SELECT 1 FROM ?? " + (view.join || "") + queryString + " " + (view.groupBy ? "GROUP BY " + view.groupBy : "") + (subview?.having ? " HAVING " + subview?.having : "") + ") s", [view.tableName])
|
|
236
238
|
if (err) {
|
|
237
239
|
res.send({
|
|
238
240
|
records,
|
|
@@ -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,
|
|
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,
|