Remove context refs in row processor
This commit is contained in:
parent
3ee95938c3
commit
e4caf8b737
|
@ -81,7 +81,7 @@ export async function save(ctx: UserCtx) {
|
||||||
|
|
||||||
const table = await sdk.tables.getTable(tableId)
|
const table = await sdk.tables.getTable(tableId)
|
||||||
const { table: updatedTable, row } = inputProcessing(
|
const { table: updatedTable, row } = inputProcessing(
|
||||||
ctx.user,
|
ctx.user?._id,
|
||||||
cloneDeep(table),
|
cloneDeep(table),
|
||||||
inputs
|
inputs
|
||||||
)
|
)
|
||||||
|
|
|
@ -59,7 +59,7 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
|
||||||
const tableClone = cloneDeep(dbTable)
|
const tableClone = cloneDeep(dbTable)
|
||||||
|
|
||||||
// this returns the table and row incase they have been updated
|
// this returns the table and row incase they have been updated
|
||||||
let { table, row } = inputProcessing(ctx.user, tableClone, combinedRow)
|
let { table, row } = inputProcessing(ctx.user?._id, tableClone, combinedRow)
|
||||||
const validateResult = await sdk.rows.utils.validate({
|
const validateResult = await sdk.rows.utils.validate({
|
||||||
row,
|
row,
|
||||||
table,
|
table,
|
||||||
|
@ -106,7 +106,7 @@ export async function save(ctx: UserCtx) {
|
||||||
// need to copy the table so it can be differenced on way out
|
// need to copy the table so it can be differenced on way out
|
||||||
const tableClone = cloneDeep(dbTable)
|
const tableClone = cloneDeep(dbTable)
|
||||||
|
|
||||||
let { table, row } = inputProcessing(ctx.user, tableClone, inputs)
|
let { table, row } = inputProcessing(ctx.user?._id, tableClone, inputs)
|
||||||
|
|
||||||
const validateResult = await sdk.rows.utils.validate({
|
const validateResult = await sdk.rows.utils.validate({
|
||||||
row,
|
row,
|
||||||
|
|
|
@ -113,7 +113,7 @@ export function importToRows(
|
||||||
|
|
||||||
// We use a reference to table here and update it after input processing,
|
// We use a reference to table here and update it after input processing,
|
||||||
// so that we can auto increment auto IDs in imported data properly
|
// so that we can auto increment auto IDs in imported data properly
|
||||||
const processed = inputProcessing(user, table, row, {
|
const processed = inputProcessing(user?._id, table, row, {
|
||||||
noAutoRelationships: true,
|
noAutoRelationships: true,
|
||||||
})
|
})
|
||||||
row = processed.row
|
row = processed.row
|
||||||
|
|
|
@ -5,8 +5,8 @@ import { ObjectStoreBuckets } from "../../constants"
|
||||||
import { context, db as dbCore, objectStore } from "@budibase/backend-core"
|
import { context, db as dbCore, objectStore } from "@budibase/backend-core"
|
||||||
import { InternalTables } from "../../db/utils"
|
import { InternalTables } from "../../db/utils"
|
||||||
import { TYPE_TRANSFORM_MAP } from "./map"
|
import { TYPE_TRANSFORM_MAP } from "./map"
|
||||||
import { Row, RowAttachment, Table, ContextUser } from "@budibase/types"
|
import { Row, RowAttachment, Table } from "@budibase/types"
|
||||||
const { cloneDeep } = require("lodash/fp")
|
import { cloneDeep } from "lodash/fp"
|
||||||
export * from "./utils"
|
export * from "./utils"
|
||||||
|
|
||||||
type AutoColumnProcessingOpts = {
|
type AutoColumnProcessingOpts = {
|
||||||
|
@ -48,12 +48,12 @@ function getRemovedAttachmentKeys(
|
||||||
* for automatic ID purposes.
|
* for automatic ID purposes.
|
||||||
*/
|
*/
|
||||||
export function processAutoColumn(
|
export function processAutoColumn(
|
||||||
user: ContextUser | null,
|
userId: string | null | undefined,
|
||||||
table: Table,
|
table: Table,
|
||||||
row: Row,
|
row: Row,
|
||||||
opts?: AutoColumnProcessingOpts
|
opts?: AutoColumnProcessingOpts
|
||||||
) {
|
) {
|
||||||
let noUser = !user || !user.userId
|
let noUser = !userId
|
||||||
let isUserTable = table._id === InternalTables.USER_METADATA
|
let isUserTable = table._id === InternalTables.USER_METADATA
|
||||||
let now = new Date().toISOString()
|
let now = new Date().toISOString()
|
||||||
// if a row doesn't have a revision then it doesn't exist yet
|
// if a row doesn't have a revision then it doesn't exist yet
|
||||||
|
@ -70,8 +70,8 @@ export function processAutoColumn(
|
||||||
}
|
}
|
||||||
switch (schema.subtype) {
|
switch (schema.subtype) {
|
||||||
case AutoFieldSubTypes.CREATED_BY:
|
case AutoFieldSubTypes.CREATED_BY:
|
||||||
if (creating && shouldUpdateUserFields && user) {
|
if (creating && shouldUpdateUserFields && userId) {
|
||||||
row[key] = [user.userId]
|
row[key] = [userId]
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case AutoFieldSubTypes.CREATED_AT:
|
case AutoFieldSubTypes.CREATED_AT:
|
||||||
|
@ -80,8 +80,8 @@ export function processAutoColumn(
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case AutoFieldSubTypes.UPDATED_BY:
|
case AutoFieldSubTypes.UPDATED_BY:
|
||||||
if (shouldUpdateUserFields && user) {
|
if (shouldUpdateUserFields && userId) {
|
||||||
row[key] = [user.userId]
|
row[key] = [userId]
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case AutoFieldSubTypes.UPDATED_AT:
|
case AutoFieldSubTypes.UPDATED_AT:
|
||||||
|
@ -131,7 +131,7 @@ export function coerce(row: any, type: string) {
|
||||||
* @returns {object} the row which has been prepared to be written to the DB.
|
* @returns {object} the row which has been prepared to be written to the DB.
|
||||||
*/
|
*/
|
||||||
export function inputProcessing(
|
export function inputProcessing(
|
||||||
user: ContextUser | null,
|
userId: string | null | undefined,
|
||||||
table: Table,
|
table: Table,
|
||||||
row: Row,
|
row: Row,
|
||||||
opts?: AutoColumnProcessingOpts
|
opts?: AutoColumnProcessingOpts
|
||||||
|
@ -174,7 +174,7 @@ export function inputProcessing(
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle auto columns - this returns an object like {table, row}
|
// handle auto columns - this returns an object like {table, row}
|
||||||
return processAutoColumn(user, table, clonedRow, opts)
|
return processAutoColumn(userId, table, clonedRow, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue