From ae3976343cf75cc77360ac3f558047c164d4b9de Mon Sep 17 00:00:00 2001 From: QuantumlyTangled Date: Mon, 14 Sep 2020 21:13:08 +0200 Subject: [PATCH] feat: add guild tax rates --- src/lib/orm/entities/GuildEconomyEntity.ts | 21 +++++++++++++++++++++ src/lib/orm/entities/GuildEntity.ts | 8 ++++++-- src/lib/structures/DbSet.ts | 9 +++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/lib/orm/entities/GuildEconomyEntity.ts 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); }