2023-03-04 01:34:42 +01:00
|
|
|
const { Model, DataTypes } = require('sequelize');
|
|
|
|
const { sequelize } = require('.');
|
|
|
|
|
|
|
|
class Permission extends Model {
|
2023-03-09 14:26:00 +01:00
|
|
|
static async getAllForUser(user) {
|
|
|
|
return await this.findAll({where: {user}});
|
2023-03-05 10:01:03 +01:00
|
|
|
}
|
2023-03-04 01:34:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Permission.structure = {
|
2023-03-05 10:01:03 +01:00
|
|
|
id: {
|
|
|
|
type: DataTypes.BIGINT,
|
|
|
|
primaryKey: true,
|
|
|
|
autoIncrement: true,
|
|
|
|
allowNull: false
|
|
|
|
},
|
2023-03-04 01:34:42 +01:00
|
|
|
user: {
|
|
|
|
type: DataTypes.BIGINT,
|
|
|
|
allowNull: false
|
|
|
|
},
|
2023-03-09 14:26:00 +01:00
|
|
|
perms: {
|
|
|
|
type: DataTypes.JSONB,
|
2023-03-04 01:34:42 +01:00
|
|
|
allowNull: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let init = (sequelize, DataTypes) => {
|
|
|
|
let perm = Permission.init(Permission.structure, {
|
|
|
|
sequelize,
|
|
|
|
modelName: 'Permission',
|
|
|
|
tableName: 'permissions'
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
init.class = Permission;
|
|
|
|
module.exports = init;
|