Add support for extra time for a specific day

This commit is contained in:
Jonas Lochmann
2020-03-02 01:00:00 +01:00
parent af17e6cc8e
commit 0ecb7e4830
10 changed files with 121 additions and 46 deletions
+13 -5
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -21,8 +21,9 @@ import { ParentAction } from './basetypes'
export class IncrementCategoryExtraTimeAction extends ParentAction {
readonly categoryId: string
readonly addedExtraTime: number
readonly day: number
constructor ({ categoryId, addedExtraTime }: {categoryId: string, addedExtraTime: number}) {
constructor ({ categoryId, addedExtraTime, day }: {categoryId: string, addedExtraTime: number, day: number}) {
super()
assertIdWithinFamily(categoryId)
@@ -31,18 +32,24 @@ export class IncrementCategoryExtraTimeAction extends ParentAction {
throw new Error('must add some extra time with IncrementCategoryExtraTimeAction')
}
if (day < -1 || (!Number.isSafeInteger(day))) {
throw Error('day must be valid')
}
this.categoryId = categoryId
this.addedExtraTime = addedExtraTime
this.day = day
}
serialize = (): SerializedIncrementCategoryExtraTimeAction => ({
type: 'INCREMENT_CATEGORY_EXTRATIME',
categoryId: this.categoryId,
addedExtraTime: this.addedExtraTime
addedExtraTime: this.addedExtraTime,
day: this.day
})
static parse = ({ categoryId, addedExtraTime }: SerializedIncrementCategoryExtraTimeAction) => (
new IncrementCategoryExtraTimeAction({ categoryId, addedExtraTime })
static parse = ({ categoryId, addedExtraTime, day }: SerializedIncrementCategoryExtraTimeAction) => (
new IncrementCategoryExtraTimeAction({ categoryId, addedExtraTime, day: day ?? -1 })
)
}
@@ -50,4 +57,5 @@ export interface SerializedIncrementCategoryExtraTimeAction {
type: 'INCREMENT_CATEGORY_EXTRATIME'
categoryId: string
addedExtraTime: number
day?: number
}