From a9acd8d1b1eade2582fe3f02cd8da785165e6aee Mon Sep 17 00:00:00 2001 From: Casper <53900565+Dev-CasperTheGhost@users.noreply.github.com> Date: Sat, 2 Apr 2022 16:06:22 +0200 Subject: [PATCH] :tada: feat: add /:id for incidents & calls (#572) --- .../dispatch/911-calls/Calls911Controller.ts | 18 +++++++++++++++++- .../leo/incidents/IncidentController.ts | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/api/src/controllers/dispatch/911-calls/Calls911Controller.ts b/packages/api/src/controllers/dispatch/911-calls/Calls911Controller.ts index 3b643a87f..278fd0b4c 100644 --- a/packages/api/src/controllers/dispatch/911-calls/Calls911Controller.ts +++ b/packages/api/src/controllers/dispatch/911-calls/Calls911Controller.ts @@ -1,5 +1,5 @@ import { Controller } from "@tsed/di"; -import { Delete, Get, Post, Put } from "@tsed/schema"; +import { Delete, Description, Get, Post, Put } from "@tsed/schema"; import { CREATE_911_CALL, LINK_INCIDENT_TO_CALL } from "@snailycad/schemas"; import { HeaderParams, BodyParams, Context, PathParams, QueryParams } from "@tsed/platform-params"; import { BadRequest, NotFound } from "@tsed/exceptions"; @@ -59,6 +59,7 @@ export class Calls911Controller { } @Get("/") + @Description("Get all 911 calls") async get911Calls(@QueryParams("includeEnded") includeEnded: boolean) { const calls = await prisma.call911.findMany({ include: callInclude, @@ -71,6 +72,21 @@ export class Calls911Controller { return calls.map(this.officerOrDeputyToUnit); } + @Get("/:id") + @Description("Get an incident by its id") + @UsePermissions({ + permissions: [Permissions.ViewIncidents, Permissions.ManageIncidents], + fallback: (u) => u.isDispatch || u.isLeo, + }) + async getIncidentById(@PathParams("id") id: string) { + const call = await prisma.call911.findUnique({ + where: { id }, + include: callInclude, + }); + + return this.officerOrDeputyToUnit(call); + } + @Post("/") async create911Call( @BodyParams() body: unknown, diff --git a/packages/api/src/controllers/leo/incidents/IncidentController.ts b/packages/api/src/controllers/leo/incidents/IncidentController.ts index 61542b695..51d502b63 100644 --- a/packages/api/src/controllers/leo/incidents/IncidentController.ts +++ b/packages/api/src/controllers/leo/incidents/IncidentController.ts @@ -47,6 +47,21 @@ export class IncidentController { return { incidents, officers }; } + @Get("/:id") + @Description("Get an incident by its id") + @UsePermissions({ + permissions: [Permissions.ViewIncidents, Permissions.ManageIncidents], + fallback: (u) => u.isDispatch || u.isLeo, + }) + async getIncidentById(@PathParams("id") id: string) { + const incident = await prisma.leoIncident.findUnique({ + where: { id }, + include: incidentInclude, + }); + + return incident; + } + @UseBefore(ActiveOfficer) @Post("/") @UsePermissions({