diff --git a/apps/desktop-api/src/app/database.module.ts b/apps/desktop-api/src/app/database.module.ts index 85e3ab23e98..58c2b799280 100644 --- a/apps/desktop-api/src/app/database.module.ts +++ b/apps/desktop-api/src/app/database.module.ts @@ -20,7 +20,8 @@ const dbPath = process.env.GAUZY_USER_PATH ? `${process.env.GAUZY_USER_PATH}/gau logger: 'file', //Removes console logging, instead logs all queries in a file ormlogs.log synchronize: true, entities: coreEntities - }) + }), + inject: [] }), // MikroORM DB Config (SQLite3) MikroOrmModule.forRootAsync({ @@ -30,7 +31,9 @@ const dbPath = process.env.GAUZY_USER_PATH ? `${process.env.GAUZY_USER_PATH}/gau entities: coreEntities, namingStrategy: EntityCaseNamingStrategy, debug: ['query'] // by default set to false only - }) + }), + driver: BetterSqliteDriver, + inject: [] }) ] }) diff --git a/packages/config/src/lib/database.ts b/packages/config/src/lib/database.ts index 342d045c098..517a5741066 100644 --- a/packages/config/src/lib/database.ts +++ b/packages/config/src/lib/database.ts @@ -1,5 +1,3 @@ -import * as path from 'path'; -import * as chalk from 'chalk'; import { TypeOrmModuleOptions } from '@nestjs/typeorm'; import { MikroOrmModuleOptions } from '@mikro-orm/nestjs'; import { EntityCaseNamingStrategy } from '@mikro-orm/core'; @@ -8,9 +6,11 @@ import { BetterSqliteDriver, Options as MikroOrmBetterSqliteOptions } from '@mik import { PostgreSqlDriver, Options as MikroOrmPostgreSqlOptions } from '@mikro-orm/postgresql'; import { Options as MikroOrmMySqlOptions, MySqlDriver } from '@mikro-orm/mysql'; import { DataSourceOptions } from 'typeorm'; -import { KnexModuleOptions } from 'nest-knexjs'; import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions'; import { MysqlConnectionOptions } from 'typeorm/driver/mysql/MysqlConnectionOptions'; +import { KnexModuleOptions } from 'nest-knexjs'; +import * as path from 'path'; +import * as chalk from 'chalk'; import { DatabaseTypeEnum, getLoggingMikroOptions, getLoggingOptions, getTlsOptions } from './database-helpers'; /** diff --git a/packages/core/src/lib/bootstrap/index.ts b/packages/core/src/lib/bootstrap/index.ts index a90f5b25d02..91369684546 100644 --- a/packages/core/src/lib/bootstrap/index.ts +++ b/packages/core/src/lib/bootstrap/index.ts @@ -31,7 +31,6 @@ startTracing(); // Start tracing if OTEL is enabled. import { ConflictException, INestApplication, Type } from '@nestjs/common'; import { NestFactory, Reflector } from '@nestjs/core'; import { NestExpressApplication } from '@nestjs/platform-express'; -import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import { EventSubscriber } from '@mikro-orm/core'; import { useContainer } from 'class-validator'; import * as helmet from 'helmet'; @@ -51,6 +50,7 @@ import { SharedModule } from '../shared/shared.module'; import { AppService } from '../app/app.service'; import { AppModule } from '../app/app.module'; import { configureRedisSession } from './redis-store'; +import { setupSwagger } from './swagger'; /** * Bootstrap the NestJS application, configuring various settings and initializing the server. @@ -161,10 +161,8 @@ export async function bootstrap(pluginConfig?: Partial) console.log(chalk.green(`Configured Port: ${port}`)); // Configure Swagger for API documentation - const options = new DocumentBuilder().setTitle('Gauzy API').setVersion('1.0').addBearerAuth().build(); - const document = SwaggerModule.createDocument(app, options); - SwaggerModule.setup('swg', app, document); - console.log(chalk.green(`Swagger UI available at http://${host}:${port}/swg`)); + const swaggerPath = await setupSwagger(app); + console.log(chalk.green(`Swagger documentation available at http://${host}:${port}/${swaggerPath}`)); // Configure Atlassian Connect Express // const addon = ac(express()); diff --git a/packages/core/src/lib/bootstrap/swagger.ts b/packages/core/src/lib/bootstrap/swagger.ts new file mode 100644 index 00000000000..1ec4b47ee2c --- /dev/null +++ b/packages/core/src/lib/bootstrap/swagger.ts @@ -0,0 +1,39 @@ +import { INestApplication } from '@nestjs/common'; +import { SwaggerModule, DocumentBuilder, SwaggerDocumentOptions, SwaggerCustomOptions } from '@nestjs/swagger'; + +/** + * Sets up and configures Swagger API documentation for the given NestJS application. + * + * This function creates a Swagger configuration using the DocumentBuilder by setting the title, + * description, version, and enabling bearer authentication. It then generates the Swagger document + * with any additional options and sets up the Swagger UI at the specified endpoint. + * + * @param {INestApplication} app - The NestJS application instance. + * @returns {Promise} A promise that resolves to the Swagger documentation path. + */ +export const setupSwagger = async (app: INestApplication): Promise => { + const config = new DocumentBuilder() + .setTitle('Gauzy API') + .setDescription('Gauzy API Documentation') + .setVersion('1.0') + .addBearerAuth() + .build(); + + // Swagger document options (if needed, can add additional options here) + const options: SwaggerDocumentOptions = {}; + + // Generate the Swagger document from the app instance and configuration + const document = SwaggerModule.createDocument(app, config, options); + + // Custom options for the Swagger UI (e.g., custom CSS, custom site title, etc.) + const customOptions: SwaggerCustomOptions = {}; + + // Define the Swagger endpoint path + const swaggerPath = 'docs'; + + // Setup Swagger UI at the `/docs` endpoint + SwaggerModule.setup(swaggerPath, app, document, customOptions); + + // Return the Swagger path + return swaggerPath; +}; diff --git a/packages/core/src/lib/database/database.module.ts b/packages/core/src/lib/database/database.module.ts index 745c509ed4f..a9af55357fe 100644 --- a/packages/core/src/lib/database/database.module.ts +++ b/packages/core/src/lib/database/database.module.ts @@ -19,13 +19,13 @@ import { ConnectionEntityManager } from './connection-entity-manager'; * @type {MikroORMModuleOptions} */ MikroOrmModule.forRootAsync({ - imports: [ConfigModule], - inject: [ConfigService], // Use useFactory, useClass, or useExisting useFactory: async (configService: ConfigService) => { const dbMikroOrmConnectionOptions = configService.getConfigValue('dbMikroOrmConnectionOptions'); return dbMikroOrmConnectionOptions; - } + }, + imports: [ConfigModule], + inject: [ConfigService] }), /** * Configuration for TypeORM database connection. @@ -33,25 +33,25 @@ import { ConnectionEntityManager } from './connection-entity-manager'; * @type {TypeOrmModuleOptions} */ TypeOrmModule.forRootAsync({ - imports: [ConfigModule], - inject: [ConfigService], // Use useFactory, useClass, or useExisting useFactory: async (configService: ConfigService) => { const dbConnectionOptions = configService.getConfigValue('dbConnectionOptions'); return dbConnectionOptions; - } + }, + imports: [ConfigModule], + inject: [ConfigService] }), /** * Configure the Knex.js module for the application using asynchronous options. */ KnexModule.forRootAsync({ - imports: [ConfigModule], - inject: [ConfigService], // Use useFactory, useClass, or useExisting useFactory: async (configService: ConfigService) => { const dbKnexConnectionOptions = configService.getConfigValue('dbKnexConnectionOptions'); return dbKnexConnectionOptions; - } + }, + imports: [ConfigModule], + inject: [ConfigService] }) ], providers: [ConnectionEntityManager], diff --git a/packages/ui-core/shared/src/lib/table-filters/input-filter.component.ts b/packages/ui-core/shared/src/lib/table-filters/input-filter.component.ts index d8c9f7ba214..eee7c46a871 100644 --- a/packages/ui-core/shared/src/lib/table-filters/input-filter.component.ts +++ b/packages/ui-core/shared/src/lib/table-filters/input-filter.component.ts @@ -21,7 +21,7 @@ export class InputFilterComponent extends DefaultFilter implements OnInit, OnDes this.subscription = this.inputControl.valueChanges .pipe( // Apply a debounce time to reduce the frequency of value changes - debounceTime(this.delay), + debounceTime(this.debounceTime), // Ensure distinct values to avoid redundant operations distinctUntilChanged(), // Use tap to perform a side effect, invoking the filterFunction of the column diff --git a/packages/ui-core/shared/src/lib/table-filters/range-filter.component.ts b/packages/ui-core/shared/src/lib/table-filters/range-filter.component.ts index 4a9f75f99e0..d3fee3b3e51 100644 --- a/packages/ui-core/shared/src/lib/table-filters/range-filter.component.ts +++ b/packages/ui-core/shared/src/lib/table-filters/range-filter.component.ts @@ -1,4 +1,4 @@ -import { Component, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; import { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators'; import { Subscription } from 'rxjs/internal/Subscription'; @@ -27,7 +27,7 @@ import { DefaultFilter } from 'angular2-smart-table'; ` }) -export class RangeFilterComponent extends DefaultFilter implements OnInit, OnDestroy, OnChanges { +export class RangeFilterComponent extends DefaultFilter implements OnInit, OnDestroy { public rangeControl = new FormGroup({ min: new FormControl(), max: new FormControl() @@ -42,7 +42,7 @@ export class RangeFilterComponent extends DefaultFilter implements OnInit, OnDes // Subscribe to both min and max value changes this.subscription = this.rangeControl.valueChanges .pipe( - debounceTime(this.delay), // Reduce unnecessary requests + debounceTime(this.debounceTime), // Reduce unnecessary requests distinctUntilChanged(), // Avoid redundant filtering tap(({ min, max }) => { if (min !== null || max !== null) { @@ -53,8 +53,6 @@ export class RangeFilterComponent extends DefaultFilter implements OnInit, OnDes .subscribe(); } - ngOnChanges(changes: SimpleChanges) {} - ngOnDestroy() { // Cleanup subscription to avoid memory leaks this.subscription.unsubscribe();