Skip to content

Commit 5ce4a71

Browse files
authored
Merge pull request #887 from ELEVATE-Project/develop
Develop to staging
2 parents e798654 + 4c2152e commit 5ce4a71

2 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict'
2+
3+
/** @type {import('sequelize-cli').Migration} */
4+
module.exports = {
5+
async up(queryInterface, Sequelize) {
6+
try {
7+
const permissionsData = [
8+
{
9+
code: 'entity_lists_permissions',
10+
module: 'entity',
11+
request_type: ['POST'],
12+
api_path: '/mentoring/v1/entity/list',
13+
status: 'ACTIVE',
14+
created_at: new Date(),
15+
updated_at: new Date(),
16+
},
17+
]
18+
await queryInterface.bulkInsert('permissions', permissionsData)
19+
} catch (error) {
20+
console.log(error)
21+
}
22+
},
23+
24+
down: async (queryInterface, Sequelize) => {
25+
await queryInterface.bulkDelete('permissions', null, {})
26+
},
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict'
2+
3+
require('module-alias/register')
4+
const userRequests = require('@requests/user')
5+
require('dotenv').config()
6+
const common = require('@constants/common')
7+
const Permissions = require('@database/models/index').Permission
8+
9+
const getPermissionId = async (module, request_type, api_path) => {
10+
try {
11+
const permission = await Permissions.findOne({
12+
where: { module, request_type, api_path },
13+
})
14+
if (!permission) {
15+
throw error
16+
}
17+
return permission.id
18+
} catch (error) {
19+
throw error
20+
}
21+
}
22+
23+
module.exports = {
24+
async up(queryInterface, Sequelize) {
25+
try {
26+
const rolePermissionsData = [
27+
{
28+
role_title: common.MENTEE_ROLE,
29+
permission_id: await getPermissionId('entity', ['POST'], '/mentoring/v1/entity/list'),
30+
module: 'entity',
31+
request_type: ['POST'],
32+
api_path: '/mentoring/v1/entity/list',
33+
created_at: new Date(),
34+
updated_at: new Date(),
35+
created_by: 0,
36+
},
37+
{
38+
role_title: common.MENTOR_ROLE,
39+
permission_id: await getPermissionId('entity', ['POST'], '/mentoring/v1/entity/list'),
40+
module: 'entity',
41+
request_type: ['POST'],
42+
api_path: '/mentoring/v1/entity/list',
43+
created_at: new Date(),
44+
updated_at: new Date(),
45+
created_by: 0,
46+
},
47+
{
48+
role_title: common.SESSION_MANAGER_ROLE,
49+
permission_id: await getPermissionId('entity', ['POST'], '/mentoring/v1/entity/list'),
50+
module: 'entity',
51+
request_type: ['POST'],
52+
api_path: '/mentoring/v1/entity/list',
53+
created_at: new Date(),
54+
updated_at: new Date(),
55+
created_by: 0,
56+
},
57+
]
58+
await queryInterface.bulkInsert('role_permission_mapping', rolePermissionsData)
59+
} catch (error) {
60+
console.error(error)
61+
}
62+
},
63+
64+
down: async (queryInterface, Sequelize) => {
65+
await queryInterface.bulkDelete('role_permission_mapping', null, {})
66+
},
67+
}

0 commit comments

Comments
 (0)