Search code examples
javascriptnode.jsnestjsmapper

How to convert boolean to string - NestJS / JS / Node


I am new to NestJS as a server. I have a table in DB that I am querying, and the column name is precedence, and it is boolean meaning in DB just 0 or 1.
I have this code that I understood maps the data to DTO.

forMember(
          (destination) => destination.precedence,
          mapFrom((source) => source.precedence),
        ),

but instead of 1 I need it to be true and instead of 0 I need it to be false

Can it be done? in the mapper?


Solution

  • you just have to check if source.precedence is equal to '1' then return true else return false

    forMember(
     (destination) => destination.precedence,
     mapFrom((source) => source.precedence === 1), // this will return false also if the value is different from 0 and 1
    ),