Switching the basic single row read to use the enrich endpoint.
This commit is contained in:
parent
c4f5b42a90
commit
7b3318a19e
|
@ -184,6 +184,29 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"enrichedRow": {
|
||||
"value": {
|
||||
"row": {
|
||||
"_id": "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
|
||||
"name": "eg",
|
||||
"tableId": "ta_5b1649e42a5b41dea4ef7742a36a7a70",
|
||||
"type": "row",
|
||||
"relationship": [
|
||||
{
|
||||
"_id": "ro_ta_users_us_8f3d717147d74d759d8cef5b6712062f",
|
||||
"name": "Joe",
|
||||
"tableId": "ta_users",
|
||||
"internal": [
|
||||
{
|
||||
"_id": "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
|
||||
"primaryDisplay": "eg"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"rows": {
|
||||
"value": {
|
||||
"rows": [
|
||||
|
@ -523,6 +546,16 @@
|
|||
"row": {
|
||||
"description": "The row to be created/updated, based on the table schema.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"_id": {
|
||||
"description": "The ID of the row.",
|
||||
"type": "string"
|
||||
},
|
||||
"tableId": {
|
||||
"description": "The ID of the table this row comes from.",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": {
|
||||
"oneOf": [
|
||||
{
|
||||
|
@ -549,6 +582,16 @@
|
|||
"row": {
|
||||
"description": "The row to be created/updated, based on the table schema.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"_id": {
|
||||
"description": "The ID of the row.",
|
||||
"type": "string"
|
||||
},
|
||||
"tableId": {
|
||||
"description": "The ID of the table this row comes from.",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": {
|
||||
"oneOf": [
|
||||
{
|
||||
|
@ -1595,6 +1638,7 @@
|
|||
},
|
||||
"get": {
|
||||
"summary": "Get a single row from the specified table.",
|
||||
"description": "This gets a single row, it will be enriched with the full related rows, rather than the squashed \"primaryDisplay\" format returned by the search endpoint.",
|
||||
"tags": [
|
||||
"rows"
|
||||
],
|
||||
|
@ -1618,8 +1662,8 @@
|
|||
"$ref": "#/components/schemas/rowOutput"
|
||||
},
|
||||
"examples": {
|
||||
"row": {
|
||||
"$ref": "#/components/examples/row"
|
||||
"enrichedRow": {
|
||||
"$ref": "#/components/examples/enrichedRow"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,6 +137,20 @@ components:
|
|||
relationship:
|
||||
- primaryDisplay: Joe
|
||||
_id: ro_ta_...
|
||||
enrichedRow:
|
||||
value:
|
||||
row:
|
||||
_id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4
|
||||
name: eg
|
||||
tableId: ta_5b1649e42a5b41dea4ef7742a36a7a70
|
||||
type: row
|
||||
relationship:
|
||||
- _id: ro_ta_users_us_8f3d717147d74d759d8cef5b6712062f
|
||||
name: Joe
|
||||
tableId: ta_users
|
||||
internal:
|
||||
- _id: ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4
|
||||
primaryDisplay: eg
|
||||
rows:
|
||||
value:
|
||||
rows:
|
||||
|
@ -381,6 +395,13 @@ components:
|
|||
row:
|
||||
description: The row to be created/updated, based on the table schema.
|
||||
type: object
|
||||
properties:
|
||||
_id:
|
||||
description: The ID of the row.
|
||||
type: string
|
||||
tableId:
|
||||
description: The ID of the table this row comes from.
|
||||
type: string
|
||||
additionalProperties:
|
||||
oneOf:
|
||||
- type: string
|
||||
|
@ -394,6 +415,13 @@ components:
|
|||
row:
|
||||
description: The row to be created/updated, based on the table schema.
|
||||
type: object
|
||||
properties:
|
||||
_id:
|
||||
description: The ID of the row.
|
||||
type: string
|
||||
tableId:
|
||||
description: The ID of the table this row comes from.
|
||||
type: string
|
||||
additionalProperties:
|
||||
oneOf:
|
||||
- type: string
|
||||
|
@ -1115,6 +1143,9 @@ paths:
|
|||
$ref: "#/components/examples/row"
|
||||
get:
|
||||
summary: Get a single row from the specified table.
|
||||
description: This gets a single row, it will be enriched with the full related
|
||||
rows, rather than the squashed "primaryDisplay" format returned by the
|
||||
search endpoint.
|
||||
tags:
|
||||
- rows
|
||||
parameters:
|
||||
|
@ -1129,8 +1160,8 @@ paths:
|
|||
schema:
|
||||
$ref: "#/components/schemas/rowOutput"
|
||||
examples:
|
||||
row:
|
||||
$ref: "#/components/examples/row"
|
||||
enrichedRow:
|
||||
$ref: "#/components/examples/enrichedRow"
|
||||
"/tables/{tableId}/rows/search":
|
||||
post:
|
||||
summary: Used to search for rows within a table.
|
||||
|
|
|
@ -24,9 +24,39 @@ const row = {
|
|||
],
|
||||
}
|
||||
|
||||
const enrichedRow = {
|
||||
_id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
|
||||
name: "eg",
|
||||
tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70",
|
||||
type: "row",
|
||||
relationship: [
|
||||
{
|
||||
_id: "ro_ta_users_us_8f3d717147d74d759d8cef5b6712062f",
|
||||
name: "Joe",
|
||||
tableId: "ta_users",
|
||||
internal: [
|
||||
{
|
||||
_id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
|
||||
primaryDisplay: "eg",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const rowSchema = {
|
||||
description: "The row to be created/updated, based on the table schema.",
|
||||
type: "object",
|
||||
properties: {
|
||||
_id: {
|
||||
description: "The ID of the row.",
|
||||
type: "string",
|
||||
},
|
||||
tableId: {
|
||||
description: "The ID of the table this row comes from.",
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
additionalProperties: {
|
||||
oneOf: [
|
||||
{ type: "string" },
|
||||
|
@ -48,6 +78,11 @@ module.exports = new Resource()
|
|||
row: row,
|
||||
},
|
||||
},
|
||||
enrichedRow: {
|
||||
value: {
|
||||
row: enrichedRow,
|
||||
},
|
||||
},
|
||||
rows: {
|
||||
value: {
|
||||
rows: [row],
|
||||
|
|
|
@ -45,7 +45,7 @@ export async function create(ctx: any) {
|
|||
}
|
||||
|
||||
export async function read(ctx: any) {
|
||||
await rowController.find(ctx)
|
||||
await rowController.fetchEnrichedRow(ctx)
|
||||
ctx.body = { row: ctx.body }
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ const linkRows = require("../../../db/linkedRows")
|
|||
const {
|
||||
generateRowID,
|
||||
getRowParams,
|
||||
getTableIDFromRowID,
|
||||
DocumentTypes,
|
||||
InternalTables,
|
||||
} = require("../../../db/utils")
|
||||
|
@ -386,6 +387,9 @@ exports.fetchEnrichedRow = async ctx => {
|
|||
let groups = {},
|
||||
tables = {}
|
||||
for (let row of response) {
|
||||
if (!row.tableId) {
|
||||
row.tableId = getTableIDFromRowID(row._id)
|
||||
}
|
||||
const linkedTableId = row.tableId
|
||||
if (groups[linkedTableId] == null) {
|
||||
groups[linkedTableId] = [row]
|
||||
|
|
|
@ -104,6 +104,8 @@ write.push(
|
|||
* /tables/{tableId}/rows/{rowId}:
|
||||
* get:
|
||||
* summary: Get a single row from the specified table.
|
||||
* description: This gets a single row, it will be enriched with the full related rows, rather than
|
||||
* the squashed "primaryDisplay" format returned by the search endpoint.
|
||||
* tags:
|
||||
* - rows
|
||||
* parameters:
|
||||
|
@ -118,8 +120,8 @@ write.push(
|
|||
* schema:
|
||||
* $ref: '#/components/schemas/rowOutput'
|
||||
* examples:
|
||||
* row:
|
||||
* $ref: '#/components/examples/row'
|
||||
* enrichedRow:
|
||||
* $ref: '#/components/examples/enrichedRow'
|
||||
*/
|
||||
read.push(new Endpoint("get", "/tables/:tableId/rows/:rowId", controller.read))
|
||||
|
||||
|
|
|
@ -146,6 +146,18 @@ exports.getRowParams = (tableId = null, rowId = null, otherProps = {}) => {
|
|||
return getDocParams(DocumentTypes.ROW, endOfKey, otherProps)
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a row ID this will find the table ID within it (only works for internal tables).
|
||||
* @param {string} rowId The ID of the row.
|
||||
* @returns {string} The table ID.
|
||||
*/
|
||||
exports.getTableIDFromRowID = rowId => {
|
||||
const components = rowId
|
||||
.split(DocumentTypes.TABLE + SEPARATOR)[1]
|
||||
.split(SEPARATOR)
|
||||
return `${DocumentTypes.TABLE}${SEPARATOR}${components[0]}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new row ID for the specified table.
|
||||
* @param {string} tableId The table which the row is being created for.
|
||||
|
|
Loading…
Reference in New Issue