Set showAfter to 0 for immediately recurring requests (#26)
This commit is contained in:
		
							parent
							
								
									7e08d7375f
								
							
						
					
					
						commit
						0ea4249b65
					
				| @ -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 = | ||||
| @ -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<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 | ||||
| @ -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 | ||||
|  | ||||
| @ -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') | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -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') | ||||
|  | ||||
| @ -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) | ||||
|       } | ||||
|     }, | ||||
|  | ||||
| @ -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") | ||||
|  | ||||
| @ -2,7 +2,7 @@ | ||||
| 
 | ||||
|   <PropertyGroup> | ||||
|     <OutputType>Exe</OutputType> | ||||
|     <TargetFramework>netcoreapp3.0</TargetFramework> | ||||
|     <TargetFramework>netcoreapp2.2</TargetFramework> | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
| @ -10,7 +10,7 @@ | ||||
|   </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" /> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user