Models/User: Add instance method to get counted cards with chartcers
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
const {
|
const {
|
||||||
Model
|
Model
|
||||||
} = require('sequelize');
|
} = require('sequelize');
|
||||||
|
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
class User extends Model {
|
class User extends Model {
|
||||||
/**
|
/**
|
||||||
@@ -13,6 +14,18 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
// define association here
|
// define association here
|
||||||
User.hasMany(models.Card);
|
User.hasMany(models.Card);
|
||||||
}
|
}
|
||||||
|
//instance methods
|
||||||
|
async getCardsWithCharactersCounted() {
|
||||||
|
let cards = await sequelize.models.Card.findAndCountAll({
|
||||||
|
where: {
|
||||||
|
userId: this.id
|
||||||
|
},
|
||||||
|
include: [{
|
||||||
|
model: sequelize.models.Character,
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
return cards;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
User.init({
|
User.init({
|
||||||
discordId: DataTypes.BIGINT,
|
discordId: DataTypes.BIGINT,
|
||||||
|
|||||||
Reference in New Issue
Block a user