From f7500d19a366d3b39542547bbe46747d861c7782 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Mon, 4 Mar 2019 00:00:00 +0000 Subject: [PATCH] Add column for block all notifications --- src/database/category.ts | 17 ++++++++- ...190304-add-block-all-notifications-flag.ts | 37 +++++++++++++++++++ .../dispatch-parent-action/createcategory.ts | 3 +- src/function/sync/get-server-data-status.ts | 9 +++-- src/object/serverdatastatus.ts | 1 + 5 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 src/database/migration/migrations/20190304-add-block-all-notifications-flag.ts diff --git a/src/database/category.ts b/src/database/category.ts index f1f9d52..088928c 100644 --- a/src/database/category.ts +++ b/src/database/category.ts @@ -38,7 +38,12 @@ export interface CategoryAttributesVersion2 { parentCategoryId: string } -export type CategoryAttributes = CategoryAttributesVersion1 & CategoryAttributesVersion2 +export interface CategoryAttributesVersion3 { + blockAllNotifications: boolean +} + +export type CategoryAttributes = CategoryAttributesVersion1 & CategoryAttributesVersion2 & + CategoryAttributesVersion3 export type CategoryInstance = Sequelize.Instance & CategoryAttributes export type CategoryModel = Sequelize.Model @@ -82,9 +87,17 @@ export const attributesVersion2: SequelizeAttributes } } +export const attributesVersion3: SequelizeAttributes = { + blockAllNotifications: { + ...booleanColumn, + defaultValue: false + } +} + export const attributes: SequelizeAttributes = { ...attributesVersion1, - ...attributesVersion2 + ...attributesVersion2, + ...attributesVersion3 } export const createCategoryModel = (sequelize: Sequelize.Sequelize): CategoryModel => sequelize.define('Category', attributes) diff --git a/src/database/migration/migrations/20190304-add-block-all-notifications-flag.ts b/src/database/migration/migrations/20190304-add-block-all-notifications-flag.ts new file mode 100644 index 0000000..cde7086 --- /dev/null +++ b/src/database/migration/migrations/20190304-add-block-all-notifications-flag.ts @@ -0,0 +1,37 @@ +/* + * 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 . + */ + +import { QueryInterface, Sequelize } from 'sequelize' +import { attributesVersion3 as categoryAttributes } from '../../category' + +export async function up (queryInterface: QueryInterface, sequelize: Sequelize) { + await sequelize.transaction({ + type: 'EXCLUSIVE' + }, async (transaction) => { + await queryInterface.addColumn('Categories', 'blockAllNotifications', { + ...categoryAttributes.blockAllNotifications + }, { transaction }) + }) +} + +export async function down (queryInterface: QueryInterface, sequelize: Sequelize) { + await sequelize.transaction({ + type: 'EXCLUSIVE' + }, async (transaction) => { + await queryInterface.removeColumn('Categories', 'blockAllNotifications', { transaction }) + }) +} diff --git a/src/function/sync/apply-actions/dispatch-parent-action/createcategory.ts b/src/function/sync/apply-actions/dispatch-parent-action/createcategory.ts index ab3f7a3..9b49685 100644 --- a/src/function/sync/apply-actions/dispatch-parent-action/createcategory.ts +++ b/src/function/sync/apply-actions/dispatch-parent-action/createcategory.ts @@ -50,7 +50,8 @@ export async function dispatchCreateCategory ({ action, cache }: { baseVersion: generateVersionId(), assignedAppsVersion: generateVersionId(), usedTimesVersion: generateVersionId(), - parentCategoryId: '' + parentCategoryId: '', + blockAllNotifications: false }, { transaction: cache.transaction }) // update the cache diff --git a/src/function/sync/get-server-data-status.ts b/src/function/sync/get-server-data-status.ts index 0b3a205..9a4804b 100644 --- a/src/function/sync/get-server-data-status.ts +++ b/src/function/sync/get-server-data-status.ts @@ -299,7 +299,8 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI 'extraTimeInMillis', 'temporarilyBlocked', 'baseVersion', - 'parentCategoryId' + 'parentCategoryId', + 'blockAllNotifications' ], transaction })).map((item) => ({ @@ -310,7 +311,8 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI extraTimeInMillis: item.extraTimeInMillis, temporarilyBlocked: item.temporarilyBlocked, baseVersion: item.baseVersion, - parentCategoryId: item.parentCategoryId + parentCategoryId: item.parentCategoryId, + blockAllNotifications: item.blockAllNotifications })) result.categoryBase = dataForSyncing.map((item): ServerUpdatedCategoryBaseData => ({ @@ -321,7 +323,8 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI extraTime: item.extraTimeInMillis, tempBlocked: item.temporarilyBlocked, version: item.baseVersion, - parentCategoryId: item.parentCategoryId + parentCategoryId: item.parentCategoryId, + blockAllNotifications: item.blockAllNotifications })) } diff --git a/src/object/serverdatastatus.ts b/src/object/serverdatastatus.ts index 4bc932e..479f27e 100644 --- a/src/object/serverdatastatus.ts +++ b/src/object/serverdatastatus.ts @@ -93,6 +93,7 @@ export interface ServerUpdatedCategoryBaseData { tempBlocked: boolean version: string parentCategoryId: string + blockAllNotifications: boolean } export interface ServerUpdatedCategoryAssignedApps {