feat: Complete NestJS backend scaffold — 22 modules, 39 entities, WebSocket gateway
All checks were successful
Test Asgard Runner / test (push) Successful in 3s
All checks were successful
Test Asgard Runner / test (push) Successful in 3s
Full backend rewrite from Rust/Axum to NestJS/TypeScript. - 22 feature modules (auth, servers, wipes, maps, plugins, players, console, chat, team, notifications, settings, schedules, analytics, alerts, status, store, webstore, admin, setup, migration, users, licenses) - 39 TypeORM entities matching PostgreSQL schema (12 migrations) - Common infrastructure: JWT/RBAC guards, decorators, exception filter - NATS service with pub/sub/request-reply - Socket.IO WebSocket gateway with NATS bridge - Docker: NestJS Dockerfile + updated docker-compose.yml - Zero compile errors (npx tsc --noEmit clean) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
65
backend-nest/src/modules/alerts/alerts.service.ts
Normal file
65
backend-nest/src/modules/alerts/alerts.service.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { AlertConfig } from '../../entities/alert-config.entity';
|
||||
import { AlertHistory } from '../../entities/alert-history.entity';
|
||||
import { UpdateAlertConfigDto } from './dto/update-alert-config.dto';
|
||||
|
||||
@Injectable()
|
||||
export class AlertsService {
|
||||
constructor(
|
||||
@InjectRepository(AlertConfig)
|
||||
private readonly alertConfigRepo: Repository<AlertConfig>,
|
||||
@InjectRepository(AlertHistory)
|
||||
private readonly alertHistoryRepo: Repository<AlertHistory>,
|
||||
) {}
|
||||
|
||||
async getConfig(licenseId: string): Promise<AlertConfig> {
|
||||
let config = await this.alertConfigRepo.findOne({
|
||||
where: { license_id: licenseId },
|
||||
});
|
||||
|
||||
if (!config) {
|
||||
// Create default config if not exists
|
||||
config = this.alertConfigRepo.create({
|
||||
license_id: licenseId,
|
||||
population_drop_enabled: true,
|
||||
population_drop_threshold_percent: 30,
|
||||
fps_degradation_enabled: true,
|
||||
fps_threshold: 30,
|
||||
notify_discord: true,
|
||||
notify_pushbullet: false,
|
||||
notify_email: false,
|
||||
});
|
||||
await this.alertConfigRepo.save(config);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
async updateConfig(licenseId: string, dto: UpdateAlertConfigDto): Promise<AlertConfig> {
|
||||
let config = await this.alertConfigRepo.findOne({
|
||||
where: { license_id: licenseId },
|
||||
});
|
||||
|
||||
if (!config) {
|
||||
config = this.alertConfigRepo.create({
|
||||
license_id: licenseId,
|
||||
...dto,
|
||||
});
|
||||
} else {
|
||||
Object.assign(config, dto);
|
||||
config.updated_at = new Date();
|
||||
}
|
||||
|
||||
return this.alertConfigRepo.save(config);
|
||||
}
|
||||
|
||||
async getHistory(licenseId: string, limit: number = 50): Promise<AlertHistory[]> {
|
||||
return this.alertHistoryRepo.find({
|
||||
where: { license_id: licenseId },
|
||||
order: { triggered_at: 'DESC' },
|
||||
take: limit,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user