|
| 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