Skip to content

Commit

Permalink
🐛 Fix: Database error by deleting information and creating new relations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed May 27, 2024
1 parent da6ab68 commit 05fccc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions plugins/tickets/src/entity/Guild.entry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseEntity, Entity, JoinColumn, OneToMany, OneToOne, PrimaryColumn } from "typeorm";
import Ticket from "./Ticket.entry";
import Config from "./Config.entry";
import Template from "./Template.entry";

@Entity({ name: 'guild_tickets' })
export default class Guild extends BaseEntity {
Expand All @@ -10,6 +11,9 @@ export default class Guild extends BaseEntity {
@OneToMany(() => Ticket, (ticket) => ticket.guild, { cascade: true })
tickets!: Ticket[]

@OneToMany(() => Template, (ticket) => ticket.guild, { cascade: true })
templates!: Template[]

@OneToOne(() => Config, (config) => config.guild, { cascade: true })
@JoinColumn()
configs!: Config
Expand Down
17 changes: 12 additions & 5 deletions plugins/tickets/src/entity/Template.entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { APIEmbed } from "discord.js";
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from "typeorm";
import { BaseEntity, Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import Guild from "./Guild.entry";

interface Properties {
[key: string]: boolean | string
Expand Down Expand Up @@ -27,6 +28,9 @@ export default class Template extends BaseEntity {
@PrimaryGeneratedColumn()
id!: number

@ManyToOne(() => Guild, (guild) => guild.templates)
guild!: Guild

@Column({ type: 'text' })
messageId!: string

Expand All @@ -40,7 +44,7 @@ export default class Template extends BaseEntity {
})
type!: TypeTemplate

@Column('json', {
@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
Expand All @@ -53,7 +57,8 @@ export default class Template extends BaseEntity {
})
selects!: Select[]

@Column('json', {
@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
Expand All @@ -65,7 +70,8 @@ export default class Template extends BaseEntity {
})
categories!: Category[]

@Column('json', {
@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
Expand All @@ -77,7 +83,8 @@ export default class Template extends BaseEntity {
})
embed!: APIEmbed

@Column('json', {
@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
Expand Down

0 comments on commit 05fccc7

Please sign in to comment.