mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add child task support
This commit is contained in:
@@ -37,6 +37,7 @@ export class Cache {
|
||||
categoriesWithModifiedBaseData = new Set<string>()
|
||||
categoriesWithModifiedTimeLimitRules = new Set<string>()
|
||||
categoriesWithModifiedUsedTimes = new Set<string>()
|
||||
categoriesWithModifiedTasks = new Set<string>()
|
||||
|
||||
devicesWithModifiedInstalledApps = new Set<string>()
|
||||
devicesWithModifiedShowDeviceConnected = new Map<string, boolean>()
|
||||
@@ -209,6 +210,22 @@ export class Cache {
|
||||
this.categoriesWithModifiedUsedTimes.clear()
|
||||
}
|
||||
|
||||
if (this.categoriesWithModifiedTasks.size > 0) {
|
||||
await database.category.update({
|
||||
taskListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId,
|
||||
categoryId: {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedTasks)
|
||||
}
|
||||
},
|
||||
transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedUsedTimes.clear()
|
||||
}
|
||||
|
||||
if (this.devicesWithModifiedInstalledApps.size > 0) {
|
||||
await database.device.update({
|
||||
installedAppsVersion: generateVersionId()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -76,7 +76,8 @@ export async function dispatchCreateCategory ({ action, cache, fromChildSelfLimi
|
||||
blockAllNotifications: false,
|
||||
timeWarningFlags: 0,
|
||||
sort,
|
||||
disableLimitsUntil: 0
|
||||
disableLimitsUntil: 0,
|
||||
taskListVersion: generateVersionId()
|
||||
}, { transaction: cache.transaction })
|
||||
|
||||
// update the cache
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 { DeleteChildTaskAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
import { MissingTaskException } from '../exception/missing-item'
|
||||
|
||||
export async function dispatchDeleteChildTaskAction ({ action, cache }: {
|
||||
action: DeleteChildTaskAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const taskInfoUnsafe = await cache.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
attributes: ['categoryId']
|
||||
})
|
||||
|
||||
if (taskInfoUnsafe === null) throw new MissingTaskException()
|
||||
|
||||
const taskInfo = { categoryId: taskInfoUnsafe.categoryId }
|
||||
|
||||
await cache.database.childTask.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
CreateCategoryAction,
|
||||
CreateTimeLimitRuleAction,
|
||||
DeleteCategoryAction,
|
||||
DeleteChildTaskAction,
|
||||
DeleteTimeLimitRuleAction,
|
||||
IgnoreManipulationAction,
|
||||
IncrementCategoryExtraTimeAction,
|
||||
@@ -32,6 +33,7 @@ import {
|
||||
RenameChildAction,
|
||||
ResetCategoryNetworkIdsAction,
|
||||
ResetParentBlockedTimesAction,
|
||||
ReviewChildTaskAction,
|
||||
SetCategoryExtraTimeAction,
|
||||
SetCategoryForUnassignedAppsAction,
|
||||
SetChildPasswordAction,
|
||||
@@ -53,6 +55,7 @@ import {
|
||||
UpdateCategoryTemporarilyBlockedAction,
|
||||
UpdateCategoryTimeWarningsAction,
|
||||
UpdateCategoryTitleAction,
|
||||
UpdateChildTaskAction,
|
||||
UpdateDeviceNameAction,
|
||||
UpdateEnableActivityLevelBlockingAction,
|
||||
UpdateNetworkTimeVerificationAction,
|
||||
@@ -72,6 +75,7 @@ import { dispatchChangeParentPassword } from './changeparentpassword'
|
||||
import { dispatchCreateCategory } from './createcategory'
|
||||
import { dispatchCreateTimeLimitRule } from './createtimelimitrule'
|
||||
import { dispatchDeleteCategory } from './deletecategory'
|
||||
import { dispatchDeleteChildTaskAction } from './deletechildtaskaction'
|
||||
import { dispatchDeleteTimeLimitRule } from './deletetimelimitrule'
|
||||
import { dispatchIgnoreManipulation } from './ignoremanipulation'
|
||||
import { dispatchIncrementCategoryExtraTime } from './incrementcategoryextratime'
|
||||
@@ -80,6 +84,7 @@ import { dispatchRemoveUser } from './removeuser'
|
||||
import { dispatchRenameChild } from './renamechild'
|
||||
import { dispatchResetCategoryNetworkIds } from './resetcategorynetworkids'
|
||||
import { dispatchResetParentBlockedTimes } from './resetparentblockedtimes'
|
||||
import { dispatchReviewChildTaskAction } from './reviewchildtaskaction'
|
||||
import { dispatchSetCategoryExtraTime } from './setcategoryextratime'
|
||||
import { dispatchSetCategoryForUnassignedApps } from './setcategoryforunassignedapps'
|
||||
import { dispatchSetChildPassword } from './setchildpassword'
|
||||
@@ -101,6 +106,7 @@ import { dispatchUpdateCategorySorting } from './updatecategorysorting'
|
||||
import { dispatchUpdateCategoryTemporarilyBlocked } from './updatecategorytemporarilyblocked'
|
||||
import { dispatchUpdateCategoryTimeWarnings } from './updatecategorytimewarnings'
|
||||
import { dispatchUpdateCategoryTitle } from './updatecategorytitle'
|
||||
import { dispatchUpdateChildTaskAction } from './updatechildtaskaction'
|
||||
import { dispatchUpdateDeviceName } from './updatedevicename'
|
||||
import { dispatchUpdateEnableActivityLevelBlocking } from './updateenableactivitylevelblocking'
|
||||
import { dispatchUpdateNetworkTimeVerification } from './updatenetworktimeverification'
|
||||
@@ -210,6 +216,12 @@ export const dispatchParentAction = async ({ action, cache, parentUserId, source
|
||||
return dispatchUpdateUserFlagsAction({ action, cache })
|
||||
} else if (action instanceof UpdateUserLimitLoginCategory) {
|
||||
return dispatchUpdateUserLimitLoginCategoryAction({ action, cache, parentUserId })
|
||||
} else if (action instanceof DeleteChildTaskAction) {
|
||||
await dispatchDeleteChildTaskAction({ action, cache })
|
||||
} else if (action instanceof ReviewChildTaskAction) {
|
||||
await dispatchReviewChildTaskAction({ action, cache })
|
||||
} else if (action instanceof UpdateChildTaskAction) {
|
||||
await dispatchUpdateChildTaskAction({ action, cache })
|
||||
} else {
|
||||
throw new ActionObjectTypeNotHandledException()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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 { ReviewChildTaskAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
import { IllegalStateException } from '../exception/illegal-state'
|
||||
import { MissingTaskException } from '../exception/missing-item'
|
||||
|
||||
export async function dispatchReviewChildTaskAction ({ action, cache }: {
|
||||
action: ReviewChildTaskAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const taskInfo = await cache.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (taskInfo === null) throw new MissingTaskException()
|
||||
|
||||
if (taskInfo.pendingRequest === 0) throw new IllegalStateException({ staticMessage: 'no task review pending' })
|
||||
|
||||
if (action.ok) {
|
||||
const categoryInfoUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
attributes: ['extraTimeInMillis', 'extraTimeDay'],
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (categoryInfoUnsafe === null) {
|
||||
throw new IllegalStateException({ staticMessage: 'category referenced from task not found' })
|
||||
}
|
||||
|
||||
const categoryInfo = {
|
||||
extraTimeInMillis: categoryInfoUnsafe.extraTimeInMillis,
|
||||
extraTimeDay: categoryInfoUnsafe.extraTimeDay
|
||||
}
|
||||
|
||||
if (categoryInfo.extraTimeDay !== 0 && categoryInfo.extraTimeInMillis > 0) {
|
||||
// if the current time is daily, then extend the daily time only
|
||||
await cache.database.category.update({
|
||||
extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
} else {
|
||||
await cache.database.category.update({
|
||||
extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration,
|
||||
extraTimeDay: -1
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(taskInfo.categoryId)
|
||||
|
||||
await cache.database.childTask.update({
|
||||
pendingRequest: 0,
|
||||
lastGrantTimestamp: action.time.toString(10)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
} else {
|
||||
await cache.database.childTask.update({
|
||||
pendingRequest: 0
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 { UpdateChildTaskAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
import { IllegalStateException } from '../exception/illegal-state'
|
||||
import { MissingCategoryException, MissingTaskException } from '../exception/missing-item'
|
||||
|
||||
export async function dispatchUpdateChildTaskAction ({ action, cache }: {
|
||||
action: UpdateChildTaskAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryInfoUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
attributes: ['childId'],
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (categoryInfoUnsafe === null) throw new MissingCategoryException()
|
||||
|
||||
const taskInfo = await cache.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
const notFound = taskInfo === null
|
||||
|
||||
if (notFound !== action.isNew) {
|
||||
if (action.isNew) {
|
||||
throw new IllegalStateException({
|
||||
staticMessage: 'can not create task which exists already'
|
||||
})
|
||||
} else {
|
||||
throw new MissingTaskException()
|
||||
}
|
||||
}
|
||||
|
||||
if (taskInfo === null) {
|
||||
await cache.database.childTask.create({
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId,
|
||||
categoryId: action.categoryId,
|
||||
taskTitle: action.taskTitle,
|
||||
extraTimeDuration: action.extraTimeDuration,
|
||||
pendingRequest: 0,
|
||||
lastGrantTimestamp: '0'
|
||||
}, {
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(action.categoryId)
|
||||
} else {
|
||||
await cache.database.childTask.update({
|
||||
taskTitle: action.taskTitle,
|
||||
categoryId: action.categoryId,
|
||||
extraTimeDuration: action.extraTimeDuration
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
cache.categoriesWithModifiedTasks.add(action.categoryId)
|
||||
}
|
||||
}
|
||||
@@ -42,3 +42,9 @@ export class MissingDeviceException extends MissingItemException {
|
||||
super({ staticMessage: 'referenced device which does not exist' })
|
||||
}
|
||||
}
|
||||
|
||||
export class MissingTaskException extends MissingItemException {
|
||||
constructor () {
|
||||
super({ staticMessage: 'referenced task which does not exist' })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ export async function getCategoryDataToSync ({ database, transaction, familyEntr
|
||||
'baseVersion',
|
||||
'assignedAppsVersion',
|
||||
'timeLimitRulesVersion',
|
||||
'usedTimesVersion'
|
||||
'usedTimesVersion',
|
||||
'taskListVersion'
|
||||
],
|
||||
transaction
|
||||
})).map((item) => ({
|
||||
@@ -45,7 +46,8 @@ export async function getCategoryDataToSync ({ database, transaction, familyEntr
|
||||
baseVersion: item.baseVersion,
|
||||
assignedAppsVersion: item.assignedAppsVersion,
|
||||
timeLimitRulesVersion: item.timeLimitRulesVersion,
|
||||
usedTimesVersion: item.usedTimesVersion
|
||||
usedTimesVersion: item.usedTimesVersion,
|
||||
taskListVersion: item.taskListVersion
|
||||
}))
|
||||
|
||||
const serverCategoryIds = serverCategoriesVersions.map((item) => item.categoryId)
|
||||
@@ -60,6 +62,7 @@ export async function getCategoryDataToSync ({ database, transaction, familyEntr
|
||||
const categoryIdsToSyncAssignedApps = [...addedCategoryIds]
|
||||
const categoryIdsToSyncRules = [...addedCategoryIds]
|
||||
const categoryIdsToSyncUsedTimes = [...addedCategoryIds]
|
||||
const categoryIdsToSyncTasks = [...addedCategoryIds]
|
||||
|
||||
categoryIdsOfClientAndServer.forEach((categoryId) => {
|
||||
const serverEntry = serverCategoriesVersions.find((item) => item.categoryId === categoryId)
|
||||
@@ -84,6 +87,10 @@ export async function getCategoryDataToSync ({ database, transaction, familyEntr
|
||||
if (serverEntry.usedTimesVersion !== clientEntry.usedTime) {
|
||||
categoryIdsToSyncUsedTimes.push(categoryId)
|
||||
}
|
||||
|
||||
if (serverEntry.taskListVersion !== clientEntry.tasks) {
|
||||
categoryIdsToSyncTasks.push(categoryId)
|
||||
}
|
||||
})
|
||||
|
||||
const serverCategoriesVersionsMap = new Map<string, ServerCategoryVersion>()
|
||||
@@ -96,6 +103,7 @@ export async function getCategoryDataToSync ({ database, transaction, familyEntr
|
||||
categoryIdsToSyncAssignedApps,
|
||||
categoryIdsToSyncRules,
|
||||
categoryIdsToSyncUsedTimes,
|
||||
categoryIdsToSyncTasks,
|
||||
serverCategoriesVersions: {
|
||||
list: serverCategoriesVersions,
|
||||
requireByCategoryId: (categoryId) => {
|
||||
@@ -117,6 +125,7 @@ export interface GetCategoryDataToSyncResult {
|
||||
categoryIdsToSyncAssignedApps: Array<string>
|
||||
categoryIdsToSyncRules: Array<string>
|
||||
categoryIdsToSyncUsedTimes: Array<string>
|
||||
categoryIdsToSyncTasks: Array<string>
|
||||
serverCategoriesVersions: ServerCategoryVersions
|
||||
}
|
||||
|
||||
@@ -131,4 +140,5 @@ export interface ServerCategoryVersion {
|
||||
assignedAppsVersion: string
|
||||
timeLimitRulesVersion: string
|
||||
usedTimesVersion: string
|
||||
taskListVersion: string
|
||||
}
|
||||
|
||||
@@ -18,5 +18,6 @@
|
||||
export { getCategoryDataToSync } from './diff'
|
||||
export { getCategoryBaseDatas } from './base-data'
|
||||
export { getRules } from './rules'
|
||||
export { getTasks } from './tasks'
|
||||
export { getUsedTimes } from './used-times'
|
||||
export { getCategoryAssignedApps } from './assigned-apps'
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 * as Sequelize from 'sequelize'
|
||||
import { Database, Transaction } from '../../../../database'
|
||||
import { ServerUpdatedCategoryTask, ServerUpdatedCategoryTasks } from '../../../../object/serverdatastatus'
|
||||
import { FamilyEntry } from '../family-entry'
|
||||
import { ServerCategoryVersions } from './diff'
|
||||
|
||||
export async function getTasks ({
|
||||
database, transaction, categoryIdsToSyncTasks, familyEntry,
|
||||
serverCategoriesVersions
|
||||
}: {
|
||||
database: Database
|
||||
transaction: Transaction
|
||||
categoryIdsToSyncTasks: Array<string>
|
||||
familyEntry: FamilyEntry
|
||||
serverCategoriesVersions: ServerCategoryVersions
|
||||
}): Promise<Array<ServerUpdatedCategoryTasks>> {
|
||||
const dataToSync = (await database.childTask.findAll({
|
||||
where: {
|
||||
familyId: familyEntry.familyId,
|
||||
categoryId: {
|
||||
[Sequelize.Op.in]: categoryIdsToSyncTasks
|
||||
}
|
||||
},
|
||||
attributes: [
|
||||
'taskId',
|
||||
'categoryId',
|
||||
'taskTitle',
|
||||
'extraTimeDuration',
|
||||
'pendingRequest',
|
||||
'lastGrantTimestamp'
|
||||
],
|
||||
transaction
|
||||
})).map((item) => ({
|
||||
taskId: item.taskId,
|
||||
categoryId: item.categoryId,
|
||||
taskTitle: item.taskTitle,
|
||||
extraTimeDuration: item.extraTimeDuration,
|
||||
pendingRequest: item.pendingRequest,
|
||||
lastGrantTimestamp: item.lastGrantTimestamp
|
||||
}))
|
||||
|
||||
return categoryIdsToSyncTasks.map((categoryId) => ({
|
||||
categoryId,
|
||||
version: serverCategoriesVersions.requireByCategoryId(categoryId).taskListVersion,
|
||||
tasks: dataToSync.filter((item) => item.categoryId === categoryId).map((item): ServerUpdatedCategoryTask => ({
|
||||
i: item.taskId,
|
||||
t: item.taskTitle,
|
||||
d: item.extraTimeDuration,
|
||||
p: item.pendingRequest !== 0,
|
||||
l: parseInt(item.lastGrantTimestamp, 10)
|
||||
}))
|
||||
}))
|
||||
}
|
||||
@@ -23,7 +23,8 @@ import { ClientDataStatus } from '../../../object/clientdatastatus'
|
||||
import { ServerDataStatus } from '../../../object/serverdatastatus'
|
||||
import { getAppList } from './app-list'
|
||||
import {
|
||||
getCategoryAssignedApps, getCategoryBaseDatas, getCategoryDataToSync, getRules, getUsedTimes
|
||||
getCategoryAssignedApps, getCategoryBaseDatas, getCategoryDataToSync,
|
||||
getRules, getTasks, getUsedTimes
|
||||
} from './category'
|
||||
import { getDeviceList } from './device-list'
|
||||
import { getFamilyEntry } from './family-entry'
|
||||
@@ -36,6 +37,7 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI
|
||||
transaction: Sequelize.Transaction
|
||||
}): Promise<ServerDataStatus> => {
|
||||
const familyEntry = await getFamilyEntry({ database, familyId, transaction })
|
||||
const doesClientSupportTasks = clientStatus.clientLevel !== undefined && clientStatus.clientLevel >= 3
|
||||
|
||||
let result: ServerDataStatus = {
|
||||
fullVersion: config.alwaysPro ? 1 : (
|
||||
@@ -92,5 +94,13 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI
|
||||
})
|
||||
}
|
||||
|
||||
if (categoryDataToSync.categoryIdsToSyncTasks.length > 0 && doesClientSupportTasks) {
|
||||
result.tasks = await getTasks({
|
||||
database, transaction, familyEntry,
|
||||
serverCategoriesVersions: categoryDataToSync.serverCategoriesVersions,
|
||||
categoryIdsToSyncTasks: categoryDataToSync.categoryIdsToSyncTasks
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user