Skip to content

custom decorators

John Biundo edited this page Aug 25, 2019 · 2 revisions

Custom decorators chapter

With this chapter, if you want to follow along, check out the custom-decorators-start branch and go to the following along section.

If you just want a final version of the project as of the end of the chapter, check out the custom-decorators-end branch, and proceed to the upon completion section.

Following along

Refer to the comments below, corresponding to chapter sections, to guide you through the code changes for nest cats as you proceed through the docs chapter.

Read through the Custom decorators chapter until you get to the Passing data section, then return here.

Passing data section

When you get to the Passing data section of the docs, go ahead and create the user.decorator.ts file as described. Place this file in src/common/decorators.

As with the roles.guard in the Guards chapter, we can create the custom decorator from this chapter, but seeing it in action depends on creating some state on the request object that we haven't really dealt with yet. We've created the decorator in anticipation of using it later in our fully integrated auth example.

Upon completion

We're done. As mentioned, we can't see the results of our custom user decorator yet.

What's next

Next up is the Cats Enhancements chapter.

Clone this wiki locally