mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add support for child users adding limits themself
This commit is contained in:
@@ -18,16 +18,30 @@
|
||||
import { CreateTimeLimitRuleAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
|
||||
export async function dispatchCreateTimeLimitRule ({ action, cache }: {
|
||||
export async function dispatchCreateTimeLimitRule ({ action, cache, fromChildSelfLimitAddChildUserId }: {
|
||||
action: CreateTimeLimitRuleAction
|
||||
cache: Cache
|
||||
fromChildSelfLimitAddChildUserId: string | null
|
||||
}) {
|
||||
const doesCategoryExist = await cache.doesCategoryExist(action.rule.categoryId)
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.rule.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
attributes: ['childId']
|
||||
})
|
||||
|
||||
if (!doesCategoryExist) {
|
||||
if (!categoryEntryUnsafe) {
|
||||
throw new Error('invalid category id for new rule')
|
||||
}
|
||||
|
||||
if (fromChildSelfLimitAddChildUserId !== null) {
|
||||
if (fromChildSelfLimitAddChildUserId !== categoryEntryUnsafe.childId) {
|
||||
throw new Error('can not add rules for other users')
|
||||
}
|
||||
}
|
||||
|
||||
await cache.database.timelimitRule.create({
|
||||
familyId: cache.familyId,
|
||||
ruleId: action.rule.ruleId,
|
||||
|
||||
Reference in New Issue
Block a user