Skip to content

Commit

Permalink
⛩ Add new table System
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Jun 15, 2024
1 parent 5dad4ed commit beb4894
Showing 1 changed file with 95 additions and 75 deletions.
170 changes: 95 additions & 75 deletions plugins/tickets/src/entity/Template.entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIEmbed } from "discord.js";
import { BaseEntity, Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, Relation } from "typeorm";
import { BaseEntity, Column, CreateDateColumn, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn, Relation, UpdateDateColumn } from "typeorm";
import Guild from "./Guild.entry.js";
import Ticket from "./Ticket.entry.js";

Expand All @@ -19,84 +19,104 @@ export interface Select {
emoji: string
}

interface Category {
export interface Category {
title: string
emoji: string
}

export interface System {
name: string
isEnabled: boolean
}

@Entity({ name: 'tickets_templates' })
export default class Template extends BaseEntity {
@PrimaryGeneratedColumn()
id!: number

@ManyToOne(() => Guild, (guild) => guild.templates, { cascade: true })
guild!: Relation<Guild>

@OneToMany(() => Ticket, (ticket) => ticket.template)
tickets!: Relation<Template>[]

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

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

@Column({
type: 'enum',
enum: ['button', 'select', 'modal'],
default: TypeTemplate.Button
})
type!: TypeTemplate

@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
},
from(value: string): Select[] {
return JSON.parse(value)
},
}
})
selects!: Select[]

@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
},
from(value: string): Category[] {
return JSON.parse(value)
},
}
})
categories!: Category[]

@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
},
from(value: string): APIEmbed {
return JSON.parse(value)
},
}
})
embed!: APIEmbed

@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
},
from(value: string): Properties {
return JSON.parse(value)
},
}
})
properties!: Properties
@PrimaryGeneratedColumn()
id!: number

@ManyToOne(() => Guild, (guild) => guild.templates, { cascade: true })
guild!: Relation<Guild>

@OneToMany(() => Ticket, (ticket) => ticket.template)
tickets!: Relation<Template>[]

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

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

@Column({
type: 'enum',
enum: ['button', 'select', 'modal'],
default: TypeTemplate.Button
})
type!: TypeTemplate

@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
},
from(value: string): Select[] {
return JSON.parse(value)
},
}
})
selects!: Select[]

@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
},
from(value: string): Category[] {
return JSON.parse(value)
},
}
})
categories!: Category[]

@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
},
from(value: string): APIEmbed {
return JSON.parse(value)
},
}
})
embed!: APIEmbed

@Column('simple-json', {
nullable: true,
transformer: {
to(value: string): string {
return JSON.stringify(value)
},
from(value: string): Properties {
return JSON.parse(value)
},
}
})
properties!: Properties

@Column('simple-json', {
nullable: true,
transformer: {
from(value: string): System[] { return JSON.parse(value) },
to(value: string): string { return JSON.stringify(value) },
}
})
systems!: System[]

@CreateDateColumn()
createAt!: Date

@UpdateDateColumn()
updateAt!: Date
}

0 comments on commit beb4894

Please sign in to comment.