Add categories database table

This commit is contained in:
Isaac 2021-02-25 13:12:15 +00:00
parent 1f2d40234b
commit 74fa568a7c
No known key found for this signature in database
GPG Key ID: 279D1F53391CED07
2 changed files with 36 additions and 4 deletions

View File

@ -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'
});

View File

@ -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' };
});