diff --git a/src/main/java/net/frozenorb/apiv3/auditLog/AuditLogActionType.java b/src/main/java/net/frozenorb/apiv3/auditLog/AuditLogActionType.java index 8a19032..f6023d1 100644 --- a/src/main/java/net/frozenorb/apiv3/auditLog/AuditLogActionType.java +++ b/src/main/java/net/frozenorb/apiv3/auditLog/AuditLogActionType.java @@ -3,6 +3,9 @@ package net.frozenorb.apiv3.auditLog; import com.mongodb.async.SingleResultCallback; import lombok.Getter; import net.frozenorb.apiv3.model.AuditLogEntry; +import net.frozenorb.apiv3.model.Punishment; + +import java.time.Instant; public enum AuditLogActionType { @@ -26,7 +29,28 @@ public enum AuditLogActionType { NOTIFICATION_TEMPLATE_CREATE(false), NOTIFICATION_TEMPLATE_UPDATE(false), NOTIFICATION_TEMPLATE_DELETE(false), - PUNISHMENT_CREATE(false), + PUNISHMENT_CREATE(true) { + + @Override + public void reverse(AuditLogEntry entry, SingleResultCallback callback) { + String punishmentId = (String) entry.getMetadata().get("punishmentId"); + + Punishment.findById(punishmentId, (punishment, error) -> { + if (error != null) { + callback.onResult(null, error); + return; + } + + if (punishment == null || !punishment.isActive()) { + callback.onResult(null, null); + return; + } + + punishment.delete(null, "Removed via audit log reversal at " + Instant.now().toString() + ".", callback); + }); + } + + }, PUNISHMENT_UPDATE(false), PUNISHMENT_DELETE(false), RANK_CREATE(false),