feat: add env-based super admin authentication and complete role & permission system
deploy-chabokan / deploy (push) Canceled after 0s

This commit is contained in:
2026-08-18 00:08:04 +03:30
parent 86655f2b69
commit 2b94fdb034
11 changed files with 814 additions and 64 deletions
+5 -4
View File
@@ -2,15 +2,16 @@ const Role = require('./roleModel')
const AppError = require('../../globalErrorHandler/AppError')
module.exports.getAllRoles = async () => {
return Role.find({}, null, null)
return Role.find({}).populate('permissions').sort({ createdAt: -1 })
}
module.exports.createRole = async (data) => {
return await Role.create(data)
const role = await Role.create(data)
return Role.findById(role._id).populate('permissions')
}
module.exports.getRole = async (roleId) => {
const role = await Role.findById(roleId)
const role = await Role.findById(roleId).populate('permissions')
if (!role) {
throw new AppError('NoRoleFound', 404, {})
@@ -20,7 +21,7 @@ module.exports.getRole = async (roleId) => {
}
module.exports.updateRole = async (roleId, data) => {
const role = await Role.findOneAndUpdate({ _id: roleId }, data, { new: true })
const role = await Role.findOneAndUpdate({ _id: roleId }, data, { new: true }).populate('permissions')
if (!role) {
throw new AppError('NoRoleFound', 404, {})