- Add modules: ai, audit, billing-usage, biometrics, branches, dashboard, feature-flags, invoices, mcp, mobile, notifications, partners, payment-terminals, products, profiles, purchases, reports, sales, storage, warehouses, webhooks, whatsapp - Add controllers, DTOs, entities, and services for each module - Add shared services and utilities Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { Router } from 'express';
|
|
import { DataSource } from 'typeorm';
|
|
import { AIService } from './services';
|
|
import { AIController } from './controllers';
|
|
import {
|
|
AIModel,
|
|
AIPrompt,
|
|
AIConversation,
|
|
AIMessage,
|
|
AIUsageLog,
|
|
AITenantQuota,
|
|
} from './entities';
|
|
|
|
export interface AIModuleOptions {
|
|
dataSource: DataSource;
|
|
basePath?: string;
|
|
}
|
|
|
|
export class AIModule {
|
|
public router: Router;
|
|
public aiService: AIService;
|
|
private dataSource: DataSource;
|
|
private basePath: string;
|
|
|
|
constructor(options: AIModuleOptions) {
|
|
this.dataSource = options.dataSource;
|
|
this.basePath = options.basePath || '';
|
|
this.router = Router();
|
|
this.initializeServices();
|
|
this.initializeRoutes();
|
|
}
|
|
|
|
private initializeServices(): void {
|
|
const modelRepository = this.dataSource.getRepository(AIModel);
|
|
const conversationRepository = this.dataSource.getRepository(AIConversation);
|
|
const messageRepository = this.dataSource.getRepository(AIMessage);
|
|
const promptRepository = this.dataSource.getRepository(AIPrompt);
|
|
const usageLogRepository = this.dataSource.getRepository(AIUsageLog);
|
|
const quotaRepository = this.dataSource.getRepository(AITenantQuota);
|
|
|
|
this.aiService = new AIService(
|
|
modelRepository,
|
|
conversationRepository,
|
|
messageRepository,
|
|
promptRepository,
|
|
usageLogRepository,
|
|
quotaRepository
|
|
);
|
|
}
|
|
|
|
private initializeRoutes(): void {
|
|
const aiController = new AIController(this.aiService);
|
|
this.router.use(`${this.basePath}/ai`, aiController.router);
|
|
}
|
|
|
|
static getEntities(): Function[] {
|
|
return [
|
|
AIModel,
|
|
AIPrompt,
|
|
AIConversation,
|
|
AIMessage,
|
|
AIUsageLog,
|
|
AITenantQuota,
|
|
];
|
|
}
|
|
}
|