Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,4 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd
/Tests.Remote/appsettings.json
/Tests.Remote/appsettings.json
55 changes: 30 additions & 25 deletions Apps.Remote/Actions/EmploymentActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,48 +134,53 @@ public async Task<CustomFieldValueResponse> UpdateEmploymentCustomFieldValue(
[Action("Create employment", Description = "Create employment with specified data")]
public async Task<EmploymentResponse> CreateEmployment([ActionParameter] CreateEmploymentRequest request)
{
var hasSeniorityDate = request.SeniorityDate.HasValue;
var body = new Dictionary<string, object>()
var type = string.IsNullOrWhiteSpace(request.Type)
? "employee"
: request.Type.Trim().ToLowerInvariant();

var body = new Dictionary<string, object?>()
{
{ "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<string, object>
var basicInformation = new Dictionary<string, object?>()
{
{ "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<string>() },
{ "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);

var response = await Client.ExecuteWithErrorHandling<BaseDto<EmploymentDto>>(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")]
Expand Down
23 changes: 23 additions & 0 deletions Apps.Remote/Api/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ protected override Exception ConfigureErrorException(RestResponse response)
return ConfigureException(response);
}

public override async Task<T> ExecuteWithErrorHandling<T>(RestRequest request)
{
string content = (await ExecuteWithErrorHandling(request)).Content;
T val = JsonConvert.DeserializeObject<T>(content, JsonSettings);
if (val == null)
{
throw new Exception($"Could not parse {content} to {typeof(T)}");
}

return val;
}

public override async Task<RestResponse> ExecuteWithErrorHandling(RestRequest request)
{
RestResponse restResponse = await ExecuteAsync(request);
if (!restResponse.IsSuccessStatusCode)
{
throw ConfigureErrorException(restResponse);
}

return restResponse;
}

public async Task<List<T>> Paginate<T, TV>(RestRequest request) where TV : PaginationResponse<T>
{
var result = new List<T>();
Expand Down
2 changes: 1 addition & 1 deletion Apps.Remote/Apps.Remote.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<Product>Remote</Product>
<Description>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.</Description>
<Version>1.0.14</Version>
<Version>1.0.15</Version>
<AssemblyName>Apps.Remote</AssemblyName>
<RootNamespace>Apps.Remote</RootNamespace>
<PackageId>Apps.Remote</PackageId>
Expand Down
3 changes: 3 additions & 0 deletions Tests.Remote/Tests.Remote.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.json.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down