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]
|
|
|
|
}
|