mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add support for extra time for a specific day
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user