|
|
@@ -1,3 +1,4 @@
|
|
|
+import { join } from 'path'
|
|
|
import { Injectable } from '@nestjs/common'
|
|
|
import { InjectRepository } from '@nestjs/typeorm'
|
|
|
import { CommissionConfig } from './entities/commission-config.entity'
|
|
|
@@ -7,6 +8,8 @@ import { Users } from '../users/entities/users.entity'
|
|
|
import { UserBalanceService } from '../user-balance/user-balance.service'
|
|
|
import { BalanceType as BalanceType } from 'src/user-balance/entities/balance-record.entity'
|
|
|
import { BigNumber } from 'bignumber.js'
|
|
|
+import { CommissionRecordDto } from './dto/commission-record.dto'
|
|
|
+import { hideSensitiveData } from 'src/utils/common'
|
|
|
|
|
|
@Injectable()
|
|
|
export class CommissionService {
|
|
|
@@ -60,13 +63,40 @@ export class CommissionService {
|
|
|
}
|
|
|
|
|
|
async getRecords(userId: number) {
|
|
|
- return await this.commissionRecordRepository.find({
|
|
|
- where: {
|
|
|
- userId
|
|
|
- },
|
|
|
- order: {
|
|
|
- createdAt: 'DESC'
|
|
|
- }
|
|
|
+ return (
|
|
|
+ await this.commissionRecordRepository
|
|
|
+ .createQueryBuilder()
|
|
|
+ .leftJoinAndMapOne(
|
|
|
+ 'CommissionRecord.fromUser',
|
|
|
+ Users,
|
|
|
+ 'fromUser',
|
|
|
+ 'CommissionRecord.fromUserId = fromUser.id'
|
|
|
+ )
|
|
|
+ .where('CommissionRecord.userId = :userId', { userId })
|
|
|
+ .orderBy('CommissionRecord.createdAt', 'DESC')
|
|
|
+ .getMany()
|
|
|
+ ).map((record) => {
|
|
|
+ return new CommissionRecordDto({
|
|
|
+ id: record.id,
|
|
|
+ userId: record.userId,
|
|
|
+ fromUserId: record.fromUserId,
|
|
|
+ name: hideSensitiveData(record.fromUser?.name),
|
|
|
+ level: record.level,
|
|
|
+ ratio: record.ratio,
|
|
|
+ amount: record.amount
|
|
|
+ })
|
|
|
})
|
|
|
+
|
|
|
+ // return await this.commissionRecordRepository.find({
|
|
|
+ // relations: {
|
|
|
+ // fromUser: true
|
|
|
+ // },
|
|
|
+ // where: {
|
|
|
+ // userId
|
|
|
+ // },
|
|
|
+ // order: {
|
|
|
+ // createdAt: 'DESC'
|
|
|
+ // }
|
|
|
+ // })
|
|
|
}
|
|
|
}
|