Skip to content

Commit

Permalink
Merge pull request #206 from Uzo-Felix/feat/payment-schema
Browse files Browse the repository at this point in the history
Feat/payment schema
  • Loading branch information
incredible-phoenix246 authored Jul 24, 2024
2 parents c2874e1 + 7791b37 commit eaab35f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from "./like";
export * from "./tag";
export * from "./comment";
export * from "./category";
export * from "./payment";
4 changes: 4 additions & 0 deletions src/models/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { User } from ".";
import { v4 as uuidv4 } from "uuid";
import { UserOrganization } from "./user-organisation";
import ExtendedBaseEntity from "./extended-base-entity";
import { Payment } from "./payment";

@Entity()
export class Organization extends ExtendedBaseEntity {
Expand Down Expand Up @@ -62,6 +63,9 @@ export class Organization extends ExtendedBaseEntity {
@ManyToMany(() => User, (user) => user.organizations)
users: User[];

@OneToMany(() => Payment, payment => payment.organization)
payments: Payment[];

@BeforeInsert()
generateSlug() {
this.slug = uuidv4();
Expand Down
56 changes: 56 additions & 0 deletions src/models/payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ManyToOne } from "typeorm";
import { IsEmail } from "class-validator";
import { User } from "./user";
import { Organization } from "./organization";

@Entity()
export class Payment {
@PrimaryGeneratedColumn("uuid")
id: string;

@Column("decimal", { precision: 10, scale: 2 })
amount: number;

@Column()
currency: string;

@Column({
type: "enum",
enum: ["pending", "completed", "failed"],
})
status: "pending" | "completed" | "failed";

@Column({
type: "enum",
enum: ["stripe", "flutterwave", "lemonsqueezy", "paystack"],
})
provider: "stripe" | "flutterwave" | "lemonsqueezy" | "paystack";

@Column("uuid", { nullable: true })
userId: string | null;

@ManyToOne(() => User, user => user.payments, { nullable: true })
user: User | null;

@Column("uuid", { nullable: true })
organizationId: string | null;

@ManyToOne(() => Organization, organization => organization.payments, { nullable: true })
organization: Organization | null;

@Column({ nullable: true })
@IsEmail()
payer_email: string;

@Column({ nullable: true })
description: string;

@Column("jsonb", { nullable: true })
metadata: object;

@CreateDateColumn()
created_at: Date;

@UpdateDateColumn()
updated_at: Date;
}
4 changes: 4 additions & 0 deletions src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ExtendedBaseEntity from "./extended-base-entity";
import { getIsInvalidMessage } from "../utils";
import { UserRole } from "../enums/userRoles";
import { Like } from "./like";
import { Payment } from "./payment";

@Entity()
@Unique(["email"])
Expand Down Expand Up @@ -75,6 +76,9 @@ export class User extends ExtendedBaseEntity {
@OneToMany(() => Sms, (sms) => sms.sender, { cascade: true })
sms: Sms[];

@OneToMany(() => Payment, payment => payment.user)
payments: Payment[];

@ManyToMany(() => Organization, (organization) => organization.users, {
cascade: true,
})
Expand Down

0 comments on commit eaab35f

Please sign in to comment.