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
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
11 changed files with 123 additions and 12 deletions

View file

@ -640,6 +640,9 @@
}, },
"time": { "time": {
"type": "number" "type": "number"
},
"day": {
"type": "number"
} }
}, },
"additionalProperties": false, "additionalProperties": false,

View file

@ -54,10 +54,14 @@
}, },
"message": { "message": {
"type": "string" "type": "string"
},
"apiLevel": {
"type": "number"
} }
}, },
"additionalProperties": false, "additionalProperties": false,
"required": [ "required": [
"apiLevel",
"fullVersion" "fullVersion"
], ],
"definitions": { "definitions": {

View file

@ -0,0 +1,15 @@
# Untitled number in SerializedParentAction Schema
```txt
https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/day
```
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :----------------------------------------------------------------------------------------------- |
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedParentAction.schema.json*](SerializedParentAction.schema.json "open original schema") |
## day Type
`number`

View file

@ -22,6 +22,7 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTa
| [taskId](#taskid) | `string` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-taskid.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/taskId") | | [taskId](#taskid) | `string` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-taskid.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/taskId") |
| [ok](#ok) | `boolean` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-ok.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/ok") | | [ok](#ok) | `boolean` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-ok.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/ok") |
| [time](#time) | `number` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-time.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/time") | | [time](#time) | `number` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-time.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/time") |
| [day](#day) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-day.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/day") |
## type ## type
@ -102,3 +103,21 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTa
### time Type ### time Type
`number` `number`
## day
`day`
* is optional
* Type: `number`
* cannot be null
* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-day.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/day")
### day Type
`number`

View file

@ -1791,6 +1791,7 @@ Reference this group by using
| [taskId](#taskid-1) | `string` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-taskid.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/taskId") | | [taskId](#taskid-1) | `string` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-taskid.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/taskId") |
| [ok](#ok) | `boolean` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-ok.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/ok") | | [ok](#ok) | `boolean` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-ok.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/ok") |
| [time](#time-1) | `number` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-time.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/time") | | [time](#time-1) | `number` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-time.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/time") |
| [day](#day-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-day.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/day") |
### type ### type
@ -1872,6 +1873,24 @@ Reference this group by using
`number` `number`
### day
`day`
* is optional
* Type: `number`
* cannot be null
* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-day.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/day")
#### day Type
`number`
## Definitions group SerializedSetCategoryExtraTimeAction ## Definitions group SerializedSetCategoryExtraTimeAction
Reference this group by using Reference this group by using
@ -1885,7 +1904,7 @@ Reference this group by using
| [type](#type-16) | `string` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedsetcategoryextratimeaction-properties-type.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedSetCategoryExtraTimeAction/properties/type") | | [type](#type-16) | `string` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedsetcategoryextratimeaction-properties-type.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedSetCategoryExtraTimeAction/properties/type") |
| [categoryId](#categoryid-8) | `string` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedsetcategoryextratimeaction-properties-categoryid.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedSetCategoryExtraTimeAction/properties/categoryId") | | [categoryId](#categoryid-8) | `string` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedsetcategoryextratimeaction-properties-categoryid.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedSetCategoryExtraTimeAction/properties/categoryId") |
| [newExtraTime](#newextratime) | `number` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedsetcategoryextratimeaction-properties-newextratime.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedSetCategoryExtraTimeAction/properties/newExtraTime") | | [newExtraTime](#newextratime) | `number` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedsetcategoryextratimeaction-properties-newextratime.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedSetCategoryExtraTimeAction/properties/newExtraTime") |
| [day](#day-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedsetcategoryextratimeaction-properties-day.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedSetCategoryExtraTimeAction/properties/day") | | [day](#day-2) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedsetcategoryextratimeaction-properties-day.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedSetCategoryExtraTimeAction/properties/day") |
### type ### type

View file

@ -0,0 +1,15 @@
# Untitled number in ServerDataStatus Schema
```txt
https://timelimit.io/ServerDataStatus#/properties/apiLevel
```
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :----------------------------------------------------------------------------------- |
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [ServerDataStatus.schema.json*](ServerDataStatus.schema.json "open original schema") |
## apiLevel Type
`number`

View file

@ -29,6 +29,7 @@ https://timelimit.io/ServerDataStatus
| [users](#users) | `object` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serveruserlist.md "https://timelimit.io/ServerDataStatus#/properties/users") | | [users](#users) | `object` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serveruserlist.md "https://timelimit.io/ServerDataStatus#/properties/users") |
| [fullVersion](#fullversion) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-properties-fullversion.md "https://timelimit.io/ServerDataStatus#/properties/fullVersion") | | [fullVersion](#fullversion) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-properties-fullversion.md "https://timelimit.io/ServerDataStatus#/properties/fullVersion") |
| [message](#message) | `string` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-properties-message.md "https://timelimit.io/ServerDataStatus#/properties/message") | | [message](#message) | `string` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-properties-message.md "https://timelimit.io/ServerDataStatus#/properties/message") |
| [apiLevel](#apilevel) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-properties-apilevel.md "https://timelimit.io/ServerDataStatus#/properties/apiLevel") |
## devices ## devices
@ -228,6 +229,24 @@ https://timelimit.io/ServerDataStatus
`string` `string`
## apiLevel
`apiLevel`
* is required
* Type: `number`
* cannot be null
* defined in: [ServerDataStatus](serverdatastatus-properties-apilevel.md "https://timelimit.io/ServerDataStatus#/properties/apiLevel")
### apiLevel Type
`number`
# ServerDataStatus Definitions # ServerDataStatus Definitions
## Definitions group ServerDeviceList ## Definitions group ServerDeviceList

View file

@ -1,6 +1,6 @@
/* /*
* server component for the TimeLimit App * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * 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 taskId: string
readonly ok: boolean readonly ok: boolean
readonly time: number readonly time: number
readonly day?: number
constructor ({ taskId, ok, time }: { constructor ({ taskId, ok, time, day }: {
taskId: string taskId: string
ok: boolean ok: boolean
time: number time: number
day?: number
}) { }) {
super() super()
@ -39,13 +41,22 @@ export class ReviewChildTaskAction extends ParentAction {
throwOutOfRange({ actionType, field: 'time', value: time }) 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.taskId = taskId
this.ok = ok this.ok = ok
this.time = time this.time = time
this.day = day
} }
static parse = ({ taskId, ok, time }: SerializedReviewChildTaskAction) => ( static parse = ({ taskId, ok, time, day }: SerializedReviewChildTaskAction) => (
new ReviewChildTaskAction({ taskId, ok, time }) new ReviewChildTaskAction({ taskId, ok, time, day })
) )
} }
@ -54,4 +65,5 @@ export interface SerializedReviewChildTaskAction {
taskId: string taskId: string
ok: boolean ok: boolean
time: number time: number
day?: number
} }

View file

@ -589,6 +589,9 @@ const definitions = {
}, },
"time": { "time": {
"type": "number" "type": "number"
},
"day": {
"type": "number"
} }
}, },
"additionalProperties": false, "additionalProperties": false,

View file

@ -1,6 +1,6 @@
/* /*
* server component for the TimeLimit App * 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 * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * 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 extraTimeDay: categoryInfoUnsafe.extraTimeDay
} }
if (categoryInfo.extraTimeDay !== 0 && categoryInfo.extraTimeInMillis > 0) { const resetDayBoundExtraTime = categoryInfo.extraTimeDay !== -1 &&
// if the current time is daily, then extend the daily time only action.day !== undefined && categoryInfo.extraTimeDay !== action.day
if (resetDayBoundExtraTime) {
await cache.database.category.update({ await cache.database.category.update({
extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration extraTimeInMillis: taskInfo.extraTimeDuration,
extraTimeDay: -1
}, { }, {
where: { where: {
familyId: cache.familyId, familyId: cache.familyId,
@ -73,8 +76,7 @@ export async function dispatchReviewChildTaskAction ({ action, cache }: {
}) })
} else { } else {
await cache.database.category.update({ await cache.database.category.update({
extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration, extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration
extraTimeDay: -1
}, { }, {
where: { where: {
familyId: cache.familyId, familyId: cache.familyId,

View file

@ -44,7 +44,7 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI
familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0 familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0
), ),
message: await getStatusMessage({ database, transaction }) || undefined, message: await getStatusMessage({ database, transaction }) || undefined,
apiLevel: 1 apiLevel: 2
} }
if (familyEntry.deviceListVersion !== clientStatus.devices) { if (familyEntry.deviceListVersion !== clientStatus.devices) {