diff --git a/docs/schema/README.md b/docs/schema/README.md
index 5a58f7e..993ad77 100644
--- a/docs/schema/README.md
+++ b/docs/schema/README.md
@@ -308,6 +308,8 @@
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategorybasedata-properties-networks.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/networks`
+* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/atw`
+
* [Untitled array in ServerDataStatus](./serverdatastatus-properties-categoryapp.md) – `https://timelimit.io/ServerDataStatus#/properties/categoryApp`
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategoryassignedapps-properties-apps.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryAssignedApps/properties/apps`
@@ -336,6 +338,8 @@
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategorybasedata-properties-networks.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/networks`
+* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/atw`
+
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategoryassignedapps-properties-apps.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryAssignedApps/properties/apps`
* [Untitled array in ServerDataStatus](./serverdatastatus-definitions-serverupdatedcategoryusedtimes-properties-times.md) – `https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryUsedTimes/properties/times`
diff --git a/docs/schema/SerializedParentAction.schema.json b/docs/schema/SerializedParentAction.schema.json
index 87f0346..4dd2902 100644
--- a/docs/schema/SerializedParentAction.schema.json
+++ b/docs/schema/SerializedParentAction.schema.json
@@ -1165,6 +1165,9 @@
},
"flags": {
"type": "number"
+ },
+ "minutes": {
+ "type": "number"
}
},
"additionalProperties": false,
diff --git a/docs/schema/ServerDataStatus.schema.json b/docs/schema/ServerDataStatus.schema.json
index 6745fb7..fbb5831 100644
--- a/docs/schema/ServerDataStatus.schema.json
+++ b/docs/schema/ServerDataStatus.schema.json
@@ -395,10 +395,17 @@
},
"blockNotificationDelay": {
"type": "number"
+ },
+ "atw": {
+ "type": "array",
+ "items": {
+ "type": "number"
+ }
}
},
"additionalProperties": false,
"required": [
+ "atw",
"blockAllNotifications",
"blockNotificationDelay",
"blockedTimes",
diff --git a/docs/schema/serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-minutes.md b/docs/schema/serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-minutes.md
new file mode 100644
index 0000000..d71f59c
--- /dev/null
+++ b/docs/schema/serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-minutes.md
@@ -0,0 +1,15 @@
+# Untitled number in SerializedParentAction Schema
+
+```txt
+https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/minutes
+```
+
+
+
+| 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") |
+
+## minutes Type
+
+`number`
diff --git a/docs/schema/serializedparentaction-definitions-serializedupdatecategorytimewarningsaction.md b/docs/schema/serializedparentaction-definitions-serializedupdatecategorytimewarningsaction.md
index 7b7701c..b0bc098 100644
--- a/docs/schema/serializedparentaction-definitions-serializedupdatecategorytimewarningsaction.md
+++ b/docs/schema/serializedparentaction-definitions-serializedupdatecategorytimewarningsaction.md
@@ -22,6 +22,7 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategor
| [categoryId](#categoryid) | `string` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-categoryid.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/categoryId") |
| [enable](#enable) | `boolean` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-enable.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/enable") |
| [flags](#flags) | `number` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-flags.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/flags") |
+| [minutes](#minutes) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-minutes.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/minutes") |
## type
@@ -102,3 +103,21 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategor
### flags Type
`number`
+
+## minutes
+
+
+
+`minutes`
+
+* is optional
+
+* Type: `number`
+
+* cannot be null
+
+* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-minutes.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/minutes")
+
+### minutes Type
+
+`number`
diff --git a/docs/schema/serializedparentaction.md b/docs/schema/serializedparentaction.md
index 505891d..66bfd57 100644
--- a/docs/schema/serializedparentaction.md
+++ b/docs/schema/serializedparentaction.md
@@ -3501,6 +3501,7 @@ Reference this group by using
| [categoryId](#categoryid-17) | `string` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-categoryid.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/categoryId") |
| [enable](#enable-2) | `boolean` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-enable.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/enable") |
| [flags](#flags) | `number` | Required | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-flags.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/flags") |
+| [minutes](#minutes) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-minutes.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/minutes") |
### type
@@ -3582,6 +3583,24 @@ Reference this group by using
`number`
+### minutes
+
+
+
+`minutes`
+
+* is optional
+
+* Type: `number`
+
+* cannot be null
+
+* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedupdatecategorytimewarningsaction-properties-minutes.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateCategoryTimeWarningsAction/properties/minutes")
+
+#### minutes Type
+
+`number`
+
## Definitions group SerializedUpdateCategoryTitleAction
Reference this group by using
diff --git a/docs/schema/serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw-items.md b/docs/schema/serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw-items.md
new file mode 100644
index 0000000..55799df
--- /dev/null
+++ b/docs/schema/serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw-items.md
@@ -0,0 +1,15 @@
+# Untitled number in ServerDataStatus Schema
+
+```txt
+https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/atw/items
+```
+
+
+
+| 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") |
+
+## items Type
+
+`number`
diff --git a/docs/schema/serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw.md b/docs/schema/serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw.md
new file mode 100644
index 0000000..f3bbc76
--- /dev/null
+++ b/docs/schema/serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw.md
@@ -0,0 +1,15 @@
+# Untitled array in ServerDataStatus Schema
+
+```txt
+https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/atw
+```
+
+
+
+| 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") |
+
+## atw Type
+
+`number[]`
diff --git a/docs/schema/serverdatastatus-definitions-serverupdatedcategorybasedata.md b/docs/schema/serverdatastatus-definitions-serverupdatedcategorybasedata.md
index dcf1bdd..8c34534 100644
--- a/docs/schema/serverdatastatus-definitions-serverupdatedcategorybasedata.md
+++ b/docs/schema/serverdatastatus-definitions-serverupdatedcategorybasedata.md
@@ -37,6 +37,7 @@ https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData
| [dlu](#dlu) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverupdatedcategorybasedata-properties-dlu.md "https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/dlu") |
| [flags](#flags) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverupdatedcategorybasedata-properties-flags.md "https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/flags") |
| [blockNotificationDelay](#blocknotificationdelay) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverupdatedcategorybasedata-properties-blocknotificationdelay.md "https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/blockNotificationDelay") |
+| [atw](#atw) | `array` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw.md "https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/atw") |
## categoryId
@@ -379,3 +380,21 @@ https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData
### blockNotificationDelay Type
`number`
+
+## atw
+
+
+
+`atw`
+
+* is required
+
+* Type: `number[]`
+
+* cannot be null
+
+* defined in: [ServerDataStatus](serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw.md "https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/atw")
+
+### atw Type
+
+`number[]`
diff --git a/docs/schema/serverdatastatus.md b/docs/schema/serverdatastatus.md
index 7e35768..f473884 100644
--- a/docs/schema/serverdatastatus.md
+++ b/docs/schema/serverdatastatus.md
@@ -1296,6 +1296,7 @@ Reference this group by using
| [dlu](#dlu) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverupdatedcategorybasedata-properties-dlu.md "https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/dlu") |
| [flags](#flags) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverupdatedcategorybasedata-properties-flags.md "https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/flags") |
| [blockNotificationDelay](#blocknotificationdelay) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverupdatedcategorybasedata-properties-blocknotificationdelay.md "https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/blockNotificationDelay") |
+| [atw](#atw) | `array` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw.md "https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/atw") |
### categoryId
@@ -1639,6 +1640,24 @@ Reference this group by using
`number`
+### atw
+
+
+
+`atw`
+
+* is required
+
+* Type: `number[]`
+
+* cannot be null
+
+* defined in: [ServerDataStatus](serverdatastatus-definitions-serverupdatedcategorybasedata-properties-atw.md "https://timelimit.io/ServerDataStatus#/definitions/ServerUpdatedCategoryBaseData/properties/atw")
+
+#### atw Type
+
+`number[]`
+
## Definitions group ServerCategoryNetworkId
Reference this group by using
diff --git a/src/action/updatecategorytimewarnings.ts b/src/action/updatecategorytimewarnings.ts
index d69583e..19abc09 100644
--- a/src/action/updatecategorytimewarnings.ts
+++ b/src/action/updatecategorytimewarnings.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
@@ -16,6 +16,7 @@
*/
import { allowedTimeWarningFlags } from '../database/category'
+import { categoryTimeWarningConstants } from '../database/categorytimewarning'
import { ParentAction } from './basetypes'
import { assertIdWithinFamily, assertSafeInteger, throwOutOfRange } from './meta/util'
@@ -25,11 +26,13 @@ export class UpdateCategoryTimeWarningsAction extends ParentAction {
readonly categoryId: string
readonly enable: boolean
readonly flags: number
+ readonly minutes?: number
- constructor ({ categoryId, enable, flags }: {
+ constructor ({ categoryId, enable, flags, minutes }: {
categoryId: string
enable: boolean
- flags: number
+ flags: number,
+ minutes?: number
}) {
super()
@@ -40,13 +43,25 @@ export class UpdateCategoryTimeWarningsAction extends ParentAction {
throwOutOfRange({ actionType, field: 'flags', value: flags })
}
+ if (minutes !== undefined) {
+ assertSafeInteger({ actionType, field: 'minutes', value: minutes })
+
+ if (
+ minutes < categoryTimeWarningConstants.minMinutes ||
+ minutes > categoryTimeWarningConstants.maxMinutes
+ ) {
+ throwOutOfRange({ actionType, field: 'minutes', value: minutes })
+ }
+ }
+
this.categoryId = categoryId
this.enable = enable
this.flags = flags
+ this.minutes = minutes
}
- static parse = ({ categoryId, enable, flags }: SerializedUpdateCategoryTimeWarningsAction) => (
- new UpdateCategoryTimeWarningsAction({ categoryId, enable, flags })
+ static parse = ({ categoryId, enable, flags, minutes }: SerializedUpdateCategoryTimeWarningsAction) => (
+ new UpdateCategoryTimeWarningsAction({ categoryId, enable, flags, minutes })
)
}
@@ -55,4 +70,5 @@ export interface SerializedUpdateCategoryTimeWarningsAction {
categoryId: string
enable: boolean
flags: number
+ minutes?: number
}
diff --git a/src/api/validator.ts b/src/api/validator.ts
index ce297eb..d77b657 100644
--- a/src/api/validator.ts
+++ b/src/api/validator.ts
@@ -1093,6 +1093,9 @@ const definitions = {
},
"flags": {
"type": "number"
+ },
+ "minutes": {
+ "type": "number"
}
},
"additionalProperties": false,
@@ -2057,10 +2060,17 @@ const definitions = {
},
"blockNotificationDelay": {
"type": "number"
+ },
+ "atw": {
+ "type": "array",
+ "items": {
+ "type": "number"
+ }
}
},
"additionalProperties": false,
"required": [
+ "atw",
"blockAllNotifications",
"blockNotificationDelay",
"blockedTimes",
diff --git a/src/database/categorytimewarning.ts b/src/database/categorytimewarning.ts
new file mode 100644
index 0000000..525aeb4
--- /dev/null
+++ b/src/database/categorytimewarning.ts
@@ -0,0 +1,58 @@
+/*
+ * server component for the TimeLimit App
+ * 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
+ * published by the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import * as Sequelize from 'sequelize'
+import { familyIdColumn, idWithinFamilyColumn } from './columns'
+import { SequelizeAttributes } from './types'
+
+export const categoryTimeWarningConstants = {
+ minMinutes: 1,
+ maxMinutes: 60 * 24 * 7 - 2
+}
+
+export interface CategoryTimeWarningAttributes {
+ familyId: string
+ categoryId: string
+ minutes: number
+}
+
+export type CategoryTimeWarningModel = Sequelize.Model & CategoryTimeWarningAttributes
+export type CategoryTimeWarningModelStatic = typeof Sequelize.Model & {
+ new (values?: object, options?: Sequelize.BuildOptions): CategoryTimeWarningModel;
+}
+
+export const attributes: SequelizeAttributes = {
+ familyId: {
+ ...familyIdColumn,
+ primaryKey: true
+ },
+ categoryId: {
+ ...idWithinFamilyColumn,
+ primaryKey: true
+ },
+ minutes: {
+ type: Sequelize.INTEGER,
+ allowNull: false,
+ validate: {
+ min: categoryTimeWarningConstants.minMinutes,
+ max: categoryTimeWarningConstants.maxMinutes
+ },
+ primaryKey: true
+ }
+}
+
+export const createCategoryTimeWarningModel = (sequelize: Sequelize.Sequelize): CategoryTimeWarningModelStatic => sequelize.define('CategoryTimeWarning', attributes) as CategoryTimeWarningModelStatic
diff --git a/src/database/main.ts b/src/database/main.ts
index 808a825..ed96c8a 100644
--- a/src/database/main.ts
+++ b/src/database/main.ts
@@ -23,6 +23,7 @@ import { AuthTokenModelStatic, createAuthtokenModel } from './authtoken'
import { CategoryModelStatic, createCategoryModel } from './category'
import { CategoryAppModelStatic, createCategoryAppModel } from './categoryapp'
import { CategoryNetworkIdModelStatic, createCategoryNetworkIdModel } from './categorynetworkid'
+import { CategoryTimeWarningModelStatic, createCategoryTimeWarningModel } from './categorytimewarning'
import { ChildTaskModelStatic, createChildTaskModel } from './childtask'
import { ConfigModelStatic, createConfigModel } from './config'
import { createDeviceModel, DeviceModelStatic } from './device'
@@ -47,6 +48,7 @@ export interface Database {
category: CategoryModelStatic
categoryApp: CategoryAppModelStatic
categoryNetworkId: CategoryNetworkIdModelStatic
+ categoryTimeWarning: CategoryTimeWarningModelStatic
childTask: ChildTaskModelStatic
config: ConfigModelStatic
device: DeviceModelStatic
@@ -72,6 +74,7 @@ const createDatabase = (sequelize: Sequelize.Sequelize): Database => ({
categoryApp: createCategoryAppModel(sequelize),
childTask: createChildTaskModel(sequelize),
categoryNetworkId: createCategoryNetworkIdModel(sequelize),
+ categoryTimeWarning: createCategoryTimeWarningModel(sequelize),
config: createConfigModel(sequelize),
device: createDeviceModel(sequelize),
family: createFamilyModel(sequelize),
diff --git a/src/database/migration/migrations/20220328-add-custom-time-limits.ts b/src/database/migration/migrations/20220328-add-custom-time-limits.ts
new file mode 100644
index 0000000..cec7198
--- /dev/null
+++ b/src/database/migration/migrations/20220328-add-custom-time-limits.ts
@@ -0,0 +1,55 @@
+/*
+ * server component for the TimeLimit App
+ * 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
+ * published by the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import { QueryInterface, Sequelize, Transaction } from 'sequelize'
+
+export async function up (_: QueryInterface, sequelize: Sequelize) {
+ await sequelize.transaction({
+ type: Transaction.TYPES.EXCLUSIVE
+ }, async (transaction) => {
+ const dialect = sequelize.getDialect()
+ const isMysql = dialect === 'mysql' || dialect === 'mariadb'
+
+ if (isMysql) {
+ await sequelize.query(
+ 'CREATE TABLE `CategoryTimeWarnings` ' +
+ '(`familyId` VARCHAR(10) NOT NULL, `categoryId` VARCHAR(6) NOT NULL,' +
+ '`minutes` INTEGER NOT NULL, ' +
+ 'PRIMARY KEY(`familyId`, `categoryId`, `minutes`), FOREIGN KEY(`familyId`, `categoryId`)' +
+ 'REFERENCES `Categories`(`familyId`, `categoryId`) ON UPDATE CASCADE ON DELETE CASCADE )',
+ { transaction }
+ )
+ } else {
+ await sequelize.query(
+ 'CREATE TABLE "CategoryTimeWarnings" ' +
+ '("familyId" VARCHAR(10) NOT NULL, "categoryId" VARCHAR(6) NOT NULL,' +
+ '"minutes" INTEGER NOT NULL, ' +
+ 'PRIMARY KEY("familyId", "categoryId", "minutes"), FOREIGN KEY("familyId", "categoryId")' +
+ 'REFERENCES "Categories"("familyId", "categoryId") ON UPDATE CASCADE ON DELETE CASCADE )',
+ { transaction }
+ )
+ }
+ })
+}
+
+export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
+ await sequelize.transaction({
+ type: Transaction.TYPES.EXCLUSIVE
+ }, async (transaction) => {
+ await queryInterface.dropTable('CategoryTimeWarnings', { transaction })
+ })
+}
diff --git a/src/function/sync/apply-actions/dispatch-parent-action/updatecategorytimewarnings.ts b/src/function/sync/apply-actions/dispatch-parent-action/updatecategorytimewarnings.ts
index 7748899..21045b7 100644
--- a/src/function/sync/apply-actions/dispatch-parent-action/updatecategorytimewarnings.ts
+++ b/src/function/sync/apply-actions/dispatch-parent-action/updatecategorytimewarnings.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
@@ -43,6 +43,28 @@ export async function dispatchUpdateCategoryTimeWarnings ({ action, cache }: {
await categoryEntry.save({ transaction: cache.transaction })
+ if (action.minutes !== undefined) {
+ if (action.enable) {
+ await cache.database.categoryTimeWarning.create({
+ familyId: cache.familyId,
+ categoryId: action.categoryId,
+ minutes: action.minutes
+ }, {
+ transaction: cache.transaction,
+ ignoreDuplicates: true
+ })
+ } else {
+ await cache.database.categoryTimeWarning.destroy({
+ where: {
+ familyId: cache.familyId,
+ categoryId: action.categoryId,
+ minutes: action.minutes
+ },
+ transaction: cache.transaction
+ })
+ }
+ }
+
cache.categoriesWithModifiedBaseData.add(action.categoryId)
cache.areChangesImportant = true
}
diff --git a/src/function/sync/get-server-data-status/category/base-data.ts b/src/function/sync/get-server-data-status/category/base-data.ts
index c9e5cbd..696c2c4 100644
--- a/src/function/sync/get-server-data-status/category/base-data.ts
+++ b/src/function/sync/get-server-data-status/category/base-data.ts
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
- * Copyright (C) 2019 - 2021 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
@@ -96,6 +96,23 @@ export async function getCategoryBaseDatas ({
hashedNetworkId: item.hashedNetworkId
}))
+ const additionalTimeWarningsForSyncing = (await database.categoryTimeWarning.findAll({
+ where: {
+ familyId: familyEntry.familyId,
+ categoryId: {
+ [Sequelize.Op.in]: categoryIdsToSyncBaseData
+ }
+ },
+ attributes: [
+ 'categoryId',
+ 'minutes'
+ ],
+ transaction
+ })).map((item) => ({
+ categoryId: item.categoryId,
+ minutes: item.minutes
+ }))
+
return dataForSyncing.map((item): ServerUpdatedCategoryBaseData => ({
categoryId: item.categoryId,
childId: item.childId,
@@ -120,6 +137,9 @@ export async function getCategoryBaseDatas ({
})),
dlu: parseInt(item.disableLimitsUntil, 10),
flags: parseInt(item.flags, 10),
- blockNotificationDelay: parseInt(item.blockNotificationDelay, 10)
+ blockNotificationDelay: parseInt(item.blockNotificationDelay, 10),
+ atw: additionalTimeWarningsForSyncing
+ .filter((timeWarning) => timeWarning.categoryId === item.categoryId)
+ .map((timeWarning) => timeWarning.minutes)
}))
}
diff --git a/src/function/sync/get-server-data-status/index.ts b/src/function/sync/get-server-data-status/index.ts
index c3be92a..5b03fb6 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: 2
+ apiLevel: 3
}
if (familyEntry.deviceListVersion !== clientStatus.devices) {
diff --git a/src/object/serverdatastatus.ts b/src/object/serverdatastatus.ts
index f1fda56..5ec2203 100644
--- a/src/object/serverdatastatus.ts
+++ b/src/object/serverdatastatus.ts
@@ -120,6 +120,8 @@ export interface ServerUpdatedCategoryBaseData {
dlu: number
flags: number
blockNotificationDelay: number
+ // atw = additionalTimeWarnings
+ atw: Array
}
export interface ServerCategoryNetworkId {