diff --git a/src/constants/common.js b/src/constants/common.js index 2b8ecf34c..58341b1b4 100644 --- a/src/constants/common.js +++ b/src/constants/common.js @@ -115,4 +115,5 @@ module.exports = { NO_OF_ATTEMPTS: 3, materializedViewsPrefix: 'm_', DELETED_STATUS: 'DELETED', + DEFAULT_ORG_VISIBILITY: 'PUBLIC', } diff --git a/src/database/migrations/20231211061329-user-roles-visibility-orgId.js b/src/database/migrations/20231211061329-user-roles-visibility-orgId.js new file mode 100644 index 000000000..a6c69b697 --- /dev/null +++ b/src/database/migrations/20231211061329-user-roles-visibility-orgId.js @@ -0,0 +1,22 @@ +'use strict' +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + const defaultOrgId = queryInterface.sequelize.options.defaultOrgId + await queryInterface.addColumn('user_roles', 'visiblity', { + type: Sequelize.STRING, + allowNull: false, + defaultValue: 'PUBLIC', + }) + await queryInterface.addColumn('user_roles', 'organization_id', { + type: Sequelize.STRING, + allowNull: false, + defaultValue: defaultOrgId, + }) + }, + + async down(queryInterface, Sequelize) { + await queryInterface.removeColumn('user_roles', 'visiblity') + await queryInterface.removeColumn('user_roles', 'organization_id') + }, +} diff --git a/src/database/models/userRole.js b/src/database/models/userRole.js index 259ac73ab..59514b3d4 100644 --- a/src/database/models/userRole.js +++ b/src/database/models/userRole.js @@ -1,4 +1,5 @@ 'use strict' +const common = require('@constants/common') module.exports = (sequelize, DataTypes) => { const UserRole = sequelize.define( 'UserRole', @@ -20,7 +21,15 @@ module.exports = (sequelize, DataTypes) => { }, status: { type: DataTypes.STRING, - defaultValue: 'ACTIVE', + defaultValue: common.ACTIVE_STATUS, + }, + visiblity: { + type: DataTypes.STRING, + defaultValue: common.DEFAULT_ORG_VISIBILITY, + }, + organization_id: { + type: DataTypes.INTEGER, + allowNull: false, }, }, { sequelize, modelName: 'UserRole', tableName: 'user_roles', freezeTableName: true, paranoid: true } diff --git a/src/database/seeders/20230718130102-add_roles_to_roles_table.js b/src/database/seeders/20230718130102-add_roles_to_roles_table.js index e6cadc6ca..9449c880f 100644 --- a/src/database/seeders/20230718130102-add_roles_to_roles_table.js +++ b/src/database/seeders/20230718130102-add_roles_to_roles_table.js @@ -1,6 +1,7 @@ module.exports = { up: async (queryInterface, Sequelize) => { let rolesData = [] + const defaultOrgId = queryInterface.sequelize.options.defaultOrgId const roleArray = ['user', 'mentor', 'mentee', 'admin'] //user_type denotes the role is system user or not 1: system user, 0: non system user roleArray.forEach(async function (role) { @@ -12,6 +13,8 @@ module.exports = { let eachRow = { title: role, user_type: user_type, + visiblity: 'PUBLIC', + organization_id: defaultOrgId, updated_at: new Date(), created_at: new Date(), }