From 469e06280a63428c05c7be71e08e83f76292f883 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Fri, 3 May 2024 19:05:56 +0100 Subject: [PATCH] refactor: Improve code readability and maintainability in AnalyticsDatabaseService.ts --- .../Services/AnalyticsDatabaseService.ts | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/CommonServer/Services/AnalyticsDatabaseService.ts b/CommonServer/Services/AnalyticsDatabaseService.ts index aa2c83aa20..31e5097573 100644 --- a/CommonServer/Services/AnalyticsDatabaseService.ts +++ b/CommonServer/Services/AnalyticsDatabaseService.ts @@ -53,14 +53,14 @@ import TableColumnType from 'Common/Types/AnalyticsDatabase/TableColumnType'; export default class AnalyticsDatabaseService< TBaseModel extends AnalyticsBaseModel > extends BaseService { - public modelType!: { new(): TBaseModel }; + public modelType!: { new (): TBaseModel }; public database!: ClickhouseDatabase; public model!: TBaseModel; public databaseClient!: ClickhouseClient; public statementGenerator!: StatementGenerator; public constructor(data: { - modelType: { new(): TBaseModel }; + modelType: { new (): TBaseModel }; database?: ClickhouseDatabase | undefined; }) { super(); @@ -334,18 +334,18 @@ export default class AnalyticsDatabaseService< if (countBy.limit) { statement.append(SQL` LIMIT ${{ - value: Number(countBy.limit), - type: TableColumnType.Number, - }} + value: Number(countBy.limit), + type: TableColumnType.Number, + }} `); } if (countBy.skip) { statement.append(SQL` OFFSET ${{ - value: Number(countBy.skip), - type: TableColumnType.Number, - }} + value: Number(countBy.skip), + type: TableColumnType.Number, + }} `); } logger.info(`${this.model.tableName} Count Statement`); @@ -551,8 +551,8 @@ export default class AnalyticsDatabaseService< statement instanceof Statement ? statement : { - query: statement, // TODO remove and only accept Statements - } + query: statement, // TODO remove and only accept Statements + } ); } @@ -654,16 +654,16 @@ export default class AnalyticsDatabaseService< const onCreate: OnCreate = createBy.props.ignoreHooks ? { - createBy: { - data: data, - props: createBy.props, - }, - carryForward: [], - } + createBy: { + data: data, + props: createBy.props, + }, + carryForward: [], + } : await this._onBeforeCreate({ - data: data, - props: createBy.props, - }); + data: data, + props: createBy.props, + }); data = onCreate.createBy.data; @@ -765,7 +765,8 @@ export default class AnalyticsDatabaseService< await Promise.allSettled(promises); } else { logger.warn( - `Realtime is not initialized. Skipping emitModelEvent for ${this.getModel().tableName + `Realtime is not initialized. Skipping emitModelEvent for ${ + this.getModel().tableName }` ); } @@ -868,7 +869,6 @@ export default class AnalyticsDatabaseService< requiredField, data.getDefaultValueForColumn(requiredField) ); - } else { throw new BadDataException(`${requiredField} is required`); }