title: Nestjs-create custom json response from entity class
body: <p>I am using typeorm and MySQL. My entity stores different types of sports data like Football, Athletics->100m,200m,400m.</p>
  
  <p>In the the get call I want group data by gameType that is <strong>athletics or football</strong> and want create nested JSON like below</p>
  
  <p><strong>JSON format:</strong>
      {</p>
  
  <pre><code>  "footBall":[
         {"location":"use",gameType:"footbal", "goals":2,"result":"won"},
         {"location":"use",gameType:"footbal", "goals":1,"result":"draw"}
      ],
  
      "athletics":[
           {"location":"poland",gameType:"athletics", gameSubType:"100m", "rank":2,"result":"first place"},
           {"location":"ireland",gameType:"athletics", gameSubType:"200m", "rank":1,"result":"second place"}
        ]
  
  }
  </code></pre>
  
  <p>My entity class is like this:  </p>
  
  <pre><code>  @Entity('competition')
  export class CompetitionEntity {
      @PrimaryGeneratedColumn()
      id:Number
  
      @Column({ type: 'timestamp', default: () =&gt; "CURRENT_TIMESTAMP"})
      date:Date
  
      @Column()
      location:String
  
      @Column()
      rank:Number
  
      @Column()
      eventType: string
  
      @Column()
      minutes: number
  
      @Column()
      seconds: number
  
      @Column()
      miliseconds: number
  
      @Column()
      gameType: string  //it can take values like athletics or football or baseball etc
  
      @Column()
      gameSubType: string //it can take value like 100m, 200m, relay etc
  }
  </code></pre>
  
  <p>In service I have written code like this to get all data in competition table</p>
  
  <pre><code>    const qb = await getRepository(CompetitionEntity)
          .createQueryBuilder('competition')
  
  
      const competitions = await qb.getMany();
  </code></pre>
  
  <p>After getting result form database, I want group data by gameType column and send it as nested json.</p>
  
  <p>Please guide me on this</p>
  
  <p>Thank you all</p>