1
0
Fork 0
mirror of synced 2024-09-25 22:01:43 +12:00
budibase/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts

28 lines
588 B
TypeScript
Raw Normal View History

2023-09-15 21:21:10 +12:00
import { cache } from "@budibase/backend-core"
import { utils } from "@budibase/shared-core"
2023-09-15 20:33:36 +12:00
import { FieldSubtype } from "@budibase/types"
2023-09-15 21:21:10 +12:00
export async function processInputBBReferences(
2023-09-15 20:33:36 +12:00
value: string,
subtype: FieldSubtype
2023-09-15 21:21:10 +12:00
) {
const result = []
const ids = value.split(",").map((id: string) => id.trim())
switch (subtype) {
case FieldSubtype.USER:
for (const id of ids) {
result.push(await cache.user.getUser(id))
}
break
default:
utils.unreachable(subtype)
}
if (result.length > 1) {
return result
}
return result[0]
}