fix: handle non-numeric values in Resources integer fields
Autotask API returns string values like 'PRIMARY' for some integer fields (e.g., emailTypeCode). Added safeInt() helper function to: - Parse numeric values correctly - Return null for non-numeric strings - Handle null/undefined/empty values This prevents database errors when syncing Resources with non-standard field values from Autotask API.
This commit is contained in:
parent
8e0ca0a63b
commit
bc01a6aafb
1 changed files with 15 additions and 8 deletions
|
|
@ -275,6 +275,13 @@ function mapProject(data: any): Record<string, any> {
|
|||
* Map Resource entity
|
||||
*/
|
||||
function mapResource(data: any): Record<string, any> {
|
||||
// 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<string, any> {
|
|||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue