2021-04-13 12:56:57 +02:00
|
|
|
const CouchDB = require("../db")
|
2021-06-08 17:06:30 +02:00
|
|
|
const { InternalTables } = require("../db/utils")
|
|
|
|
const { getGlobalUser } = require("../utilities/global")
|
2021-04-12 16:54:14 +02:00
|
|
|
|
2021-04-19 17:26:33 +02:00
|
|
|
exports.getFullUser = async (ctx, userId) => {
|
2021-06-08 17:06:30 +02:00
|
|
|
const global = await getGlobalUser(ctx.appId, userId)
|
2021-04-14 17:00:58 +02:00
|
|
|
let metadata
|
|
|
|
try {
|
2021-04-15 16:57:55 +02:00
|
|
|
// this will throw an error if the db doesn't exist, or there is no appId
|
|
|
|
const db = new CouchDB(ctx.appId)
|
2021-04-19 17:26:33 +02:00
|
|
|
metadata = await db.get(userId)
|
2021-04-14 17:00:58 +02: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-12 16:54:14 +02:00
|
|
|
return {
|
|
|
|
...global,
|
2021-04-14 17:00:58 +02:00
|
|
|
...metadata,
|
2021-05-19 17:24:20 +02:00
|
|
|
tableId: InternalTables.USER_METADATA,
|
2021-04-12 16:54:14 +02:00
|
|
|
// make sure the ID is always a local ID, not a global one
|
2021-04-19 17:26:33 +02:00
|
|
|
_id: userId,
|
2021-04-12 16:54:14 +02:00
|
|
|
}
|
|
|
|
}
|