#TIL 10 - Add User Define Function to TypeORM entity
This is a workaround that I found from the TypeORM issue. Simply, the solution would implement as below
Step 1: Add custom field to the class entity
// add to User.ts entity
@Column('int', { insert: false, readonly: true })
public qty: number;
Step 2: query the custom field with query builder
// need to mapping with the convention: table + _ + UDF column (user_qty)
.addSelect('dbo.udfFindTotalQty(user.id)', 'user_qty')
...
.printSql()
.getManyAndCount();