Add support for custom time warnings

This commit is contained in:
Jonas Lochmann
2022-03-28 02:00:00 +02:00
parent d7799f2d06
commit 2ab23ea811
19 changed files with 330 additions and 9 deletions
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
* Copyright (C) 2019 - 2022 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,28 @@ export async function dispatchUpdateCategoryTimeWarnings ({ action, cache }: {
await categoryEntry.save({ transaction: cache.transaction })
if (action.minutes !== undefined) {
if (action.enable) {
await cache.database.categoryTimeWarning.create({
familyId: cache.familyId,
categoryId: action.categoryId,
minutes: action.minutes
}, {
transaction: cache.transaction,
ignoreDuplicates: true
})
} else {
await cache.database.categoryTimeWarning.destroy({
where: {
familyId: cache.familyId,
categoryId: action.categoryId,
minutes: action.minutes
},
transaction: cache.transaction
})
}
}
cache.categoriesWithModifiedBaseData.add(action.categoryId)
cache.areChangesImportant = true
}
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2021 Jonas Lochmann
* Copyright (C) 2019 - 2022 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
@@ -96,6 +96,23 @@ export async function getCategoryBaseDatas ({
hashedNetworkId: item.hashedNetworkId
}))
const additionalTimeWarningsForSyncing = (await database.categoryTimeWarning.findAll({
where: {
familyId: familyEntry.familyId,
categoryId: {
[Sequelize.Op.in]: categoryIdsToSyncBaseData
}
},
attributes: [
'categoryId',
'minutes'
],
transaction
})).map((item) => ({
categoryId: item.categoryId,
minutes: item.minutes
}))
return dataForSyncing.map((item): ServerUpdatedCategoryBaseData => ({
categoryId: item.categoryId,
childId: item.childId,
@@ -120,6 +137,9 @@ export async function getCategoryBaseDatas ({
})),
dlu: parseInt(item.disableLimitsUntil, 10),
flags: parseInt(item.flags, 10),
blockNotificationDelay: parseInt(item.blockNotificationDelay, 10)
blockNotificationDelay: parseInt(item.blockNotificationDelay, 10),
atw: additionalTimeWarningsForSyncing
.filter((timeWarning) => timeWarning.categoryId === item.categoryId)
.map((timeWarning) => timeWarning.minutes)
}))
}
@@ -44,7 +44,7 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI
familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0
),
message: await getStatusMessage({ database, transaction }) || undefined,
apiLevel: 2
apiLevel: 3
}
if (familyEntry.deviceListVersion !== clientStatus.devices) {