Init commit

This commit is contained in:
2024-12-22 16:52:30 +03:30
parent 28ab698dfc
commit aeb38982ca
28 changed files with 1532 additions and 68 deletions
+40
View File
@@ -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
}