From 9be7b76e4b47ee1529a024c5c5ffd2eebf6e1585 Mon Sep 17 00:00:00 2001 From: Dev-CasperTheGhost <53900565+Dev-CasperTheGhost@users.noreply.github.com> Date: Tue, 9 Nov 2021 17:49:28 +0100 Subject: [PATCH 1/5] :tada: initial suggested input --- .../src/controllers/leo/SearchController.ts | 24 +++++-- .../active-bolos/ManageBoloModal.tsx | 33 +++++++--- .../src/components/form/InputSuggestions.tsx | 62 +++++++++++++++++++ 3 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 packages/client/src/components/form/InputSuggestions.tsx diff --git a/packages/api/src/controllers/leo/SearchController.ts b/packages/api/src/controllers/leo/SearchController.ts index a3e716d11..0bc330358 100644 --- a/packages/api/src/controllers/leo/SearchController.ts +++ b/packages/api/src/controllers/leo/SearchController.ts @@ -1,7 +1,7 @@ import { Controller, UseBeforeEach } from "@tsed/common"; import { JsonRequestBody, Post } from "@tsed/schema"; import { NotFound } from "@tsed/exceptions"; -import { BodyParams } from "@tsed/platform-params"; +import { BodyParams, QueryParams } from "@tsed/platform-params"; import { prisma } from "../../lib/prisma"; import { IsAuth } from "../../middlewares"; import { ActiveOfficer } from "../../middlewares/ActiveOfficer"; @@ -113,12 +113,15 @@ export class SearchController { } @Post("/vehicle") - async searchVehicle(@BodyParams("plateOrVin") plateOrVin: string) { + async searchVehicle( + @QueryParams("includeMany") includeMany: boolean, + @BodyParams("plateOrVin") plateOrVin: string, + ) { if (!plateOrVin || plateOrVin.length < 3) { return null; } - const vehicle = await prisma.registeredVehicle.findFirst({ + const data = { where: { OR: [ { plate: { startsWith: plateOrVin.toUpperCase() } }, @@ -130,7 +133,20 @@ export class SearchController { model: { include: { value: true } }, registrationStatus: true, }, - }); + }; + + if (includeMany) { + const vehicles = await prisma.registeredVehicle.findMany({ + where: { plate: { startsWith: plateOrVin.toUpperCase() } }, + include: data.include, + }); + + console.log({ vehicles }); + + return vehicles; + } + + const vehicle = await prisma.registeredVehicle.findFirst(data); if (!vehicle) { throw new NotFound("vehicleNotFound"); diff --git a/packages/client/src/components/active-bolos/ManageBoloModal.tsx b/packages/client/src/components/active-bolos/ManageBoloModal.tsx index 0c9faf829..47fad04e2 100644 --- a/packages/client/src/components/active-bolos/ManageBoloModal.tsx +++ b/packages/client/src/components/active-bolos/ManageBoloModal.tsx @@ -10,13 +10,14 @@ import { Form, Formik } from "formik"; import { handleValidate } from "lib/handleValidate"; import useFetch from "lib/useFetch"; import { ModalIds } from "types/ModalIds"; -import { BoloType } from "types/prisma"; +import { BoloType, RegisteredVehicle } from "types/prisma"; import { useTranslations } from "use-intl"; import { CREATE_BOLO_SCHEMA } from "@snailycad/schemas"; import { FullBolo, useDispatchState } from "state/dispatchState"; import { Person, ThreeDots } from "react-bootstrap-icons"; import { FormRow } from "components/form/FormRow"; import { classNames } from "lib/classNames"; +import { InputSuggestions } from "components/form/InputSuggestions"; interface Props { onClose?: () => void; @@ -133,11 +134,29 @@ export const ManageBoloModal = ({ onClose, bolo }: Props) => { {values.type === BoloType.VEHICLE ? ( <> - { + setFieldValue("plate", suggestion.plate); + setFieldValue("model", suggestion.model); + setFieldValue("color", suggestion.color); + }} + Component={({ suggestion }: { suggestion: RegisteredVehicle }) => ( +

+ {suggestion.plate.toUpperCase()} ( + {suggestion.model?.value?.value?.toUpperCase() ?? null}) +

+ )} /> {errors.plate}
@@ -186,7 +205,7 @@ export const ManageBoloModal = ({ onClose, bolo }: Props) => { {errors.description} -