mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
chore: add user relation enum
this enum is used to specify which relation of the user object should be populated. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
337854c86a
commit
5e4eb574c5
3 changed files with 18 additions and 7 deletions
|
@ -20,6 +20,7 @@ import { User } from '../users/user.entity';
|
|||
import { UsersService } from '../users/users.service';
|
||||
import {
|
||||
bufferToBase64Url,
|
||||
checkPassword,
|
||||
hashPassword,
|
||||
} from '../utils/password';
|
||||
import { TimestampMillis } from '../utils/timestamp';
|
||||
|
|
10
src/users/user-relation.enum.ts
Normal file
10
src/users/user-relation.enum.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export enum UserRelationEnum {
|
||||
AUTHTOKENS = 'authTokens',
|
||||
IDENTITIES = 'identities',
|
||||
}
|
|
@ -10,6 +10,7 @@ import { Repository } from 'typeorm';
|
|||
import { AlreadyInDBError, NotInDBError } from '../errors/errors';
|
||||
import { ConsoleLoggerService } from '../logger/console-logger.service';
|
||||
import { UserInfoDto } from './user-info.dto';
|
||||
import { UserRelationEnum } from './user-relation.enum';
|
||||
import { User } from './user.entity';
|
||||
|
||||
@Injectable()
|
||||
|
@ -73,17 +74,16 @@ export class UsersService {
|
|||
* @async
|
||||
* Get the user specified by the username
|
||||
* @param {string} userName the username by which the user is specified
|
||||
* @param {boolean} [withTokens=false] if the returned user object should contain authTokens
|
||||
* @param {UserRelationEnum[]} [withRelations=[]] if the returned user object should contain certain relations
|
||||
* @return {User} the specified user
|
||||
*/
|
||||
async getUserByUsername(userName: string, withTokens = false): Promise<User> {
|
||||
const relations: string[] = [];
|
||||
if (withTokens) {
|
||||
relations.push('authTokens');
|
||||
}
|
||||
async getUserByUsername(
|
||||
userName: string,
|
||||
withRelations: UserRelationEnum[] = [],
|
||||
): Promise<User> {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { userName: userName },
|
||||
relations: relations,
|
||||
relations: withRelations,
|
||||
});
|
||||
if (user === undefined) {
|
||||
throw new NotInDBError(`User with username '${userName}' not found`);
|
||||
|
|
Loading…
Reference in a new issue