Skip to content

Commit

Permalink
feat: Make createOutcomeWithValues public
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 committed Jul 3, 2024
1 parent 1cf1120 commit af63e18
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions Sources/CareKitEssentials/Cards/Shared/CareKitEssentialView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public extension CareKitEssentialView {

// Update the outcome with the new value
guard var outcome = event.outcome else {
let outcome = try createOutcomeWithValues(
let outcome = createOutcomeWithValues(
values,
event: event,
store: store
Expand Down Expand Up @@ -142,7 +142,7 @@ public extension CareKitEssentialView {
// If the event has already been completed
guard var currentOutcome = event.outcome else {
// Create a new outcome with the new values.
let outcome = try createOutcomeWithValues(
let outcome = createOutcomeWithValues(
values,
event: event,
store: store
Expand All @@ -155,35 +155,28 @@ public extension CareKitEssentialView {
_ = try await store.updateAnyOutcome(currentOutcome)
}

static func eventQuery(
with taskIDs: [String],
on date: Date
) -> OCKEventQuery {
var query = OCKEventQuery(for: date)
query.taskIDs = taskIDs
return query
}
}

extension CareKitEssentialView {

/// Create an outcome for an event with the given outcome values.
/// - Parameters:
/// - values: The outcome values to attach to the outcome.
func createOutcomeWithValues(
_ values: [OCKOutcomeValue],
event: OCKAnyEvent,
store: OCKAnyStoreProtocol
) throws -> OCKAnyOutcome {
guard let task = event.task as? OCKAnyVersionableTask else {
throw CareKitEssentialsError.errorString("Cannot make outcome for event: \(event)")
}
) -> OCKAnyOutcome {
let outcome = OCKOutcome(
taskUUID: task.uuid,
taskUUID: event.task.uuid ,
taskOccurrenceIndex: event.scheduleEvent.occurrence,
values: values
)
return outcome
}

static func eventQuery(
with taskIDs: [String],
on date: Date
) -> OCKEventQuery {
var query = OCKEventQuery(for: date)
query.taskIDs = taskIDs
return query
}
}

0 comments on commit af63e18

Please sign in to comment.