From 74fa568a7cd5f37762a15087c5c02afec9ae9be0 Mon Sep 17 00:00:00 2001 From: Isaac Date: Thu, 25 Feb 2021 13:12:15 +0000 Subject: [PATCH] Add categories database table --- src/database/index.js | 31 +++++++++++++++++++++++++++++++ src/server/index.js | 9 +++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/database/index.js b/src/database/index.js index c7eaa12..10a2471 100644 --- a/src/database/index.js +++ b/src/database/index.js @@ -82,6 +82,29 @@ module.exports = async (log) => { tableName: DB_TABLE_PREFIX + 'guilds' }); + const Category = sequelize.define('Category', { + id: { + type: DataTypes.CHAR(18), + primaryKey: true, + allowNull: false, + }, + name: { + type: DataTypes.STRING, + allowNull: false, + unique: 'name_guild' + }, + guild: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: Guild, + key: 'id' + }, + unique: 'name_guild' + }, + }, { + tableName: DB_TABLE_PREFIX + 'categories' + }); const Ticket = sequelize.define('Ticket', { id: { @@ -102,6 +125,14 @@ module.exports = async (log) => { key: 'id' }, }, + category: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: Category, + key: 'id' + }, + }, }, { tableName: DB_TABLE_PREFIX + 'tickets' }); diff --git a/src/server/index.js b/src/server/index.js index 374fed0..e15e5b3 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -1,5 +1,4 @@ const { Plugin } = require('../modules/plugins'); -const fastify = require('fastify')(); module.exports = class SettingsServer extends Plugin { constructor(client){ @@ -10,23 +9,25 @@ module.exports = class SettingsServer extends Plugin { commands: [] }); + this.fastify = require('fastify')(); + this.client.plugins.plugins.set(this.id, this); this.preload(); } async preload() { - fastify.register(this.client.log.fastify, { + this.fastify.register(this.client.log.fastify, { type: 'http' }); } async load() { - fastify.listen(process.env.HTTP_PORT || 8080, (err, address) => { + this.fastify.listen(process.env.HTTP_PORT || 8080, (err, address) => { if (err) throw err; this.client.log.info(`Settings server listening at ${address}`); }); - fastify.get('/', async (req, res) => { + this.fastify.get('/', async (req, res) => { res.type('application/json').code(200); return { hello: 'world' }; });