mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add battery limit support
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 Jonas Lochmann
|
||||
* 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
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
SetSendDeviceConnected,
|
||||
SetUserDisableLimitsUntilAction,
|
||||
SetUserTimezoneAction,
|
||||
UpdateCategoryBatteryLimitAction,
|
||||
UpdateCategoryBlockAllNotificationsAction,
|
||||
UpdateCategoryBlockedTimesAction,
|
||||
UpdateCategoryTemporarilyBlockedAction,
|
||||
@@ -82,6 +83,7 @@ import { dispatchSetRelaxPrimaryDevice } from './setrelaxprimarydevice'
|
||||
import { dispatchSetSendDeviceConnected } from './setsenddeviceconnected'
|
||||
import { dispatchUserSetDisableLimitsUntil } from './setuserdisablelmitsuntil'
|
||||
import { dispatchSetUserTimezone } from './setusertimezone'
|
||||
import { dispatchUpdateCategoryBatteryLimit } from './updatecategorybatterylimit'
|
||||
import { dispatchUpdateCategoryBlockAllNotifications } from './updatecategoryblockallnotifications'
|
||||
import { dispatchUpdateCategoryBlockedTimes } from './updatecategoryblockedtimes'
|
||||
import { dispatchUpdateCategoryTemporarilyBlocked } from './updatecategorytemporarilyblocked'
|
||||
@@ -140,6 +142,8 @@ export const dispatchParentAction = async ({ action, cache, parentUserId, source
|
||||
await dispatchUserSetDisableLimitsUntil({ action, cache })
|
||||
} else if (action instanceof SetUserTimezoneAction) {
|
||||
await dispatchSetUserTimezone({ action, cache })
|
||||
} else if (action instanceof UpdateCategoryBatteryLimitAction) {
|
||||
await dispatchUpdateCategoryBatteryLimit({ action, cache })
|
||||
} else if (action instanceof UpdateCategoryBlockAllNotificationsAction) {
|
||||
await dispatchUpdateCategoryBlockAllNotifications({ action, cache })
|
||||
} else if (action instanceof UpdateCategoryBlockedTimesAction) {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 { UpdateCategoryBatteryLimitAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
|
||||
export async function dispatchUpdateCategoryBatteryLimit ({ action, cache }: {
|
||||
action: UpdateCategoryBatteryLimitAction
|
||||
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.chargeLimit !== undefined) {
|
||||
categoryEntry.minBatteryCharging = action.chargeLimit
|
||||
}
|
||||
|
||||
if (action.mobileLimit !== undefined) {
|
||||
categoryEntry.minBatteryMobile = action.mobileLimit
|
||||
}
|
||||
|
||||
await categoryEntry.save({ transaction: cache.transaction })
|
||||
|
||||
cache.categoriesWithModifiedBaseData.push(action.categoryId)
|
||||
cache.areChangesImportant = true
|
||||
}
|
||||
Reference in New Issue
Block a user