From 18deb1e4b0ea5b709a854966166077faa537ebef Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Thu, 26 Aug 2021 20:48:09 +0200 Subject: :sparkles: use RelationId --- util/src/entities/Webhook.ts | 46 +++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'util/src/entities/Webhook.ts') diff --git a/util/src/entities/Webhook.ts b/util/src/entities/Webhook.ts index 54233638..dc929c18 100644 --- a/util/src/entities/Webhook.ts +++ b/util/src/entities/Webhook.ts @@ -1,5 +1,9 @@ -import { Column, Entity, JoinColumn } from "typeorm"; +import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; +import { Application } from "./Application"; import { BaseClass } from "./BaseClass"; +import { Channel } from "./Channel"; +import { Guild } from "./Guild"; +import { User } from "./User"; export enum WebhookType { Incoming = 1, @@ -23,18 +27,38 @@ export class Webhook extends BaseClass { @Column() token?: string; - @JoinColumn() - guild?: string; + @RelationId((webhook: Webhook) => webhook.guild) + guild_id: string; - @JoinColumn() - channel: string; + @JoinColumn({ name: "guild_id" }) + @ManyToOne(() => Guild, (guild: Guild) => guild.id) + guild: Guild; - @JoinColumn() - application?: string; + @RelationId((webhook: Webhook) => webhook.channel) + channel_id: string; - @JoinColumn() - user?: string; + @JoinColumn({ name: "channel_id" }) + @ManyToOne(() => Channel, (channel: Channel) => channel.id) + channel: Channel; - @JoinColumn() - source_guild: string; + @RelationId((webhook: Webhook) => webhook.application) + application_id: string; + + @JoinColumn({ name: "application_id" }) + @ManyToOne(() => Application, (application: Application) => application.id) + application: Application; + + @RelationId((webhook: Webhook) => webhook.user) + user_id: string; + + @JoinColumn({ name: "user_id" }) + @ManyToOne(() => User, (user: User) => user.id) + user: User; + + @RelationId((webhook: Webhook) => webhook.guild) + source_guild_id: string; + + @JoinColumn({ name: "source_guild_id" }) + @ManyToOne(() => Guild, (guild: Guild) => guild.id) + source_guild: Guild; } -- cgit 1.5.1