59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { MaintenanceFormData } from "../types.ts";
|
|
|
|
export interface ValidationError {
|
|
field: string;
|
|
message: string;
|
|
}
|
|
|
|
export function validateMaintenanceRequest(
|
|
data: MaintenanceFormData,
|
|
): ValidationError[] {
|
|
const errors: ValidationError[] = [];
|
|
|
|
if (!data.title?.trim()) {
|
|
errors.push({ field: "title", message: "Issue title is required" });
|
|
} else if (data.title.length < 3) {
|
|
errors.push({
|
|
field: "title",
|
|
message: "Title must be at least 3 characters long",
|
|
});
|
|
} else if (data.title.length > 100) {
|
|
errors.push({
|
|
field: "title",
|
|
message: "Title must be less than 100 characters",
|
|
});
|
|
}
|
|
|
|
if (!data.category?.trim()) {
|
|
errors.push({ field: "category", message: "Category is required" });
|
|
}
|
|
|
|
if (!data.priority?.trim()) {
|
|
errors.push({ field: "priority", message: "Priority level is required" });
|
|
}
|
|
|
|
if (!data.description?.trim()) {
|
|
errors.push({ field: "description", message: "Description is required" });
|
|
} else if (data.description.length < 10) {
|
|
errors.push({
|
|
field: "description",
|
|
message: "Description must be at least 10 characters long",
|
|
});
|
|
} else if (data.description.length > 2000) {
|
|
errors.push({
|
|
field: "description",
|
|
message: "Description must be less than 2000 characters",
|
|
});
|
|
}
|
|
|
|
if (!data.property_id?.trim()) {
|
|
errors.push({ field: "property_id", message: "Property ID is required" });
|
|
}
|
|
|
|
if (!data.tenant_id?.trim()) {
|
|
errors.push({ field: "tenant_id", message: "Tenant ID is required" });
|
|
}
|
|
|
|
return errors;
|
|
}
|