From 48d7d83db339f03f8eaf0b3578f23e95c1554742 Mon Sep 17 00:00:00 2001 From: Jonas Lochmann Date: Mon, 3 Jan 2022 01:00:00 +0100 Subject: [PATCH] Fix granting extra time for another day after task completion --- .../schema/SerializedParentAction.schema.json | 3 +++ docs/schema/ServerDataStatus.schema.json | 4 ++++ ...zedreviewchildtaskaction-properties-day.md | 15 +++++++++++++ ...nitions-serializedreviewchildtaskaction.md | 19 +++++++++++++++++ docs/schema/serializedparentaction.md | 21 ++++++++++++++++++- .../serverdatastatus-properties-apilevel.md | 15 +++++++++++++ docs/schema/serverdatastatus.md | 19 +++++++++++++++++ src/action/reviewchildtaskaction.ts | 20 ++++++++++++++---- src/api/validator.ts | 3 +++ .../reviewchildtaskaction.ts | 14 +++++++------ .../sync/get-server-data-status/index.ts | 2 +- 11 files changed, 123 insertions(+), 12 deletions(-) create mode 100644 docs/schema/serializedparentaction-definitions-serializedreviewchildtaskaction-properties-day.md create mode 100644 docs/schema/serverdatastatus-properties-apilevel.md diff --git a/docs/schema/SerializedParentAction.schema.json b/docs/schema/SerializedParentAction.schema.json index 110417f..87f0346 100644 --- a/docs/schema/SerializedParentAction.schema.json +++ b/docs/schema/SerializedParentAction.schema.json @@ -640,6 +640,9 @@ }, "time": { "type": "number" + }, + "day": { + "type": "number" } }, "additionalProperties": false, diff --git a/docs/schema/ServerDataStatus.schema.json b/docs/schema/ServerDataStatus.schema.json index 50e9bf1..6745fb7 100644 --- a/docs/schema/ServerDataStatus.schema.json +++ b/docs/schema/ServerDataStatus.schema.json @@ -54,10 +54,14 @@ }, "message": { "type": "string" + }, + "apiLevel": { + "type": "number" } }, "additionalProperties": false, "required": [ + "apiLevel", "fullVersion" ], "definitions": { diff --git a/docs/schema/serializedparentaction-definitions-serializedreviewchildtaskaction-properties-day.md b/docs/schema/serializedparentaction-definitions-serializedreviewchildtaskaction-properties-day.md new file mode 100644 index 0000000..8819b04 --- /dev/null +++ b/docs/schema/serializedparentaction-definitions-serializedreviewchildtaskaction-properties-day.md @@ -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` diff --git a/docs/schema/serializedparentaction-definitions-serializedreviewchildtaskaction.md b/docs/schema/serializedparentaction-definitions-serializedreviewchildtaskaction.md index 45f3206..71a6aaa 100644 --- a/docs/schema/serializedparentaction-definitions-serializedreviewchildtaskaction.md +++ b/docs/schema/serializedparentaction-definitions-serializedreviewchildtaskaction.md @@ -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") | | [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") | +| [day](#day) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-day.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/day") | ## type @@ -102,3 +103,21 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTa ### time Type `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` diff --git a/docs/schema/serializedparentaction.md b/docs/schema/serializedparentaction.md index 26fa488..505891d 100644 --- a/docs/schema/serializedparentaction.md +++ b/docs/schema/serializedparentaction.md @@ -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") | | [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") | +| [day](#day-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedreviewchildtaskaction-properties-day.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedReviewChildTaskAction/properties/day") | ### type @@ -1872,6 +1873,24 @@ Reference this group by using `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 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") | | [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") | -| [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 diff --git a/docs/schema/serverdatastatus-properties-apilevel.md b/docs/schema/serverdatastatus-properties-apilevel.md new file mode 100644 index 0000000..9d07d88 --- /dev/null +++ b/docs/schema/serverdatastatus-properties-apilevel.md @@ -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` diff --git a/docs/schema/serverdatastatus.md b/docs/schema/serverdatastatus.md index 22b9657..7e35768 100644 --- a/docs/schema/serverdatastatus.md +++ b/docs/schema/serverdatastatus.md @@ -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") | | [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") | +| [apiLevel](#apilevel) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-properties-apilevel.md "https://timelimit.io/ServerDataStatus#/properties/apiLevel") | ## devices @@ -228,6 +229,24 @@ https://timelimit.io/ServerDataStatus `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 ## Definitions group ServerDeviceList diff --git a/src/action/reviewchildtaskaction.ts b/src/action/reviewchildtaskaction.ts index fc61d39..2389505 100644 --- a/src/action/reviewchildtaskaction.ts +++ b/src/action/reviewchildtaskaction.ts @@ -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 } diff --git a/src/api/validator.ts b/src/api/validator.ts index b7ed729..3bc8b06 100644 --- a/src/api/validator.ts +++ b/src/api/validator.ts @@ -589,6 +589,9 @@ const definitions = { }, "time": { "type": "number" + }, + "day": { + "type": "number" } }, "additionalProperties": false, diff --git a/src/function/sync/apply-actions/dispatch-parent-action/reviewchildtaskaction.ts b/src/function/sync/apply-actions/dispatch-parent-action/reviewchildtaskaction.ts index c338bf2..30b382b 100644 --- a/src/function/sync/apply-actions/dispatch-parent-action/reviewchildtaskaction.ts +++ b/src/function/sync/apply-actions/dispatch-parent-action/reviewchildtaskaction.ts @@ -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, diff --git a/src/function/sync/get-server-data-status/index.ts b/src/function/sync/get-server-data-status/index.ts index e8bb2cb..a2ddd25 100644 --- a/src/function/sync/get-server-data-status/index.ts +++ b/src/function/sync/get-server-data-status/index.ts @@ -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) {