Fix granting extra time for another day after task completion

This commit is contained in:
Jonas Lochmann
2022-01-03 01:00:00 +01:00
parent 54faa8cef3
commit 48d7d83db3
11 changed files with 123 additions and 12 deletions
+16 -4
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
* Copyright (C) 2019 - 2022 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
@@ -24,11 +24,13 @@ export class ReviewChildTaskAction extends ParentAction {
readonly taskId: string
readonly ok: boolean
readonly time: number
readonly day?: number
constructor ({ taskId, ok, time }: {
constructor ({ taskId, ok, time, day }: {
taskId: string
ok: boolean
time: number
day?: number
}) {
super()
@@ -39,13 +41,22 @@ export class ReviewChildTaskAction extends ParentAction {
throwOutOfRange({ actionType, field: 'time', value: time })
}
if (day !== undefined) {
assertSafeInteger({ actionType, field: 'day', value: day })
if (day < 0) {
throwOutOfRange({ actionType, field: 'day', value: day })
}
}
this.taskId = taskId
this.ok = ok
this.time = time
this.day = day
}
static parse = ({ taskId, ok, time }: SerializedReviewChildTaskAction) => (
new ReviewChildTaskAction({ taskId, ok, time })
static parse = ({ taskId, ok, time, day }: SerializedReviewChildTaskAction) => (
new ReviewChildTaskAction({ taskId, ok, time, day })
)
}
@@ -54,4 +65,5 @@ export interface SerializedReviewChildTaskAction {
taskId: string
ok: boolean
time: number
day?: number
}
+3
View File
@@ -589,6 +589,9 @@ const definitions = {
},
"time": {
"type": "number"
},
"day": {
"type": "number"
}
},
"additionalProperties": false,
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
* Copyright (C) 2019 - 2022 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
@@ -60,10 +60,13 @@ export async function dispatchReviewChildTaskAction ({ action, cache }: {
extraTimeDay: categoryInfoUnsafe.extraTimeDay
}
if (categoryInfo.extraTimeDay !== 0 && categoryInfo.extraTimeInMillis > 0) {
// if the current time is daily, then extend the daily time only
const resetDayBoundExtraTime = categoryInfo.extraTimeDay !== -1 &&
action.day !== undefined && categoryInfo.extraTimeDay !== action.day
if (resetDayBoundExtraTime) {
await cache.database.category.update({
extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration
extraTimeInMillis: taskInfo.extraTimeDuration,
extraTimeDay: -1
}, {
where: {
familyId: cache.familyId,
@@ -73,8 +76,7 @@ export async function dispatchReviewChildTaskAction ({ action, cache }: {
})
} else {
await cache.database.category.update({
extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration,
extraTimeDay: -1
extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration
}, {
where: {
familyId: cache.familyId,
@@ -44,7 +44,7 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI
familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0
),
message: await getStatusMessage({ database, transaction }) || undefined,
apiLevel: 1
apiLevel: 2
}
if (familyEntry.deviceListVersion !== clientStatus.devices) {