FIX: createRole, updateRole, and deleteRole logics
This commit is contained in:
@@ -6,7 +6,7 @@ module.exports.getAllRoles = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.createRole = async (data) => {
|
module.exports.createRole = async (data) => {
|
||||||
return Role.create(data, null)
|
return await Role.create(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getRole = async (roleId) => {
|
module.exports.getRole = async (roleId) => {
|
||||||
@@ -20,7 +20,7 @@ module.exports.getRole = async (roleId) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.updateRole = async (roleId, data) => {
|
module.exports.updateRole = async (roleId, data) => {
|
||||||
const role = await Role.findOneAndUpdate({ _id: roleId},data, null)
|
const role = await Role.findOneAndUpdate({ _id: roleId }, data, { new: true })
|
||||||
|
|
||||||
if (!role) {
|
if (!role) {
|
||||||
throw new AppError('NoRoleFound', 404, {})
|
throw new AppError('NoRoleFound', 404, {})
|
||||||
@@ -30,7 +30,7 @@ module.exports.updateRole = async (roleId, data) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.deleteRole = async (roleId) => {
|
module.exports.deleteRole = async (roleId) => {
|
||||||
const role = await Role.findByIdAndUpdate(roleId, { isActive: false }, null)
|
const role = await Role.findByIdAndUpdate(roleId, { isActive: false }, { new: true })
|
||||||
|
|
||||||
if (!role) {
|
if (!role) {
|
||||||
throw new AppError('NoRoleFound', 404, {})
|
throw new AppError('NoRoleFound', 404, {})
|
||||||
|
|||||||
Reference in New Issue
Block a user