DB: Add models and migration for badges

This commit is contained in:
2023-02-27 01:56:44 +01:00
parent 1a5e7c1b62
commit 06575d280f
4 changed files with 69 additions and 0 deletions

24
models/badge.js Normal file
View File

@@ -0,0 +1,24 @@
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Badge extends Model {
static associate(models) {
// A badge can belong to many cards
Badge.belongsToMany(models.Character, { through: 'BadgeCharacter' });
// A badge can belong to many users
Badge.belongsToMany(models.User, { through: 'BadgeUser' });
}
}
Badge.init({
name: DataTypes.STRING,
description: DataTypes.STRING,
image: DataTypes.STRING
}, {
sequelize,
modelName: 'Badge',
});
return Badge;
};