Skip to content

Commit

Permalink
Fix one year permit issue (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
gchauhan-aot authored Mar 21, 2024
1 parent 8a91e1b commit d837a15
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions vehicles/src/common/helper/permit-fee.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
TROS_MIN_VALID_DURATION,
TROS_PRICE_PER_TERM,
TROS_TERM,
TROW_MAX_VALID_DURATION,
TROW_MIN_VALID_DURATION,
} from '../constants/permit.constant';
import { differenceBetween } from './date-time.helper';

Expand All @@ -28,14 +30,12 @@ export const permitFee = (application: Permit, oldAmount: number): number => {

switch (application.permitType) {
case PermitType.TERM_OVERSIZE:
if (
duration < TROS_MIN_VALID_DURATION ||
duration >= TROS_MAX_VALID_DURATION
) {
throw new NotAcceptableException(
`Invalid duration (${duration} days) for TROS permit type.`,
);
}
validateDuration(
duration,
TROS_MIN_VALID_DURATION,
TROS_MAX_VALID_DURATION,
application.permitType,
);
// Adjusting duration for one year term permit
if (duration <= 365 && duration >= 361) duration = 360;
return currentPermitFee(
Expand All @@ -45,7 +45,20 @@ export const permitFee = (application: Permit, oldAmount: number): number => {
oldAmount,
);
case PermitType.TERM_OVERWEIGHT:
// Handle TERM_OVERWEIGHT case
validateDuration(
duration,
TROW_MIN_VALID_DURATION,
TROW_MAX_VALID_DURATION,
application.permitType,
);
// Adjusting duration for one year term permit
if (duration <= 365 && duration >= 361) duration = 360;
return currentPermitFee(
duration,
TROS_PRICE_PER_TERM,
TROS_TERM,
oldAmount,
);
break;
default:
throw new BadRequestException(
Expand All @@ -54,6 +67,19 @@ export const permitFee = (application: Permit, oldAmount: number): number => {
}
};

export const validateDuration = (
duration: number,
minDuration: number,
maxDuration: number,
permitType: string,
): void => {
if (duration < minDuration || duration > maxDuration) {
throw new BadRequestException(
`Invalid duration (${duration} days) for ${permitType} permit type.`,
);
}
};

/**
* Calculates the permit fee based on the provided duration, price per term, permit type term, and old amount.
*
Expand Down

0 comments on commit d837a15

Please sign in to comment.