fix: bug in the send reminder send
This commit is contained in:
@@ -59,6 +59,7 @@ export const enum AuthMessage {
|
||||
INVALID_REFRESH_TOKEN = "توکن رفرش نامعتبر است",
|
||||
REFRESH_TOKEN_EXPIRED = "توکن رفرش منقضی شده است",
|
||||
LOGOUT_SUCCESS = "خروج با موفقیت انجام شد",
|
||||
CURRENT_PASSWORD_INVALID = "رمز عبور فعلی نامعتبر است",
|
||||
}
|
||||
|
||||
export const enum UserMessage {
|
||||
|
||||
@@ -206,7 +206,7 @@ export class AuthService {
|
||||
const { user } = await this.usersService.findOneById(userId);
|
||||
|
||||
const passCompare = await this.passwordService.comparePassword(updateDto.password, user.password);
|
||||
if (!passCompare) throw new BadRequestException(AuthMessage.INVALID_PASSWORD);
|
||||
if (!passCompare) throw new BadRequestException(AuthMessage.CURRENT_PASSWORD_INVALID);
|
||||
|
||||
if (updateDto.newPassword !== updateDto.repeatPassword) throw new BadRequestException(AuthMessage.INVALID_REAPET_PASSWORD);
|
||||
|
||||
|
||||
@@ -11,5 +11,5 @@ export const INVOICE = Object.freeze({
|
||||
FINE_PERCENTAGE: 0.01, // 1% of the total price
|
||||
MAX_DAYS_AFTER_OVERDUE: 10,
|
||||
DUEDATE: 7,
|
||||
DAYS_BEFORE_OVERDUE: 3,
|
||||
DAYS_BEFORE_OVERDUE: 6,
|
||||
});
|
||||
|
||||
@@ -96,10 +96,10 @@ export class InvoicesService {
|
||||
INVOICE.INVOICE_REMINDER_JOB_NAME,
|
||||
{ invoiceId: invoice.id },
|
||||
{
|
||||
delay: dayjs(invoice.dueDate).subtract(3, "day").diff(dayjs()),
|
||||
// delay: dayjs(invoice.dueDate).subtract(INVOICE.DAYS_BEFORE_OVERDUE, "day").diff(dayjs()),
|
||||
delay: 900000, // 15 minutes in milliseconds
|
||||
attempts: INVOICE.INVOICE_REMINDER_JOB_ATTEMPTS,
|
||||
backoff: INVOICE.INVOICE_REMINDER_JOB_BACKOFF,
|
||||
repeat: { every: 300000 }, // Repeat every 5 minutes (300,000 ms)
|
||||
},
|
||||
);
|
||||
|
||||
@@ -198,6 +198,8 @@ export class InvoicesService {
|
||||
queryRunner,
|
||||
);
|
||||
|
||||
await this.otpService.delOtpFormCache(user.phone, "INVOICE_VERIFY");
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
return {
|
||||
@@ -255,7 +257,8 @@ export class InvoicesService {
|
||||
INVOICE.INVOICE_REMINDER_JOB_NAME,
|
||||
{ invoiceId: invoice.id },
|
||||
{
|
||||
delay: dayjs(invoice.dueDate).subtract(INVOICE.DAYS_BEFORE_OVERDUE, "day").diff(dayjs()),
|
||||
// delay: dayjs(invoice.dueDate).subtract(INVOICE.DAYS_BEFORE_OVERDUE, "day").diff(dayjs()),
|
||||
delay: 900000, // 15 minutes in milliseconds
|
||||
attempts: INVOICE.INVOICE_REMINDER_JOB_ATTEMPTS,
|
||||
backoff: INVOICE.INVOICE_REMINDER_JOB_BACKOFF,
|
||||
repeat: { every: 300000 },
|
||||
|
||||
@@ -15,8 +15,6 @@ import { InvoiceStatus } from "../enums/invoice-status.enum";
|
||||
@Processor(INVOICE.INVOICE_QUEUE_NAME)
|
||||
export class InvoiceProcessor extends WorkerProcessor {
|
||||
protected readonly logger = new Logger(InvoiceProcessor.name);
|
||||
private readonly FINE_PERCENTAGE = 0.01;
|
||||
private readonly MAX_DAYS_OVERDUE = 1;
|
||||
|
||||
constructor(
|
||||
@InjectQueue(INVOICE.INVOICE_QUEUE_NAME) private readonly invoiceQueue: Queue,
|
||||
@@ -88,7 +86,7 @@ export class InvoiceProcessor extends WorkerProcessor {
|
||||
//********************************** */
|
||||
|
||||
private isInvoiceOverdueForCancellation(invoice: Invoice): boolean {
|
||||
const fiveDaysAfterDueDate = dayjs(invoice.dueDate).add(this.MAX_DAYS_OVERDUE, "day");
|
||||
const fiveDaysAfterDueDate = dayjs(invoice.dueDate).add(INVOICE.MAX_DAYS_AFTER_OVERDUE, "day");
|
||||
return dayjs().isAfter(fiveDaysAfterDueDate);
|
||||
}
|
||||
//********************************** */
|
||||
@@ -96,7 +94,7 @@ export class InvoiceProcessor extends WorkerProcessor {
|
||||
private async cancelOverdueInvoice(invoice: Invoice, queryRunner: QueryRunner) {
|
||||
invoice.status = InvoiceStatus.CANCELLED;
|
||||
await queryRunner.manager.save(Invoice, invoice);
|
||||
this.logger.log(`Invoice ${invoice.id} has been cancelled as it is more than 5 days overdue.`);
|
||||
this.logger.log(`Invoice ${invoice.id} has been cancelled as it is more than 7 days overdue.`);
|
||||
}
|
||||
//********************************** */
|
||||
|
||||
@@ -105,11 +103,11 @@ export class InvoiceProcessor extends WorkerProcessor {
|
||||
const dueDate = dayjs(invoice.dueDate);
|
||||
|
||||
if (today.isAfter(dueDate)) {
|
||||
const daysOverdue = Math.min(today.diff(dueDate, "day"), this.MAX_DAYS_OVERDUE);
|
||||
const daysOverdue = Math.min(today.diff(dueDate, "day"), INVOICE.MAX_DAYS_AFTER_OVERDUE);
|
||||
|
||||
const currentFine = invoice.lateFee || new Decimal(0);
|
||||
const totalDaysFineShouldBeApplied = daysOverdue;
|
||||
const finePerDay = new Decimal(invoice.totalPrice).mul(this.FINE_PERCENTAGE);
|
||||
const finePerDay = new Decimal(invoice.totalPrice).mul(INVOICE.FINE_PERCENTAGE);
|
||||
const newTotalFine = finePerDay.mul(totalDaysFineShouldBeApplied);
|
||||
|
||||
if (newTotalFine.gt(currentFine)) {
|
||||
|
||||
Reference in New Issue
Block a user