mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Extend transaction usage
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -21,14 +21,15 @@ import { Database } from '../../database'
|
||||
import { generateAuthToken, generateVersionId } from '../../util/token'
|
||||
import { WebsocketApi } from '../../websocket'
|
||||
import { prepareDeviceEntry } from '../device/prepare-device-entry'
|
||||
import { notifyClientsAboutChanges } from '../websocket'
|
||||
import { notifyClientsAboutChangesDelayed } from '../websocket'
|
||||
|
||||
export const addChildDevice = async ({ database, websocket, request }: {
|
||||
database: Database
|
||||
websocket: WebsocketApi
|
||||
request: RegisterChildDeviceRequest
|
||||
// no transaction here because this is directly called from an API endpoint
|
||||
}) => {
|
||||
const { response, familyId } = await database.transaction(async (transaction) => {
|
||||
return database.transaction(async (transaction) => {
|
||||
const entry = await database.addDeviceToken.findOne({
|
||||
where: {
|
||||
token: request.registerToken.toLowerCase()
|
||||
@@ -63,16 +64,11 @@ export const addChildDevice = async ({ database, websocket, request }: {
|
||||
transaction
|
||||
})
|
||||
|
||||
await notifyClientsAboutChangesDelayed({ familyId, websocket, database, isImportant: true, sourceDeviceId: deviceId, transaction })
|
||||
|
||||
return {
|
||||
response: {
|
||||
deviceId,
|
||||
deviceAuthToken
|
||||
},
|
||||
familyId
|
||||
deviceId,
|
||||
deviceAuthToken
|
||||
}
|
||||
})
|
||||
|
||||
await notifyClientsAboutChanges({ familyId, websocket, database, isImportant: true, sourceDeviceId: response.deviceId })
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user