mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
refactor connection logic
This commit is contained in:
parent
013ea81614
commit
2ce14d1a89
@ -8,7 +8,7 @@ import { Logger } from 'log4js'
|
|||||||
|
|
||||||
import { CONFIG } from '@/config'
|
import { CONFIG } from '@/config'
|
||||||
import { schema } from '@/graphql/schema'
|
import { schema } from '@/graphql/schema'
|
||||||
import { connection } from '@/typeorm/connection'
|
import { getConnection } from '@/typeorm/connection'
|
||||||
import { checkDBVersion } from '@/typeorm/DBVersion'
|
import { checkDBVersion } from '@/typeorm/DBVersion'
|
||||||
import { elopageWebhook } from '@/webhook/elopage'
|
import { elopageWebhook } from '@/webhook/elopage'
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ export const createServer = async (
|
|||||||
logger.debug('createServer...')
|
logger.debug('createServer...')
|
||||||
|
|
||||||
// open mysql connection
|
// open mysql connection
|
||||||
const con = await connection()
|
const con = await getConnection()
|
||||||
if (!con?.isConnected) {
|
if (!con?.isConnected) {
|
||||||
logger.fatal(`Couldn't open connection to database!`)
|
logger.fatal(`Couldn't open connection to database!`)
|
||||||
throw new Error(`Fatal: Couldn't open connection to database`)
|
throw new Error(`Fatal: Couldn't open connection to database`)
|
||||||
|
|||||||
@ -5,7 +5,15 @@ import { entities } from '@entity/index'
|
|||||||
|
|
||||||
import { CONFIG } from '@/config'
|
import { CONFIG } from '@/config'
|
||||||
|
|
||||||
export const connection = async (): Promise<Connection | null> => {
|
let connection: Connection | null
|
||||||
|
|
||||||
|
export const getConnection = async (): Promise<Connection | null> => {
|
||||||
|
if (connection) return connection
|
||||||
|
connection = await createMyConnection()
|
||||||
|
return connection
|
||||||
|
}
|
||||||
|
|
||||||
|
const createMyConnection = async (): Promise<Connection | null> => {
|
||||||
try {
|
try {
|
||||||
return createConnection({
|
return createConnection({
|
||||||
name: 'default',
|
name: 'default',
|
||||||
|
|||||||
@ -5,10 +5,10 @@ import { getKlickTippUser, addFieldsToSubscriber } from '@/apis/KlicktippControl
|
|||||||
import { EventType } from '@/event/EventType'
|
import { EventType } from '@/event/EventType'
|
||||||
import { lastDateTimeEvents } from '@/graphql/resolver/util/eventList'
|
import { lastDateTimeEvents } from '@/graphql/resolver/util/eventList'
|
||||||
import { LogError } from '@/server/LogError'
|
import { LogError } from '@/server/LogError'
|
||||||
import { connection } from '@/typeorm/connection'
|
import { getConnection } from '@/typeorm/connection'
|
||||||
|
|
||||||
export async function retrieveNotRegisteredEmails(): Promise<string[]> {
|
export async function retrieveNotRegisteredEmails(): Promise<string[]> {
|
||||||
const con = await connection()
|
const con = await getConnection()
|
||||||
if (!con) {
|
if (!con) {
|
||||||
throw new LogError('No connection to database')
|
throw new LogError('No connection to database')
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ async function klickTippSendFieldToUser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function exportEventDataToKlickTipp(): Promise<void> {
|
export async function exportEventDataToKlickTipp(): Promise<void> {
|
||||||
const connectionInstance = await connection()
|
const connectionInstance = await getConnection()
|
||||||
if (!connectionInstance) {
|
if (!connectionInstance) {
|
||||||
throw new LogError('No connection to database')
|
throw new LogError('No connection to database')
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user