Formatting.

This commit is contained in:
mike12345567 2021-06-08 16:11:46 +01:00
parent 33184be064
commit b05c67e8b5
3 changed files with 23 additions and 21 deletions

View File

@ -4,9 +4,7 @@ const {
getUserMetadataParams, getUserMetadataParams,
} = require("../../db/utils") } = require("../../db/utils")
const { InternalTables } = require("../../db/utils") const { InternalTables } = require("../../db/utils")
const { const { addAppRoleToUser } = require("../../utilities/workerRequests")
addAppRoleToUser,
} = require("../../utilities/workerRequests")
const { getGlobalUsers, getGlobalUser } = require("../../utilities/global") const { getGlobalUsers, getGlobalUser } = require("../../utilities/global")
const { getFullUser } = require("../../utilities/users") const { getFullUser } = require("../../utilities/users")

View File

@ -11,10 +11,7 @@ const {
const { flatten } = require("lodash") const { flatten } = require("lodash")
const CouchDB = require("../../db") const CouchDB = require("../../db")
const { FieldTypes } = require("../../constants") const { FieldTypes } = require("../../constants")
const { const { getMultiIDParams, USER_METDATA_PREFIX } = require("../../db/utils")
getMultiIDParams,
USER_METDATA_PREFIX,
} = require("../../db/utils")
const { partition } = require("lodash") const { partition } = require("lodash")
const { getGlobalUsers } = require("../../utilities/global") const { getGlobalUsers } = require("../../utilities/global")
@ -70,20 +67,21 @@ async function getFullLinkedDocs(appId, links) {
row => row.doc row => row.doc
) )
// need to handle users as specific cases // need to handle users as specific cases
let [users, other] = partition(linked, linkRow => linkRow._id.startsWith(USER_METDATA_PREFIX)) let [users, other] = partition(linked, linkRow =>
linkRow._id.startsWith(USER_METDATA_PREFIX)
)
const globalUsers = await getGlobalUsers(appId, users) const globalUsers = await getGlobalUsers(appId, users)
users = users.map(user => { users = users.map(user => {
const globalUser = globalUsers.find(globalUser => globalUser && user._id.includes(globalUser._id)) const globalUser = globalUsers.find(
globalUser => globalUser && user._id.includes(globalUser._id)
)
return { return {
...globalUser, ...globalUser,
// doing user second overwrites the id and rev (always metadata) // doing user second overwrites the id and rev (always metadata)
...user, ...user,
} }
}) })
return [ return [...other, ...users]
...other,
...users,
]
} }
/** /**

View File

@ -43,11 +43,17 @@ exports.getGlobalUsers = async (appId = null, users = null) => {
row => row.doc row => row.doc
) )
} else { } else {
globalUsers = (await db.allDocs(getGlobalUserParams(null,{ globalUsers = (
await db.allDocs(
getGlobalUserParams(null, {
include_docs: true, include_docs: true,
}))).rows.map(row => row.doc) })
)
).rows.map(row => row.doc)
} }
globalUsers = globalUsers.filter(user => user != null).map(user => { globalUsers = globalUsers
.filter(user => user != null)
.map(user => {
delete user.password delete user.password
return user return user
}) })