Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hunting fishing license #1810

Merged
merged 4 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
24 changes: 24 additions & 0 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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[]
Expand All @@ -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[]
Expand Down Expand Up @@ -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])
}
Expand Down Expand Up @@ -1709,6 +1729,8 @@ enum LicenseExamType {
FIREARM
WATER
PILOT
HUNTING
FISHING
}

enum QualificationValueType {
Expand Down Expand Up @@ -1798,6 +1820,8 @@ enum DriversLicenseCategoryType {
AVIATION
WATER
FIREARM
HUNTING
FISHING
}

enum EmployeeAsEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export class ImportCitizensController {
gender: true,
ethnicity: true,
weaponLicense: true,
huntingLicense: true,
fishingLicense: true,
driversLicense: true,
pilotLicense: true,
waterLicense: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ export class CADSettingsController {
waterLicenseNumberLength: data.waterLicenseNumberLength,
signal100RepeatAmount: data.signal100RepeatAmount,
signal100RepeatIntervalMs: data.signal100RepeatIntervalMs,
huntingLicenseTemplate: data.huntingLicenseTemplate,
huntingLicenseMaxPoints: data.huntingLicenseMaxPoints,
huntingLicenseNumberLength: data.huntingLicenseNumberLength,
fishingLicenseTemplate: data.fishingLicenseTemplate,
fishingLicenseMaxPoints: data.fishingLicenseMaxPoints,
fishingLicenseNumberLength: data.fishingLicenseNumberLength,
},
include: { webhooks: true },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export class AdminManageCitizensController {
driversLicenseId: data.driversLicense,
weaponLicenseId: data.weaponLicense,
pilotLicenseId: data.pilotLicense,
fishingLicenseId: data.fishingLicense,
huntingLicenseId: data.huntingLicense,
phoneNumber: data.phoneNumber,
socialSecurityNumber:
data.socialSecurityNumber && isEditableSSNEnabled
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/controllers/citizen/CitizenController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export const citizenInclude = Prisma.validator<Prisma.CitizenSelect>()({
gender: true,
weaponLicense: true,
driversLicense: true,
huntingLicense: true,
fishingLicense: true,
pilotLicense: true,
waterLicense: true,
dlCategory: { include: { value: true } },
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/controllers/citizen/LicenseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class LicensesController {
pilotLicenseId: suspendedLicenses?.pilotLicense ? undefined : data.pilotLicense,
weaponLicenseId: suspendedLicenses?.firearmsLicense ? undefined : data.weaponLicense,
waterLicenseId: suspendedLicenses?.waterLicense ? undefined : data.waterLicense,
fishingLicenseId: suspendedLicenses?.fishingLicense ? undefined : data.fishingLicense,
huntingLicenseId: suspendedLicenses?.huntingLicense ? undefined : data.huntingLicense,
},
include: citizenInclude,
});
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/controllers/leo/LicenseExamsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ export class LicenseExamsController {
FIREARM: "weaponLicenseId",
WATER: "waterLicenseId",
PILOT: "pilotLicenseId",
HUNTING: "huntingLicenseId",
FISHING: "fishingLicenseId",
} as const;
const prismaName = prismaNames[exam.type];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export class SearchActionsController {
pilotLicenseTimeEnd: data.suspended.pilotLicenseTimeEnd,
waterLicense: data.suspended.waterLicense,
waterLicenseTimeEnd: data.suspended.waterLicenseTimeEnd,
fishingLicense: data.suspended.fishingLicense,
fishingLicenseTimeEnd: data.suspended.fishingLicenseTimeEnd,
huntingLicense: data.suspended.huntingLicense,
huntingLicenseTimeEnd: data.suspended.huntingLicenseTimeEnd,
};

suspendedLicenses = await prisma.suspendedCitizenLicenses.upsert({
Expand All @@ -108,6 +112,8 @@ export class SearchActionsController {
driversLicenseId: data.driversLicense,
pilotLicenseId: data.pilotLicense,
weaponLicenseId: data.weaponLicense,
huntingLicenseId: data.huntingLicense,
fishingLicenseId: data.fishingLicense,
waterLicenseId: data.waterLicense,
suspendedLicensesId: suspendedLicenses?.id,
},
Expand Down Expand Up @@ -143,6 +149,8 @@ export class SearchActionsController {
pilotLicensePoints: data.pilotLicensePoints,
waterLicensePoints: data.waterLicensePoints,
firearmsLicensePoints: data.firearmsLicensePoints,
huntingLicensePoints: data.huntingLicensePoints,
fishingLicensePoints: data.fishingLicensePoints,
};

const updated = await prisma.citizen.update({
Expand Down
12 changes: 12 additions & 0 deletions apps/api/src/lib/citizen/citizen-create-data-obj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ export async function citizenObjectFromData(options: Options) {
template: miscCadSettings?.waterLicenseTemplate,
length: miscCadSettings?.waterLicenseNumberLength ?? 8,
}),

huntingLicenseNumber: generateLicenseNumber({
template: miscCadSettings?.huntingLicenseTemplate,
length: miscCadSettings?.huntingLicenseNumberLength ?? 8,
}),

fishingLicenseNumber: generateLicenseNumber({
template: miscCadSettings?.fishingLicenseTemplate,
length: miscCadSettings?.fishingLicenseNumberLength ?? 8,
}),
};

if (typeof options.defaultLicenseValueId !== "undefined") {
Expand All @@ -72,6 +82,8 @@ export async function citizenObjectFromData(options: Options) {
weaponLicenseId: options.data.weaponLicense || options.defaultLicenseValueId,
pilotLicenseId: options.data.pilotLicense || options.defaultLicenseValueId,
waterLicenseId: options.data.waterLicense || options.defaultLicenseValueId,
huntingLicenseId: options.data.huntingLicense || options.defaultLicenseValueId,
fishingLicenseId: options.data.fishingLicense || options.defaultLicenseValueId,
};
}

Expand Down
12 changes: 12 additions & 0 deletions apps/client/locales/en/cad-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
"weaponLicenseTemplateInfo": "This is the template for weapon license numbers. You can use the following variables: {variables}. Note: this will only apply to newly created citizens.",
"waterLicenseTemplate": "Water license number template",
"waterLicenseTemplateInfo": "This is the template for water license numbers. You can use the following variables: {variables}. Note: this will only apply to newly created citizens.",
"huntingLicenseTemplate": "Hunting license number template",
"huntingLicenseTemplateInfo": "This is the template for hunting license numbers. You can use the following variables: {variables}. Note: this will only apply to newly created citizens.",
"fishingLicenseTemplate": "Fishing license number template",
"fishingLicenseTemplateInfo": "This is the template for fishing license numbers. You can use the following variables: {variables}. Note: this will only apply to newly created citizens.",
"miscSettings": "Miscellaneous Settings",
"cadRelated": "CAD Related",
"inactivityTimeouts": "Inactivity Timeouts",
Expand All @@ -156,6 +160,10 @@
"maxPilotLicensePointsDescription": "The maximum amount of license points a citizen can have before their pilots license is suspended (Default: 12)",
"maxWeaponLicensePoints": "Max Weapon License Points",
"maxWeaponLicensePointsDescription": "The maximum amount of license points a citizen can have before their weapon license is suspended (Default: 12)",
"maxFishingLicensePoints": "Max Fishing License Points",
"maxFishingLicensePointsDescription": "The maximum amount of license points a citizen can have before their fishing license is suspended (Default: 12)",
"maxHuntingLicensePoints": "Max Hunting License Points",
"maxHuntingLicensePointsDescription": "The maximum amount of license points a citizen can have before their hunting license is suspended (Default: 12)",
"maxWaterLicensePoints": "Max Water License Points",
"maxWaterLicensePointsDescription": "The maximum amount of license points a citizen can have before their water license is suspended (Default: 12)",
"other": "Other",
Expand Down Expand Up @@ -191,6 +199,10 @@
"weaponLicenseNumberLengthDescription": "The length of the weapon license number (Default: 8)",
"waterLicenseNumberLength": "Water License Number Length",
"waterLicenseNumberLengthDescription": "The length of the water license number (Default: 8)",
"fishingLicenseNumberLength": "Fishing License Number Length",
"fishingLicenseNumberLengthDescription": "The length of the fishing license number (Default: 8)",
"huntingLicenseNumberLength": "Hunting License Number Length",
"huntingLicenseNumberLengthDescription": "The length of the hunting license number (Default: 8)",
"seconds": "Seconds",
"minutes": "Minutes",
"hours": "Hours",
Expand Down
8 changes: 7 additions & 1 deletion apps/client/locales/en/citizen.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@
"createPreviousRecordsStepDescription": "Here you can optionally add previous records this citizen has had. This is useful for when a citizen has been arrested before.",
"alert_markCitizenDeceased": "Are you sure you want mark <span>{citizen}</span> as deceased? Only EMS/FD can mark you alive again.",
"alert_deleteCitizen": "Are you sure you want to delete <span>{citizen}</span>? This action cannot be undone.",
"id": "Id"
"id": "Id",
"fishingLicense": "Fishing License",
"huntingLicense": "Hunting License",
"fishingLicenseCategory": "Fishing License Categories",
"huntingLicenseCategory": "Hunting License Categories",
"huntingLicensePoints": "Hunting License Points",
"fishingLicensePoints": "Fishing License Points"
},
"Vehicles": {
"model": "Model",
Expand Down
2 changes: 2 additions & 0 deletions apps/client/locales/en/leo.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@
"suspendPilotLicense": "Suspended Pilot license",
"suspendWaterLicense": "Suspended Water license",
"suspendFirearmsLicense": "Suspended Firearms license",
"suspendedHuntingLicense": "Suspended Hunting license",
"suspendedFishingLicense": "Suspended Fishing license",
"endDate": "End Date",
"patrolVehicle": "Patrol Vehicle",
"callUpdated": "Your call #{caseNumber} has been updated",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export function LicenseNumbersTab() {
weaponLicenseNumberLength: miscSettings.weaponLicenseNumberLength ?? 8,
pilotLicenseNumberLength: miscSettings.pilotLicenseNumberLength ?? 6,
waterLicenseNumberLength: miscSettings.waterLicenseNumberLength ?? 8,
fishingLicenseNumberLength: miscSettings.fishingLicenseNumberLength ?? 8,
huntingLicenseNumberLength: miscSettings.huntingLicenseNumberLength ?? 8,
};

return (
Expand Down Expand Up @@ -112,6 +114,34 @@ export function LicenseNumbersTab() {
/>
</SettingsFormField>

<SettingsFormField
errorMessage={errors.fishingLicenseNumberLength}
description={t("fishingLicenseNumberLengthDescription")}
label={t("fishingLicenseNumberLength")}
action="short-input"
>
<Input
type="number"
name="fishingLicenseNumberLength"
value={values.fishingLicenseNumberLength}
onChange={handleChange}
/>
</SettingsFormField>

<SettingsFormField
errorMessage={errors.huntingLicenseNumberLength}
description={t("huntingLicenseNumberLengthDescription")}
label={t("huntingLicenseNumberLength")}
action="short-input"
>
<Input
type="number"
name="huntingLicenseNumberLength"
value={values.huntingLicenseNumberLength}
onChange={handleChange}
/>
</SettingsFormField>

<Button
className="flex items-center float-right"
type="submit"
Expand Down
Loading
Loading