2019-07-14 03:55:53 +00:00
|
|
|
[<AutoOpen>]
|
|
|
|
/// The data model for myPrayerJournal
|
|
|
|
module MyPrayerJournal.Domain
|
|
|
|
|
2019-08-09 22:00:09 +00:00
|
|
|
open Cuid
|
2019-07-14 03:55:53 +00:00
|
|
|
|
|
|
|
/// Request ID is a CUID
|
|
|
|
type RequestId =
|
|
|
|
| RequestId of Cuid
|
2019-07-28 01:02:01 +00:00
|
|
|
module RequestId =
|
2019-07-14 03:55:53 +00:00
|
|
|
/// The string representation of the request ID
|
2019-07-28 01:02:01 +00:00
|
|
|
let toString x = match x with RequestId y -> (Cuid.toString >> sprintf "Requests/%s") y
|
2019-07-14 03:55:53 +00:00
|
|
|
/// Create a request ID from a string representation
|
2019-07-28 01:02:01 +00:00
|
|
|
let fromIdString (y : string) = (Cuid >> RequestId) <| y.Replace("Requests/", "")
|
2019-07-14 03:55:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// User ID is a string (the "sub" part of the JWT)
|
|
|
|
type UserId =
|
|
|
|
| UserId of string
|
2019-07-28 01:02:01 +00:00
|
|
|
module UserId =
|
2019-07-14 03:55:53 +00:00
|
|
|
/// The string representation of the user ID
|
2019-07-28 01:02:01 +00:00
|
|
|
let toString x = match x with UserId y -> y
|
2019-07-14 03:55:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// A long integer representing seconds since the epoch
|
|
|
|
type Ticks =
|
|
|
|
| Ticks of int64
|
2019-07-28 01:02:01 +00:00
|
|
|
module Ticks =
|
2019-07-14 03:55:53 +00:00
|
|
|
/// The int64 (long) representation of ticks
|
2019-07-28 01:02:01 +00:00
|
|
|
let toLong x = match x with Ticks y -> y
|
2019-07-14 03:55:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// How frequently a request should reappear after it is marked "Prayed"
|
|
|
|
type Recurrence =
|
|
|
|
| Immediate
|
|
|
|
| Hours
|
|
|
|
| Days
|
|
|
|
| Weeks
|
2019-07-28 01:02:01 +00:00
|
|
|
module Recurrence =
|
2019-07-14 03:55:53 +00:00
|
|
|
/// Create a recurrence value from a string
|
2019-07-28 01:02:01 +00:00
|
|
|
let fromString x =
|
2019-07-14 03:55:53 +00:00
|
|
|
match x with
|
2019-08-01 00:13:36 +00:00
|
|
|
| "Immediate" -> Immediate
|
|
|
|
| "Hours" -> Hours
|
|
|
|
| "Days" -> Days
|
|
|
|
| "Weeks" -> Weeks
|
2019-07-14 03:55:53 +00:00
|
|
|
| _ -> invalidOp (sprintf "%s is not a valid recurrence" x)
|
2019-07-15 01:47:31 +00:00
|
|
|
/// The duration of the recurrence
|
2019-07-28 01:02:01 +00:00
|
|
|
let duration x =
|
2019-07-15 01:47:31 +00:00
|
|
|
match x with
|
|
|
|
| Immediate -> 0L
|
|
|
|
| Hours -> 3600000L
|
|
|
|
| Days -> 86400000L
|
|
|
|
| Weeks -> 604800000L
|
2019-07-14 03:55:53 +00:00
|
|
|
|
|
|
|
|
2019-07-29 01:47:11 +00:00
|
|
|
/// The action taken on a request as part of a history entry
|
|
|
|
type RequestAction =
|
|
|
|
| Created
|
|
|
|
| Prayed
|
|
|
|
| Updated
|
|
|
|
| Answered
|
|
|
|
module RequestAction =
|
|
|
|
/// Create a RequestAction from a string
|
|
|
|
let fromString x =
|
|
|
|
match x with
|
|
|
|
| "Created" -> Created
|
|
|
|
| "Prayed" -> Prayed
|
|
|
|
| "Updated" -> Updated
|
|
|
|
| "Answered" -> Answered
|
|
|
|
| _ -> (sprintf "Bad request action %s" >> invalidOp) x
|
|
|
|
|
|
|
|
|
2019-07-14 03:55:53 +00:00
|
|
|
/// History is a record of action taken on a prayer request, including updates to its text
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
|
|
|
type History =
|
|
|
|
{ /// The time when this history entry was made
|
|
|
|
asOf : Ticks
|
|
|
|
/// The status for this history entry
|
2019-07-29 01:47:11 +00:00
|
|
|
status : RequestAction
|
2019-07-14 03:55:53 +00:00
|
|
|
/// The text of the update, if applicable
|
|
|
|
text : string option
|
|
|
|
}
|
|
|
|
with
|
|
|
|
/// An empty history entry
|
|
|
|
static member empty =
|
|
|
|
{ asOf = Ticks 0L
|
2019-07-29 01:47:11 +00:00
|
|
|
status = Created
|
2019-07-14 03:55:53 +00:00
|
|
|
text = None
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Note is a note regarding a prayer request that does not result in an update to its text
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
|
|
|
type Note =
|
|
|
|
{ /// The time when this note was made
|
|
|
|
asOf : Ticks
|
|
|
|
/// The text of the notes
|
|
|
|
notes : string
|
|
|
|
}
|
|
|
|
with
|
|
|
|
/// An empty note
|
|
|
|
static member empty =
|
|
|
|
{ asOf = Ticks 0L
|
|
|
|
notes = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Request is the identifying record for a prayer request
|
|
|
|
[<CLIMutable; NoComparison; NoEquality>]
|
|
|
|
type Request =
|
|
|
|
{ /// The ID of the request
|
|
|
|
Id : string
|
|
|
|
/// The time this request was initially entered
|
|
|
|
enteredOn : Ticks
|
|
|
|
/// The ID of the user to whom this request belongs ("sub" from the JWT)
|
|
|
|
userId : UserId
|
|
|
|
/// The time at which this request should reappear in the user's journal by manual user choice
|
|
|
|
snoozedUntil : Ticks
|
|
|
|
/// The time at which this request should reappear in the user's journal by recurrence
|
|
|
|
showAfter : Ticks
|
|
|
|
/// The type of recurrence for this request
|
|
|
|
recurType : Recurrence
|
|
|
|
/// How many of the recurrence intervals should occur between appearances in the journal
|
|
|
|
recurCount : int16
|
|
|
|
/// The history entries for this request
|
|
|
|
history : History list
|
|
|
|
/// The notes for this request
|
|
|
|
notes : Note list
|
|
|
|
}
|
|
|
|
with
|
|
|
|
/// An empty request
|
|
|
|
static member empty =
|
|
|
|
{ Id = ""
|
|
|
|
enteredOn = Ticks 0L
|
|
|
|
userId = UserId ""
|
|
|
|
snoozedUntil = Ticks 0L
|
|
|
|
showAfter = Ticks 0L
|
|
|
|
recurType = Immediate
|
|
|
|
recurCount = 0s
|
|
|
|
history = []
|
|
|
|
notes = []
|
|
|
|
}
|
|
|
|
|
|
|
|
/// JournalRequest is the form of a prayer request returned for the request journal display. It also contains
|
2019-07-31 04:56:34 +00:00
|
|
|
/// properties that may be filled for history and notes.
|
|
|
|
// RavenDB doesn't like the "@"-suffixed properties from record types in a ProjectInto clause
|
|
|
|
[<NoComparison; NoEquality>]
|
|
|
|
type JournalRequest () =
|
2019-08-01 00:13:36 +00:00
|
|
|
/// The ID of the request (just the CUID part)
|
|
|
|
[<DefaultValue>] val mutable requestId : string
|
2019-07-31 04:56:34 +00:00
|
|
|
/// The ID of the user to whom the request belongs
|
|
|
|
[<DefaultValue>] val mutable userId : UserId
|
|
|
|
/// The current text of the request
|
|
|
|
[<DefaultValue>] val mutable text : string
|
|
|
|
/// The last time action was taken on the request
|
|
|
|
[<DefaultValue>] val mutable asOf : Ticks
|
|
|
|
/// The last status for the request
|
|
|
|
[<DefaultValue>] val mutable lastStatus : string
|
|
|
|
/// The time that this request should reappear in the user's journal
|
|
|
|
[<DefaultValue>] val mutable snoozedUntil : Ticks
|
|
|
|
/// The time after which this request should reappear in the user's journal by configured recurrence
|
|
|
|
[<DefaultValue>] val mutable showAfter : Ticks
|
|
|
|
/// The type of recurrence for this request
|
|
|
|
[<DefaultValue>] val mutable recurType : Recurrence
|
|
|
|
/// How many of the recurrence intervals should occur between appearances in the journal
|
|
|
|
[<DefaultValue>] val mutable recurCount : int16
|
|
|
|
/// History entries for the request
|
|
|
|
[<DefaultValue>] val mutable history : History list
|
|
|
|
/// Note entries for the request
|
|
|
|
[<DefaultValue>] val mutable notes : Note list
|