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.

Built-in pipes (ParseBooleanPipe)

Built-in pipes (ParseBooleanPipe)

The parse bool pipe in NestJS is a built-in transformation pipe which transforms incoming string values from request parameters like query strings, body parameters, etc. into Boolean values. This can be useful when dealing with API endpoints that expect Boolean flags or filters. Let's check an example. Inside the controller file, I'll give the get handler and a method getValue. Inside this method's argument, I'll give the query decorator and the parameter value as isActive and the parse boolean py. So this query string will hold a boolean value and if any other value other than boolean is given as a query, it will display an error. Let me give a property isActive of type Boolean and inside the method, I will give an if condition that if the isActive exists, return a welcome admin message else return welcome user message if the value is false. Let's save this and open the postman. I'll give the route path and give the query. Let's first set the query value as a random string value and…

Contents