mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-18 12:09:43 +02:00
- bot-services: Add registerAsync to AI, Calendar, Clock, Todo modules - bot-services: Add convenience methods to ClockService for bot handlers - bot-services: Make CreateEventInput.endTime optional with sensible defaults - bot-services: Fix empty interface ESLint errors (use type aliases) - questions-backend: Add missing schema columns (isDefault, sortOrder, deletedAt) - questions-backend: Fix or() return type handling in question service - questions-web: Add guard for undefined question ID in route params - skilltree-web: Fix DBSchema type by not extending idb interface directly - calendar-web: Fix Check icon prop (use weight instead of strokeWidth) - matrix-mana-bot: Update clock handler to use new service methods Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
import { Module, DynamicModule, Provider, Type, ModuleMetadata } from '@nestjs/common';
|
|
import { ClockService } from './clock.service';
|
|
import { ClockServiceConfig } from './types';
|
|
|
|
export type ClockModuleOptions = Partial<ClockServiceConfig>;
|
|
|
|
export interface ClockModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
useFactory: (...args: unknown[]) => Promise<ClockModuleOptions> | ClockModuleOptions;
|
|
inject?: (Type<unknown> | string | symbol)[];
|
|
}
|
|
|
|
@Module({})
|
|
export class ClockModule {
|
|
/**
|
|
* Register with default configuration (uses environment variables)
|
|
*/
|
|
static register(options?: ClockModuleOptions): DynamicModule {
|
|
return {
|
|
module: ClockModule,
|
|
providers: [
|
|
{
|
|
provide: 'CLOCK_SERVICE_CONFIG',
|
|
useValue: options ?? {},
|
|
},
|
|
{
|
|
provide: ClockService,
|
|
useFactory: (config: Partial<ClockServiceConfig>) => new ClockService(config),
|
|
inject: ['CLOCK_SERVICE_CONFIG'],
|
|
},
|
|
],
|
|
exports: [ClockService],
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Register with explicit configuration
|
|
*/
|
|
static forRoot(config: ClockServiceConfig): DynamicModule {
|
|
return {
|
|
module: ClockModule,
|
|
providers: [
|
|
{
|
|
provide: ClockService,
|
|
useFactory: () => new ClockService(config),
|
|
},
|
|
],
|
|
exports: [ClockService],
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Register asynchronously with factory function
|
|
*/
|
|
static registerAsync(options: ClockModuleAsyncOptions): DynamicModule {
|
|
const configProvider: Provider = {
|
|
provide: 'CLOCK_SERVICE_CONFIG',
|
|
useFactory: options.useFactory,
|
|
inject: options.inject || [],
|
|
};
|
|
|
|
return {
|
|
module: ClockModule,
|
|
imports: options.imports || [],
|
|
providers: [
|
|
configProvider,
|
|
{
|
|
provide: ClockService,
|
|
useFactory: (config: Partial<ClockServiceConfig>) => new ClockService(config),
|
|
inject: ['CLOCK_SERVICE_CONFIG'],
|
|
},
|
|
],
|
|
exports: [ClockService],
|
|
};
|
|
}
|
|
}
|