mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
prepare new database abstraction layer
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Unauthorized } from 'http-errors'
|
||||
import { Database, Transaction } from '../../../database'
|
||||
import { SimpleDatabaseTransaction } from '../../../database/simple'
|
||||
import { SourceFamilyNotFoundException } from './exception/illegal-state'
|
||||
|
||||
export interface ApplyActionBaseInfo {
|
||||
@@ -26,15 +26,14 @@ export interface ApplyActionBaseInfo {
|
||||
hasFullVersion: boolean
|
||||
}
|
||||
|
||||
export async function getApplyActionBaseInfo ({ database, transaction, deviceAuthToken }: {
|
||||
database: Database
|
||||
transaction: Transaction
|
||||
export async function getApplyActionBaseInfo ({ transaction, deviceAuthToken }: {
|
||||
transaction: SimpleDatabaseTransaction
|
||||
deviceAuthToken: string
|
||||
}): Promise<ApplyActionBaseInfo> {
|
||||
const deviceEntryUnsafe = await database.device.findOne({
|
||||
const deviceEntryUnsafe = await transaction.legacy.database.device.findOne({
|
||||
where: { deviceAuthToken },
|
||||
attributes: ['familyId', 'deviceId', 'nextSequenceNumber'],
|
||||
transaction
|
||||
transaction: transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -47,11 +46,11 @@ export async function getApplyActionBaseInfo ({ database, transaction, deviceAut
|
||||
nextSequenceNumber: deviceEntryUnsafe.nextSequenceNumber
|
||||
}
|
||||
|
||||
const familyEntryUnsafe = await database.family.findOne({
|
||||
const familyEntryUnsafe = await transaction.legacy.database.family.findOne({
|
||||
where: {
|
||||
familyId: deviceEntry.familyId
|
||||
},
|
||||
transaction,
|
||||
transaction: transaction.legacy.transaction,
|
||||
attributes: ['hasFullVersion']
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -19,7 +19,7 @@ import { memoize } from 'lodash'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { config } from '../../../config'
|
||||
import { VisibleConnectedDevicesManager } from '../../../connected-devices'
|
||||
import { Database } from '../../../database'
|
||||
import { SimpleDatabaseTransaction } from '../../../database/simple'
|
||||
import { setToList } from '../../../util/list'
|
||||
import { generateVersionId } from '../../../util/token'
|
||||
import { SourceUserNotFoundException } from './exception/illegal-state'
|
||||
@@ -29,8 +29,7 @@ export class Cache {
|
||||
readonly familyId: string
|
||||
readonly deviceId: string
|
||||
readonly hasFullVersion: boolean
|
||||
transaction: Sequelize.Transaction
|
||||
readonly database: Database
|
||||
transaction: SimpleDatabaseTransaction
|
||||
readonly connectedDevicesManager: VisibleConnectedDevicesManager
|
||||
private requireSenderDoFullSync = false
|
||||
|
||||
@@ -48,18 +47,16 @@ export class Cache {
|
||||
triggeredSyncLevel: 0 | 1 | 2 = 0 // 0 = no, 1 = unimportant, 2 = important
|
||||
targetedTriggeredSyncLevels = new Map<string, 0 | 1 | 2>()
|
||||
|
||||
constructor ({ familyId, deviceId, hasFullVersion, database, transaction, connectedDevicesManager }: {
|
||||
constructor ({ familyId, deviceId, hasFullVersion, transaction, connectedDevicesManager }: {
|
||||
familyId: string
|
||||
deviceId: string
|
||||
hasFullVersion: boolean
|
||||
database: Database
|
||||
transaction: Sequelize.Transaction
|
||||
transaction: SimpleDatabaseTransaction
|
||||
connectedDevicesManager: VisibleConnectedDevicesManager
|
||||
}) {
|
||||
this.familyId = familyId
|
||||
this.deviceId = deviceId
|
||||
this.hasFullVersion = hasFullVersion || config.alwaysPro
|
||||
this.database = database
|
||||
this.transaction = transaction
|
||||
this.connectedDevicesManager = connectedDevicesManager
|
||||
}
|
||||
@@ -77,7 +74,7 @@ export class Cache {
|
||||
async subtransaction<T> (callback: () => Promise<T>): Promise<T> {
|
||||
const oldTransaction = this.transaction
|
||||
|
||||
return this.database.transaction(async (newTransaction) => {
|
||||
return this.transaction.transaction(async (newTransaction) => {
|
||||
try {
|
||||
this.transaction = newTransaction
|
||||
|
||||
@@ -87,18 +84,18 @@ export class Cache {
|
||||
} finally {
|
||||
this.transaction = oldTransaction
|
||||
}
|
||||
}, { transaction: oldTransaction })
|
||||
})
|
||||
}
|
||||
|
||||
getSecondPasswordHashOfParent = memoize(async (parentId: string) => {
|
||||
const userEntryUnsafe = await this.database.user.findOne({
|
||||
const userEntryUnsafe = await this.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: this.familyId,
|
||||
userId: parentId,
|
||||
type: 'parent'
|
||||
},
|
||||
attributes: ['secondPasswordHash'],
|
||||
transaction: this.transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!userEntryUnsafe) {
|
||||
@@ -109,14 +106,14 @@ export class Cache {
|
||||
})
|
||||
|
||||
getSecondPasswordHashOfChild = memoize(async (childId: string) => {
|
||||
const userEntryUnsafe = await this.database.user.findOne({
|
||||
const userEntryUnsafe = await this.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: this.familyId,
|
||||
userId: childId,
|
||||
type: 'child'
|
||||
},
|
||||
attributes: ['secondPasswordHash'],
|
||||
transaction: this.transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!userEntryUnsafe) {
|
||||
@@ -131,24 +128,24 @@ export class Cache {
|
||||
})
|
||||
|
||||
doesCategoryExist = memoize(async (categoryId: string) => {
|
||||
const categoryEntry = await this.database.category.findOne({
|
||||
const categoryEntry = await this.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: this.familyId,
|
||||
categoryId
|
||||
},
|
||||
transaction: this.transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
return !!categoryEntry
|
||||
})
|
||||
|
||||
doesUserExist = memoize(async (userId: string) => {
|
||||
const userEntry = await this.database.user.findOne({
|
||||
const userEntry = await this.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: this.familyId,
|
||||
userId
|
||||
},
|
||||
transaction: this.transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
return !!userEntry
|
||||
@@ -158,10 +155,10 @@ export class Cache {
|
||||
requireSenderFullSync: () => void = () => this.requireSenderDoFullSync = true
|
||||
|
||||
async saveModifiedVersionNumbers () {
|
||||
const { database, transaction, familyId } = this
|
||||
const { familyId } = this
|
||||
|
||||
if (this.categoriesWithModifiedApps.size > 0) {
|
||||
await database.category.update({
|
||||
await this.transaction.legacy.database.category.update({
|
||||
assignedAppsVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
@@ -170,14 +167,14 @@ export class Cache {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedApps)
|
||||
}
|
||||
},
|
||||
transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedApps.clear()
|
||||
}
|
||||
|
||||
if (this.categoriesWithModifiedBaseData.size > 0) {
|
||||
await database.category.update({
|
||||
await this.transaction.legacy.database.category.update({
|
||||
baseVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
@@ -186,14 +183,14 @@ export class Cache {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedBaseData)
|
||||
}
|
||||
},
|
||||
transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedBaseData.clear()
|
||||
}
|
||||
|
||||
if (this.categoriesWithModifiedTimeLimitRules.size > 0) {
|
||||
await database.category.update({
|
||||
await this.transaction.legacy.database.category.update({
|
||||
timeLimitRulesVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
@@ -202,14 +199,14 @@ export class Cache {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedTimeLimitRules)
|
||||
}
|
||||
},
|
||||
transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedTimeLimitRules.clear()
|
||||
}
|
||||
|
||||
if (this.categoriesWithModifiedUsedTimes.size > 0) {
|
||||
await database.category.update({
|
||||
await this.transaction.legacy.database.category.update({
|
||||
usedTimesVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
@@ -218,14 +215,14 @@ export class Cache {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedUsedTimes)
|
||||
}
|
||||
},
|
||||
transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedUsedTimes.clear()
|
||||
}
|
||||
|
||||
if (this.categoriesWithModifiedTasks.size > 0) {
|
||||
await database.category.update({
|
||||
await this.transaction.legacy.database.category.update({
|
||||
taskListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
@@ -234,46 +231,46 @@ export class Cache {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedTasks)
|
||||
}
|
||||
},
|
||||
transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedUsedTimes.clear()
|
||||
}
|
||||
|
||||
if (this.invalidiateUserList) {
|
||||
await database.family.update({
|
||||
await this.transaction.legacy.database.family.update({
|
||||
userListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId: this.familyId
|
||||
},
|
||||
transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
this.invalidiateUserList = false
|
||||
}
|
||||
|
||||
if (this.invalidiateDeviceList) {
|
||||
await database.family.update({
|
||||
await this.transaction.legacy.database.family.update({
|
||||
deviceListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId: this.familyId
|
||||
},
|
||||
transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
this.invalidiateDeviceList = false
|
||||
}
|
||||
|
||||
if (this.invalidateU2fList) {
|
||||
await database.family.update({
|
||||
await this.transaction.legacy.database.family.update({
|
||||
u2fKeysVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId: this.familyId
|
||||
},
|
||||
transaction
|
||||
transaction: this.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
this.invalidateU2fList = false
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -37,12 +37,12 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
}) {
|
||||
const roundedTimestamp = getRoundedTimestamp().toString(10)
|
||||
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: [
|
||||
'childId',
|
||||
'parentCategoryId',
|
||||
@@ -65,7 +65,7 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
currentExtraTime: number
|
||||
}) => {
|
||||
if (action.timeToAdd !== 0) {
|
||||
const oldItem = await cache.database.usedTime.findOne({
|
||||
const oldItem = await cache.transaction.legacy.database.usedTime.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
@@ -73,7 +73,7 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
startMinuteOfDay: MinuteOfDay.MIN,
|
||||
endMinuteOfDay: MinuteOfDay.MAX
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (oldItem) {
|
||||
@@ -84,7 +84,7 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
const newLastUpdate = parseInt(roundedTimestamp, 10)
|
||||
|
||||
if (oldUsedTime !== newUsedTime || oldLastUpdate !== newLastUpdate) {
|
||||
const [updatedRows] = await cache.database.usedTime.update({
|
||||
const [updatedRows] = await cache.transaction.legacy.database.usedTime.update({
|
||||
usedTime: newUsedTime,
|
||||
lastUpdate: newLastUpdate.toString(10)
|
||||
}, {
|
||||
@@ -95,7 +95,7 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
startMinuteOfDay: MinuteOfDay.MIN,
|
||||
endMinuteOfDay: MinuteOfDay.MAX
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (updatedRows === 0) {
|
||||
@@ -103,7 +103,7 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await cache.database.usedTime.create({
|
||||
await cache.transaction.legacy.database.usedTime.create({
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
dayOfEpoch: action.dayOfEpoch,
|
||||
@@ -112,20 +112,20 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
startMinuteOfDay: MinuteOfDay.MIN,
|
||||
endMinuteOfDay: MinuteOfDay.MAX
|
||||
}, {
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (action.extraTimeToSubtract !== 0) {
|
||||
await cache.database.category.update({
|
||||
await cache.transaction.legacy.database.category.update({
|
||||
extraTimeInMillis: Math.max(0, currentExtraTime - action.extraTimeToSubtract)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(categoryId)
|
||||
@@ -140,13 +140,13 @@ export async function dispatchAddUsedTime ({ action, cache }: {
|
||||
})
|
||||
|
||||
if (categoryEntry.parentCategoryId !== '') {
|
||||
const parentCategoryEntry = await cache.database.category.findOne({
|
||||
const parentCategoryEntry = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: categoryEntry.parentCategoryId,
|
||||
childId: categoryEntry.childId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (parentCategoryEntry) {
|
||||
|
||||
@@ -37,13 +37,13 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
cache: Cache
|
||||
eventHandler: EventHandler
|
||||
}) {
|
||||
const deviceEntryUnsafe = await cache.database.device.findOne({
|
||||
const deviceEntryUnsafe = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: deviceId
|
||||
},
|
||||
attributes: ['currentUserId'],
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -60,12 +60,12 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
let addUsedTimeForADifferentUserThanTheCurrentUserOfTheDevice = false
|
||||
|
||||
for (const item of action.items) {
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: [
|
||||
'childId',
|
||||
'extraTimeInMillis'
|
||||
@@ -93,7 +93,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
const lengthInMinutes = (end - start) + 1
|
||||
const lengthInMs = lengthInMinutes * 1000 * 60
|
||||
|
||||
const oldItem = await cache.database.usedTime.findOne({
|
||||
const oldItem = await cache.transaction.legacy.database.usedTime.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId,
|
||||
@@ -101,7 +101,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
startMinuteOfDay: start,
|
||||
endMinuteOfDay: end
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (oldItem) {
|
||||
@@ -112,7 +112,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
const newLastUpdate = parseInt(roundedTimestampForUsedTime, 10)
|
||||
|
||||
if (oldUsedTime !== newUsedTime || oldLastUpdate !== newLastUpdate) {
|
||||
const [updatedRows] = await cache.database.usedTime.update({
|
||||
const [updatedRows] = await cache.transaction.legacy.database.usedTime.update({
|
||||
usedTime: newUsedTime,
|
||||
lastUpdate: newLastUpdate.toString(10)
|
||||
}, {
|
||||
@@ -123,7 +123,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
startMinuteOfDay: start,
|
||||
endMinuteOfDay: end
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (updatedRows === 0) {
|
||||
@@ -131,7 +131,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const oldTime: number | null = await cache.database.usedTime.aggregate(
|
||||
const oldTime: number | null = await cache.transaction.legacy.database.usedTime.aggregate(
|
||||
'usedTime',
|
||||
'MAX',
|
||||
{
|
||||
@@ -146,13 +146,13 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
[Sequelize.Op.lte]: end
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
}
|
||||
) || 0
|
||||
|
||||
if (oldTime !== null && typeof oldTime !== 'number') throw new Error()
|
||||
|
||||
await cache.database.usedTime.create({
|
||||
await cache.transaction.legacy.database.usedTime.create({
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId,
|
||||
dayOfEpoch: action.dayOfEpoch,
|
||||
@@ -161,7 +161,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
startMinuteOfDay: start,
|
||||
endMinuteOfDay: end
|
||||
}, {
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -179,7 +179,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
for (let j = 0; j < item.sessionDurationLimits.length; j++) {
|
||||
const limit = item.sessionDurationLimits[j]
|
||||
|
||||
const oldItem = await cache.database.sessionDuration.findOne({
|
||||
const oldItem = await cache.transaction.legacy.database.sessionDuration.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId,
|
||||
@@ -188,11 +188,11 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
startMinuteOfDay: limit.start,
|
||||
endMinuteOfDay: limit.end
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
const oldDuration: () => Promise<number> = async () => {
|
||||
const fittingDurationItems = await cache.database.sessionDuration.findAll({
|
||||
const fittingDurationItems = await cache.transaction.legacy.database.sessionDuration.findAll({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId,
|
||||
@@ -209,7 +209,7 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
[Sequelize.Op.lte]: limit.pause
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
const fittingDurationItemsLastUsageFiltered =
|
||||
@@ -259,9 +259,9 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
}
|
||||
}
|
||||
|
||||
await oldItem.save({ transaction: cache.transaction })
|
||||
await oldItem.save({ transaction: cache.transaction.legacy.transaction })
|
||||
} else {
|
||||
await cache.database.sessionDuration.create({
|
||||
await cache.transaction.legacy.database.sessionDuration.create({
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId,
|
||||
maxSessionDuration: limit.duration,
|
||||
@@ -272,21 +272,21 @@ export async function dispatchAddUsedTimeVersion2 ({ deviceId, action, cache, ev
|
||||
lastUsage: action.trustedTimestamp.toString(10),
|
||||
lastSessionDuration: await oldDuration() + item.timeToAdd,
|
||||
roundedLastUpdate: roundedTimestampForSessionDuration
|
||||
}, { transaction: cache.transaction })
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
}
|
||||
}
|
||||
|
||||
cache.categoriesWithModifiedUsedTimes.add(item.categoryId)
|
||||
|
||||
if (item.extraTimeToSubtract !== 0) {
|
||||
await cache.database.category.update({
|
||||
await cache.transaction.legacy.database.category.update({
|
||||
extraTimeInMillis: Math.max(0, categoryEntry.extraTimeInMillis - item.extraTimeToSubtract)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: item.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(item.categoryId)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,13 +23,13 @@ export async function dispatchFinishKeyRequestAction ({ action, cache, deviceId
|
||||
action: FinishKeyRequestAction
|
||||
cache: Cache
|
||||
}) {
|
||||
await cache.database.keyRequest.destroy({
|
||||
await cache.transaction.legacy.database.keyRequest.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
senderDeviceId: deviceId,
|
||||
senderSequenceNumber: action.deviceSequenceNumber.toString(10)
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
// no sync triggered
|
||||
|
||||
+13
-13
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -26,12 +26,12 @@ export async function dispatchMarkTaskPendingAction ({ action, cache, deviceId }
|
||||
action: MarkTaskPendingAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const taskInfoUnsafe = await cache.database.childTask.findOne({
|
||||
const taskInfoUnsafe = await cache.transaction.legacy.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['categoryId', 'pendingRequest', 'taskTitle']
|
||||
})
|
||||
|
||||
@@ -45,13 +45,13 @@ export async function dispatchMarkTaskPendingAction ({ action, cache, deviceId }
|
||||
|
||||
if (taskInfo.pendingRequest !== 0) return // review already requested
|
||||
|
||||
const categoryInfoUnsafe = await cache.database.category.findOne({
|
||||
const categoryInfoUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
attributes: ['childId'],
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (categoryInfoUnsafe === null) {
|
||||
@@ -60,13 +60,13 @@ export async function dispatchMarkTaskPendingAction ({ action, cache, deviceId }
|
||||
|
||||
const categoryInfo = { childId: categoryInfoUnsafe.childId }
|
||||
|
||||
const deviceInfoUnsafe = await cache.database.device.findOne({
|
||||
const deviceInfoUnsafe = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
attributes: ['currentUserId'],
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (deviceInfoUnsafe === null) throw new SourceDeviceNotFoundException()
|
||||
@@ -77,33 +77,33 @@ export async function dispatchMarkTaskPendingAction ({ action, cache, deviceId }
|
||||
throw new IllegalStateException({ staticMessage: 'Can not mark task pending for other user than the current user' })
|
||||
}
|
||||
|
||||
const childInfoUnsafe = await cache.database.user.findOne({
|
||||
const childInfoUnsafe = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: categoryInfo.childId
|
||||
},
|
||||
attributes: ['name'],
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (childInfoUnsafe === null) throw new SourceUserNotFoundException()
|
||||
|
||||
const childInfo = { name: childInfoUnsafe.name }
|
||||
|
||||
await cache.database.childTask.update({ pendingRequest: 1 }, {
|
||||
await cache.transaction.legacy.database.childTask.update({ pendingRequest: 1 }, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
cache.incrementTriggeredSyncLevel(1) // parents are not faster reachable
|
||||
|
||||
await sendTaskDoneMails({
|
||||
database: cache.database,
|
||||
transaction: cache.transaction,
|
||||
database: cache.transaction.legacy.database,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
familyId: cache.familyId,
|
||||
childName: childInfo.name,
|
||||
taskTitle: taskInfo.taskTitle
|
||||
|
||||
@@ -33,25 +33,25 @@ export async function dispatchPingAction ({ action, cache, deviceId }: {
|
||||
else throw new Error()
|
||||
|
||||
// delete any previous ping/pong
|
||||
await cache.database.ping.destroy({
|
||||
await cache.transaction.legacy.database.ping.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: action.deviceId,
|
||||
senderDeviceId: deviceId,
|
||||
type: type
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
// insert
|
||||
await cache.database.ping.create({
|
||||
await cache.transaction.legacy.database.ping.create({
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: action.deviceId,
|
||||
senderDeviceId: deviceId,
|
||||
type,
|
||||
token: action.token
|
||||
}, {
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
// notify
|
||||
@@ -60,14 +60,14 @@ export async function dispatchPingAction ({ action, cache, deviceId }: {
|
||||
|
||||
// handle deleting
|
||||
if (action.event === 'pong' || action.event === 'clear') {
|
||||
await cache.database.ping.destroy({
|
||||
await cache.transaction.legacy.database.ping.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: deviceId,
|
||||
senderDeviceId: action.deviceId,
|
||||
token: action.token
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -26,13 +26,13 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
|
||||
cache: Cache
|
||||
eventHandler: EventHandler
|
||||
}) {
|
||||
const requestUnsafe = await cache.database.keyRequest.findOne({
|
||||
const requestUnsafe = await cache.transaction.legacy.database.keyRequest.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
serverSequenceNumber: action.requestServerSequenceNumber.toString(10)
|
||||
},
|
||||
attributes: ['senderDeviceId', 'senderSequenceNumber'],
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!requestUnsafe) {
|
||||
@@ -46,14 +46,14 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
|
||||
senderSequenceNumber: requestUnsafe.senderSequenceNumber
|
||||
}
|
||||
|
||||
const oldReplyCounter = await cache.database.keyResponse.count({
|
||||
const oldReplyCounter = await cache.transaction.legacy.database.keyResponse.count({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: request.senderDeviceId,
|
||||
requestServerSequenceNumber: action.requestServerSequenceNumber.toString(10),
|
||||
senderDeviceId: deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (oldReplyCounter !== 0) {
|
||||
@@ -62,12 +62,12 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
|
||||
return
|
||||
}
|
||||
|
||||
const deviceEntryUnsafe = await cache.database.device.findOne({
|
||||
const deviceEntryUnsafe = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: request.senderDeviceId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['nextKeyReplySequenceNumber']
|
||||
})
|
||||
|
||||
@@ -81,17 +81,17 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
|
||||
nextKeyReplySequenceNumber: deviceEntryUnsafe.nextKeyReplySequenceNumber
|
||||
}
|
||||
|
||||
await cache.database.device.update({
|
||||
await cache.transaction.legacy.database.device.update({
|
||||
nextKeyReplySequenceNumber: (parseInt(deviceEntry.nextKeyReplySequenceNumber) + 1).toString(10)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: request.senderDeviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
await cache.database.keyResponse.create({
|
||||
await cache.transaction.legacy.database.keyResponse.create({
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: request.senderDeviceId,
|
||||
requestServerSequenceNumber: action.requestServerSequenceNumber.toString(10),
|
||||
@@ -102,7 +102,7 @@ export async function dispatchReplyToKeyRequestAction ({ deviceId, action, cache
|
||||
encryptedKey: action.encryptedKey,
|
||||
signature: action.signature
|
||||
}, {
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.incrementTargetedTriggeredSyncLevel(request.senderDeviceId, 2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -24,11 +24,11 @@ export async function dispatchSendKeyRequestAction ({ action, cache, deviceId }:
|
||||
action: SendKeyRequestAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const familyEntryUnsafe = await cache.database.family.findOne({
|
||||
const familyEntryUnsafe = await cache.transaction.legacy.database.family.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['nextServerKeyRequestSeq']
|
||||
})
|
||||
|
||||
@@ -38,16 +38,16 @@ export async function dispatchSendKeyRequestAction ({ action, cache, deviceId }:
|
||||
|
||||
const serverSequenceNumber = familyEntryUnsafe.nextServerKeyRequestSeq
|
||||
|
||||
await cache.database.family.update({
|
||||
await cache.transaction.legacy.database.family.update({
|
||||
nextServerKeyRequestSeq: (parseInt(serverSequenceNumber, 10) + 1).toString(10)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
await cache.database.keyRequest.destroy({
|
||||
await cache.transaction.legacy.database.keyRequest.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
senderDeviceId: deviceId,
|
||||
@@ -55,10 +55,10 @@ export async function dispatchSendKeyRequestAction ({ action, cache, deviceId }:
|
||||
deviceId: action.deviceId || null,
|
||||
categoryId: action.categoryId || null
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
await cache.database.keyRequest.create({
|
||||
await cache.transaction.legacy.database.keyRequest.create({
|
||||
familyId: cache.familyId,
|
||||
serverSequenceNumber: serverSequenceNumber,
|
||||
senderDeviceId: deviceId,
|
||||
@@ -69,7 +69,7 @@ export async function dispatchSendKeyRequestAction ({ action, cache, deviceId }:
|
||||
tempKey: action.tempKey,
|
||||
signature: action.signature
|
||||
}, {
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -30,12 +30,12 @@ export async function dispatchSignOutAtDevice ({ deviceId, cache }: {
|
||||
throw new PremiumVersionMissingException()
|
||||
}
|
||||
|
||||
const deviceEntry = await cache.database.device.findOne({
|
||||
const deviceEntry = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntry) {
|
||||
|
||||
+4
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -26,12 +26,12 @@ export async function dispatchTriedDisablingDeviceAdmin ({ deviceId, cache }: {
|
||||
action: TriedDisablingDeviceAdminAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const deviceEntry = await cache.database.device.findOne({
|
||||
const deviceEntry = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (deviceEntry === null) {
|
||||
@@ -43,7 +43,7 @@ export async function dispatchTriedDisablingDeviceAdmin ({ deviceId, cache }: {
|
||||
if (!deviceEntry.triedDisablingDeviceAdmin) {
|
||||
deviceEntry.triedDisablingDeviceAdmin = true
|
||||
|
||||
await deviceEntry.save({ transaction: cache.transaction })
|
||||
await deviceEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.invalidiateDeviceList = true
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
@@ -51,7 +51,6 @@ export async function dispatchTriedDisablingDeviceAdmin ({ deviceId, cache }: {
|
||||
|
||||
if (!hadManipulationBefore) {
|
||||
await sendManipulationWarnings({
|
||||
database: cache.database,
|
||||
transaction: cache.transaction,
|
||||
deviceName: deviceEntry.name,
|
||||
familyId: cache.familyId
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2023 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -30,12 +30,12 @@ export async function dispatchUpdateDeviceStatus ({ deviceId, action, cache }: {
|
||||
action: UpdateDeviceStatusAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const deviceEntry = await cache.database.device.findOne({
|
||||
const deviceEntry = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntry) {
|
||||
@@ -175,12 +175,11 @@ export async function dispatchUpdateDeviceStatus ({ deviceId, action, cache }: {
|
||||
}
|
||||
}
|
||||
|
||||
await deviceEntry.save({ transaction: cache.transaction })
|
||||
await deviceEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
if (hasDeviceManipulation(deviceEntry)) {
|
||||
if (!hadManipulationBefore) {
|
||||
await sendManipulationWarnings({
|
||||
database: cache.database,
|
||||
transaction: cache.transaction,
|
||||
deviceName: deviceEntry.name,
|
||||
familyId: cache.familyId
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -26,13 +26,13 @@ export async function dispatchUpdateInstalledApps ({ deviceId, action, cache }:
|
||||
cache: Cache
|
||||
}) {
|
||||
async function upsert({ type, data }: { type: number, data: Buffer }) {
|
||||
await cache.database.encryptedAppList.upsert({
|
||||
await cache.transaction.legacy.database.encryptedAppList.upsert({
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
type,
|
||||
version: generateVersionId(),
|
||||
data
|
||||
}, { transaction: cache.transaction })
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
}
|
||||
|
||||
if (action.base) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -26,12 +26,12 @@ export async function dispatchUploadDevicePublicKeyAction ({ deviceId, action, c
|
||||
cache: Cache
|
||||
eventHandler: EventHandler
|
||||
}) {
|
||||
const deviceEntry = await cache.database.device.findOne({
|
||||
const deviceEntry = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (deviceEntry === null) {
|
||||
@@ -39,7 +39,7 @@ export async function dispatchUploadDevicePublicKeyAction ({ deviceId, action, c
|
||||
} else if (deviceEntry.publicKey === null) {
|
||||
deviceEntry.publicKey = action.key
|
||||
|
||||
await deviceEntry.save({ transaction: cache.transaction })
|
||||
await deviceEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.invalidiateDeviceList = true
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -25,13 +25,13 @@ export const dispatchChildChangePassword = async ({ action, childUserId, cache }
|
||||
childUserId: string
|
||||
cache: Cache
|
||||
}) => {
|
||||
const childEntry = await cache.database.user.findOne({
|
||||
const childEntry = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: childUserId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!childEntry) {
|
||||
@@ -44,7 +44,7 @@ export const dispatchChildChangePassword = async ({ action, childUserId, cache }
|
||||
childEntry.secondPasswordSalt = newPassword.secondSalt
|
||||
childEntry.secondPasswordHash = newPassword.secondHash
|
||||
|
||||
await childEntry.save({ transaction: cache.transaction })
|
||||
await childEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
{
|
||||
const clear = cache.getSecondPasswordHashOfChild.cache.clear
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -39,13 +39,13 @@ export const dispatchChildSignIn = async ({ deviceId, childUserId, cache }: {
|
||||
cache
|
||||
})
|
||||
|
||||
const userEntryUnsafe = await cache.database.user.findOne({
|
||||
const userEntryUnsafe = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
type: 'child',
|
||||
userId: childUserId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: [
|
||||
'currentDevice'
|
||||
]
|
||||
@@ -58,7 +58,7 @@ export const dispatchChildSignIn = async ({ deviceId, childUserId, cache }: {
|
||||
if (userEntryUnsafe.currentDevice === deviceId) {
|
||||
// unassign to prevent way aroundprimary device rule
|
||||
|
||||
await cache.database.user.update({
|
||||
await cache.transaction.legacy.database.user.update({
|
||||
currentDevice: ''
|
||||
}, {
|
||||
where: {
|
||||
@@ -66,7 +66,7 @@ export const dispatchChildSignIn = async ({ deviceId, childUserId, cache }: {
|
||||
type: 'child',
|
||||
userId: childUserId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -45,14 +45,14 @@ export async function dispatchParentAction ({
|
||||
parser: parseParentAction,
|
||||
applier: async (parsedAction) => {
|
||||
if (isChildLimitAdding) {
|
||||
const deviceEntryUnsafe = await cache.database.device.findOne({
|
||||
const deviceEntryUnsafe = await cache.transaction.legacy.database.device.findOne({
|
||||
attributes: ['currentUserId'],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
currentUserId: action.userId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -67,14 +67,14 @@ export async function dispatchParentAction ({
|
||||
})
|
||||
}
|
||||
|
||||
const deviceUserEntryUnsafe = await cache.database.user.findOne({
|
||||
const deviceUserEntryUnsafe = await cache.transaction.legacy.database.user.findOne({
|
||||
attributes: ['flags'],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: deviceUserId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!deviceUserEntryUnsafe) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -29,12 +29,12 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
cache: Cache
|
||||
fromChildSelfLimitAddChildUserId: string | null
|
||||
}) {
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['childId']
|
||||
})
|
||||
|
||||
@@ -50,13 +50,13 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
}
|
||||
}
|
||||
|
||||
const categoriesOfSameChild = (await cache.database.category.findAll({
|
||||
const categoriesOfSameChild = (await cache.transaction.legacy.database.category.findAll({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
childId
|
||||
},
|
||||
attributes: ['categoryId', 'parentCategoryId'],
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})).map((item) => ({
|
||||
categoryId: item.categoryId,
|
||||
parentCategoryId: item.parentCategoryId
|
||||
@@ -64,7 +64,7 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
|
||||
const userCategoryIds = categoriesOfSameChild.map((item) => item.categoryId)
|
||||
|
||||
const oldCategories = (await cache.database.categoryApp.findAll({
|
||||
const oldCategories = (await cache.transaction.legacy.database.categoryApp.findAll({
|
||||
attributes: [ 'categoryId' ],
|
||||
group: [ 'categoryId' ],
|
||||
where: {
|
||||
@@ -76,7 +76,7 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
[Sequelize.Op.in]: action.packageNames
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})).map((item) => item.categoryId)
|
||||
|
||||
if (fromChildSelfLimitAddChildUserId !== null) {
|
||||
@@ -92,13 +92,13 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
|
||||
try {
|
||||
const parentCategoriesOfTargetCategory = getCategoryWithParentCategories(categoriesOfSameChild, action.categoryId)
|
||||
const userEntryUnsafe = await cache.database.user.findOne({
|
||||
const userEntryUnsafe = await cache.transaction.legacy.database.user.findOne({
|
||||
attributes: [ 'categoryForNotAssignedApps' ],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: fromChildSelfLimitAddChildUserId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!userEntryUnsafe) {
|
||||
@@ -111,7 +111,7 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
parentCategoriesOfTargetCategory.indexOf(validatedDefaultCategoryId) !== -1
|
||||
|
||||
const assertCanAddApp = async (packageName: string, isApp: boolean) => {
|
||||
const categoryAppEntryUnsafe = await cache.database.categoryApp.findOne({
|
||||
const categoryAppEntryUnsafe = await cache.transaction.legacy.database.categoryApp.findOne({
|
||||
attributes: [ 'categoryId' ],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
@@ -120,7 +120,7 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
},
|
||||
packageName: packageName
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
const categoryAppEntry = categoryAppEntryUnsafe ? { categoryId: categoryAppEntryUnsafe.categoryId } : null
|
||||
@@ -162,7 +162,7 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
}
|
||||
|
||||
if (oldCategories.length > 0) {
|
||||
await cache.database.categoryApp.destroy({
|
||||
await cache.transaction.legacy.database.categoryApp.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: {
|
||||
@@ -172,18 +172,18 @@ export async function dispatchAddCategoryApps ({ action, cache, fromChildSelfLim
|
||||
[Sequelize.Op.in]: action.packageNames
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
|
||||
await cache.database.categoryApp.bulkCreate(
|
||||
await cache.transaction.legacy.database.categoryApp.bulkCreate(
|
||||
action.packageNames.map((packageName): CategoryAppAttributes => ({
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
packageName
|
||||
})),
|
||||
{
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -25,12 +25,12 @@ export async function dispatchAddCategoryNetworkId ({ action, cache }: {
|
||||
action: AddCategoryNetworkIdAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['childId']
|
||||
})
|
||||
|
||||
@@ -38,12 +38,12 @@ export async function dispatchAddCategoryNetworkId ({ action, cache }: {
|
||||
throw new MissingCategoryException()
|
||||
}
|
||||
|
||||
const count = await cache.database.categoryNetworkId.count({
|
||||
const count = await cache.transaction.legacy.database.categoryNetworkId.count({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (count + 1 > maxNetworkIdsPerCategory) {
|
||||
@@ -52,13 +52,13 @@ export async function dispatchAddCategoryNetworkId ({ action, cache }: {
|
||||
})
|
||||
}
|
||||
|
||||
const hasOldItem = (await cache.database.categoryNetworkId.count({
|
||||
const hasOldItem = (await cache.transaction.legacy.database.categoryNetworkId.count({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
networkItemId: action.itemId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})) !== 0
|
||||
|
||||
if (hasOldItem) {
|
||||
@@ -67,12 +67,12 @@ export async function dispatchAddCategoryNetworkId ({ action, cache }: {
|
||||
})
|
||||
}
|
||||
|
||||
await cache.database.categoryNetworkId.create({
|
||||
await cache.transaction.legacy.database.categoryNetworkId.create({
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
networkItemId: action.itemId,
|
||||
hashedNetworkId: action.hashedNetworkId
|
||||
}, { transaction: cache.transaction })
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(action.categoryId)
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -25,16 +25,16 @@ export async function dispatchAddU2f ({ action, cache, parentUserId }: {
|
||||
cache: Cache
|
||||
parentUserId: string
|
||||
}) {
|
||||
const counter = await cache.database.u2fKey.count({
|
||||
const counter = await cache.transaction.legacy.database.u2fKey.count({
|
||||
where: {
|
||||
familyId: cache.familyId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (counter >= 16) throw new LimitReachedException({ type: 'u2f keys' })
|
||||
|
||||
await cache.database.u2fKey.create({
|
||||
await cache.transaction.legacy.database.u2fKey.create({
|
||||
familyId: cache.familyId,
|
||||
keyId: getU2fKeyId({ keyHandle: action.keyHandle, publicKey: action.publicKey }),
|
||||
userId: parentUserId,
|
||||
@@ -42,7 +42,7 @@ export async function dispatchAddU2f ({ action, cache, parentUserId }: {
|
||||
keyHandle: action.keyHandle,
|
||||
publicKey: action.publicKey,
|
||||
nextCounter: '0'
|
||||
}, { transaction: cache.transaction })
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.invalidateU2fList = true
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -28,7 +28,7 @@ export async function dispatchAddUser ({ action, cache }: {
|
||||
await decryptParentPassword({ cache, password: action.password }) :
|
||||
null
|
||||
|
||||
await cache.database.user.create({
|
||||
await cache.transaction.legacy.database.user.create({
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId,
|
||||
type: action.userType,
|
||||
@@ -45,7 +45,7 @@ export async function dispatchAddUser ({ action, cache }: {
|
||||
mailNotificationFlags: 0,
|
||||
blockedTimes: '',
|
||||
flags: '0'
|
||||
}, { transaction: cache.transaction })
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
|
||||
@@ -24,13 +24,13 @@ export async function dispatchChangeParentPassword ({ action, cache }: {
|
||||
action: ChangeParentPasswordAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const parentEntry = await cache.database.user.findOne({
|
||||
const parentEntry = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.parentUserId,
|
||||
type: 'parent'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!parentEntry) {
|
||||
@@ -51,7 +51,7 @@ export async function dispatchChangeParentPassword ({ action, cache }: {
|
||||
parentEntry.secondPasswordSalt = action.newPasswordSecondSalt
|
||||
parentEntry.secondPasswordHash = newSecondPasswordHash
|
||||
|
||||
await parentEntry.save({ transaction: cache.transaction })
|
||||
await parentEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
{
|
||||
const clear = cache.getSecondPasswordHashOfParent.cache.clear
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -33,21 +33,21 @@ export async function dispatchCreateCategory ({ action, cache, fromChildSelfLimi
|
||||
}
|
||||
|
||||
// check that the child exists
|
||||
const childEntry = await cache.database.user.findOne({
|
||||
const childEntry = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.childId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!childEntry) {
|
||||
throw new MissingUserException()
|
||||
}
|
||||
|
||||
const oldMaxSort: number = await cache.database.category.max('sort', {
|
||||
transaction: cache.transaction,
|
||||
const oldMaxSort: number = await cache.transaction.legacy.database.category.max('sort', {
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
childId: action.childId
|
||||
@@ -58,7 +58,7 @@ export async function dispatchCreateCategory ({ action, cache, fromChildSelfLimi
|
||||
const sort = Number.isSafeInteger(oldMaxSort + 1) ? (oldMaxSort + 1) : 0
|
||||
|
||||
// no version number needs to be updated
|
||||
await cache.database.category.create({
|
||||
await cache.transaction.legacy.database.category.create({
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
childId: action.childId,
|
||||
@@ -82,7 +82,7 @@ export async function dispatchCreateCategory ({ action, cache, fromChildSelfLimi
|
||||
minBatteryMobile: 0,
|
||||
flags: '0',
|
||||
blockNotificationDelay: '0'
|
||||
}, { transaction: cache.transaction })
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
// update the cache
|
||||
cache.doesCategoryExist.cache.set(action.categoryId, true)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2024 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -25,12 +25,12 @@ export async function dispatchCreateTimeLimitRule ({ action, cache, fromChildSel
|
||||
cache: Cache
|
||||
fromChildSelfLimitAddChildUserId: string | null
|
||||
}) {
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.rule.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['childId']
|
||||
})
|
||||
|
||||
@@ -44,7 +44,7 @@ export async function dispatchCreateTimeLimitRule ({ action, cache, fromChildSel
|
||||
}
|
||||
}
|
||||
|
||||
await cache.database.timelimitRule.create({
|
||||
await cache.transaction.legacy.database.timelimitRule.create({
|
||||
familyId: cache.familyId,
|
||||
ruleId: action.rule.ruleId,
|
||||
categoryId: action.rule.categoryId,
|
||||
@@ -57,7 +57,7 @@ export async function dispatchCreateTimeLimitRule ({ action, cache, fromChildSel
|
||||
sessionPauseMilliseconds: action.rule.sessionPauseMilliseconds,
|
||||
perDay: action.rule.perDay ? 1 : 0,
|
||||
expiresAt: action.rule.expiresAt ? action.rule.expiresAt.toString() : null
|
||||
}, { transaction: cache.transaction })
|
||||
}, { transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.categoriesWithModifiedTimeLimitRules.add(action.rule.categoryId)
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,59 +23,59 @@ export async function dispatchDeleteCategory ({ action, cache }: {
|
||||
action: DeleteCategoryAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const { familyId, transaction } = cache
|
||||
const { familyId } = cache
|
||||
const { categoryId } = action
|
||||
|
||||
const categoryEntry = await cache.database.category.findOne({
|
||||
const categoryEntry = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId,
|
||||
categoryId
|
||||
},
|
||||
transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!categoryEntry) { throw new MissingCategoryException() }
|
||||
|
||||
await cache.database.timelimitRule.destroy({
|
||||
await cache.transaction.legacy.database.timelimitRule.destroy({
|
||||
where: {
|
||||
familyId,
|
||||
categoryId
|
||||
},
|
||||
transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
await cache.database.usedTime.destroy({
|
||||
await cache.transaction.legacy.database.usedTime.destroy({
|
||||
where: {
|
||||
familyId,
|
||||
categoryId
|
||||
},
|
||||
transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
await cache.database.categoryApp.destroy({
|
||||
await cache.transaction.legacy.database.categoryApp.destroy({
|
||||
where: {
|
||||
familyId,
|
||||
categoryId
|
||||
},
|
||||
transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
const [affectedUserRows] = await cache.database.user.update({
|
||||
const [affectedUserRows] = await cache.transaction.legacy.database.user.update({
|
||||
categoryForNotAssignedApps: ''
|
||||
}, {
|
||||
where: {
|
||||
familyId,
|
||||
categoryForNotAssignedApps: categoryId
|
||||
},
|
||||
transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
await cache.database.category.destroy({
|
||||
await cache.transaction.legacy.database.category.destroy({
|
||||
where: {
|
||||
familyId,
|
||||
categoryId
|
||||
},
|
||||
transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
// update the cache
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,12 +23,12 @@ export async function dispatchDeleteChildTaskAction ({ action, cache }: {
|
||||
action: DeleteChildTaskAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const taskInfoUnsafe = await cache.database.childTask.findOne({
|
||||
const taskInfoUnsafe = await cache.transaction.legacy.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['categoryId']
|
||||
})
|
||||
|
||||
@@ -36,12 +36,12 @@ export async function dispatchDeleteChildTaskAction ({ action, cache }: {
|
||||
|
||||
const taskInfo = { categoryId: taskInfoUnsafe.categoryId }
|
||||
|
||||
await cache.database.childTask.destroy({
|
||||
await cache.transaction.legacy.database.childTask.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,19 +23,19 @@ export async function dispatchDeleteTimeLimitRule ({ action, cache }: {
|
||||
action: DeleteTimeLimitRuleAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const ruleEntry = await cache.database.timelimitRule.findOne({
|
||||
const ruleEntry = await cache.transaction.legacy.database.timelimitRule.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
ruleId: action.ruleId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!ruleEntry) {
|
||||
throw new MissingRuleException()
|
||||
}
|
||||
|
||||
await ruleEntry.destroy({ transaction: cache.transaction })
|
||||
await ruleEntry.destroy({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.categoriesWithModifiedTimeLimitRules.add(ruleEntry.categoryId)
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,12 +23,12 @@ export async function dispatchIgnoreManipulation ({ action, cache }: {
|
||||
action: IgnoreManipulationAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const deviceEntry = await cache.database.device.findOne({
|
||||
const deviceEntry = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (deviceEntry === null) {
|
||||
@@ -85,7 +85,7 @@ export async function dispatchIgnoreManipulation ({ action, cache }: {
|
||||
deviceEntry.manipulationFlags = deviceEntry.manipulationFlags & (~action.ignoreManipulationFlags)
|
||||
}
|
||||
|
||||
await deviceEntry.save({ transaction: cache.transaction })
|
||||
await deviceEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
cache.invalidiateDeviceList = true
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
cache.incrementTargetedTriggeredSyncLevel(action.deviceId, 2)
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -38,18 +38,18 @@ export async function dispatchIncrementCategoryExtraTime ({ action, cache }: {
|
||||
|
||||
category.extraTimeDay = action.day
|
||||
|
||||
await category.save({ transaction: cache.transaction })
|
||||
await category.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(category.categoryId)
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
}
|
||||
|
||||
const categoryEntry = await cache.database.category.findOne({
|
||||
const categoryEntry = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!categoryEntry) {
|
||||
@@ -59,12 +59,12 @@ export async function dispatchIncrementCategoryExtraTime ({ action, cache }: {
|
||||
await handleCategory(categoryEntry)
|
||||
|
||||
if (categoryEntry.parentCategoryId !== '') {
|
||||
const parentCategoryEntry = await cache.database.category.findOne({
|
||||
const parentCategoryEntry = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: categoryEntry.parentCategoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (parentCategoryEntry) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -24,7 +24,7 @@ export async function dispatchRemoveCategoryApps ({ action, cache }: {
|
||||
action: RemoveCategoryAppsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const affectedRows = await cache.database.categoryApp.destroy({
|
||||
const affectedRows = await cache.transaction.legacy.database.categoryApp.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
@@ -32,7 +32,7 @@ export async function dispatchRemoveCategoryApps ({ action, cache }: {
|
||||
[Sequelize.Op.in]: action.packageNames
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (affectedRows !== action.packageNames.length) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -31,7 +31,7 @@ export async function dispatchRemoveU2f ({ action, cache, parentUserId, authenti
|
||||
throw new ApplyActionUnacceptableAuthMethodException()
|
||||
}
|
||||
|
||||
await cache.database.u2fKey.destroy({
|
||||
await cache.transaction.legacy.database.u2fKey.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
keyId: getU2fKeyId({ keyHandle: action.keyHandle, publicKey: action.publicKey }),
|
||||
@@ -39,7 +39,7 @@ export async function dispatchRemoveU2f ({ action, cache, parentUserId, authenti
|
||||
keyHandle: action.keyHandle,
|
||||
publicKey: action.publicKey
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.invalidateU2fList = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -30,12 +30,12 @@ export async function dispatchRemoveUser ({ action, cache, parentUserId }: {
|
||||
cache: Cache
|
||||
parentUserId: string
|
||||
}) {
|
||||
const user = await cache.database.user.findOne({
|
||||
const user = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!user) {
|
||||
@@ -60,8 +60,8 @@ export async function dispatchRemoveUser ({ action, cache, parentUserId }: {
|
||||
}
|
||||
|
||||
if (user.mail !== '') {
|
||||
const usersWithLinkedMail = await cache.database.user.count({
|
||||
transaction: cache.transaction,
|
||||
const usersWithLinkedMail = await cache.transaction.legacy.database.user.count({
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
type: 'parent',
|
||||
@@ -76,16 +76,16 @@ export async function dispatchRemoveUser ({ action, cache, parentUserId }: {
|
||||
}
|
||||
}
|
||||
|
||||
const usersWithLimitLoginCategories = (await cache.database.userLimitLoginCategory.findAll({
|
||||
transaction: cache.transaction,
|
||||
const usersWithLimitLoginCategories = (await cache.transaction.legacy.database.userLimitLoginCategory.findAll({
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId
|
||||
},
|
||||
attributes: ['userId']
|
||||
})).map((item) => item.userId)
|
||||
|
||||
const allParentUserIds = (await cache.database.user.findAll({
|
||||
transaction: cache.transaction,
|
||||
const allParentUserIds = (await cache.transaction.legacy.database.user.findAll({
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
type: 'parent'
|
||||
@@ -101,56 +101,56 @@ export async function dispatchRemoveUser ({ action, cache, parentUserId }: {
|
||||
}
|
||||
|
||||
if (user.type === 'child') {
|
||||
const categories = await cache.database.category.findAll({
|
||||
const categories = await cache.transaction.legacy.database.category.findAll({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
childId: action.userId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
await cache.database.categoryApp.destroy({
|
||||
await cache.transaction.legacy.database.categoryApp.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: {
|
||||
[Sequelize.Op.in]: categories.map((category) => category.categoryId)
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
await cache.database.timelimitRule.destroy({
|
||||
await cache.transaction.legacy.database.timelimitRule.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: {
|
||||
[Sequelize.Op.in]: categories.map((category) => category.categoryId)
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
await cache.database.usedTime.destroy({
|
||||
await cache.transaction.legacy.database.usedTime.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: {
|
||||
[Sequelize.Op.in]: categories.map((category) => category.categoryId)
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
await cache.database.category.destroy({
|
||||
await cache.transaction.legacy.database.category.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: {
|
||||
[Sequelize.Op.in]: categories.map((category) => category.categoryId)
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
|
||||
const [updatedDevices1] = await cache.database.device.update({
|
||||
const [updatedDevices1] = await cache.transaction.legacy.database.device.update({
|
||||
currentUserId: '',
|
||||
isUserKeptSignedIn: false
|
||||
}, {
|
||||
@@ -158,24 +158,24 @@ export async function dispatchRemoveUser ({ action, cache, parentUserId }: {
|
||||
familyId: cache.familyId,
|
||||
currentUserId: action.userId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
const [updatedDevices2] = await cache.database.device.update({
|
||||
const [updatedDevices2] = await cache.transaction.legacy.database.device.update({
|
||||
defaultUserId: ''
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
defaultUserId: action.userId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (updatedDevices1 > 0 || updatedDevices2 > 0) {
|
||||
cache.invalidiateDeviceList = true
|
||||
}
|
||||
|
||||
await user.destroy({ transaction: cache.transaction })
|
||||
await user.destroy({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,20 +23,20 @@ export async function dispatchRenameChild ({ action, cache }: {
|
||||
action: RenameChildAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const oldItem = await cache.database.user.findOne({
|
||||
const oldItem = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.childId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!oldItem) {
|
||||
throw new MissingUserException()
|
||||
}
|
||||
|
||||
await cache.database.user.update({
|
||||
await cache.transaction.legacy.database.user.update({
|
||||
name: action.newName
|
||||
}, {
|
||||
where: {
|
||||
@@ -44,7 +44,7 @@ export async function dispatchRenameChild ({ action, cache }: {
|
||||
userId: action.childId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,12 +23,12 @@ export async function dispatchResetCategoryNetworkIds ({ action, cache }: {
|
||||
action: ResetCategoryNetworkIdsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['childId']
|
||||
})
|
||||
|
||||
@@ -36,12 +36,12 @@ export async function dispatchResetCategoryNetworkIds ({ action, cache }: {
|
||||
throw new MissingCategoryException()
|
||||
}
|
||||
|
||||
await cache.database.categoryNetworkId.destroy({
|
||||
await cache.transaction.legacy.database.categoryNetworkId.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(action.categoryId)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -29,12 +29,12 @@ export async function dispatchReviewChildTaskAction ({ action, cache }: {
|
||||
throw new PremiumVersionMissingException()
|
||||
}
|
||||
|
||||
const taskInfo = await cache.database.childTask.findOne({
|
||||
const taskInfo = await cache.transaction.legacy.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (taskInfo === null) throw new MissingTaskException()
|
||||
@@ -42,13 +42,13 @@ export async function dispatchReviewChildTaskAction ({ action, cache }: {
|
||||
if (taskInfo.pendingRequest === 0) throw new IllegalStateException({ staticMessage: 'no task review pending' })
|
||||
|
||||
if (action.ok) {
|
||||
const categoryInfoUnsafe = await cache.database.category.findOne({
|
||||
const categoryInfoUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
attributes: ['extraTimeInMillis', 'extraTimeDay'],
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (categoryInfoUnsafe === null) {
|
||||
@@ -64,7 +64,7 @@ export async function dispatchReviewChildTaskAction ({ action, cache }: {
|
||||
action.day !== undefined && categoryInfo.extraTimeDay !== action.day
|
||||
|
||||
if (resetDayBoundExtraTime) {
|
||||
await cache.database.category.update({
|
||||
await cache.transaction.legacy.database.category.update({
|
||||
extraTimeInMillis: taskInfo.extraTimeDuration,
|
||||
extraTimeDay: -1
|
||||
}, {
|
||||
@@ -72,23 +72,23 @@ export async function dispatchReviewChildTaskAction ({ action, cache }: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
} else {
|
||||
await cache.database.category.update({
|
||||
await cache.transaction.legacy.database.category.update({
|
||||
extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(taskInfo.categoryId)
|
||||
|
||||
await cache.database.childTask.update({
|
||||
await cache.transaction.legacy.database.childTask.update({
|
||||
pendingRequest: 0,
|
||||
lastGrantTimestamp: action.time.toString(10)
|
||||
}, {
|
||||
@@ -96,19 +96,19 @@ export async function dispatchReviewChildTaskAction ({ action, cache }: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
} else {
|
||||
await cache.database.childTask.update({
|
||||
await cache.transaction.legacy.database.childTask.update({
|
||||
pendingRequest: 0
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -28,19 +28,19 @@ export async function dispatchSetCategoryExtraTime ({ action, cache }: {
|
||||
throw new PremiumVersionMissingException()
|
||||
}
|
||||
|
||||
const oldItem = await cache.database.category.findOne({
|
||||
const oldItem = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!oldItem) {
|
||||
throw new MissingCategoryException()
|
||||
}
|
||||
|
||||
await cache.database.category.update({
|
||||
await cache.transaction.legacy.database.category.update({
|
||||
extraTimeInMillis: action.newExtraTime,
|
||||
extraTimeDay: action.day
|
||||
}, {
|
||||
@@ -48,7 +48,7 @@ export async function dispatchSetCategoryExtraTime ({ action, cache }: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(action.categoryId)
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -24,13 +24,13 @@ export async function dispatchSetCategoryForUnassignedApps ({ action, cache }: {
|
||||
action: SetCategoryForUnassignedAppsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const oldUserEntry = await cache.database.user.findOne({
|
||||
const oldUserEntry = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.childId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!oldUserEntry) {
|
||||
@@ -40,13 +40,13 @@ export async function dispatchSetCategoryForUnassignedApps ({ action, cache }: {
|
||||
if (action.categoryId === '') {
|
||||
// nothing to check
|
||||
} else {
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
attributes: ['childId'],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!categoryEntryUnsafe) {
|
||||
@@ -66,7 +66,7 @@ export async function dispatchSetCategoryForUnassignedApps ({ action, cache }: {
|
||||
}
|
||||
}
|
||||
|
||||
await cache.database.user.update({
|
||||
await cache.transaction.legacy.database.user.update({
|
||||
categoryForNotAssignedApps: action.categoryId
|
||||
}, {
|
||||
where: {
|
||||
@@ -74,7 +74,7 @@ export async function dispatchSetCategoryForUnassignedApps ({ action, cache }: {
|
||||
userId: action.childId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
|
||||
@@ -24,13 +24,13 @@ export async function dispatchSetChildPassword ({ action, cache }: {
|
||||
action: SetChildPasswordAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const childEntry = await cache.database.user.findOne({
|
||||
const childEntry = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.childUserId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!childEntry) {
|
||||
@@ -43,7 +43,7 @@ export async function dispatchSetChildPassword ({ action, cache }: {
|
||||
childEntry.secondPasswordSalt = newPassword.secondSalt
|
||||
childEntry.secondPasswordHash = newPassword.secondHash
|
||||
|
||||
await childEntry.save({ transaction: cache.transaction })
|
||||
await childEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
{
|
||||
const clear = cache.getSecondPasswordHashOfChild.cache.clear
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,8 +23,8 @@ export async function dispatchSetConsiderRebootManipulation ({ action, cache }:
|
||||
action: SetConsiderRebootManipulationAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const oldDevice = await cache.database.device.findOne({
|
||||
transaction: cache.transaction,
|
||||
const oldDevice = await cache.transaction.legacy.database.device.findOne({
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
@@ -35,10 +35,10 @@ export async function dispatchSetConsiderRebootManipulation ({ action, cache }:
|
||||
throw new MissingDeviceException()
|
||||
}
|
||||
|
||||
await cache.database.device.update({
|
||||
await cache.transaction.legacy.database.device.update({
|
||||
considerRebootManipulation: action.enable
|
||||
}, {
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -31,8 +31,8 @@ export async function dispatchSetDeviceDefaultUser ({ action, cache }: {
|
||||
}
|
||||
}
|
||||
|
||||
const oldDeviceItem = await cache.database.device.findOne({
|
||||
transaction: cache.transaction,
|
||||
const oldDeviceItem = await cache.transaction.legacy.database.device.findOne({
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
@@ -43,10 +43,10 @@ export async function dispatchSetDeviceDefaultUser ({ action, cache }: {
|
||||
throw new MissingDeviceException()
|
||||
}
|
||||
|
||||
await cache.database.device.update({
|
||||
await cache.transaction.legacy.database.device.update({
|
||||
defaultUserId: action.defaultUserId
|
||||
}, {
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,8 +23,8 @@ export async function dispatchSetDeviceDefaultUserTimeout ({ action, cache }: {
|
||||
action: SetDeviceDefaultUserTimeoutAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const oldDeviceItem = await cache.database.device.findOne({
|
||||
transaction: cache.transaction,
|
||||
const oldDeviceItem = await cache.transaction.legacy.database.device.findOne({
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
@@ -35,10 +35,10 @@ export async function dispatchSetDeviceDefaultUserTimeout ({ action, cache }: {
|
||||
throw new MissingDeviceException()
|
||||
}
|
||||
|
||||
await cache.database.device.update({
|
||||
await cache.transaction.legacy.database.device.update({
|
||||
defaultUserTimeout: action.timeout
|
||||
}, {
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -31,19 +31,19 @@ export async function dispatchSetDeviceUser ({ action, cache }: {
|
||||
}
|
||||
}
|
||||
|
||||
const oldDeviceItem = await cache.database.device.findOne({
|
||||
const oldDeviceItem = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!oldDeviceItem) {
|
||||
throw new MissingDeviceException()
|
||||
}
|
||||
|
||||
await cache.database.device.update({
|
||||
await cache.transaction.legacy.database.device.update({
|
||||
currentUserId: action.userId,
|
||||
isUserKeptSignedIn: false
|
||||
}, {
|
||||
@@ -51,7 +51,7 @@ export async function dispatchSetDeviceUser ({ action, cache }: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.invalidiateDeviceList = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -32,12 +32,12 @@ export async function dispatchSetKeepSignedIn ({ action, cache, parentUserId }:
|
||||
throw new SourceUserNotFoundException()
|
||||
}
|
||||
|
||||
const deviceEntry = await cache.database.device.findOne({
|
||||
const deviceEntry = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntry) {
|
||||
@@ -50,7 +50,7 @@ export async function dispatchSetKeepSignedIn ({ action, cache, parentUserId }:
|
||||
}
|
||||
}
|
||||
|
||||
const [affectedRows] = await cache.database.device.update({
|
||||
const [affectedRows] = await cache.transaction.legacy.database.device.update({
|
||||
isUserKeptSignedIn: action.keepSignedIn
|
||||
}, {
|
||||
where: {
|
||||
@@ -58,7 +58,7 @@ export async function dispatchSetKeepSignedIn ({ action, cache, parentUserId }:
|
||||
deviceId: action.deviceId,
|
||||
currentUserId: deviceEntry.currentUserId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (affectedRows !== 0) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -27,12 +27,12 @@ export async function dispatchSetParentCategory ({ action, cache, fromChildSelfL
|
||||
cache: Cache
|
||||
fromChildSelfLimitAddChildUserId: string | null
|
||||
}) {
|
||||
const categoryEntry = await cache.database.category.findOne({
|
||||
const categoryEntry = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!categoryEntry) {
|
||||
@@ -46,13 +46,13 @@ export async function dispatchSetParentCategory ({ action, cache, fromChildSelfL
|
||||
}
|
||||
|
||||
if (action.parentCategory !== '') {
|
||||
const categoriesByUserId = (await cache.database.category.findAll({
|
||||
const categoriesByUserId = (await cache.transaction.legacy.database.category.findAll({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
childId: categoryEntry.childId
|
||||
},
|
||||
attributes: ['categoryId', 'parentCategoryId'],
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})).map((item) => ({
|
||||
categoryId: item.categoryId,
|
||||
parentCategoryId: item.parentCategoryId
|
||||
@@ -107,14 +107,14 @@ export async function dispatchSetParentCategory ({ action, cache, fromChildSelfL
|
||||
}
|
||||
}
|
||||
|
||||
await cache.database.category.update({
|
||||
await cache.transaction.legacy.database.category.update({
|
||||
parentCategoryId: action.parentCategory
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(action.categoryId)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,8 +23,8 @@ export async function dispatchSetRelaxPrimaryDevice ({ action, cache }: {
|
||||
action: SetRelaxPrimaryDeviceAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const oldUser = cache.database.user.findOne({
|
||||
transaction: cache.transaction,
|
||||
const oldUser = cache.transaction.legacy.database.user.findOne({
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId,
|
||||
@@ -36,10 +36,10 @@ export async function dispatchSetRelaxPrimaryDevice ({ action, cache }: {
|
||||
throw new MissingUserException()
|
||||
}
|
||||
|
||||
await cache.database.user.update({
|
||||
await cache.transaction.legacy.database.user.update({
|
||||
relaxPrimaryDeviceRule: action.relax
|
||||
}, {
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -30,10 +30,10 @@ export async function dispatchSetSendDeviceConnected ({ action, cache, sourceDev
|
||||
})
|
||||
}
|
||||
|
||||
await cache.database.device.update({
|
||||
await cache.transaction.legacy.database.device.update({
|
||||
showDeviceConnected: action.enable
|
||||
}, {
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -30,20 +30,20 @@ export async function dispatchUserSetDisableLimitsUntil ({ action, cache }: {
|
||||
}
|
||||
}
|
||||
|
||||
const oldUser = await cache.database.user.findOne({
|
||||
const oldUser = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.childId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!oldUser) {
|
||||
throw new MissingUserException()
|
||||
}
|
||||
|
||||
await cache.database.user.update({
|
||||
await cache.transaction.legacy.database.user.update({
|
||||
disableTimelimitsUntil: action.timestamp.toString(10)
|
||||
}, {
|
||||
where: {
|
||||
@@ -51,7 +51,7 @@ export async function dispatchUserSetDisableLimitsUntil ({ action, cache }: {
|
||||
userId: action.childId,
|
||||
type: 'child'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,22 +23,22 @@ export async function dispatchSetUserTimezone ({ action, cache }: {
|
||||
action: SetUserTimezoneAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const oldUser = await cache.database.user.findOne({
|
||||
const oldUser = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!oldUser) {
|
||||
throw new MissingUserException()
|
||||
}
|
||||
|
||||
await cache.database.user.update({
|
||||
await cache.transaction.legacy.database.user.update({
|
||||
timeZone: action.timezone
|
||||
}, {
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,12 +23,12 @@ export async function dispatchUpdateCategoryBatteryLimit ({ action, cache }: {
|
||||
action: UpdateCategoryBatteryLimitAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryEntry = await cache.database.category.findOne({
|
||||
const categoryEntry = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!categoryEntry) {
|
||||
@@ -43,7 +43,7 @@ export async function dispatchUpdateCategoryBatteryLimit ({ action, cache }: {
|
||||
categoryEntry.minBatteryMobile = action.mobileLimit
|
||||
}
|
||||
|
||||
await categoryEntry.save({ transaction: cache.transaction })
|
||||
await categoryEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(action.categoryId)
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -25,12 +25,12 @@ export async function dispatchUpdateCategoryBlockAllNotifications ({ action, cac
|
||||
cache: Cache
|
||||
fromChildSelfLimitAddChildUserId: string | null
|
||||
}) {
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['childId', 'blockAllNotifications']
|
||||
})
|
||||
|
||||
@@ -57,7 +57,7 @@ export async function dispatchUpdateCategoryBlockAllNotifications ({ action, cac
|
||||
}
|
||||
}
|
||||
|
||||
const [affectedRows] = await cache.database.category.update(action.blockDelay === undefined ? {
|
||||
const [affectedRows] = await cache.transaction.legacy.database.category.update(action.blockDelay === undefined ? {
|
||||
blockAllNotifications: action.blocked
|
||||
} : {
|
||||
blockAllNotifications: action.blocked,
|
||||
@@ -67,7 +67,7 @@ export async function dispatchUpdateCategoryBlockAllNotifications ({ action, cac
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (affectedRows !== 0) {
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -26,12 +26,12 @@ export async function dispatchUpdateCategoryBlockedTimes ({ action, cache, fromC
|
||||
cache: Cache
|
||||
fromChildSelfLimitAddChildUserId: string | null
|
||||
}) {
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['childId', 'blockedMinutesInWeek']
|
||||
})
|
||||
|
||||
@@ -59,14 +59,14 @@ export async function dispatchUpdateCategoryBlockedTimes ({ action, cache, fromC
|
||||
})
|
||||
}
|
||||
|
||||
await cache.database.category.update({
|
||||
await cache.transaction.legacy.database.category.update({
|
||||
blockedMinutesInWeek: action.blockedTimes
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(action.categoryId)
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -36,12 +36,12 @@ export async function dispatchUpdateCategoryDisableLimits ({ action, cache, from
|
||||
}
|
||||
}
|
||||
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['childId']
|
||||
})
|
||||
|
||||
@@ -59,14 +59,14 @@ export async function dispatchUpdateCategoryDisableLimits ({ action, cache, from
|
||||
}
|
||||
}
|
||||
|
||||
const [affectedRows] = await cache.database.category.update({
|
||||
const [affectedRows] = await cache.transaction.legacy.database.category.update({
|
||||
disableLimitsUntil: action.endTime.toString(10)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (affectedRows !== 0) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -24,12 +24,12 @@ export async function dispatchUpdateCategoryFlagsAction ({ action, cache }: {
|
||||
action: UpdateCategoryFlagsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryEntry = await cache.database.category.findOne({
|
||||
const categoryEntry = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!categoryEntry) {
|
||||
@@ -46,7 +46,7 @@ export async function dispatchUpdateCategoryFlagsAction ({ action, cache }: {
|
||||
|
||||
categoryEntry.flags = newFlags.toString(10)
|
||||
|
||||
await categoryEntry.save({ transaction: cache.transaction })
|
||||
await categoryEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(action.categoryId)
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -30,10 +30,10 @@ export async function dispatchUpdateCategorySorting ({ action, cache }: {
|
||||
for (let i = 0; i < action.categoryIds.length; i++) {
|
||||
const categoryId = action.categoryIds[i]
|
||||
|
||||
await cache.database.category.update({
|
||||
await cache.transaction.legacy.database.category.update({
|
||||
sort: i
|
||||
}, {
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -32,12 +32,12 @@ export async function dispatchUpdateCategoryTemporarilyBlocked ({ action, cache,
|
||||
}
|
||||
}
|
||||
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['childId', 'temporarilyBlocked', 'temporarilyBlockedEndTime']
|
||||
})
|
||||
|
||||
@@ -67,7 +67,7 @@ export async function dispatchUpdateCategoryTemporarilyBlocked ({ action, cache,
|
||||
}
|
||||
}
|
||||
|
||||
const [affectedRows] = await cache.database.category.update({
|
||||
const [affectedRows] = await cache.transaction.legacy.database.category.update({
|
||||
temporarilyBlocked: action.blocked,
|
||||
temporarilyBlockedEndTime: action.blocked ? (action.endTime ?? 0).toString(10) : '0'
|
||||
}, {
|
||||
@@ -75,7 +75,7 @@ export async function dispatchUpdateCategoryTemporarilyBlocked ({ action, cache,
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (affectedRows !== 0) {
|
||||
|
||||
+8
-8
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,12 +23,12 @@ export async function dispatchUpdateCategoryTimeWarnings ({ action, cache }: {
|
||||
action: UpdateCategoryTimeWarningsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryEntry = await cache.database.category.findOne({
|
||||
const categoryEntry = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!categoryEntry) {
|
||||
@@ -41,26 +41,26 @@ export async function dispatchUpdateCategoryTimeWarnings ({ action, cache }: {
|
||||
categoryEntry.timeWarningFlags &= ~action.flags
|
||||
}
|
||||
|
||||
await categoryEntry.save({ transaction: cache.transaction })
|
||||
await categoryEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
if (action.minutes !== undefined) {
|
||||
if (action.enable) {
|
||||
await cache.database.categoryTimeWarning.create({
|
||||
await cache.transaction.legacy.database.categoryTimeWarning.create({
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
minutes: action.minutes
|
||||
}, {
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
ignoreDuplicates: true
|
||||
})
|
||||
} else {
|
||||
await cache.database.categoryTimeWarning.destroy({
|
||||
await cache.transaction.legacy.database.categoryTimeWarning.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId,
|
||||
minutes: action.minutes
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,26 +23,26 @@ export async function dispatchUpdateCategoryTitle ({ action, cache }: {
|
||||
action: UpdateCategoryTitleAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const oldCategory = await cache.database.category.findOne({
|
||||
const oldCategory = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!oldCategory) {
|
||||
throw new MissingCategoryException()
|
||||
}
|
||||
|
||||
const [affectedRows] = await cache.database.category.update({
|
||||
const [affectedRows] = await cache.transaction.legacy.database.category.update({
|
||||
title: action.newTitle
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (affectedRows !== 0) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -24,23 +24,23 @@ export async function dispatchUpdateChildTaskAction ({ action, cache }: {
|
||||
action: UpdateChildTaskAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryInfoUnsafe = await cache.database.category.findOne({
|
||||
const categoryInfoUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
attributes: ['childId'],
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (categoryInfoUnsafe === null) throw new MissingCategoryException()
|
||||
|
||||
const taskInfo = await cache.database.childTask.findOne({
|
||||
const taskInfo = await cache.transaction.legacy.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
const notFound = taskInfo === null
|
||||
@@ -56,7 +56,7 @@ export async function dispatchUpdateChildTaskAction ({ action, cache }: {
|
||||
}
|
||||
|
||||
if (taskInfo === null) {
|
||||
await cache.database.childTask.create({
|
||||
await cache.transaction.legacy.database.childTask.create({
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId,
|
||||
categoryId: action.categoryId,
|
||||
@@ -65,12 +65,12 @@ export async function dispatchUpdateChildTaskAction ({ action, cache }: {
|
||||
pendingRequest: 0,
|
||||
lastGrantTimestamp: '0'
|
||||
}, {
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(action.categoryId)
|
||||
} else {
|
||||
await cache.database.childTask.update({
|
||||
await cache.transaction.legacy.database.childTask.update({
|
||||
taskTitle: action.taskTitle,
|
||||
categoryId: action.categoryId,
|
||||
extraTimeDuration: action.extraTimeDuration
|
||||
@@ -79,7 +79,7 @@ export async function dispatchUpdateChildTaskAction ({ action, cache }: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,26 +23,26 @@ export async function dispatchUpdateDeviceName ({ action, cache }: {
|
||||
action: UpdateDeviceNameAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const oldDevice = await cache.database.device.findOne({
|
||||
const oldDevice = await cache.transaction.legacy.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!oldDevice) {
|
||||
throw new MissingDeviceException()
|
||||
}
|
||||
|
||||
const [affectedRows] = await cache.database.device.update({
|
||||
const [affectedRows] = await cache.transaction.legacy.database.device.update({
|
||||
name: action.name
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (affectedRows !== 0) {
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,8 +23,8 @@ export async function dispatchUpdateEnableActivityLevelBlocking ({ action, cache
|
||||
action: UpdateEnableActivityLevelBlockingAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const oldDevice = await cache.database.device.findOne({
|
||||
transaction: cache.transaction,
|
||||
const oldDevice = await cache.transaction.legacy.database.device.findOne({
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
@@ -35,10 +35,10 @@ export async function dispatchUpdateEnableActivityLevelBlocking ({ action, cache
|
||||
throw new MissingDeviceException()
|
||||
}
|
||||
|
||||
await cache.database.device.update({
|
||||
await cache.transaction.legacy.database.device.update({
|
||||
activityLevelBlocking: action.enable
|
||||
}, {
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,8 +23,8 @@ export async function dispatchUpdateNetworkTimeVerification ({ action, cache }:
|
||||
action: UpdateNetworkTimeVerificationAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const oldDevice = await cache.database.device.findOne({
|
||||
transaction: cache.transaction,
|
||||
const oldDevice = await cache.transaction.legacy.database.device.findOne({
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
@@ -35,14 +35,14 @@ export async function dispatchUpdateNetworkTimeVerification ({ action, cache }:
|
||||
throw new MissingDeviceException()
|
||||
}
|
||||
|
||||
await cache.database.device.update({
|
||||
await cache.transaction.legacy.database.device.update({
|
||||
networkTime: action.mode
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId: action.deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
cache.invalidiateDeviceList = true
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -23,13 +23,13 @@ export async function dispatchUpdateParentNotificationFlags ({ action, cache }:
|
||||
action: UpdateParentNotificationFlagsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const parentEntry = await cache.database.user.findOne({
|
||||
const parentEntry = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.parentId,
|
||||
type: 'parent'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!parentEntry) {
|
||||
@@ -42,7 +42,7 @@ export async function dispatchUpdateParentNotificationFlags ({ action, cache }:
|
||||
parentEntry.mailNotificationFlags &= ~action.flags
|
||||
}
|
||||
|
||||
await parentEntry.save({ transaction: cache.transaction })
|
||||
await parentEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
|
||||
@@ -29,12 +29,12 @@ export async function dispatchUpdateTimelimitRule ({
|
||||
cache: Cache
|
||||
fromChildSelfLimitAddChildUserId: string | null
|
||||
}) {
|
||||
const ruleEntry = await cache.database.timelimitRule.findOne({
|
||||
const ruleEntry = await cache.transaction.legacy.database.timelimitRule.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
ruleId: action.ruleId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!ruleEntry) {
|
||||
@@ -42,12 +42,12 @@ export async function dispatchUpdateTimelimitRule ({
|
||||
}
|
||||
|
||||
if (fromChildSelfLimitAddChildUserId != null) {
|
||||
const categoryEntryUnsafe = await cache.database.category.findOne({
|
||||
const categoryEntryUnsafe = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: ruleEntry.categoryId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
attributes: ['childId']
|
||||
})
|
||||
|
||||
@@ -103,7 +103,7 @@ export async function dispatchUpdateTimelimitRule ({
|
||||
ruleEntry.perDay = action.perDay ? 1 : 0
|
||||
ruleEntry.expiresAt = action.expiresAt ? action.expiresAt.toString() : null
|
||||
|
||||
await ruleEntry.save({ transaction: cache.transaction })
|
||||
await ruleEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.categoriesWithModifiedTimeLimitRules.add(ruleEntry.categoryId)
|
||||
cache.incrementTriggeredSyncLevel(2)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -24,12 +24,12 @@ export async function dispatchUpdateUserFlagsAction ({ action, cache }: {
|
||||
action: UpdateUserFlagsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const userEntry = await cache.database.user.findOne({
|
||||
const userEntry = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!userEntry) {
|
||||
@@ -46,7 +46,7 @@ export async function dispatchUpdateUserFlagsAction ({ action, cache }: {
|
||||
|
||||
userEntry.flags = newFlags.toString(10)
|
||||
|
||||
await userEntry.save({ transaction: cache.transaction })
|
||||
await userEntry.save({ transaction: cache.transaction.legacy.transaction })
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
|
||||
+9
-9
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -25,13 +25,13 @@ export async function dispatchUpdateUserLimitLoginCategoryAction ({ action, cach
|
||||
cache: Cache
|
||||
parentUserId: string
|
||||
}) {
|
||||
const userEntry = await cache.database.user.findOne({
|
||||
const userEntry = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId,
|
||||
type: 'parent'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!userEntry) {
|
||||
@@ -44,34 +44,34 @@ export async function dispatchUpdateUserLimitLoginCategoryAction ({ action, cach
|
||||
})
|
||||
}
|
||||
|
||||
await cache.database.userLimitLoginCategory.destroy({
|
||||
await cache.transaction.legacy.database.userLimitLoginCategory.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (action.categoryId !== undefined) {
|
||||
const categoryEntry = await cache.database.category.findOne({
|
||||
const categoryEntry = await cache.transaction.legacy.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!categoryEntry) {
|
||||
throw new MissingCategoryException()
|
||||
}
|
||||
|
||||
await cache.database.userLimitLoginCategory.create({
|
||||
await cache.transaction.legacy.database.userLimitLoginCategory.create({
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId,
|
||||
categoryId: action.categoryId,
|
||||
preBlockDuration: 0
|
||||
}, {
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -25,13 +25,13 @@ export async function dispatchUpdateUserLimitPreBlockDuration ({ action, cache,
|
||||
cache: Cache
|
||||
parentUserId: string
|
||||
}) {
|
||||
const userEntry = await cache.database.user.findOne({
|
||||
const userEntry = await cache.transaction.legacy.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId,
|
||||
type: 'parent'
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!userEntry) {
|
||||
@@ -44,8 +44,8 @@ export async function dispatchUpdateUserLimitPreBlockDuration ({ action, cache,
|
||||
})
|
||||
}
|
||||
|
||||
const preBlockItem = await cache.database.userLimitLoginCategory.findOne({
|
||||
transaction: cache.transaction,
|
||||
const preBlockItem = await cache.transaction.legacy.database.userLimitLoginCategory.findOne({
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId
|
||||
@@ -58,10 +58,10 @@ export async function dispatchUpdateUserLimitPreBlockDuration ({ action, cache,
|
||||
})
|
||||
}
|
||||
|
||||
await cache.database.userLimitLoginCategory.update({
|
||||
await cache.transaction.legacy.database.userLimitLoginCategory.update({
|
||||
preBlockDuration: action.preBlockDuration
|
||||
}, {
|
||||
transaction: cache.transaction,
|
||||
transaction: cache.transaction.legacy.transaction,
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -18,7 +18,8 @@
|
||||
import { BadRequest } from 'http-errors'
|
||||
import { ClientPushChangesRequest } from '../../../api/schema'
|
||||
import { VisibleConnectedDevicesManager } from '../../../connected-devices'
|
||||
import { Database, shouldRetryWithException } from '../../../database'
|
||||
import { SimpleDatabase } from '../../../database/simple'
|
||||
import { shouldRetryWithException } from '../../../database'
|
||||
import { EventHandler } from '../../../monitoring/eventhandler'
|
||||
import { WebsocketApi } from '../../../websocket'
|
||||
import { notifyClientsAboutChangesDelayed } from '../../websocket'
|
||||
@@ -31,7 +32,7 @@ import { SequenceNumberRepeatedException } from './exception/sequence'
|
||||
import { assertActionIntegrity } from './integrity'
|
||||
|
||||
export const applyActionsFromDevice = async ({ database, request, websocket, connectedDevicesManager, eventHandler }: {
|
||||
database: Database
|
||||
database: SimpleDatabase
|
||||
websocket: WebsocketApi
|
||||
request: ClientPushChangesRequest
|
||||
connectedDevicesManager: VisibleConnectedDevicesManager
|
||||
@@ -47,12 +48,11 @@ export const applyActionsFromDevice = async ({ database, request, websocket, con
|
||||
}
|
||||
|
||||
return database.transaction(async (transaction) => {
|
||||
const baseInfo = await getApplyActionBaseInfo({ database, transaction, deviceAuthToken: request.deviceAuthToken })
|
||||
const baseInfo = await getApplyActionBaseInfo({ transaction, deviceAuthToken: request.deviceAuthToken })
|
||||
|
||||
const cache = new Cache({
|
||||
database,
|
||||
hasFullVersion: baseInfo.hasFullVersion,
|
||||
transaction,
|
||||
hasFullVersion: baseInfo.hasFullVersion,
|
||||
familyId: baseInfo.familyId,
|
||||
deviceId: baseInfo.deviceId,
|
||||
connectedDevicesManager
|
||||
@@ -112,7 +112,7 @@ export const applyActionsFromDevice = async ({ database, request, websocket, con
|
||||
}
|
||||
})
|
||||
} catch (ex) {
|
||||
if (shouldRetryWithException(database, ex)) {
|
||||
if (shouldRetryWithException(transaction.legacy.database, ex)) {
|
||||
eventHandler.countEvent('applyActionsFromDevice got exception which should cause retry')
|
||||
|
||||
throw ex
|
||||
@@ -132,14 +132,14 @@ export const applyActionsFromDevice = async ({ database, request, websocket, con
|
||||
if (nextSequenceNumber !== baseInfo.nextSequenceNumber) {
|
||||
eventHandler.countEvent('applyActionsFromDevice updateSequenceNumber')
|
||||
|
||||
await database.device.update({
|
||||
await transaction.legacy.database.device.update({
|
||||
nextSequenceNumber
|
||||
}, {
|
||||
where: {
|
||||
familyId: baseInfo.familyId,
|
||||
deviceId: baseInfo.deviceId
|
||||
},
|
||||
transaction
|
||||
transaction: transaction.legacy.transaction
|
||||
})
|
||||
}
|
||||
|
||||
@@ -149,18 +149,17 @@ export const applyActionsFromDevice = async ({ database, request, websocket, con
|
||||
familyId: baseInfo.familyId,
|
||||
sourceDeviceId: baseInfo.deviceId,
|
||||
websocket,
|
||||
database,
|
||||
transaction,
|
||||
generalLevel: cache.triggeredSyncLevel,
|
||||
targetedLevels: cache.targetedTriggeredSyncLevels
|
||||
})
|
||||
|
||||
if (cache.triggeredSyncLevel === 2) {
|
||||
transaction.afterCommit(() => {
|
||||
transaction.enqueueAfterCommit(() => {
|
||||
eventHandler.countEvent('applyActionsFromDevice areChangesImportant')
|
||||
})
|
||||
} else if ([...cache.targetedTriggeredSyncLevels.entries()].some((entry) => entry[1] === 2)) {
|
||||
transaction.afterCommit(() => {
|
||||
transaction.enqueueAfterCommit(() => {
|
||||
eventHandler.countEvent('applyActionsFromDevice areChangesImportantTargeted')
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 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
|
||||
@@ -37,7 +37,7 @@ export async function assertActionIntegrity ({ action, cache, deviceId }: {
|
||||
}> {
|
||||
if (action.type === 'parent') {
|
||||
if (action.integrity === 'device') {
|
||||
const deviceEntryUnsafe = await cache.database.device.findOne({
|
||||
const deviceEntryUnsafe = await cache.transaction.legacy.database.device.findOne({
|
||||
attributes: ['currentUserId'],
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
@@ -45,7 +45,7 @@ export async function assertActionIntegrity ({ action, cache, deviceId }: {
|
||||
currentUserId: action.userId,
|
||||
isUserKeptSignedIn: true
|
||||
},
|
||||
transaction: cache.transaction
|
||||
transaction: cache.transaction.legacy.transaction
|
||||
})
|
||||
|
||||
if (!deviceEntryUnsafe) {
|
||||
@@ -74,7 +74,6 @@ export async function assertActionIntegrity ({ action, cache, deviceId }: {
|
||||
hasFullVersion: cache.hasFullVersion,
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
database: cache.database,
|
||||
transaction: cache.transaction,
|
||||
calculateHmac: (secret) => calculateActionHmac({
|
||||
action,
|
||||
|
||||
Reference in New Issue
Block a user