Skip to content

Commit

Permalink
fix(api): add limitation to user serch endpoint (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
brightAMasiuk authored Dec 28, 2022
1 parent 5c00a5b commit a987e5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions public/src/pages/auth/AdminPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const AdminPage: FC = () => {
{isAdmin ? (
<>
<div>User catalog:</div>
<div><b>Hint</b>: to see more results typing specific name</div>
<input
type="text"
className="au-input au-input--full"
Expand Down
2 changes: 1 addition & 1 deletion src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class UsersController {
async searchByName(@Param('name') name: string): Promise<UserDto[]> {
try {
this.logger.debug(`Search users by name: ${name}`);
const users = await this.usersService.searchByName(name);
const users = await this.usersService.searchByName(name, 50);
return users.map((user) => new UserDto(user));
} catch (err) {
throw new HttpException(err.message, err.status);
Expand Down
8 changes: 5 additions & 3 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ export class UsersService {
return user;
}

async searchByName(query: string): Promise<User[]> {
async searchByName(query: string, limit?: number): Promise<User[]> {
this.log.debug(`Called searchUsersByName`);
return this.usersRepository.find({
firstName: { $like: query + '%' },
});
firstName: { $like: query + '%' },
},
limit ? { limit } : {},
);
}

async getPermissions(email: string): Promise<PermissionDto> {
Expand Down

0 comments on commit a987e5e

Please sign in to comment.