Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering data by user #38

Closed
mso1985 opened this issue Jul 14, 2020 · 2 comments
Closed

Filtering data by user #38

mso1985 opened this issue Jul 14, 2020 · 2 comments

Comments

@mso1985
Copy link

mso1985 commented Jul 14, 2020

say you have a new entity you want to list.. wich will be the best way of filtering by logged user id? interceptor would be the best choice right?

@NarHakobyan
Copy link
Owner

NarHakobyan commented Jul 14, 2020

Hi @mso1985, You can get logged in user by @authuser decorator and pass to your service function as options (options always need to be Partial)

    @Get('users')
    @Roles(RoleType.USER)
    @HttpCode(HttpStatus.OK)
    async admin(@AuthUser() currentUser: UserEntity) {
        const userEntities = await this.yourService.getUsers({parentId: currentUser.id});
		return userEntities.toDtos();
    }

@mso1985
Copy link
Author

mso1985 commented Jul 15, 2020

Great! this boilerplate is proving itself

@mso1985 mso1985 closed this as completed Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants