Typeorm - Get Alias Column name with join tables

Viewed 18
await this.createQueryBuilder('users')
    .select([
        'users.*',
        'user_profiles.* AS profile'
    ])

    .where({
        email: Like(`%${keyword}%`),
        userType: requestType == 'drivers' ? 2 : 1
    })
    .addSelect('users.userId', 'id')
    .leftJoinAndSelect('users.profile', 'user_profiles')
    .orderBy('users.updatedAt', 'DESC')
    .skip(skip)
    .take(10)
    .getRawMany()

Expected Result:

{
  "data": {
    "getAllUsers": {
      "results": [
        {
          "id": "28",
          "email": "nave@gmail.com",
          "profile": {
            "userId": "3a613b2f-3169-4e1b-8eff-797159d9104b",
            "profileId": 28,
            "__typename": "UserProfile"
          },
          "__typename": "UserType"
        }
      ],
      "__typename": "UserFullType"
    }
  }
}

Got Result:

{
  "data": {
    "getAllUsers": {
      "results": [
        {
          "id": "1",
          "email": "nave@gmail.com",
          "profile": null,
          "__typename": "UserType"
        }
      ],
      "__typename": "UserManagementWholeType"
    }
  }
}

Here I have three problems:

  1. getMany() is working well but in getRawMany() that result needs an alias column instead of id needs to show userId as Id
  2. If have 20 columns in table for one alias cannot write every column. Any solution is there
  3. Need join table output exactly like getMany()

Could anybody help me to solve this issue?

0 Answers
Related