diff --git a/src/lib/orm/entities/GuildEconomyEntity.ts b/src/lib/orm/entities/GuildEconomyEntity.ts new file mode 100644 index 0000000..38c1e7b --- /dev/null +++ b/src/lib/orm/entities/GuildEconomyEntity.ts @@ -0,0 +1,21 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { BaseEntity, Column, Entity, JoinColumn, OneToOne } from "typeorm"; +import { GuildEntity } from "./GuildEntity"; + +@Entity("guild_economy", { schema: "public" }) +export class GuildEconomyEntity extends BaseEntity { + // #region Global tax rate offsets + @Column("numeric", { name: "tax_offset_general", precision: 8, default: 0 }) + public toGeneral = 0; + + @Column("numeric", { name: "tax_offset_gambling", precision: 8, default: 0 }) + public toGambling = 0; + + @Column("numeric", { name: "tax_offset_sales", precision: 8, default: 0 }) + public toSales = 0; + // #endregion Global tax rate offsets + + @OneToOne(() => GuildEntity, { primary: true, onDelete: "CASCADE" }) + @JoinColumn() + public guild?: GuildEntity; +} diff --git a/src/lib/orm/entities/GuildEntity.ts b/src/lib/orm/entities/GuildEntity.ts index 9990c85..026bb85 100644 --- a/src/lib/orm/entities/GuildEntity.ts +++ b/src/lib/orm/entities/GuildEntity.ts @@ -1,5 +1,6 @@ import { PREFIX } from "@root/config"; -import { BaseEntity, Check, Column, Entity, PrimaryColumn } from "typeorm"; +import { BaseEntity, Check, Column, Entity, OneToOne, PrimaryColumn } from "typeorm"; +import { GuildEconomyEntity } from "./GuildEconomyEntity"; @Entity("guild", { schema: "public" }) @Check(/* sql */ `"prefix"::text <> ''::text`) @@ -11,5 +12,8 @@ export class GuildEntity extends BaseEntity { public prefix: string = PREFIX; @Column("varchar", { name: "language", length: 10, default: "en-US" }) - public language = "en-US"; + public language = "en-US"; + + @OneToOne(() => GuildEconomyEntity, eco => eco.guild, { cascade: true }) + public economy?: GuildEconomyEntity; } diff --git a/src/lib/structures/DbSet.ts b/src/lib/structures/DbSet.ts index a82513c..3c1cfdc 100644 --- a/src/lib/structures/DbSet.ts +++ b/src/lib/structures/DbSet.ts @@ -1,9 +1,10 @@ import { connect } from "@orm/dbConfig"; +import { GuildEconomyEntity } from "@orm/entities/GuildEconomyEntity"; +import { UserEconomyEntity } from "@orm/entities/UserEconomyEntity"; +import { UserGametagEntity } from "@orm/entities/UserGametagEntity"; import { GuildRepository } from "@orm/repositories/GuildRepository"; import { UserRepository } from "@orm/repositories/UserRepository"; import type { Connection } from "typeorm"; -import { UserGametagEntity } from "@orm/entities/UserGametagEntity"; -import { UserEconomyEntity } from "@orm/entities/UserEconomyEntity"; export class DbSet { @@ -16,6 +17,10 @@ export class DbSet { return this.connection.getCustomRepository(GuildRepository); } + public get guildEconomyEntities() { + return this.connection.getRepository(GuildEconomyEntity); + } + public get users() { return this.connection.getCustomRepository(UserRepository); }