diff --git a/lib/utils/entity-mapper.ts b/lib/utils/entity-mapper.ts index a844084..0abbde7 100644 --- a/lib/utils/entity-mapper.ts +++ b/lib/utils/entity-mapper.ts @@ -275,6 +275,13 @@ function mapProject(data: any): Record { * Map Resource entity */ function mapResource(data: any): Record { + // Helper to safely parse integer values (returns null for non-numeric strings) + const safeInt = (value: any): number | null => { + if (value === null || value === undefined || value === '') return null; + const num = typeof value === 'number' ? value : parseInt(value, 10); + return isNaN(num) ? null : num; + }; + return { id: data.id, // Name fields @@ -300,29 +307,29 @@ function mapResource(data: any): Record { is_active: data.isActive !== undefined ? data.isActive : true, // Employment details - resource_type: data.resourceType, + resource_type: safeInt(data.resourceType), payroll_identifier: data.payrollIdentifier, pay_roll_identifier: data.payrollIdentifier, // Keep for backward compatibility - payroll_type: data.payrollType, + payroll_type: safeInt(data.payrollType), accounting_reference_id: data.accountingReferenceID, internal_cost: data.internalCost, hire_date: data.hireDate, // Location and availability - location_id: data.locationID, + location_id: safeInt(data.locationID), travel_availability_pct: data.travelAvailabilityPct, - default_service_desk_role_id: data.defaultServiceDeskRoleID, + default_service_desk_role_id: safeInt(data.defaultServiceDeskRoleID), // System preferences - email_type_code: data.emailTypeCode, + email_type_code: safeInt(data.emailTypeCode), number_format: data.numberFormat, time_format: data.timeFormat, date_format: data.dateFormat, // Demographics and security - gender: data.gender, - license_type: data.licenseType, - security_level: data.securityLevel, + gender: safeInt(data.gender), + license_type: safeInt(data.licenseType), + security_level: safeInt(data.securityLevel), // Ratings survey_resource_rating: data.surveyResourceRating,