diff --git a/apps/api/prisma/migrations/20230929182215_hunting_fishing_licenses/migration.sql b/apps/api/prisma/migrations/20230929182215_hunting_fishing_licenses/migration.sql new file mode 100644 index 000000000..570fa3ee3 --- /dev/null +++ b/apps/api/prisma/migrations/20230929182215_hunting_fishing_licenses/migration.sql @@ -0,0 +1,51 @@ +-- AlterEnum +-- This migration adds more than one value to an enum. +-- With PostgreSQL versions 11 and earlier, this is not possible +-- in a single migration. This can be worked around by creating +-- multiple migrations, each migration adding only one value to +-- the enum. + + +ALTER TYPE "DriversLicenseCategoryType" ADD VALUE 'HUNTING'; +ALTER TYPE "DriversLicenseCategoryType" ADD VALUE 'FISHING'; + +-- AlterEnum +-- This migration adds more than one value to an enum. +-- With PostgreSQL versions 11 and earlier, this is not possible +-- in a single migration. This can be worked around by creating +-- multiple migrations, each migration adding only one value to +-- the enum. + + +ALTER TYPE "LicenseExamType" ADD VALUE 'HUNTING'; +ALTER TYPE "LicenseExamType" ADD VALUE 'FISHING'; + +-- AlterTable +ALTER TABLE "Citizen" ADD COLUMN "fishingLicenseId" TEXT, +ADD COLUMN "fishingLicenseNumber" TEXT, +ADD COLUMN "huntingLicenseId" TEXT, +ADD COLUMN "huntingLicenseNumber" TEXT; + +-- AlterTable +ALTER TABLE "CitizenLicensePoints" ADD COLUMN "fishingLicensePoints" INTEGER NOT NULL DEFAULT 0, +ADD COLUMN "huntingLicensePoints" INTEGER NOT NULL DEFAULT 0; + +-- AlterTable +ALTER TABLE "MiscCadSettings" ADD COLUMN "fishingLicenseMaxPoints" INTEGER DEFAULT 12, +ADD COLUMN "fishingLicenseNumberLength" INTEGER DEFAULT 8, +ADD COLUMN "fishingLicenseTemplate" TEXT, +ADD COLUMN "huntingLicenseMaxPoints" INTEGER DEFAULT 12, +ADD COLUMN "huntingLicenseNumberLength" INTEGER DEFAULT 8, +ADD COLUMN "huntingLicenseTemplate" TEXT; + +-- AlterTable +ALTER TABLE "SuspendedCitizenLicenses" ADD COLUMN "fishingLicense" BOOLEAN NOT NULL DEFAULT false, +ADD COLUMN "fishingLicenseTimeEnd" TIMESTAMP(3), +ADD COLUMN "huntingLicense" BOOLEAN NOT NULL DEFAULT false, +ADD COLUMN "huntingLicenseTimeEnd" TIMESTAMP(3); + +-- AddForeignKey +ALTER TABLE "Citizen" ADD CONSTRAINT "Citizen_huntingLicenseId_fkey" FOREIGN KEY ("huntingLicenseId") REFERENCES "Value"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Citizen" ADD CONSTRAINT "Citizen_fishingLicenseId_fkey" FOREIGN KEY ("fishingLicenseId") REFERENCES "Value"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index c324ff2ca..fafeac910 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -100,11 +100,17 @@ model MiscCadSettings { weaponLicenseTemplate String? @db.Text waterLicenseNumberLength Int? @default(8) waterLicenseTemplate String? @db.Text + huntingLicenseNumberLength Int? @default(8) + huntingLicenseTemplate String? @db.Text + fishingLicenseNumberLength Int? @default(8) + fishingLicenseTemplate String? @db.Text driversLicenseMaxPoints Int? @default(12) pilotLicenseMaxPoints Int? @default(12) weaponLicenseMaxPoints Int? @default(12) waterLicenseMaxPoints Int? @default(12) + fishingLicenseMaxPoints Int? @default(12) + huntingLicenseMaxPoints Int? @default(12) lastInactivitySyncTimestamp DateTime? @@ -375,6 +381,12 @@ model Citizen { waterLicense Value? @relation("waterLicenseToValue", fields: [waterLicenseId], references: [id]) waterLicenseId String? waterLicenseNumber String? + huntingLicense Value? @relation("huntingLicenseToValue", fields: [huntingLicenseId], references: [id]) + huntingLicenseId String? + huntingLicenseNumber String? + fishingLicense Value? @relation("fishingLicenseToValue", fields: [fishingLicenseId], references: [id]) + fishingLicenseId String? + fishingLicenseNumber String? ccw Value? @relation("ccwToValue", fields: [ccwId], references: [id]) ccwId String? imageId String? @db.Text @@ -428,6 +440,8 @@ model CitizenLicensePoints { driverLicensePoints Int @default(0) pilotLicensePoints Int @default(0) waterLicensePoints Int @default(0) + huntingLicensePoints Int @default(0) + fishingLicensePoints Int @default(0) firearmsLicensePoints Int @default(0) updatedAt DateTime @default(now()) @updatedAt citizens Citizen[] @@ -441,6 +455,10 @@ model SuspendedCitizenLicenses { pilotLicenseTimeEnd DateTime? waterLicense Boolean @default(false) waterLicenseTimeEnd DateTime? + fishingLicense Boolean @default(false) + fishingLicenseTimeEnd DateTime? + huntingLicense Boolean @default(false) + huntingLicenseTimeEnd DateTime? firearmsLicense Boolean @default(false) firearmsLicenseTimeEnd DateTime? citizens Citizen[] @@ -633,6 +651,8 @@ model Value { VehicleTrimLevels VehicleValue[] @relation("vehicleTrimLevels") RegisteredVehicle RegisteredVehicle[] @relation("registeredVehicleTrimLevels") Weapon Weapon[] @relation("weaponFlags") + fishingLicenseToValue Citizen[] @relation("fishingLicenseToValue") + huntingLicenseToValue Citizen[] @relation("huntingLicenseToValue") @@index([type]) } @@ -1709,6 +1729,8 @@ enum LicenseExamType { FIREARM WATER PILOT + HUNTING + FISHING } enum QualificationValueType { @@ -1798,6 +1820,8 @@ enum DriversLicenseCategoryType { AVIATION WATER FIREARM + HUNTING + FISHING } enum EmployeeAsEnum { diff --git a/apps/api/src/controllers/leo/LicenseExamsController.ts b/apps/api/src/controllers/leo/LicenseExamsController.ts index a235d6aef..b9d1dcde0 100644 --- a/apps/api/src/controllers/leo/LicenseExamsController.ts +++ b/apps/api/src/controllers/leo/LicenseExamsController.ts @@ -216,6 +216,8 @@ export class LicenseExamsController { FIREARM: "weaponLicenseId", WATER: "waterLicenseId", PILOT: "pilotLicenseId", + HUNTING: "huntingLicenseId", + FISHING: "fishingLicenseId", } as const; const prismaName = prismaNames[exam.type]; diff --git a/apps/client/src/components/admin/manage/cad-settings/misc-features/template-tab.tsx b/apps/client/src/components/admin/manage/cad-settings/misc-features/template-tab.tsx index 3289cd1a3..46cccf5fc 100644 --- a/apps/client/src/components/admin/manage/cad-settings/misc-features/template-tab.tsx +++ b/apps/client/src/components/admin/manage/cad-settings/misc-features/template-tab.tsx @@ -36,6 +36,8 @@ const licenseNumberTypes = [ "pilotLicenseTemplate", "weaponLicenseTemplate", "waterLicenseTemplate", + "fishingLicenseTemplate", + "huntingLicenseTemplate", ] as const; export function TemplateTab() { @@ -72,6 +74,8 @@ export function TemplateTab() { pilotLicenseTemplate: miscSettings.pilotLicenseTemplate ?? "", weaponLicenseTemplate: miscSettings.weaponLicenseTemplate ?? "", waterLicenseTemplate: miscSettings.waterLicenseTemplate ?? "", + fishingLicenseTemplate: miscSettings.fishingLicenseTemplate ?? "", + huntingLicenseTemplate: miscSettings.huntingLicenseTemplate ?? "", }; return ( diff --git a/apps/client/src/components/leo/exams/manage-license-exam-modal.tsx b/apps/client/src/components/leo/exams/manage-license-exam-modal.tsx index d3be488c2..1d2faee51 100644 --- a/apps/client/src/components/leo/exams/manage-license-exam-modal.tsx +++ b/apps/client/src/components/leo/exams/manage-license-exam-modal.tsx @@ -97,6 +97,8 @@ export function ManageExamModal({ exam, onClose, onCreate, onUpdate }: Props) { [LicenseExamType.FIREARM]: DriversLicenseCategoryType.FIREARM, [LicenseExamType.WATER]: DriversLicenseCategoryType.WATER, [LicenseExamType.PILOT]: DriversLicenseCategoryType.AVIATION, + [LicenseExamType.HUNTING]: DriversLicenseCategoryType.HUNTING, + [LicenseExamType.FISHING]: DriversLicenseCategoryType.FISHING, } as const; return ( diff --git a/packages/types/src/enums.ts b/packages/types/src/enums.ts index 22ee82583..98b867c4d 100644 --- a/packages/types/src/enums.ts +++ b/packages/types/src/enums.ts @@ -177,6 +177,8 @@ export const DriversLicenseCategoryType = { AVIATION: "AVIATION", WATER: "WATER", FIREARM: "FIREARM", + HUNTING: "HUNTING", + FISHING: "FISHING", } as const; export type DriversLicenseCategoryType = @@ -286,6 +288,8 @@ export const LicenseExamType = { FIREARM: "FIREARM", WATER: "WATER", PILOT: "PILOT", + HUNTING: "HUNTING", + FISHING: "FISHING", } as const; export type LicenseExamType = (typeof LicenseExamType)[keyof typeof LicenseExamType];