diff --git a/apps/api/src/controllers/record/records-controller.ts b/apps/api/src/controllers/record/records-controller.ts index 95c967ab7..6b6e10b9b 100644 --- a/apps/api/src/controllers/record/records-controller.ts +++ b/apps/api/src/controllers/record/records-controller.ts @@ -50,6 +50,7 @@ import { citizenInclude } from "../citizen/CitizenController"; import { generateCallsign } from "@snailycad/utils"; import { Descendant, slateDataToString } from "@snailycad/utils/editor"; import puppeteer from "puppeteer"; +import { AuditLogActionType, createAuditLogEntry } from "@snailycad/audit-logger/server"; export const assignedOfficersInclude = { combinedUnit: { include: combinedUnitProperties }, @@ -387,13 +388,14 @@ export class RecordsController { @UseBefore(ActiveOfficer) @Delete("/:id") - @Description("Delete a ticket, written warning or arrest report by its id") + @Description("Delete a warrant, ticket, written warning or arrest report by its id") @UsePermissions({ permissions: [Permissions.Leo], }) async deleteRecord( @PathParams("id") id: string, @BodyParams("type") type: "WARRANT" | (string & {}), + @Context("sessionUserId") sessionUserId: string, ): Promise { if (type === "WARRANT") { const warrant = await prisma.warrant.findUnique({ @@ -420,6 +422,20 @@ export class RecordsController { where: { id }, }); + const auditLogType = + type === "WARRANT" + ? AuditLogActionType.CitizenWarrantRemove + : AuditLogActionType.CitizenRecordRemove; + + await createAuditLogEntry({ + prisma, + executorId: sessionUserId, + action: { + type: auditLogType, + new: id, + }, + }); + return true; } diff --git a/packages/audit-logger/src/types/action-types.ts b/packages/audit-logger/src/types/action-types.ts index f8ab09643..d9205ba58 100644 --- a/packages/audit-logger/src/types/action-types.ts +++ b/packages/audit-logger/src/types/action-types.ts @@ -28,6 +28,8 @@ export enum AuditLogActionType { UnitQualificationRemove = "UnitQualificationRemove", UnitDepartmentDeclined = "UnitDepartmentDeclined", UnitDepartmentAccepted = "UnitDepartmentAccepted", + CitizenRecordRemove = "CitizenRecordRemove", + CitizenWarrantRemove = "CitizenWarrantRemove", BusinessUpdate = "BusinessUpdate", BusinessDelete = "BusinessDelete", diff --git a/packages/audit-logger/src/types/actions.ts b/packages/audit-logger/src/types/actions.ts index bfa0fcb05..8c32bc651 100644 --- a/packages/audit-logger/src/types/actions.ts +++ b/packages/audit-logger/src/types/actions.ts @@ -60,7 +60,9 @@ export type AuditLogActions = | LeoIncidentsPurged | EmsIncidentsPurged | Signal100Toggled - | Call911Create; + | Call911Create + | CitizenRecordRemove + | CitizenWarrantRemove; type BaseAuditLogAction = { type: ActionType; @@ -339,3 +341,13 @@ export type Call911Create = BaseAuditLogAction< undefined, Types.Call911 >; +export type CitizenRecordRemove = BaseAuditLogAction< + AuditLogActionType.CitizenRecordRemove, + undefined, + string +>; +export type CitizenWarrantRemove = BaseAuditLogAction< + AuditLogActionType.CitizenWarrantRemove, + undefined, + string +>;