backend for client export of rows
This commit is contained in:
parent
29454f2b97
commit
222033b95e
|
@ -152,6 +152,26 @@ exports.validate = async () => {
|
|||
return { valid: true }
|
||||
}
|
||||
|
||||
exports.exportRows = async ctx => {
|
||||
const { datasourceId, tableName } = breakExternalTableId(ctx.params.tableId)
|
||||
const db = getAppDB()
|
||||
const datasource = await db.get(datasourceId)
|
||||
if (!datasource || !datasource.entities) {
|
||||
ctx.throw(400, "Datasource has not been configured for plus API.")
|
||||
}
|
||||
const tables = datasource.entities
|
||||
const table = tables[tableName]
|
||||
ctx.request.body = {
|
||||
query: {
|
||||
oneOf: {
|
||||
[table.primaryDisplay]: ctx.request.body.map(id => breakRowIdField(id)[0])
|
||||
},
|
||||
},
|
||||
}
|
||||
return exports.search(ctx)
|
||||
}
|
||||
|
||||
|
||||
exports.fetchEnrichedRow = async ctx => {
|
||||
const id = ctx.params.rowId
|
||||
const tableId = ctx.params.tableId
|
||||
|
|
|
@ -137,3 +137,13 @@ exports.fetchEnrichedRow = async function (ctx) {
|
|||
ctx.throw(400, err)
|
||||
}
|
||||
}
|
||||
|
||||
exports.export = async function (ctx) {
|
||||
const tableId = getTableId(ctx)
|
||||
try {
|
||||
ctx.body = await pickApi(tableId).exportRows(ctx)
|
||||
} catch (err) {
|
||||
ctx.throw(400, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -362,6 +362,23 @@ exports.validate = async ctx => {
|
|||
})
|
||||
}
|
||||
|
||||
exports.exportRows = async ctx => {
|
||||
const db = getAppDB()
|
||||
const table = await db.get(ctx.params.tableId)
|
||||
const rowIds = ctx.request.body
|
||||
let response = (
|
||||
await db.allDocs({
|
||||
include_docs: true,
|
||||
keys: rowIds,
|
||||
})
|
||||
).rows.map(row => row.doc)
|
||||
|
||||
let rows = await outputProcessing(table, response)
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
|
||||
exports.fetchEnrichedRow = async ctx => {
|
||||
const db = getAppDB()
|
||||
const tableId = ctx.params.tableId
|
||||
|
|
|
@ -252,4 +252,26 @@ router
|
|||
rowController.destroy
|
||||
)
|
||||
|
||||
/**
|
||||
* @api {post} /api/:tableId/rows/export Export Rows
|
||||
* @apiName Export rows
|
||||
* @apiGroup rows
|
||||
* @apiPermission table write access
|
||||
* @apiDescription This API can export a number of provided rows
|
||||
*
|
||||
* @apiParam {string} tableId The ID of the table the row is to be deleted from.
|
||||
*
|
||||
* @apiParam (Body) {object[]} [rows] The row IDs which are to be exported
|
||||
*
|
||||
* @apiSuccess {object[]|object}
|
||||
*/
|
||||
.post(
|
||||
"/api/:tableId/rows/export",
|
||||
paramResource("tableId"),
|
||||
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
|
||||
usage,
|
||||
rowController.export
|
||||
)
|
||||
|
||||
|
||||
module.exports = router
|
||||
|
|
Loading…
Reference in New Issue