2021-06-09 03:06:30 +12:00
|
|
|
const { InternalTables } = require("../db/utils")
|
|
|
|
const { getGlobalUser } = require("../utilities/global")
|
2022-01-28 07:18:31 +13:00
|
|
|
const { getAppDB } = require("@budibase/backend-core/context")
|
2021-04-13 02:54:14 +12:00
|
|
|
|
2021-04-20 03:26:33 +12:00
|
|
|
exports.getFullUser = async (ctx, userId) => {
|
2022-01-28 07:18:31 +13:00
|
|
|
const global = await getGlobalUser(userId)
|
2021-04-15 03:00:58 +12:00
|
|
|
let metadata
|
|
|
|
try {
|
2021-04-16 02:57:55 +12:00
|
|
|
// this will throw an error if the db doesn't exist, or there is no appId
|
2022-01-28 07:18:31 +13:00
|
|
|
const db = getAppDB()
|
2021-04-20 03:26:33 +12:00
|
|
|
metadata = await db.get(userId)
|
2021-04-15 03:00:58 +12:00
|
|
|
} catch (err) {
|
|
|
|
// it is fine if there is no user metadata, just remove global db info
|
|
|
|
delete global._id
|
|
|
|
delete global._rev
|
|
|
|
}
|
2021-04-13 02:54:14 +12:00
|
|
|
return {
|
|
|
|
...global,
|
2021-04-15 03:00:58 +12:00
|
|
|
...metadata,
|
2021-05-20 03:24:20 +12:00
|
|
|
tableId: InternalTables.USER_METADATA,
|
2021-04-13 02:54:14 +12:00
|
|
|
// make sure the ID is always a local ID, not a global one
|
2021-04-20 03:26:33 +12:00
|
|
|
_id: userId,
|
2021-04-13 02:54:14 +12:00
|
|
|
}
|
|
|
|
}
|