2022-02-22 16:06:08 +01:00
|
|
|
const { object } = require("./utils")
|
|
|
|
const Resource = require("./utils/Resource")
|
|
|
|
|
|
|
|
const baseRow = {
|
|
|
|
_id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4",
|
|
|
|
type: "row",
|
|
|
|
tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70",
|
|
|
|
name: "Mike",
|
|
|
|
age: 30,
|
|
|
|
}
|
|
|
|
|
|
|
|
const inputRow = {
|
|
|
|
...baseRow,
|
|
|
|
relationship: ["ro_ta_..."],
|
|
|
|
}
|
|
|
|
|
|
|
|
const row = {
|
|
|
|
...baseRow,
|
|
|
|
relationship: [
|
|
|
|
{
|
|
|
|
primaryDisplay: "Joe",
|
|
|
|
_id: "ro_ta_...",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:54:32 +01:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2022-02-22 16:06:08 +01:00
|
|
|
const rowSchema = {
|
|
|
|
description: "The row to be created/updated, based on the table schema.",
|
|
|
|
type: "object",
|
2022-03-01 19:35:08 +01:00
|
|
|
additionalProperties: {
|
2022-03-01 23:37:42 +01:00
|
|
|
description:
|
|
|
|
"Key value properties of any type, depending on the table schema.",
|
2022-03-01 19:35:08 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const rowOutputSchema = {
|
|
|
|
...rowSchema,
|
2022-02-28 13:54:32 +01:00
|
|
|
properties: {
|
2022-03-01 19:35:08 +01:00
|
|
|
...rowSchema.properties,
|
2022-02-28 13:54:32 +01:00
|
|
|
_id: {
|
|
|
|
description: "The ID of the row.",
|
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
tableId: {
|
|
|
|
description: "The ID of the table this row comes from.",
|
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
},
|
2022-03-01 19:35:08 +01:00
|
|
|
required: ["tableId", "_id"],
|
|
|
|
}
|
|
|
|
|
|
|
|
const searchOutputSchema = {
|
|
|
|
type: "object",
|
|
|
|
required: ["data"],
|
|
|
|
properties: {
|
|
|
|
data: {
|
|
|
|
description:
|
|
|
|
"An array of rows, these will each contain an _id field which can be used to update or delete them.",
|
|
|
|
type: "array",
|
|
|
|
items: {
|
|
|
|
type: "object",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bookmark: {
|
|
|
|
description: "If pagination in use, this should be provided.",
|
|
|
|
oneOf: [{ type: "string" }, { type: "integer" }],
|
|
|
|
},
|
|
|
|
hasNextPage: {
|
|
|
|
description:
|
|
|
|
"If pagination in use, this will determine if there is another page to fetch.",
|
|
|
|
type: "boolean",
|
|
|
|
},
|
2022-02-22 16:06:08 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new Resource()
|
|
|
|
.setExamples({
|
|
|
|
inputRow: {
|
|
|
|
value: inputRow,
|
|
|
|
},
|
|
|
|
row: {
|
|
|
|
value: {
|
2022-03-01 15:37:35 +01:00
|
|
|
data: row,
|
2022-02-22 16:06:08 +01:00
|
|
|
},
|
|
|
|
},
|
2022-02-28 13:54:32 +01:00
|
|
|
enrichedRow: {
|
|
|
|
value: {
|
2022-03-01 15:37:35 +01:00
|
|
|
data: enrichedRow,
|
2022-02-28 13:54:32 +01:00
|
|
|
},
|
|
|
|
},
|
2022-02-22 16:06:08 +01:00
|
|
|
rows: {
|
|
|
|
value: {
|
2022-03-01 15:37:35 +01:00
|
|
|
data: [row],
|
2022-02-22 16:06:08 +01:00
|
|
|
hasNextPage: true,
|
|
|
|
bookmark: 10,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.setSchemas({
|
|
|
|
row: rowSchema,
|
2022-03-01 19:35:08 +01:00
|
|
|
searchOutput: searchOutputSchema,
|
2022-02-22 16:06:08 +01:00
|
|
|
rowOutput: object({
|
2022-03-01 19:35:08 +01:00
|
|
|
data: rowOutputSchema,
|
2022-02-22 16:06:08 +01:00
|
|
|
}),
|
|
|
|
})
|