Add support for parent blocked times

This commit is contained in:
Jonas Lochmann
2019-08-25 09:36:31 +02:00
parent 32d278bdd5
commit 1969fe4042
15 changed files with 363 additions and 8 deletions
@@ -0,0 +1,39 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 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 { attributesVersion5 as userAttributes } from '../../user'
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => {
await queryInterface.addColumn('Users', 'blockedTimes', {
...userAttributes.blockedTimes
}, {
transaction
})
})
}
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => {
await queryInterface.removeColumn('Users', 'blockedTimes', { transaction })
})
}
+19 -2
View File
@@ -16,6 +16,7 @@
*/
import * as Sequelize from 'sequelize'
import { serializedBitmaskRegex } from '../util/bitmask'
import { optionalPasswordRegex, optionalSaltRegex } from '../util/password'
import { booleanColumn, createEnumColumn, familyIdColumn, idWithinFamilyColumn, labelColumn, optionalIdWithinFamilyColumn, timestampColumn } from './columns'
import { SequelizeAttributes } from './types'
@@ -49,8 +50,12 @@ export interface UserAttributesVersion4 {
mailNotificationFlags: number
}
export interface UserAttributesVersion5 {
blockedTimes: string
}
export type UserAttributes = UserAttributesVersion1 & UserAttributesVersion2 &
UserAttributesVersion3 & UserAttributesVersion4
UserAttributesVersion3 & UserAttributesVersion4 & UserAttributesVersion5
export type UserModel = Sequelize.Model & UserAttributes
export type UserModelStatic = typeof Sequelize.Model & {
@@ -123,11 +128,23 @@ export const attributesVersion4: SequelizeAttributes<UserAttributesVersion4> = {
}
}
export const attributesVersion5: SequelizeAttributes<UserAttributesVersion5> = {
blockedTimes: {
type: Sequelize.TEXT,
allowNull: false,
defaultValue: '',
validate: {
is: serializedBitmaskRegex
}
}
}
export const attributes: SequelizeAttributes<UserAttributes> = {
...attributesVersion1,
...attributesVersion2,
...attributesVersion3,
...attributesVersion4
...attributesVersion4,
...attributesVersion5
}
export const createUserModel = (sequelize: Sequelize.Sequelize): UserModelStatic => sequelize.define('User', attributes) as UserModelStatic