update: change the invoice status
This commit is contained in:
@@ -13,7 +13,7 @@ export function databaseConfigs(): TypeOrmModuleAsyncOptions {
|
||||
username: configService.getOrThrow<string>("DB_USER"),
|
||||
password: configService.getOrThrow<string>("DB_PASS"),
|
||||
autoLoadEntities: true,
|
||||
synchronize: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : false,
|
||||
synchronize: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
|
||||
logging: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
|
||||
migrationsTableName: "typeorm_migrations",
|
||||
migrationsRun: false,
|
||||
|
||||
@@ -3,7 +3,6 @@ export enum InvoiceStatus {
|
||||
PENDING = "PENDING",
|
||||
WAIT_PAYMENT = "WAIT_PAYMENT",
|
||||
PAID = "PAID",
|
||||
ARCHIVED = "ARCHIVED",
|
||||
OVERDUE = "OVERDUE",
|
||||
EXPIRED = "EXPIRED",
|
||||
CANCELLED = "CANCELLED",
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ export class InvoicesService {
|
||||
if (invoice.status === InvoiceStatus.PAID) throw new BadRequestException(InvoiceMessage.INVOICE_ALREADY_PAID);
|
||||
|
||||
if (dayjs().isAfter(dayjs(invoice.dueDate).add(INVOICE.MAX_DAYS_AFTER_OVERDUE, "day"))) {
|
||||
invoice.status = InvoiceStatus.EXPIRED;
|
||||
invoice.status = InvoiceStatus.ARCHIVED;
|
||||
await queryRunner.manager.save(Invoice, invoice);
|
||||
throw new BadRequestException(InvoiceMessage.INVOICE_IS_OVERDUE);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ export class InvoiceProcessor extends WorkerProcessor {
|
||||
throw new Error(`Maximum recurring cycles (${invoice.maxRecurringCycles}) reached for invoice ${invoice.id}`);
|
||||
}
|
||||
|
||||
if (invoice.status === InvoiceStatus.CANCELLED) throw new Error(`Cannot create recurring invoice for cancelled invoice ${invoice.id}`);
|
||||
if (invoice.status === InvoiceStatus.ARCHIVED) throw new Error(`Cannot create recurring invoice for archived invoice ${invoice.id}`);
|
||||
}
|
||||
|
||||
//********************************** */
|
||||
@@ -195,11 +195,11 @@ export class InvoiceProcessor extends WorkerProcessor {
|
||||
//********************************** */
|
||||
|
||||
private async cancelOverdueInvoice(invoice: Invoice, queryRunner: QueryRunner) {
|
||||
invoice.status = InvoiceStatus.CANCELLED;
|
||||
invoice.status = InvoiceStatus.ARCHIVED;
|
||||
await queryRunner.manager.save(Invoice, invoice);
|
||||
if (invoice.items[0]?.subscriptionPlan) {
|
||||
this.logger.log(
|
||||
`Invoice ${invoice.id} has been cancelled as it is more than 10 days overdue. Subscription Plan ${invoice.items[0].subscriptionPlan.id} has been cancelled.`,
|
||||
`Invoice ${invoice.id} has been archived as it is more than 10 days overdue. Subscription Plan ${invoice.items[0].subscriptionPlan.id} has been cancelled.`,
|
||||
);
|
||||
const userSubscription = invoice.items[0].subscriptionPlan;
|
||||
userSubscription.status = SubscriptionStatus.INACTIVE;
|
||||
@@ -215,7 +215,7 @@ export class InvoiceProcessor extends WorkerProcessor {
|
||||
}
|
||||
if (invoice.items[0]?.supportPlan) {
|
||||
this.logger.log(
|
||||
`Invoice ${invoice.id} has been cancelled as it is more than 10 days overdue. Support Plan ${invoice.items[0].supportPlan.id} has been cancelled.`,
|
||||
`Invoice ${invoice.id} has been archived as it is more than 10 days overdue. Support Plan ${invoice.items[0].supportPlan.id} has been cancelled.`,
|
||||
);
|
||||
const userSupportPlan = invoice.items[0].supportPlan;
|
||||
userSupportPlan.status = UserSupportPlanStatus.INACTIVE;
|
||||
@@ -223,7 +223,7 @@ export class InvoiceProcessor extends WorkerProcessor {
|
||||
|
||||
await this.applyFreeSupportPlan(invoice, queryRunner);
|
||||
}
|
||||
this.logger.log(`Invoice ${invoice.id} has been cancelled as it is more than 10 days overdue.`);
|
||||
this.logger.log(`Invoice ${invoice.id} has been archived as it is more than 10 days overdue.`);
|
||||
}
|
||||
//********************************** */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user