DEV Community

bravemaster619
bravemaster619

Posted on

1 1

Typescript: is it possible to apply multiple method decorators using class decorator?

Hi, devs. I've just opened up a question in stackoverflow. I'm sure it's a good question for you if you have some knowledege in typescript decorators.

Please help me in StackOverflow. Thanks!

I'm using experimental typescript decorators to manage access control in express.

class AccountController extends Controller {
  login(req: Request, res: Response) {
    const { email, password } = req.body;
    const token = await this.model.login(email, password);
    return res.json({
      token
    });
  }

  @hasRole('ADMIN')
  list(req: Request, res: Response) {
    res.json({
      data: await this.model.findAll()
    });

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay