mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
extent query users
This commit is contained in:
parent
e62e803541
commit
9baa94e148
@ -809,8 +809,11 @@ export class UserResolver {
|
||||
|
||||
@Authorized([RIGHTS.USER])
|
||||
@Query(() => User)
|
||||
async user(@Arg('identifier') identifier: string): Promise<User> {
|
||||
return new User(await findUserByIdentifier(identifier))
|
||||
async user(
|
||||
@Arg('identifier') identifier: string,
|
||||
@Arg('communityIdentifier') communityIdentifier?: string,
|
||||
): Promise<User> {
|
||||
return new User(await findUserByIdentifier(identifier, communityIdentifier))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,12 +6,18 @@ import { LogError } from '@/server/LogError'
|
||||
|
||||
import { VALID_ALIAS_REGEX } from './validateAlias'
|
||||
|
||||
export const findUserByIdentifier = async (identifier: string): Promise<DbUser> => {
|
||||
export const findUserByIdentifier = async (
|
||||
identifier: string,
|
||||
communityIdentifier?: string,
|
||||
): Promise<DbUser> => {
|
||||
let user: DbUser | null
|
||||
if (validate(identifier) && version(identifier) === 4) {
|
||||
user = await DbUser.findOne({ where: { gradidoID: identifier }, relations: ['emailContact'] })
|
||||
user = await DbUser.findOne({
|
||||
where: { gradidoID: identifier, communityUuid: communityIdentifier },
|
||||
relations: ['emailContact'],
|
||||
})
|
||||
if (!user) {
|
||||
throw new LogError('No user found to given identifier', identifier)
|
||||
throw new LogError('No user found to given identifier(s)', identifier, communityIdentifier)
|
||||
}
|
||||
} else if (/^.{2,}@.{2,}\..{2,}$/.exec(identifier)) {
|
||||
const userContact = await DbUserContact.findOne({
|
||||
@ -27,12 +33,21 @@ export const findUserByIdentifier = async (identifier: string): Promise<DbUser>
|
||||
if (!userContact.user) {
|
||||
throw new LogError('No user to given contact', identifier)
|
||||
}
|
||||
if (userContact.user.communityUuid !== communityIdentifier) {
|
||||
throw new LogError(
|
||||
'Found user to given contact, but belongs to foreign community',
|
||||
identifier,
|
||||
)
|
||||
}
|
||||
user = userContact.user
|
||||
user.emailContact = userContact
|
||||
} else if (VALID_ALIAS_REGEX.exec(identifier)) {
|
||||
user = await DbUser.findOne({ where: { alias: identifier }, relations: ['emailContact'] })
|
||||
user = await DbUser.findOne({
|
||||
where: { alias: identifier, communityUuid: communityIdentifier },
|
||||
relations: ['emailContact'],
|
||||
})
|
||||
if (!user) {
|
||||
throw new LogError('No user found to given identifier', identifier)
|
||||
throw new LogError('No user found to given identifier(s)', identifier, communityIdentifier)
|
||||
}
|
||||
} else {
|
||||
throw new LogError('Unknown identifier type', identifier)
|
||||
|
||||
@ -370,10 +370,14 @@ export const adminListContributionMessages = gql`
|
||||
`
|
||||
|
||||
export const user = gql`
|
||||
query ($identifier: String!) {
|
||||
user(identifier: $identifier) {
|
||||
query ($identifier: String!, $communityIdentifier?: String) {
|
||||
user(identifier: $identifier, $communityIdentifier: $communityIdentifier) {
|
||||
firstName
|
||||
lastName
|
||||
foreign
|
||||
communityUuid
|
||||
gradidoID
|
||||
alias
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user