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: updatedTable, row } = inputProcessing(
|
||||
ctx.user,
|
||||
ctx.user?._id,
|
||||
cloneDeep(table),
|
||||
inputs
|
||||
)
|
||||
|
|
|
@ -59,7 +59,7 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
|
|||
const tableClone = cloneDeep(dbTable)
|
||||
|
||||
// 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({
|
||||
row,
|
||||
table,
|
||||
|
@ -106,7 +106,7 @@ export async function save(ctx: UserCtx) {
|
|||
// need to copy the table so it can be differenced on way out
|
||||
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({
|
||||
row,
|
||||
|
|
|
@ -113,7 +113,7 @@ export function importToRows(
|
|||
|
||||
// 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
|
||||
const processed = inputProcessing(user, table, row, {
|
||||
const processed = inputProcessing(user?._id, table, row, {
|
||||
noAutoRelationships: true,
|
||||
})
|
||||
row = processed.row
|
||||
|
|
|
@ -5,8 +5,8 @@ import { ObjectStoreBuckets } from "../../constants"
|
|||
import { context, db as dbCore, objectStore } from "@budibase/backend-core"
|
||||
import { InternalTables } from "../../db/utils"
|
||||
import { TYPE_TRANSFORM_MAP } from "./map"
|
||||
import { Row, RowAttachment, Table, ContextUser } from "@budibase/types"
|
||||
const { cloneDeep } = require("lodash/fp")
|
||||
import { Row, RowAttachment, Table } from "@budibase/types"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
export * from "./utils"
|
||||
|
||||
type AutoColumnProcessingOpts = {
|
||||
|
@ -48,12 +48,12 @@ function getRemovedAttachmentKeys(
|
|||
* for automatic ID purposes.
|
||||
*/
|
||||
export function processAutoColumn(
|
||||
user: ContextUser | null,
|
||||
userId: string | null | undefined,
|
||||
table: Table,
|
||||
row: Row,
|
||||
opts?: AutoColumnProcessingOpts
|
||||
) {
|
||||
let noUser = !user || !user.userId
|
||||
let noUser = !userId
|
||||
let isUserTable = table._id === InternalTables.USER_METADATA
|
||||
let now = new Date().toISOString()
|
||||
// if a row doesn't have a revision then it doesn't exist yet
|
||||
|
@ -70,8 +70,8 @@ export function processAutoColumn(
|
|||
}
|
||||
switch (schema.subtype) {
|
||||
case AutoFieldSubTypes.CREATED_BY:
|
||||
if (creating && shouldUpdateUserFields && user) {
|
||||
row[key] = [user.userId]
|
||||
if (creating && shouldUpdateUserFields && userId) {
|
||||
row[key] = [userId]
|
||||
}
|
||||
break
|
||||
case AutoFieldSubTypes.CREATED_AT:
|
||||
|
@ -80,8 +80,8 @@ export function processAutoColumn(
|
|||
}
|
||||
break
|
||||
case AutoFieldSubTypes.UPDATED_BY:
|
||||
if (shouldUpdateUserFields && user) {
|
||||
row[key] = [user.userId]
|
||||
if (shouldUpdateUserFields && userId) {
|
||||
row[key] = [userId]
|
||||
}
|
||||
break
|
||||
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.
|
||||
*/
|
||||
export function inputProcessing(
|
||||
user: ContextUser | null,
|
||||
userId: string | null | undefined,
|
||||
table: Table,
|
||||
row: Row,
|
||||
opts?: AutoColumnProcessingOpts
|
||||
|
@ -174,7 +174,7 @@ export function inputProcessing(
|
|||
}
|
||||
|
||||
// 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