2021-04-13 12:56:57 +02:00
|
|
|
const CouchDB = require("../db")
|
2021-04-12 16:54:14 +02:00
|
|
|
const {
|
|
|
|
generateUserMetadataID,
|
|
|
|
getEmailFromUserMetadataID,
|
|
|
|
} = require("../db/utils")
|
2021-04-13 12:56:57 +02:00
|
|
|
const { getGlobalUsers } = require("../utilities/workerRequests")
|
2021-04-12 16:54:14 +02:00
|
|
|
|
|
|
|
exports.getFullUser = async ({ ctx, email, userId }) => {
|
|
|
|
if (!email) {
|
|
|
|
email = getEmailFromUserMetadataID(userId)
|
|
|
|
}
|
|
|
|
const db = new CouchDB(ctx.appId)
|
|
|
|
const global = await getGlobalUsers(ctx, ctx.appId, email)
|
2021-04-14 17:00:58 +02:00
|
|
|
let metadata
|
|
|
|
try {
|
|
|
|
metadata = await db.get(generateUserMetadataID(email))
|
|
|
|
} 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-04-12 16:54:14 +02:00
|
|
|
// make sure the ID is always a local ID, not a global one
|
|
|
|
_id: generateUserMetadataID(email),
|
|
|
|
}
|
|
|
|
}
|