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)
|
|
|
|
const user = await db.get(generateUserMetadataID(email))
|
|
|
|
return {
|
|
|
|
...global,
|
|
|
|
...user,
|
|
|
|
// make sure the ID is always a local ID, not a global one
|
|
|
|
_id: generateUserMetadataID(email),
|
|
|
|
}
|
|
|
|
}
|