Skip to content

Commit

Permalink
add extra null checking in Helpers.cs (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
SondreJDigdir authored Sep 6, 2024
1 parent 9c74414 commit 651de02
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# Azure Functions localsettings file
local.settings.json

/.idea

# User-specific files
*.rsuser
*.suo
Expand Down
36 changes: 28 additions & 8 deletions src/Dan.Plugin.Tilda/Utils/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,14 @@ public static async Task<AccountsInformation> GetAnnualTurnoverFromBR(string org
new Context(cacheKey));

dynamic tmp = JsonConvert.DeserializeObject(rawResult);
if (tmp is null)
{
return result;
}

result.ToDate = tmp[0]["regnskapsperiode"]["tilDato"];
result.FromDate = tmp[0]["regnskapsperiode"]["fraDato"];
result.AnnualTurnover = tmp[0]["resultatregnskapResultat"]["driftsresultat"]["driftsinntekter"]["sumDriftsinntekter"];
result.FromDate = tmp[0]["regnskapsperiode"]["fraDato"];
result.AnnualTurnover = tmp[0]["resultatregnskapResultat"]["driftsresultat"]["driftsinntekter"]["sumDriftsinntekter"];
}
catch
{
Expand Down Expand Up @@ -378,7 +383,7 @@ public static IAuditList Filter(IAuditList resultList, List<TildaRegistryEntry>
// *** TEMPORARY TILDA FILTERING ***
// We need to temporarily remove _all_ data from the result list if orgForm is ENK
// For all other orgforms
// - remove meldingTilAnnenMyndighet
// - remove meldingTilAnnenMyndighet
// - remove tilsynsnotater
// - remove kontaktperson name
if (orgs == null || orgs.Count == 0)
Expand All @@ -388,7 +393,7 @@ public static IAuditList Filter(IAuditList resultList, List<TildaRegistryEntry>

var firstOrg = orgs.First();
// If first organization is a specific test organization, disable filtering
if (firstOrg.OrganizationNumber == "111111111")
if (firstOrg.OrganizationNumber == "111111111")
{
return resultList;
}
Expand All @@ -398,16 +403,21 @@ bool IsEnk(string orgNo)
return orgs.Any(x => x.OrganizationNumber == orgNo && x.OrganisationForm == "ENK");
}

switch (resultList)
switch (resultList)
{
case AuditReportList filteredResultList:
filteredResultList.AuditReports?.ForEach(x =>
{
if (x is null)
{
return;
}

x.AuditNotes = null;

if (IsEnk(x.ControlObject))
{
x.NotesAndRemarks.Clear();
x.NotesAndRemarks?.Clear();
x.ControlAttributes = null;
}
});
Expand All @@ -416,6 +426,11 @@ bool IsEnk(string orgNo)
case AuditCoordinationList filteredResultList:
filteredResultList.AuditCoordinations?.ForEach(x =>
{
if (x is null)
{
return;
}

if (IsEnk(x.ControlObject))
{
x.Alerts?.Clear();
Expand All @@ -426,11 +441,16 @@ bool IsEnk(string orgNo)
case NPDIDAuditReportList filteredResultList:
filteredResultList.AuditReports?.ForEach(x =>
{
if (x is null)
{
return;
}

x.AuditNotes = null;

if (IsEnk(x.ControlObject))
{
x.NotesAndRemarks.Clear();
x.NotesAndRemarks?.Clear();
x.ControlAttributes = null;
}
});
Expand Down Expand Up @@ -460,7 +480,7 @@ public static async Task<string[]> GetFileContents(string folder, string fileNam
{
var binDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var rootDirectory = Path.GetFullPath(Path.Combine(binDirectory, ".."));
return await File.ReadAllLinesAsync(rootDirectory + $@"\{folder}\{fileName}");
return await File.ReadAllLinesAsync(rootDirectory + $@"\{folder}\{fileName}");
}

public static async Task<List<string>> GetParagraph(string paragraph)
Expand Down

0 comments on commit 651de02

Please sign in to comment.