mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add category flags
This commit is contained in:
@@ -79,7 +79,8 @@ export async function dispatchCreateCategory ({ action, cache, fromChildSelfLimi
|
||||
disableLimitsUntil: '0',
|
||||
taskListVersion: generateVersionId(),
|
||||
minBatteryCharging: 0,
|
||||
minBatteryMobile: 0
|
||||
minBatteryMobile: 0,
|
||||
flags: '0'
|
||||
}, { transaction: cache.transaction })
|
||||
|
||||
// update the cache
|
||||
|
||||
@@ -50,6 +50,7 @@ import {
|
||||
UpdateCategoryBlockAllNotificationsAction,
|
||||
UpdateCategoryBlockedTimesAction,
|
||||
UpdateCategoryDisableLimitsAction,
|
||||
UpdateCategoryFlagsAction,
|
||||
UpdateCategorySortingAction,
|
||||
UpdateCategoryTemporarilyBlockedAction,
|
||||
UpdateCategoryTimeWarningsAction,
|
||||
@@ -100,6 +101,7 @@ import { dispatchUpdateCategoryBatteryLimit } from './updatecategorybatterylimit
|
||||
import { dispatchUpdateCategoryBlockAllNotifications } from './updatecategoryblockallnotifications'
|
||||
import { dispatchUpdateCategoryBlockedTimes } from './updatecategoryblockedtimes'
|
||||
import { dispatchUpdateCategoryDisableLimits } from './updatecategorydisablelimits'
|
||||
import { dispatchUpdateCategoryFlagsAction } from './updatecategoryflags'
|
||||
import { dispatchUpdateCategorySorting } from './updatecategorysorting'
|
||||
import { dispatchUpdateCategoryTemporarilyBlocked } from './updatecategorytemporarilyblocked'
|
||||
import { dispatchUpdateCategoryTimeWarnings } from './updatecategorytimewarnings'
|
||||
@@ -178,6 +180,8 @@ export const dispatchParentAction = async ({ action, cache, parentUserId, source
|
||||
return dispatchSetUserTimezone({ action, cache })
|
||||
} else if (action instanceof UpdateCategoryBatteryLimitAction) {
|
||||
return dispatchUpdateCategoryBatteryLimit({ action, cache })
|
||||
} else if (action instanceof UpdateCategoryFlagsAction) {
|
||||
return dispatchUpdateCategoryFlagsAction({ action, cache })
|
||||
} else if (action instanceof UpdateCategorySortingAction) {
|
||||
return dispatchUpdateCategorySorting({ action, cache })
|
||||
} else if (action instanceof IncrementCategoryExtraTimeAction) {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2021 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 { UpdateCategoryFlagsAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
import { IllegalStateException } from '../exception/illegal-state'
|
||||
import { MissingCategoryException } from '../exception/missing-item'
|
||||
|
||||
export async function dispatchUpdateCategoryFlagsAction ({ action, cache }: {
|
||||
action: UpdateCategoryFlagsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryEntry = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!categoryEntry) {
|
||||
throw new MissingCategoryException()
|
||||
}
|
||||
|
||||
const oldFlags = parseInt(categoryEntry.flags, 10)
|
||||
|
||||
if (!Number.isSafeInteger(oldFlags)) {
|
||||
throw new IllegalStateException({ staticMessage: 'oldFlags is not a safe integer' })
|
||||
}
|
||||
|
||||
const newFlags = (oldFlags & ~action.modifiedBits) | action.newValues
|
||||
|
||||
categoryEntry.flags = newFlags.toString(10)
|
||||
|
||||
await categoryEntry.save({ transaction: cache.transaction })
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(action.categoryId)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2021 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
|
||||
@@ -51,7 +51,8 @@ export async function getCategoryBaseDatas ({
|
||||
'minBatteryMobile',
|
||||
'temporarilyBlockedEndTime',
|
||||
'sort',
|
||||
'disableLimitsUntil'
|
||||
'disableLimitsUntil',
|
||||
'flags'
|
||||
],
|
||||
transaction
|
||||
})).map((item) => ({
|
||||
@@ -70,7 +71,8 @@ export async function getCategoryBaseDatas ({
|
||||
minBatteryMobile: item.minBatteryMobile,
|
||||
temporarilyBlockedEndTime: item.temporarilyBlockedEndTime,
|
||||
sort: item.sort,
|
||||
disableLimitsUntil: item.disableLimitsUntil
|
||||
disableLimitsUntil: item.disableLimitsUntil,
|
||||
flags: item.flags
|
||||
}))
|
||||
|
||||
const networkIdsForSyncing = (await database.categoryNetworkId.findAll({
|
||||
@@ -114,6 +116,7 @@ export async function getCategoryBaseDatas ({
|
||||
itemId: network.networkItemId,
|
||||
hashedNetworkId: network.hashedNetworkId
|
||||
})),
|
||||
dlu: parseInt(item.disableLimitsUntil, 10)
|
||||
dlu: parseInt(item.disableLimitsUntil, 10),
|
||||
flags: parseInt(item.flags, 10)
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user