mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 17:56:30 -05:00
change getTokensByUsername to getTokensByUser
Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
parent
141b1bf5e8
commit
aa8455a079
3 changed files with 12 additions and 14 deletions
|
@ -40,8 +40,8 @@ export class TokensController {
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async getUserTokens(@RequestUser() user: User): Promise<AuthTokenDto[]> {
|
async getUserTokens(@RequestUser() user: User): Promise<AuthTokenDto[]> {
|
||||||
return (await this.authService.getTokensByUsername(user.userName)).map(
|
return (await this.authService.getTokensByUser(user)).map((token) =>
|
||||||
(token) => this.authService.toAuthTokenDto(token),
|
this.authService.toAuthTokenDto(token),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ export class TokensController {
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Param('keyId') keyId: string,
|
@Param('keyId') keyId: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const tokens = await this.authService.getTokensByUsername(user.userName);
|
const tokens = await this.authService.getTokensByUser(user);
|
||||||
try {
|
try {
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
if (token.keyId == keyId) {
|
if (token.keyId == keyId) {
|
||||||
|
|
|
@ -74,12 +74,10 @@ describe('AuthService', () => {
|
||||||
expect(service).toBeDefined();
|
expect(service).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getTokensByUsername', () => {
|
describe('getTokensByUser', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
jest
|
jest.spyOn(authTokenRepo, 'find').mockResolvedValueOnce([authToken]);
|
||||||
.spyOn(userRepo, 'findOne')
|
const tokens = await service.getTokensByUser(user);
|
||||||
.mockResolvedValueOnce({ ...user, authTokens: [authToken] });
|
|
||||||
const tokens = await service.getTokensByUsername(user.userName);
|
|
||||||
expect(tokens).toHaveLength(1);
|
expect(tokens).toHaveLength(1);
|
||||||
expect(tokens).toEqual([authToken]);
|
expect(tokens).toEqual([authToken]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -140,14 +140,14 @@ export class AuthService {
|
||||||
return accessToken;
|
return accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTokensByUsername(userName: string): Promise<AuthToken[]> {
|
async getTokensByUser(user: User): Promise<AuthToken[]> {
|
||||||
const user = await this.usersService.getUserByUsername(userName, [
|
const tokens = await this.authTokenRepository.find({
|
||||||
UserRelationEnum.AUTHTOKENS,
|
where: { user: user },
|
||||||
]);
|
});
|
||||||
if (user.authTokens === undefined) {
|
if (tokens === undefined) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return user.authTokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeToken(keyId: string): Promise<void> {
|
async removeToken(keyId: string): Promise<void> {
|
||||||
|
|
Loading…
Reference in a new issue