From 0ea4249b65c34e33d889692be2d48f673f9ff122 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Mon, 2 Sep 2019 09:20:41 -0500 Subject: [PATCH] Set showAfter to 0 for immediately recurring requests (#26) --- src/MyPrayerJournal.Api/Handlers.fs | 21 ++++++++----------- src/app/src/components/common/Navigation.vue | 2 +- .../components/request/RequestListItem.vue | 2 +- src/app/src/store/index.js | 10 +++++---- src/migrate/Program.fs | 9 +++++--- src/migrate/migrate.fsproj | 4 ++-- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/MyPrayerJournal.Api/Handlers.fs b/src/MyPrayerJournal.Api/Handlers.fs index bdc6a0d..b07c59f 100644 --- a/src/MyPrayerJournal.Api/Handlers.fs +++ b/src/MyPrayerJournal.Api/Handlers.fs @@ -126,13 +126,6 @@ module Models = recurCount : int16 } - /// Reset the "showAfter" property on a request - [] - type Show = - { /// The time after which the request should appear - showAfter : int64 - } - /// The time until which a request should not appear in the journal [] type SnoozeUntil = @@ -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 = [ @@ -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 @@ -292,8 +288,7 @@ module Request = let reqId = toReqId requestId match! Data.tryRequestById reqId usrId sess with | Some _ -> - let! show = ctx.BindJsonAsync () - 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 @@ -327,7 +322,9 @@ module Request = match! Data.tryRequestById reqId usrId sess with | Some _ -> let! recur = ctx.BindJsonAsync () - 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 diff --git a/src/app/src/components/common/Navigation.vue b/src/app/src/components/common/Navigation.vue index b4b4a68..fdf251f 100644 --- a/src/app/src/components/common/Navigation.vue +++ b/src/app/src/components/common/Navigation.vue @@ -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') } } } diff --git a/src/app/src/components/request/RequestListItem.vue b/src/app/src/components/request/RequestListItem.vue index f081e5a..9edbcce 100644 --- a/src/app/src/components/request/RequestListItem.vue +++ b/src/app/src/components/request/RequestListItem.vue @@ -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') diff --git a/src/app/src/store/index.js b/src/app/src/store/index.js index 4a4a06b..9b06795 100644 --- a/src/app/src/store/index.js +++ b/src/app/src/store/index.js @@ -1,6 +1,6 @@ 'use strict' -/* eslint-disable */ +/* eslint-disable no-multi-spaces */ import Vue from 'vue' import Vuex from 'vuex' @@ -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 @@ -39,7 +40,7 @@ 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 { @@ -47,6 +48,7 @@ const setBearer = async function () { } } } +/* eslint-enable no-console */ export default new Vuex.Store({ state: { @@ -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) } }, diff --git a/src/migrate/Program.fs b/src/migrate/Program.fs index e08a33b..093938c 100644 --- a/src/migrate/Program.fs +++ b/src/migrate/Program.fs @@ -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 + [] let main argv = let raven = new DocumentStore (Urls = [| "http://localhost:8080" |], Database = "myPrayerJournal") diff --git a/src/migrate/migrate.fsproj b/src/migrate/migrate.fsproj index 408f4a0..9067baa 100644 --- a/src/migrate/migrate.fsproj +++ b/src/migrate/migrate.fsproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0 + netcoreapp2.2 @@ -10,7 +10,7 @@ - +