fix signin signout and apply the new style

This commit is contained in:
root
2026-05-24 23:58:54 -04:00
parent bf97a072dd
commit 9bd0938951
68 changed files with 851 additions and 200 deletions
@@ -1,5 +1,14 @@
function normalizeLocations(value: unknown) {
return Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : []
}
export function presentVehicle(vehicle: any) {
return vehicle
return {
...vehicle,
pickupLocations: normalizeLocations(vehicle?.pickupLocations),
allowDifferentDropoff: Boolean(vehicle?.allowDifferentDropoff),
dropoffLocations: normalizeLocations(vehicle?.dropoffLocations),
}
}
export function presentVehicleList(vehicles: any[], meta: { total: number; page: number; pageSize: number; totalPages: number }) {
@@ -17,6 +17,9 @@ export const vehicleSchema = z.object({
notes: z.string().optional(),
isPublished: z.boolean().default(true),
status: z.enum(['AVAILABLE', 'RENTED', 'MAINTENANCE', 'OUT_OF_SERVICE']).optional(),
pickupLocations: z.array(z.string().trim().min(1)).default([]),
allowDifferentDropoff: z.boolean().default(false),
dropoffLocations: z.array(z.string().trim().min(1)).default([]),
})
export const listQuerySchema = z.object({
@@ -3,6 +3,42 @@ import { NotFoundError, ValidationError } from '../../http/errors'
import { presentVehicle, presentVehicleList } from './vehicle.presenter'
import * as repo from './vehicle.repo'
function normalizeLocations(locations: unknown) {
if (!Array.isArray(locations)) return []
const seen = new Set<string>()
const normalized: string[] = []
for (const entry of locations) {
if (typeof entry !== 'string') continue
const value = entry.trim()
const key = value.toLocaleLowerCase()
if (!value || seen.has(key)) continue
seen.add(key)
normalized.push(value)
}
return normalized
}
function applyLocationSettings(data: any) {
const patch = { ...data }
if (patch.pickupLocations !== undefined) {
patch.pickupLocations = normalizeLocations(patch.pickupLocations)
}
if (patch.dropoffLocations !== undefined) {
patch.dropoffLocations = normalizeLocations(patch.dropoffLocations)
}
if (patch.allowDifferentDropoff === false) {
patch.dropoffLocations = []
}
if (patch.allowDifferentDropoff === true && patch.dropoffLocations !== undefined && patch.dropoffLocations.length === 0) {
throw new ValidationError('Drop-off locations are required when different drop-off is enabled')
}
return patch
}
export async function listVehicles(companyId: string, query: { status?: string; category?: string; published?: string; page?: number; pageSize?: number }) {
const page = query.page ?? 1
const pageSize = query.pageSize ?? 20
@@ -22,11 +58,11 @@ export async function getVehicle(id: string, companyId: string) {
}
export async function createVehicle(data: any, companyId: string) {
return presentVehicle(await repo.create({ ...data, companyId }))
return presentVehicle(await repo.create({ ...applyLocationSettings(data), companyId }))
}
export async function updateVehicle(id: string, companyId: string, data: any) {
const patch = { ...data }
const patch = applyLocationSettings(data)
if (patch.status === 'MAINTENANCE' || patch.status === 'OUT_OF_SERVICE') {
patch.isPublished = false
} else if (patch.status === 'AVAILABLE' || patch.status === 'RENTED') {