chore: add invoice and subscription entities
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { Column, Entity, ManyToOne } from "typeorm";
|
||||
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { SubscriptionPlan } from "../../subscriptions/entities/subscription.entity";
|
||||
import { User } from "../../users/entities/user.entity";
|
||||
import { InvoiceStatus } from "../enums/invoice-status.enum";
|
||||
|
||||
@Entity()
|
||||
export class Invoice extends BaseEntity {
|
||||
@ManyToOne(() => User, (user) => user.invoices, { nullable: true, onDelete: "RESTRICT" })
|
||||
user: User;
|
||||
|
||||
@ManyToOne(() => SubscriptionPlan, { nullable: true, onDelete: "SET NULL" })
|
||||
subscriptionPlan?: SubscriptionPlan;
|
||||
|
||||
@Column({ type: "decimal", precision: 10, scale: 2, nullable: false })
|
||||
amount: number;
|
||||
|
||||
@Column({ type: "enum", enum: InvoiceStatus, default: InvoiceStatus.PENDING })
|
||||
status: InvoiceStatus;
|
||||
|
||||
@Column({ type: "timestamp", nullable: true })
|
||||
paidAt?: Date;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export enum InvoiceStatus {
|
||||
PENDING = "PENDING",
|
||||
PAID = "PAID",
|
||||
CANCELED = "CANCELED",
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Controller } from "@nestjs/common";
|
||||
|
||||
@Controller("invoices")
|
||||
export class InvoicesController {}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { Invoice } from "./entities/invoice.entity";
|
||||
import { InvoicesController } from "./invoices.controller";
|
||||
import { InvoicesService } from "./providers/invoices.service";
|
||||
import { InvoicesRepository } from "./repositories/invoices.repository";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Invoice])],
|
||||
providers: [InvoicesService, InvoicesRepository],
|
||||
controllers: [InvoicesController],
|
||||
exports: [InvoicesService],
|
||||
})
|
||||
export class InvoicesModule {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class InvoicesService {}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { Invoice } from "../entities/invoice.entity";
|
||||
|
||||
@Injectable()
|
||||
export class InvoicesRepository extends Repository<Invoice> {
|
||||
constructor(@InjectRepository(Invoice) invoicesRepository: Repository<Invoice>) {
|
||||
super(invoicesRepository.target, invoicesRepository.manager, invoicesRepository.queryRunner);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user