Skip to content

Commit

Permalink
🎉 add 911 call events
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Oct 24, 2021
1 parent d06271e commit b84c963
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 106 deletions.
26 changes: 13 additions & 13 deletions packages/api/src/controllers/dispatch/Calls911Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class Calls911Controller {

@UseBefore(IsDispatch)
@Delete("/:id")
async end911Call(@PathParams("id") id: string, @BodyParams() body: JsonRequestBody) {
async end911Call(@PathParams("id") id: string) {
const call = await prisma.call911.findUnique({
where: { id },
});
Expand All @@ -180,21 +180,12 @@ export class Calls911Controller {
throw new NotFound("callNotFound");
}

const event = await prisma.call911Event.create({
data: {
call911Id: call.id,
description: body.get("description"),
},
});

// todo: update sockets

return event;
return true;
}

@UseBefore(IsDispatch)
@Post("/events/:callId")
async createCallEvent(@PathParams("callId") callId: string) {
async createCallEvent(@PathParams("callId") callId: string, @BodyParams() body: JsonRequestBody) {
const call = await prisma.call911.findUnique({
where: { id: callId },
});
Expand All @@ -203,6 +194,15 @@ export class Calls911Controller {
throw new NotFound("callNotFound");
}

return true;
const event = await prisma.call911Event.create({
data: {
call911Id: call.id,
description: body.get("description"),
},
});

this.socket.emitAddCallEvent(event);

return event;
}
}
6 changes: 5 additions & 1 deletion packages/api/src/services/SocketService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Nsp, SocketService } from "@tsed/socketio";
import * as SocketIO from "socket.io";
import { SocketEvents } from "@snailycad/config";
import { Call911, TowCall, Bolo } from ".prisma/client";
import { Call911, TowCall, Bolo, Call911Event } from ".prisma/client";

@SocketService("/")
export class Socket {
Expand Down Expand Up @@ -63,4 +63,8 @@ export class Socket {
emitUserBanned(userId: string) {
this.io.sockets.emit(SocketEvents.UserBanned, userId);
}

emitAddCallEvent(event: Call911Event) {
this.io.sockets.emit(SocketEvents.AddCallEvent, event);
}
}
3 changes: 3 additions & 0 deletions packages/client/locales/en/calls.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
"caller": "Caller",
"createTowCall": "Create tow call",
"createTaxiCall": "Create taxi call",
"create911Call": "Create 911 call",
"editTowCall": "Edit tow call",
"assignedUnits": "Assigned Units",
"selectCitizen": "Select citizen",
"endCall": "End Call",
"end911Call": "End 911 Call",
"addEvent": "Add Event",
"noEvents": "This call does not have any events",
"alert_end911Call": "Are you sure you want to end this call?",
"alert_endTowCall": "Are you sure you want to end this call?"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/client/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"decline": "Decline",
"createdAt": "Created At",
"reset": "Reset",
"search": "Search"
"search": "Search",
"events": "Events"
},
"Errors": {
"unknown": "An unexpected error occurred",
Expand Down
40 changes: 28 additions & 12 deletions packages/client/src/components/dispatch/ModalButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,67 @@ import { ModalIds } from "types/ModalIds";
import { useModal } from "context/ModalContext";

interface MButton {
nameKey: string;
nameKey: [string, string];
modalId: string;
}

const buttons: MButton[] = [
{
nameKey: "nameSearch",
nameKey: ["Leo", "nameSearch"],
modalId: ModalIds.NameSearch,
},
{
nameKey: "plateSearch",
nameKey: ["Leo", "plateSearch"],
modalId: ModalIds.VehicleSearch,
},
{
nameKey: "weaponSearch",
nameKey: ["Leo", "weaponSearch"],
modalId: ModalIds.WeaponSearch,
},
{
nameKey: "addressSearch",
modalId: ModalIds.AddressSearch,
nameKey: ["Leo", "createWrittenWarning"],
modalId: ModalIds.CreateWrittenWarning,
},
{
nameKey: "createBolo",
nameKey: ["Leo", "createTicket"],
modalId: ModalIds.CreateTicket,
},
{
nameKey: ["Leo", "createArrestReport"],
modalId: ModalIds.CreateArrestReport,
},
{
nameKey: ["Leo", "createBolo"],
modalId: ModalIds.ManageBolo,
},
{
nameKey: "notepad",
nameKey: ["Calls", "create911Call"],
modalId: ModalIds.Manage911Call,
},
{
nameKey: ["Leo", "notepad"],
modalId: ModalIds.Notepad,
},
{
nameKey: ["Leo", "activeOfficers"],
modalId: ModalIds.ActiveOfficers,
},
];

export const DispatchModalButtons = () => {
const { openModal } = useModal();
const t = useTranslations("Leo");
const t = useTranslations();

return (
<ul className="modal-buttons-grid">
{buttons.map((button, idx) => (
<Button
id={button.nameKey}
id={button.nameKey[1]}
key={idx}
title={button.nameKey}
title={t(button.nameKey.join("."))}
onClick={() => openModal(button.modalId)}
>
{t(button.nameKey)}
{t(button.nameKey.join("."))}
</Button>
))}
</ul>
Expand Down
28 changes: 14 additions & 14 deletions packages/client/src/components/leo/ModalButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,53 @@ import { useModal } from "context/ModalContext";
import { useTranslations } from "use-intl";

interface MButton {
nameKey: string;
nameKey: [string, string];
modalId: string;
}

const buttons: MButton[] = [
{
nameKey: "nameSearch",
nameKey: ["Leo", "nameSearch"],
modalId: ModalIds.NameSearch,
},
{
nameKey: "plateSearch",
nameKey: ["Leo", "plateSearch"],
modalId: ModalIds.VehicleSearch,
},
{
nameKey: "weaponSearch",
nameKey: ["Leo", "weaponSearch"],
modalId: ModalIds.WeaponSearch,
},
{
nameKey: "createWrittenWarning",
nameKey: ["Leo", "createWrittenWarning"],
modalId: ModalIds.CreateWrittenWarning,
},
{
nameKey: "createTicket",
nameKey: ["Leo", "createTicket"],
modalId: ModalIds.CreateTicket,
},
{
nameKey: "createArrestReport",
nameKey: ["Leo", "createArrestReport"],
modalId: ModalIds.CreateArrestReport,
},
{
nameKey: "createBolo",
nameKey: ["Leo", "createBolo"],
modalId: ModalIds.ManageBolo,
},
{
nameKey: "notepad",
nameKey: ["Leo", "notepad"],
modalId: ModalIds.Notepad,
},
{
nameKey: "activeOfficers",
nameKey: ["Leo", "activeOfficers"],
modalId: ModalIds.ActiveOfficers,
},
];

export const ModalButtons = () => {
const { activeOfficer } = useLeoState();
const { openModal } = useModal();
const t = useTranslations("Leo");
const t = useTranslations();

const isButtonDisabled =
!activeOfficer ||
Expand All @@ -71,13 +71,13 @@ export const ModalButtons = () => {
<ul className="modal-buttons-grid mt-2">
{buttons.map((button, idx) => (
<Button
id={button.nameKey}
id={button.nameKey[1]}
key={idx}
disabled={isButtonDisabled}
title={isButtonDisabled ? "Go on-duty before continuing" : button.nameKey}
title={isButtonDisabled ? "Go on-duty before continuing" : t(button.nameKey.join("."))}
onClick={() => openModal(button.modalId)}
>
{t(button.nameKey)}
{t(button.nameKey.join("."))}
</Button>
))}
</ul>
Expand Down
Loading

0 comments on commit b84c963

Please sign in to comment.