File size: 1,003 Bytes
236cef4
 
 
 
 
 
 
1f6a8f9
6f05a9e
2f7395b
 
236cef4
fce755d
236cef4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
faf94f6
236cef4
 
 
 
 
 
 
e30c136
 
236cef4
 
 
2f7395b
 
6f05a9e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {
  DataTypes,
  Model,
  InferAttributes,
  InferCreationAttributes,
  CreationOptional,
} from 'sequelize';
import { sequelize } from './index'; 
import { RoleInterface } from '../shared/interfaces/role.interface';
import Permission from './permissions';
import RolePermission from './rolePermissions';

class Role extends Model<InferAttributes<Role>, InferCreationAttributes<Role>> implements RoleInterface {
  declare id: CreationOptional<number>;
  declare name: string;

}

Role.init(
  {
    id: {
      type: DataTypes.INTEGER.UNSIGNED,
      autoIncrement: true,
      primaryKey: true,
      unique: true,
    },

    name: {
      type: DataTypes.STRING,
      allowNull: false,
    }
  },
  {
    sequelize,
    tableName: 'roles', 
    underscored: true,     
    freezeTableName: true, 
    timestamps: true, 
    createdAt: 'created_at',
    updatedAt: 'updated_at',
  }
);

Role.belongsToMany(Permission, { through: 'role_permission', as : 'permissions' });

export default Role;