diff --git a/src/api/admin-winning/adminWinning.service.ts b/src/api/admin-winning/adminWinning.service.ts index 20192d6..8e05c41 100644 --- a/src/api/admin-winning/adminWinning.service.ts +++ b/src/api/admin-winning/adminWinning.service.ts @@ -107,7 +107,7 @@ export class AdminWinningService { details: item.payment?.map((paymentItem) => ({ id: paymentItem.payment_id, netAmount: Number(paymentItem.net_amount), - grossAmount: (paymentItem.gross_amount), + grossAmount: Number(paymentItem.gross_amount), totalAmount: Number(paymentItem.total_amount), installmentNumber: paymentItem.installment_number, datePaid: paymentItem.date_paid ?? undefined, diff --git a/src/api/repository/paymentMethod.repo.ts b/src/api/repository/paymentMethod.repo.ts index 6611904..4b15d0c 100644 --- a/src/api/repository/paymentMethod.repo.ts +++ b/src/api/repository/paymentMethod.repo.ts @@ -36,14 +36,13 @@ export class PaymentMethodRepository { * @returns payment methods */ private async findPaymentMethodByUserId(userId: string, tx?) { - const query = ` + const db = tx || this.prisma; + const ret = await db.$queryRaw` SELECT pm.payment_method_id, pm.payment_method_type, pm.name, pm.description, upm.status, upm.id FROM payment_method pm JOIN user_payment_methods upm ON pm.payment_method_id = upm.payment_method_id - WHERE upm.user_id = '${userId}' + WHERE upm.user_id=${userId} `; - const db = tx || this.prisma; - const ret = await db.$queryRawUnsafe(query); return (ret || []) as PaymentMethodQueryResult[]; } } diff --git a/src/api/repository/taxForm.repo.ts b/src/api/repository/taxForm.repo.ts index c92a6f0..92d17a1 100644 --- a/src/api/repository/taxForm.repo.ts +++ b/src/api/repository/taxForm.repo.ts @@ -34,15 +34,14 @@ export class TaxFormRepository { userId: string, tx?, ): Promise { - const query = ` + const db = tx || this.prisma; + + const ret = await db.$queryRaw` SELECT u.id, u.user_id, t.tax_form_id, t.name, t.text, t.description, u.date_filed, u.withholding_amount, u.withholding_percentage, u.status_id::text, u.use_percentage FROM user_tax_form_associations AS u JOIN tax_forms AS t ON u.tax_form_id = t.tax_form_id - WHERE u.user_id = '${userId}' + WHERE u.user_id=${userId} `; - const db = tx || this.prisma; - - const ret = await db.$queryRawUnsafe(query); return (ret || []) as TaxFormQueryResult[]; } } diff --git a/src/api/wallet/wallet.service.ts b/src/api/wallet/wallet.service.ts index 14e4435..5e88dc8 100644 --- a/src/api/wallet/wallet.service.ts +++ b/src/api/wallet/wallet.service.ts @@ -8,6 +8,8 @@ import { PaymentStatus, } from 'src/dto/adminWinning.dto'; import { WalletDetailDto } from 'src/dto/wallet.dto'; +import { TaxFormRepository } from '../repository/taxForm.repo'; +import { PaymentMethodRepository } from '../repository/paymentMethod.repo'; /** * The winning service. @@ -18,7 +20,11 @@ export class WalletService { * Constructs the admin winning service with the given dependencies. * @param prisma the prisma service. */ - constructor(private readonly prisma: PrismaService) {} + constructor( + private readonly prisma: PrismaService, + private readonly taxFormRepo: TaxFormRepository, + private readonly paymentMethodRepo: PaymentMethodRepository, + ) {} /** * Get wallet detail. @@ -63,6 +69,7 @@ export class WalletService { // count PAYMENT and REWARD totals let paymentTotal = 0; + // eslint-disable-next-line @typescript-eslint/no-unused-vars let rewardTotal = 0; winnings.forEach((item) => { if (item.type === WinningsType.PAYMENT) { @@ -90,6 +97,10 @@ export class WalletService { } }); + const hasActiveTaxForm = await this.taxFormRepo.hasActiveTaxForm(userId); + const hasVerifiedPaymentMethod = + await this.paymentMethodRepo.hasVerifiedPaymentMethod(userId); + const winningTotals: WalletDetailDto = { account: { balances: [ @@ -98,18 +109,19 @@ export class WalletService { amount: paymentTotal, unit: 'currency', }, - { - type: WinningsType.REWARD, - amount: rewardTotal, - unit: 'points', - }, + // hide rewards for now + // { + // type: WinningsType.REWARD, + // amount: rewardTotal, + // unit: 'points', + // }, ], }, withdrawalMethod: { - isSetupComplete: true, + isSetupComplete: hasVerifiedPaymentMethod, }, taxForm: { - isSetupComplete: true, + isSetupComplete: hasActiveTaxForm, }, }; diff --git a/src/api/winning/winning.controller.ts b/src/api/winning/winning.controller.ts index 0d015f3..d4a8e8c 100644 --- a/src/api/winning/winning.controller.ts +++ b/src/api/winning/winning.controller.ts @@ -14,8 +14,8 @@ import { ResponseStatusType, ResponseDto, WinningRequestDto, - SearchWinningResult, WinningCreateRequestDto, + WinningDto, } from 'src/dto/adminWinning.dto'; import { AdminWinningService } from '../admin-winning/adminWinning.service'; @@ -78,18 +78,21 @@ export class WinningController { @ApiResponse({ status: 200, description: 'Search winnings successfully.', - type: ResponseDto, + type: ResponseDto, }) @HttpCode(HttpStatus.OK) async searchWinnings( @Body() body: WinningRequestDto, - ): Promise> { + ): Promise> { const result = await this.adminWinningService.searchWinnings(body); result.status = result.error ? ResponseStatusType.ERROR : ResponseStatusType.SUCCESS; - return result; + return { + ...result, + data: result.data.winnings, + }; } }