Skip to content

Commit 160b807

Browse files
authored
Merge pull request #287 from adithyadinesh0412/develop-2.6
User Role model change - Katha 1050
2 parents 4586051 + 8cee478 commit 160b807

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/constants/common.js

+1
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,5 @@ module.exports = {
115115
NO_OF_ATTEMPTS: 3,
116116
materializedViewsPrefix: 'm_',
117117
DELETED_STATUS: 'DELETED',
118+
DEFAULT_ORG_VISIBILITY: 'PUBLIC',
118119
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
/** @type {import('sequelize-cli').Migration} */
3+
module.exports = {
4+
async up(queryInterface, Sequelize) {
5+
const defaultOrgId = queryInterface.sequelize.options.defaultOrgId
6+
await queryInterface.addColumn('user_roles', 'visiblity', {
7+
type: Sequelize.STRING,
8+
allowNull: false,
9+
defaultValue: 'PUBLIC',
10+
})
11+
await queryInterface.addColumn('user_roles', 'organization_id', {
12+
type: Sequelize.STRING,
13+
allowNull: false,
14+
defaultValue: defaultOrgId,
15+
})
16+
},
17+
18+
async down(queryInterface, Sequelize) {
19+
await queryInterface.removeColumn('user_roles', 'visiblity')
20+
await queryInterface.removeColumn('user_roles', 'organization_id')
21+
},
22+
}

src/database/models/userRole.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict'
2+
const common = require('@constants/common')
23
module.exports = (sequelize, DataTypes) => {
34
const UserRole = sequelize.define(
45
'UserRole',
@@ -20,7 +21,15 @@ module.exports = (sequelize, DataTypes) => {
2021
},
2122
status: {
2223
type: DataTypes.STRING,
23-
defaultValue: 'ACTIVE',
24+
defaultValue: common.ACTIVE_STATUS,
25+
},
26+
visiblity: {
27+
type: DataTypes.STRING,
28+
defaultValue: common.DEFAULT_ORG_VISIBILITY,
29+
},
30+
organization_id: {
31+
type: DataTypes.INTEGER,
32+
allowNull: false,
2433
},
2534
},
2635
{ sequelize, modelName: 'UserRole', tableName: 'user_roles', freezeTableName: true, paranoid: true }

src/database/seeders/20230718130102-add_roles_to_roles_table.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
up: async (queryInterface, Sequelize) => {
33
let rolesData = []
4+
const defaultOrgId = queryInterface.sequelize.options.defaultOrgId
45
const roleArray = ['user', 'mentor', 'mentee', 'admin']
56
//user_type denotes the role is system user or not 1: system user, 0: non system user
67
roleArray.forEach(async function (role) {
@@ -12,6 +13,8 @@ module.exports = {
1213
let eachRow = {
1314
title: role,
1415
user_type: user_type,
16+
visiblity: 'PUBLIC',
17+
organization_id: defaultOrgId,
1518
updated_at: new Date(),
1619
created_at: new Date(),
1720
}

0 commit comments

Comments
 (0)