extent query users

This commit is contained in:
Claus-Peter Huebner 2023-10-09 15:46:02 +02:00
parent e62e803541
commit 9baa94e148
3 changed files with 31 additions and 9 deletions

View File

@ -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))
}
}

View File

@ -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)

View File

@ -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
}
}
`