Init commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
const Role = require('./roleModel')
|
||||
const AppError = require('../../globalErrorHandler/AppError')
|
||||
|
||||
module.exports.getAllRoles = async () => {
|
||||
return Role.find({}, null, null)
|
||||
}
|
||||
|
||||
module.exports.createRole = async (data) => {
|
||||
return Role.create(data, null)
|
||||
}
|
||||
|
||||
module.exports.getRole = async (roleId) => {
|
||||
const role = await Role.findById(roleId)
|
||||
|
||||
if (!role) {
|
||||
throw new AppError('NoRoleFound', 404, {})
|
||||
}
|
||||
|
||||
return role
|
||||
}
|
||||
|
||||
module.exports.updateRole = async (roleId, data) => {
|
||||
const role = await Role.findOneAndUpdate({ _id: roleId},data, null)
|
||||
|
||||
if (!role) {
|
||||
throw new AppError('NoRoleFound', 404, {})
|
||||
}
|
||||
|
||||
return role
|
||||
}
|
||||
|
||||
module.exports.deleteRole = async (roleId) => {
|
||||
const role = await Role.findByIdAndUpdate(roleId, { isActive: false }, null)
|
||||
|
||||
if (!role) {
|
||||
throw new AppError('NoRoleFound', 404, {})
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user