Skip to content

Commit

Permalink
feat(audit-logs): citizen record/warrant remove (closes #1806)
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Sep 27, 2023
1 parent ca20de2 commit 5c118f9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
18 changes: 17 additions & 1 deletion apps/api/src/controllers/record/records-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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<APITypes.DeleteRecordsByIdData> {
if (type === "WARRANT") {
const warrant = await prisma.warrant.findUnique({
Expand All @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/audit-logger/src/types/action-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export enum AuditLogActionType {
UnitQualificationRemove = "UnitQualificationRemove",
UnitDepartmentDeclined = "UnitDepartmentDeclined",
UnitDepartmentAccepted = "UnitDepartmentAccepted",
CitizenRecordRemove = "CitizenRecordRemove",
CitizenWarrantRemove = "CitizenWarrantRemove",

BusinessUpdate = "BusinessUpdate",
BusinessDelete = "BusinessDelete",
Expand Down
14 changes: 13 additions & 1 deletion packages/audit-logger/src/types/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export type AuditLogActions =
| LeoIncidentsPurged
| EmsIncidentsPurged
| Signal100Toggled
| Call911Create;
| Call911Create
| CitizenRecordRemove
| CitizenWarrantRemove;

type BaseAuditLogAction<ActionType extends AuditLogActionType, Previous, New> = {
type: ActionType;
Expand Down Expand Up @@ -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
>;

0 comments on commit 5c118f9

Please sign in to comment.