fix: edit vehicle null fix
All checks were successful
Deploy to Staging / Build Images (push) Successful in 4m32s
Deploy to Staging / Deploy to Staging (push) Successful in 27s
Deploy to Staging / Verify Staging (push) Successful in 6s
Deploy to Staging / Notify Staging Ready (push) Successful in 5s
Deploy to Staging / Notify Staging Failure (push) Has been skipped
All checks were successful
Deploy to Staging / Build Images (push) Successful in 4m32s
Deploy to Staging / Deploy to Staging (push) Successful in 27s
Deploy to Staging / Verify Staging (push) Successful in 6s
Deploy to Staging / Notify Staging Ready (push) Successful in 5s
Deploy to Staging / Notify Staging Failure (push) Has been skipped
This commit is contained in:
@@ -39,16 +39,22 @@ export class VehiclesController {
|
|||||||
|
|
||||||
async createVehicle(request: FastifyRequest<{ Body: CreateVehicleBody }>, reply: FastifyReply) {
|
async createVehicle(request: FastifyRequest<{ Body: CreateVehicleBody }>, reply: FastifyReply) {
|
||||||
try {
|
try {
|
||||||
// Require either a valid 17-char VIN or a non-empty license plate
|
// Pre-1981 vehicles have no VIN/plate requirement
|
||||||
const vin = request.body?.vin?.trim();
|
const year = request.body?.year;
|
||||||
const plate = request.body?.licensePlate?.trim();
|
const isPreModern = year && year < 1981;
|
||||||
const hasValidVin = !!vin && vin.length === 17;
|
|
||||||
const hasPlate = !!plate && plate.length > 0;
|
if (!isPreModern) {
|
||||||
if (!hasValidVin && !hasPlate) {
|
// Require either a valid 17-char VIN or a non-empty license plate
|
||||||
return reply.code(400).send({
|
const vin = request.body?.vin?.trim();
|
||||||
error: 'Bad Request',
|
const plate = request.body?.licensePlate?.trim();
|
||||||
message: 'Either a valid 17-character VIN or a license plate is required'
|
const hasValidVin = !!vin && vin.length === 17;
|
||||||
});
|
const hasPlate = !!plate && plate.length > 0;
|
||||||
|
if (!hasValidVin && !hasPlate) {
|
||||||
|
return reply.code(400).send({
|
||||||
|
error: 'Bad Request',
|
||||||
|
message: 'Either a valid 17-character VIN or a license plate is required'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = (request as any).user.sub;
|
const userId = (request as any).user.sub;
|
||||||
|
|||||||
@@ -29,11 +29,14 @@ export class VehiclesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createVehicle(data: CreateVehicleRequest, userId: string): Promise<VehicleResponse> {
|
async createVehicle(data: CreateVehicleRequest, userId: string): Promise<VehicleResponse> {
|
||||||
logger.info('Creating vehicle', { userId, vin: data.vin, licensePlate: (data as any).licensePlate });
|
logger.info('Creating vehicle', { userId, vin: data.vin, licensePlate: data.licensePlate });
|
||||||
|
|
||||||
|
// Pre-1981 vehicles have no VIN format requirement
|
||||||
|
const isPreModern = data.year && data.year < 1981;
|
||||||
|
|
||||||
if (data.vin) {
|
if (data.vin) {
|
||||||
// Validate VIN if provided
|
// Validate VIN format only for modern vehicles (1981+)
|
||||||
if (!isValidVIN(data.vin)) {
|
if (!isPreModern && !isValidVIN(data.vin)) {
|
||||||
throw new Error('Invalid VIN format');
|
throw new Error('Invalid VIN format');
|
||||||
}
|
}
|
||||||
// Duplicate check only when VIN is present
|
// Duplicate check only when VIN is present
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export interface Vehicle {
|
|||||||
|
|
||||||
export interface CreateVehicleRequest {
|
export interface CreateVehicleRequest {
|
||||||
vin?: string;
|
vin?: string;
|
||||||
|
year?: number;
|
||||||
make?: string;
|
make?: string;
|
||||||
model?: string;
|
model?: string;
|
||||||
engine?: string;
|
engine?: string;
|
||||||
@@ -101,6 +102,14 @@ export interface VINDecodeResult {
|
|||||||
// Fastify-specific types for HTTP handling
|
// Fastify-specific types for HTTP handling
|
||||||
export interface CreateVehicleBody {
|
export interface CreateVehicleBody {
|
||||||
vin?: string;
|
vin?: string;
|
||||||
|
year?: number;
|
||||||
|
make?: string;
|
||||||
|
model?: string;
|
||||||
|
engine?: string;
|
||||||
|
transmission?: string;
|
||||||
|
trimLevel?: string;
|
||||||
|
driveType?: string;
|
||||||
|
fuelType?: string;
|
||||||
nickname?: string;
|
nickname?: string;
|
||||||
color?: string;
|
color?: string;
|
||||||
licensePlate?: string;
|
licensePlate?: string;
|
||||||
|
|||||||
@@ -30,14 +30,9 @@ You are a senior software engineer specializsing in NodeJS, Typescript, front en
|
|||||||
*** CHANGES TO IMPLEMENT ***
|
*** CHANGES TO IMPLEMENT ***
|
||||||
- Research this code base and ask iterative questions to compile a complete plan.
|
- Research this code base and ask iterative questions to compile a complete plan.
|
||||||
- We will pair troubleshoot this. Tell me what logs and things to run and I will
|
- We will pair troubleshoot this. Tell me what logs and things to run and I will
|
||||||
- The CSV import for the vehicle catalog fails with a basic file
|
- There is a bug in the ability to add and edit vehicles
|
||||||
- Here is the data trying to import
|
- Change it so the every vehicle older than 1981 does not have a 17 digit VIN requirement.
|
||||||
year,make,model,trim,engine_name,transmission_type
|
- Verify the edit logic. When I had a license plate but no VIN, it still said the VIN was required.
|
||||||
1968,Chevrolet,Camaro,Rally Sport Coupe,V-8,Manual
|
|
||||||
1969,Oldsmobile,Cutlass,F85,V-8,Automatic
|
|
||||||
- Here is the error. It appears it's failing the insert because there are duplicate V-8 engine items. This shouldn't cause a failure. This should be handled gracefully.
|
|
||||||
Row 0: Failed to upsert 1968 Chevrolet Camaro Rally Sport Coupe: duplicate key value violates unique constraint "engines_pkey"
|
|
||||||
Row 0: Failed to upsert 1969 Oldsmobile Cutlass F85: current transaction is aborted, commands ignored until end of transaction block
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,22 +13,25 @@ import { VehicleImageUpload } from './VehicleImageUpload';
|
|||||||
|
|
||||||
const vehicleSchema = z
|
const vehicleSchema = z
|
||||||
.object({
|
.object({
|
||||||
vin: z.string().optional(),
|
vin: z.string().nullable().optional().transform(val => val ?? undefined),
|
||||||
year: z.number().min(1950).max(new Date().getFullYear() + 1).optional(),
|
year: z.number().min(1950).max(new Date().getFullYear() + 1).nullable().optional(),
|
||||||
make: z.string().optional(),
|
make: z.string().nullable().optional(),
|
||||||
model: z.string().optional(),
|
model: z.string().nullable().optional(),
|
||||||
engine: z.string().optional(),
|
engine: z.string().nullable().optional(),
|
||||||
transmission: z.string().optional(),
|
transmission: z.string().nullable().optional(),
|
||||||
trimLevel: z.string().optional(),
|
trimLevel: z.string().nullable().optional(),
|
||||||
driveType: z.string().optional(),
|
driveType: z.string().nullable().optional(),
|
||||||
fuelType: z.string().optional(),
|
fuelType: z.string().nullable().optional(),
|
||||||
nickname: z.string().optional(),
|
nickname: z.string().nullable().optional(),
|
||||||
color: z.string().optional(),
|
color: z.string().nullable().optional(),
|
||||||
licensePlate: z.string().optional(),
|
licensePlate: z.string().nullable().optional(),
|
||||||
odometerReading: z.number().min(0).optional(),
|
odometerReading: z.number().min(0).nullable().optional(),
|
||||||
})
|
})
|
||||||
.refine(
|
.refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
|
// Pre-1981 vehicles have no VIN/plate requirement
|
||||||
|
if (data.year && data.year < 1981) return true;
|
||||||
|
|
||||||
const vin = (data.vin || '').trim();
|
const vin = (data.vin || '').trim();
|
||||||
const plate = (data.licensePlate || '').trim();
|
const plate = (data.licensePlate || '').trim();
|
||||||
// Must have either a valid 17-char VIN or a non-empty license plate
|
// Must have either a valid 17-char VIN or a non-empty license plate
|
||||||
@@ -43,6 +46,9 @@ const vehicleSchema = z
|
|||||||
)
|
)
|
||||||
.refine(
|
.refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
|
// Pre-1981 vehicles have no VIN format requirement
|
||||||
|
if (data.year && data.year < 1981) return true;
|
||||||
|
|
||||||
const vin = (data.vin || '').trim();
|
const vin = (data.vin || '').trim();
|
||||||
const plate = (data.licensePlate || '').trim();
|
const plate = (data.licensePlate || '').trim();
|
||||||
// If VIN provided but not 17 and no plate, fail; if plate exists, allow any VIN (or empty)
|
// If VIN provided but not 17 and no plate, fail; if plate exists, allow any VIN (or empty)
|
||||||
|
|||||||
Reference in New Issue
Block a user