Quick fix for saving current user._id - make sure it is the correct format of ID.
This commit is contained in:
parent
24b6d5d9ba
commit
d4335bca73
|
@ -1,13 +1,15 @@
|
||||||
import { cache } from "@budibase/backend-core"
|
import { cache, db as dbCore } from "@budibase/backend-core"
|
||||||
import { utils } from "@budibase/shared-core"
|
import { utils } from "@budibase/shared-core"
|
||||||
import { FieldSubtype } from "@budibase/types"
|
import { FieldSubtype, DocumentType, SEPARATOR } from "@budibase/types"
|
||||||
import { InvalidBBRefError } from "./errors"
|
import { InvalidBBRefError } from "./errors"
|
||||||
|
|
||||||
|
const ROW_PREFIX = DocumentType.ROW + SEPARATOR
|
||||||
|
|
||||||
export async function processInputBBReferences(
|
export async function processInputBBReferences(
|
||||||
value: string | string[] | { _id: string } | { _id: string }[],
|
value: string | string[] | { _id: string } | { _id: string }[],
|
||||||
subtype: FieldSubtype
|
subtype: FieldSubtype
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
const referenceIds: string[] = []
|
let referenceIds: string[] = []
|
||||||
|
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
referenceIds.push(
|
referenceIds.push(
|
||||||
|
@ -26,6 +28,17 @@ export async function processInputBBReferences(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure all reference IDs are correct global user IDs
|
||||||
|
// they may be user metadata references (start with row prefix)
|
||||||
|
// and these need to be converted to global IDs
|
||||||
|
referenceIds = referenceIds.map(id => {
|
||||||
|
if (id?.startsWith(ROW_PREFIX)) {
|
||||||
|
return dbCore.getGlobalIDFromUserMetadataID(id)
|
||||||
|
} else {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
switch (subtype) {
|
switch (subtype) {
|
||||||
case FieldSubtype.USER:
|
case FieldSubtype.USER:
|
||||||
const { notFoundIds } = await cache.user.getUsers(referenceIds)
|
const { notFoundIds } = await cache.user.getUsers(referenceIds)
|
||||||
|
|
Loading…
Reference in New Issue