Skip to content

Commit

Permalink
fix: unable to edit
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Sep 25, 2023
1 parent 80b6d8f commit b6597c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NotFound, InternalServerError, BadRequest } from "@tsed/exceptions";
import { QueryParams, BodyParams, Context, PathParams } from "@tsed/platform-params";
import { prisma } from "lib/data/prisma";
import { IsAuth } from "middlewares/auth/is-auth";
import { LEO_INCIDENT_SCHEMA } from "@snailycad/schemas";
import { EMS_FD_INCIDENT_SCHEMA } from "@snailycad/schemas";
import { Officer, MiscCadSettings, CombinedLeoUnit } from "@prisma/client";
import { validateSchema } from "lib/data/validate-schema";
import { Socket } from "services/socket-service";
Expand Down Expand Up @@ -117,7 +117,7 @@ export class IncidentController {
@Context("activeOfficer") activeOfficer: (CombinedLeoUnit & { officers: Officer[] }) | Officer,
@Context("sessionUserId") sessionUserId: string,
): Promise<APITypes.PostIncidentsData<"ems-fd">> {
const data = validateSchema(LEO_INCIDENT_SCHEMA, body);
const data = validateSchema(EMS_FD_INCIDENT_SCHEMA, body);
const officer = getUserOfficerFromActiveOfficer({
userId: sessionUserId,
allowDispatch: true,
Expand All @@ -136,6 +136,8 @@ export class IncidentController {
isActive: data.isActive ?? false,
situationCodeId: data.situationCodeId ?? null,
postal: data.postal ?? null,
address: data.address ?? null,
fireType: data.fireType ?? null,
},
include: {
unitsInvolved: true,
Expand Down Expand Up @@ -282,7 +284,7 @@ export class IncidentController {
@Context("cad") cad: { miscCadSettings: MiscCadSettings },
@PathParams("id") incidentId: string,
): Promise<APITypes.PutIncidentByIdData<"ems-fd">> {
const data = validateSchema(LEO_INCIDENT_SCHEMA, body);
const data = validateSchema(EMS_FD_INCIDENT_SCHEMA, body);
const maxAssignmentsToIncidents = cad.miscCadSettings.maxAssignmentsToIncidents ?? Infinity;

const incident = await prisma.emsFdIncident.findUnique({
Expand All @@ -305,6 +307,8 @@ export class IncidentController {
isActive: data.isActive ?? false,
postal: data.postal ?? null,
situationCodeId: data.situationCodeId ?? null,
address: data.address ?? null,
fireType: data.fireType ?? null,
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LEO_INCIDENT_SCHEMA } from "@snailycad/schemas";
import { EMS_FD_INCIDENT_SCHEMA, LEO_INCIDENT_SCHEMA } from "@snailycad/schemas";
import {
Loader,
Button,
Expand Down Expand Up @@ -160,12 +160,13 @@ export function ManageIncidentModal<T extends LeoIncident | EmsFdIncident>({
}
}

const validate = handleValidate(LEO_INCIDENT_SCHEMA);
const validate = handleValidate(type === "ems-fd" ? EMS_FD_INCIDENT_SCHEMA : LEO_INCIDENT_SCHEMA);
const isEmsFdIncident = incident && "fireType" in incident;

const INITIAL_VALUES = {
description: incident?.description ?? "",
postal: incident?.postal ?? "",
address: isEmsFdIncident ? incident.address : "",
descriptionData: dataToSlate(incident),
vehicleInvolved: isEmsFdIncident ? incident.vehicleInvolved : false,
firearmsInvolved: incident?.firearmsInvolved ?? false,
Expand Down Expand Up @@ -292,7 +293,7 @@ export function ManageIncidentModal<T extends LeoIncident | EmsFdIncident>({
addressOptional
isDisabled={areFieldsDisabled}
postalOnly={type === "leo"}
addressLabel="location"
addressLabel="address"
/>
</FormRow>

Expand Down
5 changes: 5 additions & 0 deletions packages/schemas/src/leo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export const LEO_INCIDENT_SCHEMA = z.object({
situationCodeId: z.string().max(255).nullish(),
});

export const EMS_FD_INCIDENT_SCHEMA = LEO_INCIDENT_SCHEMA.extend({
address: z.string().nullish(),
fireType: z.string().nullish(),
});

export const LEO_VEHICLE_LICENSE_SCHEMA = VEHICLE_SCHEMA.pick({
inspectionStatus: true,
insuranceStatus: true,
Expand Down

0 comments on commit b6597c5

Please sign in to comment.