@kipicore/dbcore 1.1.457 → 1.1.459

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export function up(queryInterface: any, Sequelize: any): Promise<void>;
2
+ export function down(queryInterface: any): Promise<void>;
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+ const up = async (queryInterface, Sequelize) => {
3
+ const table = await queryInterface.describeTable('permissions');
4
+ if (!table.user_types) {
5
+ await queryInterface.addColumn('permissions', 'user_types', {
6
+ type: Sequelize.ARRAY(Sequelize.STRING),
7
+ allowNull: true,
8
+ field: 'user_types',
9
+ });
10
+ }
11
+ };
12
+ const down = async (queryInterface) => {
13
+ const table = await queryInterface.describeTable('permissions');
14
+ // Remove only if column exists
15
+ if (table.user_types) {
16
+ await queryInterface.removeColumn('permissions', 'user_types');
17
+ }
18
+ };
19
+ module.exports = {
20
+ up,
21
+ down,
22
+ };
@@ -1,4 +1,4 @@
1
- import { APP_TYPE, PERMISSION_TYPE } from '../constants/app';
1
+ import { APP_TYPE, PERMISSION_TYPE, USER_TYPES } from '../constants/app';
2
2
  import { IDefaultAttributes } from './commonInterface';
3
3
  export interface IPermissionAttributes extends IDefaultAttributes {
4
4
  id: string;
@@ -8,4 +8,5 @@ export interface IPermissionAttributes extends IDefaultAttributes {
8
8
  permissionId: string;
9
9
  code: string;
10
10
  appType: APP_TYPE;
11
+ userTypes: USER_TYPES[];
11
12
  }
@@ -1,5 +1,5 @@
1
1
  import { Model } from 'sequelize';
2
- import { PERMISSION_TYPE } from '../../constants/app';
2
+ import { PERMISSION_TYPE, USER_TYPES } from '../../constants/app';
3
3
  import { IPermissionAttributes } from '../../interfaces';
4
4
  import { TPermissionCreationAttributes } from '../../types';
5
5
  declare class PermissionModel extends Model<IPermissionAttributes, TPermissionCreationAttributes> {
@@ -10,6 +10,7 @@ declare class PermissionModel extends Model<IPermissionAttributes, TPermissionCr
10
10
  permissionId: string;
11
11
  code: string;
12
12
  appType: string;
13
+ userTypes: USER_TYPES[];
13
14
  createdBy: string;
14
15
  updatedBy: string;
15
16
  deletedBy: string;
@@ -66,6 +66,10 @@ PermissionModel.init({
66
66
  code: {
67
67
  type: sequelize_1.DataTypes.STRING,
68
68
  },
69
+ userTypes: {
70
+ type: sequelize_1.DataTypes.ARRAY(sequelize_1.DataTypes.STRING),
71
+ defaultValue: [],
72
+ },
69
73
  }, {
70
74
  modelName: 'PermissionModel',
71
75
  tableName: 'permissions',
@@ -4,7 +4,7 @@ const sequelize_1 = require("sequelize");
4
4
  const index_1 = require("./index");
5
5
  class Permission extends sequelize_1.Model {
6
6
  static associate(models) {
7
- const { UserModel, InstituteModel, AcademicCalendarModel } = models;
7
+ const { UserModel, InstituteModel, AcademicCalendarModel, RoleManagementModel } = models;
8
8
  Permission.belongsTo(UserModel, {
9
9
  foreignKey: {
10
10
  name: 'createdBy',
@@ -57,6 +57,34 @@ class Permission extends sequelize_1.Model {
57
57
  },
58
58
  as: 'acaCalPermission',
59
59
  });
60
+ Permission.belongsTo(UserModel, {
61
+ foreignKey: {
62
+ name: 'userId',
63
+ field: 'user_id',
64
+ },
65
+ as: 'permissionUser',
66
+ });
67
+ UserModel.hasMany(Permission, {
68
+ foreignKey: {
69
+ name: 'userId',
70
+ field: 'user_id',
71
+ },
72
+ as: 'userPermission',
73
+ });
74
+ Permission.belongsTo(RoleManagementModel, {
75
+ foreignKey: {
76
+ name: 'roleId',
77
+ field: 'role_id',
78
+ },
79
+ as: 'userRole',
80
+ });
81
+ RoleManagementModel.hasMany(Permission, {
82
+ foreignKey: {
83
+ name: 'roleId',
84
+ field: 'role_id',
85
+ },
86
+ as: 'roleUser',
87
+ });
60
88
  }
61
89
  }
62
90
  Permission.init({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kipicore/dbcore",
3
- "version": "1.1.457",
3
+ "version": "1.1.459",
4
4
  "description": "Reusable DB core package with Postgres, MongoDB, models, services, interfaces, and types",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",