+
+ @HasMany(() => ServerBlocklistModel, {
+ foreignKey: {
+ allowNull: false
+ },
+ onDelete: 'CASCADE'
+ })
+ BlockedBy: ServerBlocklistModel[]
+
+ // ---------------------------------------------------------------------------
+
+ static getSQLAttributes (tableName: string, aliasPrefix = '') {
+ return buildSQLAttributes({
+ model: this,
+ tableName,
+ aliasPrefix
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ static load (id: number, transaction?: Transaction): Promise<MServer> {
+ const query = {
+ where: {
+ id
+ },
+ transaction
+ }
+
+ return ServerModel.findOne(query)
+ }
+
+ static loadByHost (host: string): Promise<MServer> {
+ const query = {
+ where: {
+ host
+ }
+ }
+
+ return ServerModel.findOne(query)
+ }
+
+ static async loadOrCreateByHost (host: string) {
+ let server = await ServerModel.loadByHost(host)
+ if (!server) server = await ServerModel.create({ host })
+
+ return server
+ }
+
+ isBlocked () {
+ return this.BlockedBy && this.BlockedBy.length !== 0
+ }
+
+ toFormattedJSON (this: MServerFormattable) {
+ return {
+ host: this.host
+ }
+ }