F# API #18
@ -37,8 +37,6 @@ module Entities =
|
||||
status : string
|
||||
/// The text of the update, if applicable
|
||||
text : string option
|
||||
/// The request to which this history entry applies
|
||||
request : Request
|
||||
}
|
||||
with
|
||||
/// An empty history entry
|
||||
@ -47,7 +45,6 @@ module Entities =
|
||||
asOf = 0L
|
||||
status = ""
|
||||
text = None
|
||||
request = Request.empty
|
||||
}
|
||||
|
||||
static member configureEF (mb : ModelBuilder) =
|
||||
@ -58,11 +55,7 @@ module Entities =
|
||||
m.Property(fun e -> e.requestId).IsRequired () |> ignore
|
||||
m.Property(fun e -> e.asOf).IsRequired () |> ignore
|
||||
m.Property(fun e -> e.status).IsRequired() |> ignore
|
||||
m.Property(fun e -> e.text) |> ignore
|
||||
m.HasOne(fun e -> e.request)
|
||||
.WithMany(fun r -> r.history :> IEnumerable<History>)
|
||||
.HasForeignKey(fun e -> e.requestId :> obj)
|
||||
|> ignore)
|
||||
m.Property(fun e -> e.text) |> ignore)
|
||||
|> ignore
|
||||
let typ = mb.Model.FindEntityType(typeof<History>)
|
||||
let prop = typ.FindProperty("text")
|
||||
@ -76,8 +69,6 @@ module Entities =
|
||||
asOf : int64
|
||||
/// The text of the notes
|
||||
notes : string
|
||||
/// The request to which this note applies
|
||||
request : Request
|
||||
}
|
||||
with
|
||||
/// An empty note
|
||||
@ -85,7 +76,6 @@ module Entities =
|
||||
{ requestId = ""
|
||||
asOf = 0L
|
||||
notes = ""
|
||||
request = Request.empty
|
||||
}
|
||||
|
||||
static member configureEF (mb : ModelBuilder) =
|
||||
@ -95,11 +85,7 @@ module Entities =
|
||||
m.HasKey ("requestId", "asOf") |> ignore
|
||||
m.Property(fun e -> e.requestId).IsRequired () |> ignore
|
||||
m.Property(fun e -> e.asOf).IsRequired () |> ignore
|
||||
m.Property(fun e -> e.notes).IsRequired () |> ignore
|
||||
m.HasOne(fun e -> e.request)
|
||||
.WithMany(fun r -> r.notes :> IEnumerable<Note>)
|
||||
.HasForeignKey(fun e -> e.requestId :> obj)
|
||||
|> ignore)
|
||||
m.Property(fun e -> e.notes).IsRequired () |> ignore)
|
||||
|> ignore
|
||||
|
||||
// Request is the identifying record for a prayer request.
|
||||
@ -136,7 +122,15 @@ module Entities =
|
||||
m.Property(fun e -> e.requestId).IsRequired () |> ignore
|
||||
m.Property(fun e -> e.enteredOn).IsRequired () |> ignore
|
||||
m.Property(fun e -> e.userId).IsRequired () |> ignore
|
||||
m.Property(fun e -> e.snoozedUntil).IsRequired () |> ignore)
|
||||
m.Property(fun e -> e.snoozedUntil).IsRequired () |> ignore
|
||||
m.HasMany(fun e -> e.history :> IEnumerable<History>)
|
||||
.WithOne()
|
||||
.HasForeignKey(fun e -> e.requestId :> obj)
|
||||
|> ignore
|
||||
m.HasMany(fun e -> e.notes :> IEnumerable<Note>)
|
||||
.WithOne()
|
||||
.HasForeignKey(fun e -> e.requestId :> obj)
|
||||
|> ignore)
|
||||
|> ignore
|
||||
|
||||
/// JournalRequest is the form of a prayer request returned for the request journal display. It also contains
|
||||
@ -230,7 +224,7 @@ type AppDbContext (opts : DbContextOptions<AppDbContext>) =
|
||||
member this.JournalByUserId userId : JournalRequest seq =
|
||||
upcast this.Journal
|
||||
.Where(fun r -> r.userId = userId && r.lastStatus <> "Answered")
|
||||
.OrderByDescending(fun r -> r.asOf)
|
||||
.OrderBy(fun r -> r.asOf)
|
||||
|
||||
/// Retrieve a request by its ID and user ID
|
||||
member this.TryRequestById reqId userId : Task<Request option> =
|
||||
|
@ -54,7 +54,7 @@ module private Helpers =
|
||||
|
||||
/// The "now" time in JavaScript
|
||||
let jsNow () =
|
||||
DateTime.Now.Subtract(DateTime (1970, 1, 1)).TotalSeconds |> int64 |> (*) 1000L
|
||||
DateTime.UtcNow.Subtract(DateTime (1970, 1, 1, 0, 0, 0)).TotalSeconds |> int64 |> (*) 1000L
|
||||
|
||||
/// Handler to return a 403 Not Authorized reponse
|
||||
let notAuthorized : HttpHandler =
|
||||
@ -102,6 +102,7 @@ module Models =
|
||||
until : int64
|
||||
}
|
||||
|
||||
|
||||
/// /api/journal URLs
|
||||
module Journal =
|
||||
|
||||
@ -206,7 +207,7 @@ module Request =
|
||||
authorize
|
||||
>=> fun next ctx ->
|
||||
task {
|
||||
let! req = (db ctx).TryRequestById reqId (userId ctx)
|
||||
let! req = (db ctx).TryJournalById reqId (userId ctx)
|
||||
match req with
|
||||
| Some r -> return! json r next ctx
|
||||
| None -> return! Error.notFound next ctx
|
||||
|
@ -10,6 +10,7 @@ article
|
||||
b-table(small hover :fields='fields' :items='log')
|
||||
template(slot='action' scope='data').
|
||||
{{ data.item.status }} on #[span.text-nowrap {{ formatDate(data.item.asOf) }}]
|
||||
template(slot='text' scope='data' v-if='data.item.text') {{ data.item.text.fields[0] }}
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@ -44,12 +45,12 @@ export default {
|
||||
},
|
||||
lastText () {
|
||||
return this.request.history
|
||||
.filter(hist => hist.text > '')
|
||||
.sort(asOfDesc)[0].text
|
||||
.filter(hist => hist.text)
|
||||
.sort(asOfDesc)[0].text.fields[0]
|
||||
},
|
||||
log () {
|
||||
return (this.request.notes || [])
|
||||
.map(note => ({ asOf: note.asOf, text: note.notes, status: 'Notes' }))
|
||||
.map(note => ({ asOf: note.asOf, text: { case: 'Some', fields: [ note.notes ] }, status: 'Notes' }))
|
||||
.concat(this.request.history)
|
||||
.sort(asOfDesc)
|
||||
.slice(1)
|
||||
|
@ -2,8 +2,8 @@
|
||||
b-list-group-item
|
||||
| {{ history.status }}
|
||||
|
|
||||
small.text-muted {{ asOf }}
|
||||
div(v-if='hasText').mpj-request-text {{ history.text }}
|
||||
small.text-muted(:title='actualDate') {{ asOf }}
|
||||
div(v-if='history.text').mpj-request-text {{ history.text.fields[0] }}
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@ -20,8 +20,8 @@ export default {
|
||||
asOf () {
|
||||
return moment(this.history.asOf).fromNow()
|
||||
},
|
||||
hasText () {
|
||||
return this.history.text.length > 0
|
||||
actualDate () {
|
||||
return moment(this.history.asOf).format('LLLL')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user