Skip to content

PM-921 qa fixes #15

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 2 commits into from
Apr 3, 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
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BHMKuGsgiBjJ7xHNxaJvBzrwdArogHSxEPmT6gNr5rZeXmJUWzrpQIstMXA9gEXX
LfKzG61idXFIwBa6t5YBCCMx+hoCxhcEiwIDAQAB
-----END RSA PUBLIC KEY-----"
AUTH0_CLIENT_ID=BXWXUWnilVUPdN01t2Se29Tw2ZYNGZvH
AUTH0_M2M_AUDIENCE=https://m2m.topcoder-dev.com/

DB_USERNAME=topcoderuser
DB_PASSWORD=randompassword
Expand Down
4 changes: 2 additions & 2 deletions src/api/admin-winning/adminWinning.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export class AdminWinningService {
attributes: item.attributes,
details: item.payment?.map((paymentItem) => ({
id: paymentItem.payment_id,
netAmount: paymentItem.net_amount,
grossAmount: paymentItem.gross_amount,
netAmount: Number(paymentItem.net_amount),
grossAmount: Number(paymentItem.gross_amount),
totalAmount: Number(paymentItem.total_amount),
installmentNumber: paymentItem.installment_number,
datePaid: paymentItem.date_paid ?? undefined,
Expand Down
1 change: 0 additions & 1 deletion src/api/winning/winning.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class WinningService {

const paymentData: Prisma.paymentCreateManyInput[] = body.details.map(
(item) => ({
net_amount: new Prisma.Decimal(item.grossAmount),
total_amount: new Prisma.Decimal(item.totalAmount),
gross_amount: new Prisma.Decimal(item.grossAmount),
installment_number: item.installmentNumber,
Expand Down
4 changes: 2 additions & 2 deletions src/core/auth/guards/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export class AuthGuard implements CanActivate {
[context.getHandler(), context.getClass()],
);

const reqScopes = req.m2mTokenScope.split(' ')
if (reqScopes.some(reqScope => allowedM2mScopes.includes(reqScope))) {
const reqScopes = req.m2mTokenScope.split(' ');
if (reqScopes.some((reqScope) => allowedM2mScopes.includes(reqScope))) {
return true;
}
return false;
Expand Down
15 changes: 10 additions & 5 deletions src/core/auth/middleware/tokenValidator.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ export class TokenValidatorMiddleware implements NestMiddleware {

let decoded: any;
try {
decoded = jwt.verify(idToken, process.env.AUTH0_CERT, {
audience: process.env.AUTH0_CLIENT_ID,
});
decoded = jwt.verify(idToken, process.env.AUTH0_CERT);
} catch (error) {
console.error('Error verifying JWT', error);
throw new UnauthorizedException('Invalid or expired JWT!');
}

// TODO: verify decoded.aud
if (!decoded) {
req.idTokenVerified = false;
return next();
}

req.idTokenVerified = true;
req.isM2M = !!decoded.scope;
const aud = req.isM2M
? process.env.AUTH0_M2M_AUDIENCE
: process.env.AUTH0_CLIENT_ID;

if (decoded.aud !== aud) {
req.idTokenVerified = false;
return next();
}

req.idTokenVerified = true;
if (decoded.scope) {
req.m2mTokenScope = decoded.scope;
req.m2mTokenAudience = decoded.aud;
Expand Down
8 changes: 0 additions & 8 deletions src/dto/adminWinning.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,6 @@ export class WinningUpdateRequestDto {
}

export class PaymentCreateRequestDto {
@ApiProperty({
description: 'The net amount of the payment',
example: 12.3,
})
@IsNumber()
@Min(0)
netAmount: number;

@ApiProperty({
description: 'The total amount of the payment',
example: 12.3,
Expand Down