mirror of
https://github.com/sasjs/server.git
synced 2026-01-11 16:20:06 +00:00
feat: add api endpoint for deleting permission
This commit is contained in:
@@ -113,9 +113,9 @@ export class PermissionController {
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Update permission setting.
|
||||
* @summary Update permission setting. Admin only
|
||||
* @param permissionId The permission's identifier
|
||||
* @example userId "1234"
|
||||
* @example permissionId 1234
|
||||
*/
|
||||
@Example<PermissionDetailsResponse>({
|
||||
permissionId: 123,
|
||||
@@ -130,6 +130,16 @@ export class PermissionController {
|
||||
): Promise<PermissionDetailsResponse> {
|
||||
return updatePermission(permissionId, body)
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Delete a permission. Admin only.
|
||||
* @param permissionId The user's identifier
|
||||
* @example permissionId 1234
|
||||
*/
|
||||
@Delete('{permissionId}')
|
||||
public async deletePermission(@Path() permissionId: number) {
|
||||
return deletePermission(permissionId)
|
||||
}
|
||||
}
|
||||
|
||||
const getAllPermissions = async (): Promise<PermissionDetailsResponse[]> =>
|
||||
@@ -233,3 +243,9 @@ const updatePermission = async (
|
||||
|
||||
return updatedPermission
|
||||
}
|
||||
|
||||
const deletePermission = async (id: number) => {
|
||||
const permission = await Permission.findOne({ id })
|
||||
if (!permission) throw new Error('Permission is not found.')
|
||||
await Permission.deleteOne({ id })
|
||||
}
|
||||
|
||||
@@ -53,4 +53,20 @@ permissionRouter.patch(
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
permissionRouter.delete(
|
||||
'/:permissionId',
|
||||
authenticateAccessToken,
|
||||
verifyAdmin,
|
||||
async (req: any, res) => {
|
||||
const { permissionId } = req.params
|
||||
|
||||
try {
|
||||
await controller.deletePermission(permissionId)
|
||||
res.status(200).send('Permission Deleted!')
|
||||
} catch (err: any) {
|
||||
res.status(403).send(err.toString())
|
||||
}
|
||||
}
|
||||
)
|
||||
export default permissionRouter
|
||||
|
||||
Reference in New Issue
Block a user