mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-05 17:14:40 -04:00
fix username spelling from userName
Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
parent
aa8455a079
commit
d33cfa4541
23 changed files with 89 additions and 91 deletions
|
@ -13,7 +13,7 @@ export class UserInfoDto {
|
|||
*/
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
userName: string;
|
||||
username: string;
|
||||
|
||||
/**
|
||||
* The display name
|
||||
|
|
|
@ -29,7 +29,7 @@ export class User {
|
|||
@Column({
|
||||
unique: true,
|
||||
})
|
||||
userName: string;
|
||||
username: string;
|
||||
|
||||
@Column()
|
||||
displayName: string;
|
||||
|
@ -77,14 +77,14 @@ export class User {
|
|||
private constructor() {}
|
||||
|
||||
public static create(
|
||||
userName: string,
|
||||
username: string,
|
||||
displayName: string,
|
||||
): Pick<
|
||||
User,
|
||||
'userName' | 'displayName' | 'ownedNotes' | 'authTokens' | 'identities'
|
||||
'username' | 'displayName' | 'ownedNotes' | 'authTokens' | 'identities'
|
||||
> {
|
||||
const newUser = new User();
|
||||
newUser.userName = userName;
|
||||
newUser.username = username;
|
||||
newUser.displayName = displayName;
|
||||
return newUser;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ describe('UsersService', () => {
|
|||
});
|
||||
it('works', async () => {
|
||||
const user = await service.createUser(username, displayname);
|
||||
expect(user.userName).toEqual(username);
|
||||
expect(user.username).toEqual(username);
|
||||
expect(user.displayName).toEqual(displayname);
|
||||
});
|
||||
it('fails if username is already taken', async () => {
|
||||
|
@ -110,7 +110,7 @@ describe('UsersService', () => {
|
|||
it('works', async () => {
|
||||
jest.spyOn(userRepo, 'findOne').mockResolvedValueOnce(user);
|
||||
const getUser = await service.getUserByUsername(username);
|
||||
expect(getUser.userName).toEqual(username);
|
||||
expect(getUser.username).toEqual(username);
|
||||
expect(getUser.displayName).toEqual(displayname);
|
||||
});
|
||||
it('fails when user does not exits', async () => {
|
||||
|
@ -144,7 +144,7 @@ describe('UsersService', () => {
|
|||
const user = User.create(username, displayname) as User;
|
||||
it('works if a user is provided', () => {
|
||||
const userDto = service.toUserDto(user);
|
||||
expect(userDto.userName).toEqual(username);
|
||||
expect(userDto.username).toEqual(username);
|
||||
expect(userDto.displayName).toEqual(displayname);
|
||||
expect(userDto.photo).toEqual('');
|
||||
expect(userDto.email).toEqual('');
|
||||
|
|
|
@ -24,37 +24,37 @@ export class UsersService {
|
|||
|
||||
/**
|
||||
* @async
|
||||
* Create a new user with a given userName and displayName
|
||||
* @param userName - the userName the new user shall have
|
||||
* Create a new user with a given username and displayName
|
||||
* @param username - the username the new user shall have
|
||||
* @param displayName - the display the new user shall have
|
||||
* @return {User} the user
|
||||
* @throws {AlreadyInDBError} the userName is already taken.
|
||||
* @throws {AlreadyInDBError} the username is already taken.
|
||||
*/
|
||||
async createUser(userName: string, displayName: string): Promise<User> {
|
||||
const user = User.create(userName, displayName);
|
||||
async createUser(username: string, displayName: string): Promise<User> {
|
||||
const user = User.create(username, displayName);
|
||||
try {
|
||||
return await this.userRepository.save(user);
|
||||
} catch {
|
||||
this.logger.debug(
|
||||
`A user with the username '${userName}' already exists.`,
|
||||
`A user with the username '${username}' already exists.`,
|
||||
'createUser',
|
||||
);
|
||||
throw new AlreadyInDBError(
|
||||
`A user with the username '${userName}' already exists.`,
|
||||
`A user with the username '${username}' already exists.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @async
|
||||
* Delete the user with the specified userName
|
||||
* Delete the user with the specified username
|
||||
* @param {User} user - the username of the user to be delete
|
||||
* @throws {NotInDBError} the userName has no user associated with it.
|
||||
* @throws {NotInDBError} the username has no user associated with it.
|
||||
*/
|
||||
async deleteUser(user: User): Promise<void> {
|
||||
await this.userRepository.remove(user);
|
||||
this.logger.debug(
|
||||
`Successfully deleted user with username ${user.userName}`,
|
||||
`Successfully deleted user with username ${user.username}`,
|
||||
'deleteUser',
|
||||
);
|
||||
}
|
||||
|
@ -73,20 +73,20 @@ export class UsersService {
|
|||
/**
|
||||
* @async
|
||||
* Get the user specified by the username
|
||||
* @param {string} userName the username by which the user is specified
|
||||
* @param {string} username the username by which the user is specified
|
||||
* @param {UserRelationEnum[]} [withRelations=[]] if the returned user object should contain certain relations
|
||||
* @return {User} the specified user
|
||||
*/
|
||||
async getUserByUsername(
|
||||
userName: string,
|
||||
username: string,
|
||||
withRelations: UserRelationEnum[] = [],
|
||||
): Promise<User> {
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { userName: userName },
|
||||
where: { username: username },
|
||||
relations: withRelations,
|
||||
});
|
||||
if (user === undefined) {
|
||||
throw new NotInDBError(`User with username '${userName}' not found`);
|
||||
throw new NotInDBError(`User with username '${username}' not found`);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ export class UsersService {
|
|||
*/
|
||||
toUserDto(user: User): UserInfoDto {
|
||||
return {
|
||||
userName: user.userName,
|
||||
username: user.username,
|
||||
displayName: user.displayName,
|
||||
photo: this.getPhotoUrl(user),
|
||||
email: user.email ?? '',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue