From 39945345ec6c00bc9df0789cb746c43630e57c03 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Wed, 4 Jun 2025 12:37:34 +0200 Subject: [PATCH] fix linting --- database/src/AppDatabase.ts | 22 +++++++++++++--------- database/src/config/index.ts | 5 +++-- database/src/entity/Community.ts | 2 +- database/src/entity/Contribution.ts | 2 +- database/src/entity/Event.ts | 2 +- database/src/entity/Transaction.ts | 2 +- database/src/entity/User.ts | 2 +- database/src/logging/index.ts | 6 +++--- 8 files changed, 24 insertions(+), 19 deletions(-) diff --git a/database/src/AppDatabase.ts b/database/src/AppDatabase.ts index 458bd4c75..7754a1f61 100644 --- a/database/src/AppDatabase.ts +++ b/database/src/AppDatabase.ts @@ -1,5 +1,5 @@ +import { Migration, entities } from '@/entity' import { DataSource as DBDataSource, FileLogger } from 'typeorm' -import { entities, Migration } from '@/entity' import { CONFIG } from '@/config' import { logger } from '@/logging' @@ -37,8 +37,10 @@ export class AppDatabase { // create database connection, initialize with automatic retry and check for correct database version public async init(): Promise { - if (this.connection?.isInitialized) return - + if (this.connection?.isInitialized) { + return + } + // log sql query only of enable by .env, this produce so much data it should be only used when really needed const logging: boolean = CONFIG.TYPEORM_LOGGING_ACTIVE this.connection = new DBDataSource({ @@ -52,9 +54,11 @@ export class AppDatabase { entities, synchronize: false, logging, - logger: logging ? new FileLogger('all', { - logPath: CONFIG.TYPEORM_LOGGING_RELATIVE_PATH, - }) : undefined, + logger: logging + ? new FileLogger('all', { + logPath: CONFIG.TYPEORM_LOGGING_RELATIVE_PATH, + }) + : undefined, extra: { charset: 'utf8mb4_unicode_ci', }, @@ -63,7 +67,7 @@ export class AppDatabase { for (let attempt = 1; attempt <= CONFIG.DB_CONNECT_RETRY_COUNT; attempt++) { try { await this.connection.initialize() - if(this.connection.isInitialized) { + if (this.connection.isInitialized) { logger.info(`Database connection established on attempt ${attempt}`) break } @@ -87,7 +91,7 @@ export class AppDatabase { // ###################################### private async checkDBVersion(): Promise { const [dbVersion] = await Migration.find({ order: { version: 'DESC' }, take: 1 }) - if(!dbVersion) { + if (!dbVersion) { throw new Error('Could not find database version') } if (!dbVersion.fileName.startsWith(latestDbVersion)) { @@ -96,7 +100,7 @@ export class AppDatabase { dbVersion.fileName }`, ) - } + } } } diff --git a/database/src/config/index.ts b/database/src/config/index.ts index a576e7ec1..906f22b79 100644 --- a/database/src/config/index.ts +++ b/database/src/config/index.ts @@ -8,7 +8,7 @@ const constants = { EXPECTED: 'v1.2022-03-18', CURRENT: '', }, - LOG4JS_CATEGORY_NAME: 'database' + LOG4JS_CATEGORY_NAME: 'database', } const database = { @@ -23,7 +23,8 @@ const database = { DB_USER: process.env.DB_USER ?? 'root', DB_PASSWORD: process.env.DB_PASSWORD ?? '', DB_DATABASE: process.env.DB_DATABASE ?? 'gradido_community', - TYPEORM_LOGGING_RELATIVE_PATH: process.env.TYPEORM_LOGGING_RELATIVE_PATH ?? 'typeorm.database.log', + TYPEORM_LOGGING_RELATIVE_PATH: + process.env.TYPEORM_LOGGING_RELATIVE_PATH ?? 'typeorm.database.log', TYPEORM_LOGGING_ACTIVE: process.env.TYPEORM_LOGGING_ACTIVE === 'true' || false, } diff --git a/database/src/entity/Community.ts b/database/src/entity/Community.ts index 11142f0ff..314e96f6a 100644 --- a/database/src/entity/Community.ts +++ b/database/src/entity/Community.ts @@ -9,9 +9,9 @@ import { PrimaryGeneratedColumn, UpdateDateColumn, } from 'typeorm' -import { GeometryTransformer } from './transformer/GeometryTransformer' import { FederatedCommunity } from './FederatedCommunity' import { User } from './User' +import { GeometryTransformer } from './transformer/GeometryTransformer' @Entity('communities') export class Community extends BaseEntity { diff --git a/database/src/entity/Contribution.ts b/database/src/entity/Contribution.ts index d4daa4e64..53ec9f36f 100644 --- a/database/src/entity/Contribution.ts +++ b/database/src/entity/Contribution.ts @@ -10,10 +10,10 @@ import { OneToOne, PrimaryGeneratedColumn, } from 'typeorm' -import { DecimalTransformer } from './transformer/DecimalTransformer' import { ContributionMessage } from './ContributionMessage' import { Transaction } from './Transaction' import { User } from './User' +import { DecimalTransformer } from './transformer/DecimalTransformer' @Entity('contributions') export class Contribution extends BaseEntity { diff --git a/database/src/entity/Event.ts b/database/src/entity/Event.ts index f5280d9a2..9d17ffdeb 100644 --- a/database/src/entity/Event.ts +++ b/database/src/entity/Event.ts @@ -8,13 +8,13 @@ import { ManyToOne, PrimaryGeneratedColumn, } from 'typeorm' -import { DecimalTransformer } from './transformer/DecimalTransformer' import { Contribution } from './Contribution' import { ContributionLink } from './ContributionLink' import { ContributionMessage } from './ContributionMessage' import { Transaction } from './Transaction' import { TransactionLink } from './TransactionLink' import { User } from './User' +import { DecimalTransformer } from './transformer/DecimalTransformer' @Entity('events') export class Event extends BaseEntity { diff --git a/database/src/entity/Transaction.ts b/database/src/entity/Transaction.ts index 50c4d3102..b7d83bdf1 100644 --- a/database/src/entity/Transaction.ts +++ b/database/src/entity/Transaction.ts @@ -1,9 +1,9 @@ /* eslint-disable no-use-before-define */ import { Decimal } from 'decimal.js-light' import { BaseEntity, Column, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm' -import { DecimalTransformer } from './transformer/DecimalTransformer' import { Contribution } from './Contribution' import { DltTransaction } from './DltTransaction' +import { DecimalTransformer } from './transformer/DecimalTransformer' @Entity('transactions') export class Transaction extends BaseEntity { diff --git a/database/src/entity/User.ts b/database/src/entity/User.ts index 3c8d31cd9..9ff6f384b 100644 --- a/database/src/entity/User.ts +++ b/database/src/entity/User.ts @@ -10,12 +10,12 @@ import { OneToOne, PrimaryGeneratedColumn, } from 'typeorm' -import { GeometryTransformer } from './transformer/GeometryTransformer' import { Community } from './Community' import { Contribution } from './Contribution' import { ContributionMessage } from './ContributionMessage' import { UserContact } from './UserContact' import { UserRole } from './UserRole' +import { GeometryTransformer } from './transformer/GeometryTransformer' @Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' }) export class User extends BaseEntity { diff --git a/database/src/logging/index.ts b/database/src/logging/index.ts index 2a582c235..ee49d3831 100644 --- a/database/src/logging/index.ts +++ b/database/src/logging/index.ts @@ -1,3 +1,5 @@ +import { CONFIG } from '@/config' +import { getLogger } from 'log4js' import { AbstractLoggingView } from './AbstractLogging.view' import { CommunityLoggingView } from './CommunityLogging.view' import { ContributionLoggingView } from './ContributionLogging.view' @@ -9,8 +11,6 @@ import { TransactionLoggingView } from './TransactionLogging.view' import { UserContactLoggingView } from './UserContactLogging.view' import { UserLoggingView } from './UserLogging.view' import { UserRoleLoggingView } from './UserRoleLogging.view' -import { CONFIG } from '@/config' -import { getLogger } from 'log4js' export { AbstractLoggingView, @@ -26,4 +26,4 @@ export { UserRoleLoggingView, } -export const logger = getLogger(CONFIG.LOG4JS_CATEGORY_NAME) \ No newline at end of file +export const logger = getLogger(CONFIG.LOG4JS_CATEGORY_NAME)