Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 62 additions & 34 deletions src/controllers/v1/user-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,80 +10,99 @@ const roleService = require('@services/user-role')

module.exports = class userRole {
/**
* Create roles.
* Create a new role.
* @method
* @name create
* @param {Object} req - Request data.
* @param {Object} req.body - Request body contains role creation details.
* @param {Object} req - Request object.
* @param {Object} req.body - Request body containing role details.
* @param {String} req.body.title - Title of the role.
* @param {Integer} req.body.userType - User type of the role.
* @param {Number} req.body.userType - User type for the role.
* @param {String} req.body.status - Role status.
* @param {String} req.body.visibility - Visibility of the role.
* @param {String} req.body.translations - Translation for roles.
* @param {Integer} req.body.organization_id - Organization ID for the role.
* @returns {JSON} - Response contains role creation details.
* @param {String} req.body.visibility - Role visibility.
* @param {String} req.body.translations - Role translations.
* @param {Number} req.body.organization_id - Organization ID.
* @param {Object} req.decodedToken - Authenticated user token.
* @returns {Object} - Created role details.
*/

async create(req) {
try {
const createRole = await roleService.create(req.body, req.decodedToken.organization_id)
const createRole = await roleService.create(
req.body,
req.decodedToken.organization_id,
req.decodedToken.tenant_code
)
return createRole
} catch (error) {
return error
}
}

/**
* Update roles.
* Update a role.
* @method
* @name update
* @param {Object} req - Request data.
* @param {Object} req.body - Request body contains role update details.
* @param {Object} req - Request object.
* @param {Object} req.body - Request body containing updated role details.
* @param {String} req.body.title - Title of the role.
* @param {Integer} req.body.userType - User type of the role.
* @param {Number} req.body.userType - User type for the role.
* @param {String} req.body.status - Role status.
* @param {String} req.body.visibility - Visibility of the role.
* @param {String} req.body.translations - Translation for roles.
* @param {Integer} req.body.organization_id - Organization ID for the role.
* @returns {JSON} - Response contains role update details.
* @param {String} req.body.visibility - Role visibility.
* @param {String} req.body.translations - Role translations.
* @param {Number} req.body.organization_id - Organization ID.
* @param {String} req.params.id - Role ID to be updated.
* @param {Object} req.decodedToken - Authenticated user token.
* @returns {Object} - Updated role details.
*/

async update(req) {
try {
const updateRole = await roleService.update(req.params.id, req.body, req.decodedToken.organization_id)
const updateRole = await roleService.update(
req.params.id,
req.body,
req.decodedToken.organization_id,
req.decodedToken.tenant_code
)
return updateRole
} catch (error) {
return error
}
}

/**
* Delete role.
* Delete a role.
* @method
* @name delete
* @param {Object} req - Request data.
* @returns {JSON} - Role deletion response.
* @param {Object} req - Request object.
* @param {String} req.params.id - Role ID to be deleted.
* @param {Object} req.decodedToken - Authenticated user token.
* @returns {Object} - Deletion response.
*/

async delete(req) {
try {
return await roleService.delete(req.params.id, req.decodedToken.organization_id)
return await roleService.delete(
req.params.id,
req.decodedToken.organization_id,
req.decodedToken.tenant_code
)
} catch (error) {
return error
}
}

/**
* Get all available roles.
* Get a paginated list of roles with optional filters and search.
* @method
* @name defaultlist
* @param {Array(String)} req.body.filters - Filters.
* @name list
* @param {Object} req - Request object.
* @param {Object} req.query - Query parameters.
* @param {Array<String>} [req.query.filters] - Filters.
* @param {String} [req.query.language] - Language code.
* @param {String} req.pageNo - Page number.
* @param {String} req.pageSize - Page size limit.
* @param {String} req.searchText - Search text.
* @param {Integer} req.decodedToken.organization_id - user organization_id.
* @query {String} req.query.language - Language Code
* @returns {JSON} - Role list.
* @param {Object} req.decodedToken - Authenticated user token.
* @returns {Object} - List of roles.
*/
async list(req) {
try {
Expand All @@ -94,7 +113,7 @@ module.exports = class userRole {
req.searchText,
req.decodedToken.organization_id,
req.decodedToken.tenant_code,
req.query.language ? req.query.language : ''
req.query.language || ''
)
return roleList
} catch (error) {
Expand All @@ -103,21 +122,30 @@ module.exports = class userRole {
}

/**
* Get all available roles.
* @deprecated
* This method is deprecated. Use `list()` instead.
* @method
* @name default
* @param {Array(String)} req.body.filters - Filters.
* @param {Object} req - Request object.
* @param {Array<String>} req.body.filters - Filters.
* @param {String} req.pageNo - Page number.
* @param {String} req.pageSize - Page size limit.
* @param {String} req.searchText - Search text.
* @returns {JSON} - Role list.
* @returns {Object} - List of roles.
*/
/*
async default(req) {
try {
const defaultRoleList = await roleService.defaultList(req.query, req.pageNo, req.pageSize, req.searchText)
const defaultRoleList = await roleService.defaultList(
req.query,
req.pageNo,
req.pageSize,
req.searchText
)
return defaultRoleList
} catch (error) {
return error
}
}
*/
}
4 changes: 2 additions & 2 deletions src/database/queries/user-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ exports.findAllRoles = async (filter, attributes, options) => {
}
}

exports.updateRole = async (filter, updatedata) => {
exports.updateRole = async (filter, updateData) => {
try {
return await UserRole.update(updatedata, {
return await UserRole.update(updateData, {
where: filter,
returning: true,
})
Expand Down
15 changes: 8 additions & 7 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@
"ROLE_CHANGE_APPROVED": "Your request for becoming a mentor has been approved. Check email or login again to start your journey.",
"MATERIALIZED_VIEW_GENERATED_SUCCESSFULLY": "Materialized views generated successfully",
"MATERIALIZED_VIEW_REFRESH_INITIATED_SUCCESSFULLY": "Materialized views refresh initiated successfully",
"ROLE_CREATED_SUCCESSFULLY": "Roles added successfully",
"ROLE_UPDATED_SUCCESSFULLY": "Roles updated successfully",
"ROLE_DELETED_SUCCESSFULLY": "Module deleted successfully",
"ROLES_FETCHED_SUCCESSFULLY": "Roles fetched successfully",
"ROLE_NOT_UPDATED": "Roles not updated",
"ROLE_ALREADY_DELETED_OR_ROLE_NOT_PRESENT": "Roles already exists OR Roles not present",
"ROLE_NOT_DELETED": "Roles not deleted",
"ROLE_CREATED_SUCCESSFULLY": "Role created successfully.",
"ROLE_UPDATED_SUCCESSFULLY": "Role updated successfully.",
"ROLE_DELETED_SUCCESSFULLY": "Role deleted successfully.",
"ROLES_FETCHED_SUCCESSFULLY": "Roles fetched successfully.",
"ROLE_IS_NOT_UNIQUE": "A role with this title already exists. Please choose a different title.",
"ROLE_NOT_UPDATED": "Role could not be updated.",
"ROLE_ALREADY_DELETED_OR_ROLE_NOT_PRESENT": "The role has already been deleted or does not exist.",
"ROLE_NOT_DELETED": "Role could not be deleted.",
"ROLES_HAS_EMPTY_LIST": "Empty roles list",
"COLUMN_DOES_NOT_EXISTS": "Role column does not exists",
"PERMISSION_DENIED": "You do not have the required permissions to access this resource. Please contact your administrator for assistance.",
Expand Down
Loading