Skip to content

Commit

Permalink
Set showAfter to 0 for immediately recurring requests (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljsummers committed Sep 2, 2019
1 parent 7e08d73 commit 0ea4249
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
21 changes: 9 additions & 12 deletions src/MyPrayerJournal.Api/Handlers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,6 @@ module Models =
recurCount : int16
}

/// Reset the "showAfter" property on a request
[<CLIMutable>]
type Show =
{ /// The time after which the request should appear
showAfter : int64
}

/// The time until which a request should not appear in the journal
[<CLIMutable>]
type SnoozeUntil =
Expand Down Expand Up @@ -175,7 +168,7 @@ module Request =
Id = RequestId.toString reqId
userId = usrId
enteredOn = now
showAfter = now
showAfter = Ticks 0L
recurType = Recurrence.fromString r.recurType
recurCount = r.recurCount
history = [
Expand Down Expand Up @@ -211,7 +204,10 @@ module Request =
} sess
match act with
| Prayed ->
let nextShow = (Ticks.toLong now) + (Recurrence.duration req.recurType * int64 req.recurCount)
let nextShow =
match Recurrence.duration req.recurType with
| 0L -> 0L
| duration -> (Ticks.toLong now) + (duration * int64 req.recurCount)
Data.updateShowAfter reqId (Ticks nextShow) sess
| _ -> ()
do! Data.saveChanges sess
Expand Down Expand Up @@ -292,8 +288,7 @@ module Request =
let reqId = toReqId requestId
match! Data.tryRequestById reqId usrId sess with
| Some _ ->
let! show = ctx.BindJsonAsync<Models.Show> ()
Data.updateShowAfter reqId (Ticks show.showAfter) sess
Data.updateShowAfter reqId (Ticks 0L) sess
do! Data.saveChanges sess
return! setStatusCode 204 next ctx
| None -> return! Error.notFound next ctx
Expand Down Expand Up @@ -327,7 +322,9 @@ module Request =
match! Data.tryRequestById reqId usrId sess with
| Some _ ->
let! recur = ctx.BindJsonAsync<Models.Recurrence> ()
Data.updateRecurrence reqId (Recurrence.fromString recur.recurType) recur.recurCount sess
let recurrence = Recurrence.fromString recur.recurType
Data.updateRecurrence reqId recurrence recur.recurCount sess
match recurrence with Immediate -> Data.updateShowAfter reqId (Ticks 0L) sess | _ -> ()
do! Data.saveChanges sess
return! setStatusCode 204 next ctx
| None -> return! Error.notFound next ctx
Expand Down
2 changes: 1 addition & 1 deletion src/app/src/components/common/Navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default {
this.$auth.logout(this.$store, this.$router)
},
showHelp () {
window.open('https://docs.prayerjournal.me','_blank')
window.open('https://docs.prayerjournal.me', '_blank')
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/src/components/request/RequestListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default {
await this.$store.dispatch(actions.SHOW_REQUEST_NOW, {
progress: this.progress,
requestId: this.request.requestId,
showAfter: Date.now()
showAfter: 0
})
this.messages.$emit('info', 'Recurrence skipped; request now shows in journal')
this.$parent.$emit('requestNowShown')
Expand Down
10 changes: 6 additions & 4 deletions src/app/src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

/* eslint-disable */
/* eslint-disable no-multi-spaces */
import Vue from 'vue'
import Vuex from 'vuex'

Expand All @@ -9,10 +9,11 @@ import auth from '@/auth/AuthService'

import mutations from './mutation-types'
import actions from './action-types'
/* eslint-enable */
/* eslint-enable no-multi-spaces */

Vue.use(Vuex)

/* eslint-disable no-console */
const logError = function (error) {
if (error.response) {
// The request was made and the server responded with a status code
Expand All @@ -39,14 +40,15 @@ const setBearer = async function () {
try {
await auth.getAccessToken()
api.setBearer(auth.session.id.token)
} catch(err) {
} catch (err) {
if (err === 'Not logged in') {
console.warn('API request attempted when user was not logged in')
} else {
console.error(err)
}
}
}
/* eslint-enable no-console */

export default new Vuex.Store({
state: {
Expand Down Expand Up @@ -100,7 +102,7 @@ export default new Vuex.Store({
try {
await auth.getAccessToken()
commit(mutations.SET_AUTHENTICATION, auth.isAuthenticated())
} catch(_) {
} catch (_) {
commit(mutations.SET_AUTHENTICATION, false)
}
},
Expand Down
9 changes: 6 additions & 3 deletions src/migrate/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,23 @@ let migrateRequests (store : IDocumentStore) =
"""SELECT "requestId", "enteredOn", "userId", "snoozedUntil", "showAfter", "recurType", "recurCount" FROM mpj.request"""
use rdr = cmd.ExecuteReader ()
while rdr.Read () do
let reqId = rdr.getString "requestId"
let reqId = rdr.getString "requestId"
let recurrence = (rdr.getString >> Recurrence.fromString) "recurType"
sess.Store (
{ Id = (RequestId.fromIdString >> RequestId.toString) reqId
enteredOn = rdr.getTicks "enteredOn"
userId = (rdr.getString >> UserId) "userId"
snoozedUntil = rdr.getTicks "snoozedUntil"
showAfter = rdr.getTicks "showAfter"
recurType = (rdr.getString >> Recurrence.fromString) "recurType"
showAfter = match recurrence with Immediate -> Ticks 0L | _ -> rdr.getTicks "showAfter"
recurType = recurrence
recurCount = rdr.getShort "recurCount"
history = getHistory reqId
notes = getNotes reqId
})
sess.SaveChanges ()

open Converters

[<EntryPoint>]
let main argv =
let raven = new DocumentStore (Urls = [| "http://localhost:8080" |], Database = "myPrayerJournal")
Expand Down
4 changes: 2 additions & 2 deletions src/migrate/migrate.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.6.2" />
<PackageReference Include="FSharp.Core" Version="4.7.0" />
<PackageReference Include="Microsoft.FSharpLu.Json" Version="0.11.2" />
<PackageReference Include="Npgsql" Version="4.0.8" />
<PackageReference Include="RavenDb.Client" Version="4.2.2" />
Expand Down

0 comments on commit 0ea4249

Please sign in to comment.