Skip to content

Commit

Permalink
Reconfigure script relationships.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Jul 26, 2023
1 parent 6e1c231 commit 9bf5319
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Server/Data/AppDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ protected override void OnModelCreating(ModelBuilder builder)
.HasMany(x => x.Results)
.WithOne(x => x.ScriptRun)
.IsRequired(false);
builder.Entity<ScriptRun>()
.HasOne(x => x.SavedScript)
.WithMany(x => x.ScriptRuns)
.IsRequired(false);

builder.Entity<ScriptResult>()
.Property(x => x.ErrorOutput)
Expand All @@ -181,6 +185,10 @@ protected override void OnModelCreating(ModelBuilder builder)
.HasOne(x => x.ScriptRun)
.WithMany(x => x.Results)
.IsRequired(false);
builder.Entity<ScriptResult>()
.HasOne(x => x.SavedScript)
.WithMany(x => x.ScriptResults)
.IsRequired(false);

builder.Entity<Alert>()
.HasOne(x => x.User)
Expand Down
6 changes: 6 additions & 0 deletions Shared/Models/SavedScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ public class SavedScript
public string? SendErrorEmailTo { get; set; }

public ScriptingShell Shell { get; set; }

[JsonIgnore]
public List<ScriptRun>? ScriptRuns { get; set; }

[JsonIgnore]
public List<ScriptResult>? ScriptResults { get; set; }
}
3 changes: 3 additions & 0 deletions Shared/Models/ScriptResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class ScriptResult : ScriptResultBase
public Organization? Organization { get; set; }
public string OrganizationID { get; set; } = string.Empty;

[JsonIgnore]
public SavedScript? SavedScript { get; set; }

[JsonIgnore]
public ScriptSchedule? Schedule { get; set; }

Expand Down
6 changes: 6 additions & 0 deletions Shared/Models/ScriptRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class ScriptRun

public DateTimeOffset RunAt { get; set; }
public bool RunOnNextConnect { get; set; }

[JsonIgnore]
public SavedScript? SavedScript { get; set; }
public Guid? SavedScriptId { get; set; }

[JsonIgnore]
public ScriptSchedule? Schedule { get; set; }
public int? ScheduleId { get; set; }
}
5 changes: 2 additions & 3 deletions Tests/Server.Tests/DataServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,17 @@ public async Task GetPendingScriptRuns_GivenMultipleRunsQueued_ReturnsOnlyLatest
Assert.AreEqual(1, pendingRuns.Count());
Assert.AreEqual(2, pendingRuns.First().Id);

var scriptResult = new ScriptResult()
var dto = new ScriptResultDto()
{
DeviceID = _testData.Org1Device1.ID,
InputType = Shared.Enums.ScriptInputType.ScheduledScript,
OrganizationID = _testData.Org1Id,
SavedScriptId = savedScript.Id,
ScriptRunId = scriptRun.Id,
Shell = Shared.Enums.ScriptingShell.PSCore,
ScriptInput = "echo test"
};

_dataService.AddOrUpdateScriptResult(scriptResult);
var scriptResult = (await _dataService.AddScriptResult(dto)).Value!;

await _dataService.AddScriptResultToScriptRun(scriptResult.ID, scriptRun.Id);

Expand Down

0 comments on commit 9bf5319

Please sign in to comment.