mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add action to configure category time warnings
This commit is contained in:
@@ -45,6 +45,7 @@ import {
|
||||
UpdateCategoryBlockAllNotificationsAction,
|
||||
UpdateCategoryBlockedTimesAction,
|
||||
UpdateCategoryTemporarilyBlockedAction,
|
||||
UpdateCategoryTimeWarningsAction,
|
||||
UpdateCategoryTitleAction,
|
||||
UpdateDeviceNameAction,
|
||||
UpdateEnableActivityLevelBlockingAction,
|
||||
@@ -81,6 +82,7 @@ import { dispatchSetUserTimezone } from './setusertimezone'
|
||||
import { dispatchUpdateCategoryBlockAllNotifications } from './updatecategoryblockallnotifications'
|
||||
import { dispatchUpdateCategoryBlockedTimes } from './updatecategoryblockedtimes'
|
||||
import { dispatchUpdateCategoryTemporarilyBlocked } from './updatecategorytemporarilyblocked'
|
||||
import { dispatchUpdateCategoryTimeWarnings } from './updatecategorytimewarnings'
|
||||
import { dispatchUpdateCategoryTitle } from './updatecategorytitle'
|
||||
import { dispatchUpdateDeviceName } from './updatedevicename'
|
||||
import { dispatchUpdateEnableActivityLevelBlocking } from './updateenableactivitylevelblocking'
|
||||
@@ -162,6 +164,8 @@ export const dispatchParentAction = async ({ action, cache, parentUserId, source
|
||||
await dispatchChangeParentPassword({ action, cache })
|
||||
} else if (action instanceof IgnoreManipulationAction) {
|
||||
await dispatchIgnoreManipulation({ action, cache })
|
||||
} else if (action instanceof UpdateCategoryTimeWarningsAction) {
|
||||
await dispatchUpdateCategoryTimeWarnings({ action, cache })
|
||||
} else {
|
||||
throw new Error('unsupported action type')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 { UpdateCategoryTimeWarningsAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
|
||||
export async function dispatchUpdateCategoryTimeWarnings ({ action, cache }: {
|
||||
action: UpdateCategoryTimeWarningsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryEntry = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!categoryEntry) {
|
||||
throw new Error('invalid category id')
|
||||
}
|
||||
|
||||
if (action.enable) {
|
||||
categoryEntry.timeWarningFlags |= action.flags
|
||||
} else {
|
||||
categoryEntry.timeWarningFlags &= ~action.flags
|
||||
}
|
||||
|
||||
await categoryEntry.save({ transaction: cache.transaction })
|
||||
|
||||
cache.categoriesWithModifiedBaseData.push(action.categoryId)
|
||||
cache.areChangesImportant = true
|
||||
}
|
||||
Reference in New Issue
Block a user