userHasPermission method
Check if a user has a permission
userId The ID of the user to check the permission for
role The role to check the permission for
permissions The permissions to check for
Implementation
Future<SuccessResponse> userHasPermission({
String? userId,
String? role,
required List<Map<String, dynamic>> permissions,
}) async {
assert(userId != null || role != null, "Either userId or role must be provided");
try {
final response = await super.dio.post(
"/admin/user-has-permission",
data: {
"userId": userId,
"role": role,
"permissions": permissions,
}..removeWhere((key, value) => value == null),
options: await super.getOptions(isTokenRequired: true),
);
return SuccessResponse.fromJson(response.data);
} catch (e) {
final message = getErrorMessage(e);
if (message == null) rethrow;
throw message;
}
}