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,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