mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add child task support
This commit is contained in:
@@ -69,10 +69,14 @@ export interface CategoryAttributesVersion9 {
|
||||
disableLimitsUntil: string
|
||||
}
|
||||
|
||||
export interface CategoryAttributesVersion10 {
|
||||
taskListVersion: string
|
||||
}
|
||||
|
||||
export type CategoryAttributes = CategoryAttributesVersion1 & CategoryAttributesVersion2 &
|
||||
CategoryAttributesVersion3 & CategoryAttributesVersion4 & CategoryAttributesVersion5 &
|
||||
CategoryAttributesVersion6 & CategoryAttributesVersion7 & CategoryAttributesVersion8 &
|
||||
CategoryAttributesVersion9
|
||||
CategoryAttributesVersion9 & CategoryAttributesVersion10
|
||||
|
||||
export type CategoryModel = Sequelize.Model & CategoryAttributes
|
||||
export type CategoryModelStatic = typeof Sequelize.Model & {
|
||||
@@ -199,6 +203,13 @@ export const attributesVersion9: SequelizeAttributes<CategoryAttributesVersion9>
|
||||
}
|
||||
}
|
||||
|
||||
export const attributesVersion10: SequelizeAttributes<CategoryAttributesVersion10> = {
|
||||
taskListVersion: {
|
||||
...versionColumn,
|
||||
defaultValue: 'abcd'
|
||||
}
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<CategoryAttributes> = {
|
||||
...attributesVersion1,
|
||||
...attributesVersion2,
|
||||
@@ -208,7 +219,8 @@ export const attributes: SequelizeAttributes<CategoryAttributes> = {
|
||||
...attributesVersion6,
|
||||
...attributesVersion7,
|
||||
...attributesVersion8,
|
||||
...attributesVersion9
|
||||
...attributesVersion9,
|
||||
...attributesVersion10
|
||||
}
|
||||
|
||||
export const createCategoryModel = (sequelize: Sequelize.Sequelize): CategoryModelStatic => sequelize.define('Category', attributes) as CategoryModelStatic
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* 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
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { familyIdColumn, idWithinFamilyColumn, timestampColumn } from './columns'
|
||||
import { SequelizeAttributes } from './types'
|
||||
|
||||
export interface ChildTaskAttributes {
|
||||
familyId: string
|
||||
taskId: string
|
||||
// end of primary key
|
||||
categoryId: string
|
||||
taskTitle: string
|
||||
extraTimeDuration: number
|
||||
pendingRequest: number
|
||||
lastGrantTimestamp: string
|
||||
}
|
||||
|
||||
export const maxExtraTime = 1000 * 60 * 60 * 24
|
||||
export const maxTitleLength = 50
|
||||
|
||||
export type ChildTaskModel = Sequelize.Model & ChildTaskAttributes
|
||||
export type ChildTaskModelStatic = typeof Sequelize.Model & {
|
||||
new (values?: object, options?: Sequelize.BuildOptions): ChildTaskModel;
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<ChildTaskAttributes> = {
|
||||
familyId: {
|
||||
...familyIdColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
taskId: {
|
||||
...idWithinFamilyColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
categoryId: { ...idWithinFamilyColumn },
|
||||
taskTitle: {
|
||||
type: Sequelize.STRING(maxTitleLength),
|
||||
allowNull: false
|
||||
},
|
||||
extraTimeDuration: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
validate: { min: 1, max: maxExtraTime }
|
||||
},
|
||||
pendingRequest: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false
|
||||
},
|
||||
lastGrantTimestamp: { ...timestampColumn }
|
||||
}
|
||||
|
||||
export const createChildTaskModel = (sequelize: Sequelize.Sequelize): ChildTaskModelStatic => sequelize.define('ChildTask', attributes) as ChildTaskModelStatic
|
||||
@@ -25,6 +25,7 @@ import { AuthTokenModelStatic, createAuthtokenModel } from './authtoken'
|
||||
import { CategoryModelStatic, createCategoryModel } from './category'
|
||||
import { CategoryAppModelStatic, createCategoryAppModel } from './categoryapp'
|
||||
import { CategoryNetworkIdModelStatic, createCategoryNetworkIdModel } from './categorynetworkid'
|
||||
import { ChildTaskModelStatic, createChildTaskModel } from './childtask'
|
||||
import { configItemIds, ConfigModelStatic, createConfigModel } from './config'
|
||||
import { createDeviceModel, DeviceModelStatic } from './device'
|
||||
import { createFamilyModel, FamilyModelStatic } from './family'
|
||||
@@ -48,6 +49,7 @@ export interface Database {
|
||||
category: CategoryModelStatic
|
||||
categoryApp: CategoryAppModelStatic
|
||||
categoryNetworkId: CategoryNetworkIdModelStatic
|
||||
childTask: ChildTaskModelStatic
|
||||
config: ConfigModelStatic
|
||||
device: DeviceModelStatic
|
||||
family: FamilyModelStatic
|
||||
@@ -70,6 +72,7 @@ const createDatabase = (sequelize: Sequelize.Sequelize): Database => ({
|
||||
appActivity: createAppActivityModel(sequelize),
|
||||
category: createCategoryModel(sequelize),
|
||||
categoryApp: createCategoryAppModel(sequelize),
|
||||
childTask: createChildTaskModel(sequelize),
|
||||
categoryNetworkId: createCategoryNetworkIdModel(sequelize),
|
||||
config: createConfigModel(sequelize),
|
||||
device: createDeviceModel(sequelize),
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* 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
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { QueryInterface, Sequelize, Transaction } from 'sequelize'
|
||||
import { attributesVersion10 as categoryAttributes } from '../../category'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await sequelize.query(
|
||||
'CREATE TABLE `ChildTasks` (' +
|
||||
'`familyId` VARCHAR(10) NOT NULL, `taskId` VARCHAR(6) NOT NULL,' +
|
||||
'`categoryId` VARCHAR(6) NOT NULL, `taskTitle` VARCHAR(50) NOT NULL,' +
|
||||
'`extraTimeDuration` INTEGER NOT NULL, `pendingRequest` INTEGER NOT NULL,' +
|
||||
'`lastGrantTimestamp` LONG NOT NULL,' +
|
||||
'PRIMARY KEY(`familyId`, `taskId`),' +
|
||||
'FOREIGN KEY(`familyId`, `categoryId`) REFERENCES `Categories`(`familyId`, `categoryId`) ' +
|
||||
'ON UPDATE CASCADE ON DELETE CASCADE' +
|
||||
')',
|
||||
{ transaction }
|
||||
)
|
||||
|
||||
await queryInterface.addColumn('Categories', 'taskListVersion', {
|
||||
...categoryAttributes.taskListVersion
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.dropTable('ChildTasks', { transaction })
|
||||
await queryInterface.removeColumn('Categories', 'taskListVersion', { transaction })
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user