From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Assignment: Hiding sensitive information

Assignment: Hiding sensitive information

Assume a scenario where we have a NestJS app with an endpoint that fetches the user data from a database. We want to create an interceptor in such a way that it transforms the user data to hide or remove sensitive information, for example, password before sending the response back to the client. And this is what we are going to implement in this assignment. So let's begin. I'll create a user service file first. So let me give the command nest generate service slash services slash user hyphen hyphen no spec. I'll open the service file. And here I will create a users array object by giving private users. And in this object, I'll define a few properties like id 1, name user A, e-mail, I'll give user A at example.com and password I'll keep secret key 1. Similarly, I'll create two more objects that is user B and user C. Now I'll define a method to find the user. It will take an ID as an argument which is of type number and in the return statement I'll give this dot users dot find user user…

Contents