Removing use of the arguments[0] as they don't mesh well with TS.

This commit is contained in:
mike12345567 2021-06-25 17:14:23 +01:00
parent 655c6ec381
commit 191646b7ee
3 changed files with 30 additions and 28 deletions

View File

@ -9,7 +9,7 @@
"url": "https://github.com/Budibase/budibase.git" "url": "https://github.com/Budibase/budibase.git"
}, },
"scripts": { "scripts": {
"build": "tsc && mv dist/src/* dist/ && rmdir dist/src/", "build": "rm -r dist/ && tsc && mv dist/src/* dist/ && rmdir dist/src/",
"test": "jest --coverage --maxWorkers=2", "test": "jest --coverage --maxWorkers=2",
"test:watch": "jest --watch", "test:watch": "jest --watch",
"build:docker": "docker build . -t app-service", "build:docker": "docker build . -t app-service",

View File

@ -87,33 +87,34 @@ async function getFullLinkedDocs(appId, links) {
/** /**
* Update link documents for a row or table - this is to be called by the API controller when a change is occurring. * Update link documents for a row or table - this is to be called by the API controller when a change is occurring.
* @param {string} eventType states what type of change which is occurring, means this can be expanded upon in the * @param {string} args.eventType states what type of change which is occurring, means this can be expanded upon in the
* future quite easily (all updates go through one function). * future quite easily (all updates go through one function).
* @param {string} appId The ID of the instance in which the change is occurring. * @param {string} args.appId The ID of the instance in which the change is occurring.
* @param {string} tableId The ID of the of the table which is being changed. * @param {string} args.tableId The ID of the of the table which is being changed.
* @param {object|null} row The row which is changing, e.g. created, updated or deleted. * @param {object|null} args.row The row which is changing, e.g. created, updated or deleted.
* @param {object|null} table If the table has already been retrieved this can be used to reduce database gets. * @param {object|null} args.table If the table has already been retrieved this can be used to reduce database gets.
* @param {object|null} oldTable If the table is being updated then the old table can be provided for differencing. * @param {object|null} args.oldTable If the table is being updated then the old table can be provided for differencing.
* @returns {Promise<object>} When the update is complete this will respond successfully. Returns the row for * @returns {Promise<object>} When the update is complete this will respond successfully. Returns the row for
* row operations and the table for table operations. * row operations and the table for table operations.
*/ */
exports.updateLinks = async function ({ exports.updateLinks = async function (args) {
const {
eventType, eventType,
appId, appId,
row, row,
tableId, tableId,
table, table,
oldTable, oldTable,
}) { } = args
const baseReturnObj = row == null ? table : row const baseReturnObj = row == null ? table : row
if (appId == null) { if (appId == null) {
throw "Cannot operate without an instance ID." throw "Cannot operate without an instance ID."
} }
// make sure table ID is set // make sure table ID is set
if (tableId == null && table != null) { if (tableId == null && table != null) {
arguments[0].tableId = table._id args.tableId = table._id
} }
let linkController = new LinkController(arguments[0]) let linkController = new LinkController(args)
try { try {
if ( if (
!(await linkController.doesTableHaveLinkedFields()) && !(await linkController.doesTableHaveLinkedFields()) &&

View File

@ -17,24 +17,25 @@ exports.createLinkView = createLinkView
/** /**
* Gets the linking documents, not the linked documents themselves. * Gets the linking documents, not the linked documents themselves.
* @param {string} appId The instance in which we are searching for linked rows. * @param {string} args.appId The instance in which we are searching for linked rows.
* @param {string} tableId The table which we are searching for linked rows against. * @param {string} args.tableId The table which we are searching for linked rows against.
* @param {string|null} fieldName The name of column/field which is being altered, only looking for * @param {string|null} args.fieldName The name of column/field which is being altered, only looking for
* linking documents that are related to it. If this is not specified then the table level will be assumed. * linking documents that are related to it. If this is not specified then the table level will be assumed.
* @param {string|null} rowId The ID of the row which we want to find linking documents for - * @param {string|null} args.rowId The ID of the row which we want to find linking documents for -
* if this is not specified then it will assume table or field level depending on whether the * if this is not specified then it will assume table or field level depending on whether the
* field name has been specified. * field name has been specified.
* @param {boolean|null} includeDocs whether to include docs in the response call, this is considerably slower so only * @param {boolean|null} args.includeDocs whether to include docs in the response call, this is considerably slower so only
* use this if actually interested in the docs themselves. * use this if actually interested in the docs themselves.
* @returns {Promise<object[]>} This will return an array of the linking documents that were found * @returns {Promise<object[]>} This will return an array of the linking documents that were found
* (if any). * (if any).
*/ */
exports.getLinkDocuments = async function ({ exports.getLinkDocuments = async function (args) {
const {
appId, appId,
tableId, tableId,
rowId, rowId,
includeDocs, includeDocs,
}) { } = args
const db = new CouchDB(appId) const db = new CouchDB(appId)
let params let params
if (rowId != null) { if (rowId != null) {