sticker db entities

This commit is contained in:
Flam3rboy 2021-10-14 19:47:02 +02:00
parent 88edaba3ab
commit 93b76035b6
2 changed files with 49 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm"; import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { User } from "./User";
import { BaseClass } from "./BaseClass"; import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild"; import { Guild } from "./Guild";
@ -25,8 +26,15 @@ export class Sticker extends BaseClass {
tags: string; tags: string;
@Column() @Column()
@RelationId((sticker: Sticker) => sticker.pack)
pack_id: string; pack_id: string;
@JoinColumn({ name: "pack_id" })
@ManyToOne(() => require("./StickerPack").StickerPack, {
onDelete: "CASCADE",
})
pack: import("./StickerPack").StickerPack;
@Column({ nullable: true }) @Column({ nullable: true })
guild_id?: string; guild_id?: string;
@ -36,6 +44,15 @@ export class Sticker extends BaseClass {
}) })
guild?: Guild; guild?: Guild;
@Column({ nullable: true })
user_id?: string;
@JoinColumn({ name: "user_id" })
@ManyToOne(() => User, {
onDelete: "CASCADE",
})
user?: User;
@Column({ type: "int" }) @Column({ type: "int" })
type: StickerType; type: StickerType;

View File

@ -0,0 +1,31 @@
import { Column, Entity, JoinColumn, OneToMany, OneToOne, RelationId } from "typeorm";
import { Sticker } from ".";
import { BaseClass } from "./BaseClass";
@Entity("stickers")
export class StickerPack extends BaseClass {
@Column()
name: string;
@Column({ nullable: true })
description?: string;
@Column({ nullable: true })
banner_asset_id?: string;
@OneToMany(() => Sticker, (sticker: Sticker) => sticker.pack_id, {
cascade: true,
orphanedRowAction: "delete",
})
stickers: Sticker[];
// sku_id: string
@Column({ nullable: true })
@RelationId((pack: StickerPack) => pack.cover_sticker)
cover_sticker_id?: string;
@OneToOne(() => Sticker, { nullable: true })
@JoinColumn()
cover_sticker?: Sticker;
}