Skip to content

PM-921 qa fixes #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/admin-winning/adminWinning.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions src/api/repository/paymentMethod.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
}
9 changes: 4 additions & 5 deletions src/api/repository/taxForm.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ export class TaxFormRepository {
userId: string,
tx?,
): Promise<TaxFormQueryResult[]> {
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[];
}
}
28 changes: 20 additions & 8 deletions src/api/wallet/wallet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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: [
Expand All @@ -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,
},
};

Expand Down
11 changes: 7 additions & 4 deletions src/api/winning/winning.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
ResponseStatusType,
ResponseDto,
WinningRequestDto,
SearchWinningResult,
WinningCreateRequestDto,
WinningDto,
} from 'src/dto/adminWinning.dto';

import { AdminWinningService } from '../admin-winning/adminWinning.service';
Expand Down Expand Up @@ -78,18 +78,21 @@ export class WinningController {
@ApiResponse({
status: 200,
description: 'Search winnings successfully.',
type: ResponseDto<SearchWinningResult>,
type: ResponseDto<WinningDto[]>,
})
@HttpCode(HttpStatus.OK)
async searchWinnings(
@Body() body: WinningRequestDto,
): Promise<ResponseDto<SearchWinningResult>> {
): Promise<ResponseDto<WinningDto[]>> {
const result = await this.adminWinningService.searchWinnings(body);

result.status = result.error
? ResponseStatusType.ERROR
: ResponseStatusType.SUCCESS;

return result;
return {
...result,
data: result.data.winnings,
};
}
}