Add child task support

This commit is contained in:
Jonas Lochmann
2020-11-16 01:00:00 +01:00
parent 020fe0aea6
commit d67b7a7619
73 changed files with 2864 additions and 88 deletions
@@ -21,6 +21,7 @@ import {
AddUsedTimeActionVersion2,
AppLogicAction,
ForceSyncAction,
MarkTaskPendingAction,
RemoveInstalledAppsAction,
SignOutAtDeviceAction,
TriedDisablingDeviceAdminAction,
@@ -34,6 +35,7 @@ import { dispatchAddInstalledApps } from './addinstalledapps'
import { dispatchAddUsedTime } from './addusedtime'
import { dispatchAddUsedTimeVersion2 } from './addusedtime2'
import { dispatchForceSyncAction } from './forcesync'
import { dispatchMarkTaskPendingAction } from './marktaskpendingaction'
import { dispatchRemoveInstalledApps } from './removeinstalledapps'
import { dispatchSignOutAtDevice } from './signoutatdevice'
import { dispatchTriedDisablingDeviceAdmin } from './trieddisablingdeviceadmin'
@@ -54,6 +56,8 @@ export const dispatchAppLogicAction = async ({ action, deviceId, cache, eventHan
await dispatchAddUsedTimeVersion2({ deviceId, action, cache, eventHandler })
} else if (action instanceof ForceSyncAction) {
await dispatchForceSyncAction({ deviceId, action, cache })
} else if (action instanceof MarkTaskPendingAction) {
await dispatchMarkTaskPendingAction({ deviceId, action, cache })
} else if (action instanceof RemoveInstalledAppsAction) {
await dispatchRemoveInstalledApps({ deviceId, action, cache })
} else if (action instanceof SignOutAtDeviceAction) {
@@ -0,0 +1,87 @@
/*
* 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 { MarkTaskPendingAction } from '../../../../action'
import { Cache } from '../cache'
import { IllegalStateException, SourceDeviceNotFoundException } from '../exception/illegal-state'
import { MissingTaskException } from '../exception/missing-item'
export async function dispatchMarkTaskPendingAction ({ action, cache, deviceId }: {
deviceId: string
action: MarkTaskPendingAction
cache: Cache
}) {
const taskInfoUnsafe = await cache.database.childTask.findOne({
where: {
familyId: cache.familyId,
taskId: action.taskId
},
transaction: cache.transaction,
attributes: ['categoryId', 'pendingRequest']
})
if (taskInfoUnsafe === null) throw new MissingTaskException()
const taskInfo = {
categoryId: taskInfoUnsafe.categoryId,
pendingRequest: taskInfoUnsafe.pendingRequest
}
if (taskInfo.pendingRequest !== 0) return // review already requested
const categoryInfoUnsafe = await cache.database.category.findOne({
where: {
familyId: cache.familyId,
categoryId: taskInfo.categoryId
},
attributes: ['childId'],
transaction: cache.transaction
})
if (categoryInfoUnsafe === null) {
throw new IllegalStateException({ staticMessage: 'category referenced from task not found' })
}
const categoryInfo = { childId: categoryInfoUnsafe.childId }
const deviceInfoUnsafe = await cache.database.device.findOne({
where: {
familyId: cache.familyId,
deviceId
},
attributes: ['currentUserId'],
transaction: cache.transaction
})
if (deviceInfoUnsafe === null) throw new SourceDeviceNotFoundException()
const deviceInfo = { currentUserId: deviceInfoUnsafe.currentUserId }
if (categoryInfo.childId !== deviceInfo.currentUserId) {
throw new IllegalStateException({ staticMessage: 'Can not mark task pending for other user than the current user' })
}
await cache.database.childTask.update({ pendingRequest: true }, {
where: {
familyId: cache.familyId,
taskId: action.taskId
},
transaction: cache.transaction
})
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
}