From ebfe6437c11ef0c13092a11211bea002c8aec5e1 Mon Sep 17 00:00:00 2001 From: Artem Riabushenko Date: Thu, 8 Jan 2026 20:44:27 +0200 Subject: [PATCH] Adjustments to action 'Create employment' --- .gitignore | 1 + Apps.Remote/Actions/EmploymentActions.cs | 55 +++++++++++++----------- Apps.Remote/Api/ApiClient.cs | 23 ++++++++++ Apps.Remote/Apps.Remote.csproj | 2 +- Tests.Remote/Tests.Remote.csproj | 3 ++ 5 files changed, 58 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index d6952cb..d1ab1b8 100644 --- a/.gitignore +++ b/.gitignore @@ -366,3 +366,4 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd /Tests.Remote/appsettings.json +/Tests.Remote/appsettings.json diff --git a/Apps.Remote/Actions/EmploymentActions.cs b/Apps.Remote/Actions/EmploymentActions.cs index 4fa86cb..34bf100 100644 --- a/Apps.Remote/Actions/EmploymentActions.cs +++ b/Apps.Remote/Actions/EmploymentActions.cs @@ -134,40 +134,42 @@ public async Task UpdateEmploymentCustomFieldValue( [Action("Create employment", Description = "Create employment with specified data")] public async Task CreateEmployment([ActionParameter] CreateEmploymentRequest request) { - var hasSeniorityDate = request.SeniorityDate.HasValue; - var body = new Dictionary() + var type = string.IsNullOrWhiteSpace(request.Type) + ? "employee" + : request.Type.Trim().ToLowerInvariant(); + + var body = new Dictionary() { - { "country_code", request.CountryCode }, - { "type", string.IsNullOrEmpty(request.Type) ? "employee" : request.Type } + ["country_code"] = request.CountryCode, + ["type"] = type }; - - if(!string.IsNullOrEmpty(request.ExternalId)) - { - body.Add("external_id", request.ExternalId); - } - if (!string.IsNullOrEmpty(request.CompanyId)) - { - body.Add("company_id", request.CompanyId); - } + if (!string.IsNullOrWhiteSpace(request.ExternalId)) + body["external_id"] = request.ExternalId; + + if (!string.IsNullOrWhiteSpace(request.CompanyId)) + body["company_id"] = request.CompanyId; - var basicInformation = new Dictionary + var basicInformation = new Dictionary() { - { "email", request.Email }, - { "job_title", request.JobTitle }, - { "name", request.Name }, - { "provisional_start_date", request.ProvisionalStartDate.ToString("yyyy-MM-dd") }, - { "has_seniority_date", hasSeniorityDate ? "yes" : "no" }, - { "tax_servicing_countries", Array.Empty() }, - { "tax_job_category", request.TaxJobCategory ?? null! } + ["email"] = request.Email, + ["job_title"] = request.JobTitle, + ["name"] = request.Name, + ["provisional_start_date"] = request.ProvisionalStartDate.ToString("yyyy-MM-dd") }; - if (hasSeniorityDate) + if (type == "employee" && request.SeniorityDate.HasValue) + { + basicInformation["has_seniority_date"] = "yes"; + basicInformation["seniority_date"] = request.SeniorityDate.Value.ToString("yyyy-MM-dd"); + } + + if (type == "employee" && !string.IsNullOrWhiteSpace(request.TaxJobCategory)) { - basicInformation.Add("seniority_date", request.SeniorityDate!.Value.ToString("yyyy-MM-dd")); + basicInformation["tax_job_category"] = request.TaxJobCategory; } - body.Add("basic_information", basicInformation); + body["basic_information"] = basicInformation; var apiRequest = new ApiRequest("/v1/employments", Method.Post, Creds) .WithJsonBody(body); @@ -175,7 +177,10 @@ public async Task CreateEmployment([ActionParameter] CreateE var response = await Client.ExecuteWithErrorHandling>(apiRequest); await Task.Delay(1500); - return await GetEmployment(new EmploymentIdentifier { EmploymentId = response.Data?.Employment!.Id! }); + return await GetEmployment(new EmploymentIdentifier + { + EmploymentId = response.Data?.Employment!.Id! + }); } [Action("Update employment", Description = "Update employment by ID with specified data")] diff --git a/Apps.Remote/Api/ApiClient.cs b/Apps.Remote/Api/ApiClient.cs index bd85087..688a4a4 100644 --- a/Apps.Remote/Api/ApiClient.cs +++ b/Apps.Remote/Api/ApiClient.cs @@ -24,6 +24,29 @@ protected override Exception ConfigureErrorException(RestResponse response) return ConfigureException(response); } + public override async Task ExecuteWithErrorHandling(RestRequest request) + { + string content = (await ExecuteWithErrorHandling(request)).Content; + T val = JsonConvert.DeserializeObject(content, JsonSettings); + if (val == null) + { + throw new Exception($"Could not parse {content} to {typeof(T)}"); + } + + return val; + } + + public override async Task ExecuteWithErrorHandling(RestRequest request) + { + RestResponse restResponse = await ExecuteAsync(request); + if (!restResponse.IsSuccessStatusCode) + { + throw ConfigureErrorException(restResponse); + } + + return restResponse; + } + public async Task> Paginate(RestRequest request) where TV : PaginationResponse { var result = new List(); diff --git a/Apps.Remote/Apps.Remote.csproj b/Apps.Remote/Apps.Remote.csproj index 7acb367..5f001f0 100644 --- a/Apps.Remote/Apps.Remote.csproj +++ b/Apps.Remote/Apps.Remote.csproj @@ -6,7 +6,7 @@ enable Remote Remote is a Global HR Platform that helps companies hire, manage, and pay their entire team — and more effectively compete in the modern global economy through our comprehensive set of core solutions including, HRIS, payroll, international employment, contractor management, and more. - 1.0.14 + 1.0.15 Apps.Remote Apps.Remote Apps.Remote diff --git a/Tests.Remote/Tests.Remote.csproj b/Tests.Remote/Tests.Remote.csproj index abb9a04..34ceb55 100644 --- a/Tests.Remote/Tests.Remote.csproj +++ b/Tests.Remote/Tests.Remote.csproj @@ -27,6 +27,9 @@ + + PreserveNewest + PreserveNewest