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:
40
backend-nest/src/modules/chat/chat.controller.ts
Normal file
40
backend-nest/src/modules/chat/chat.controller.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Controller, Get, Put, Param, Body, Query, ParseIntPipe, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
||||
import { ChatService } from './chat.service';
|
||||
import { FlagMessageDto } from './dto/flag-message.dto';
|
||||
import { CurrentTenant } from '../../common/decorators/current-tenant.decorator';
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
||||
import { RequirePermission } from '../../common/decorators/require-permission.decorator';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { PermissionsGuard } from '../../common/guards/permissions.guard';
|
||||
|
||||
@ApiTags('Chat')
|
||||
@ApiBearerAuth()
|
||||
@Controller('chat')
|
||||
@UseGuards(JwtAuthGuard, PermissionsGuard)
|
||||
export class ChatController {
|
||||
constructor(private readonly chatService: ChatService) {}
|
||||
|
||||
@Get()
|
||||
@RequirePermission('chat.view')
|
||||
@ApiOperation({ summary: 'Get recent chat messages' })
|
||||
@ApiQuery({ name: 'limit', required: false, example: 100 })
|
||||
async getMessages(
|
||||
@CurrentTenant() licenseId: string,
|
||||
@Query('limit', new ParseIntPipe({ optional: true })) limit?: number,
|
||||
) {
|
||||
return await this.chatService.getMessages(licenseId, limit || 100);
|
||||
}
|
||||
|
||||
@Put(':id/flag')
|
||||
@RequirePermission('chat.moderate')
|
||||
@ApiOperation({ summary: 'Flag or unflag a chat message' })
|
||||
async flagMessage(
|
||||
@CurrentTenant() licenseId: string,
|
||||
@CurrentUser('sub') userId: string,
|
||||
@Param('id') messageId: string,
|
||||
@Body() dto: FlagMessageDto,
|
||||
) {
|
||||
return await this.chatService.flagMessage(licenseId, messageId, userId, dto);
|
||||
}
|
||||
}
|
||||
13
backend-nest/src/modules/chat/chat.module.ts
Normal file
13
backend-nest/src/modules/chat/chat.module.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ChatController } from './chat.controller';
|
||||
import { ChatService } from './chat.service';
|
||||
import { ChatLog } from '../../entities/chat-log.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([ChatLog])],
|
||||
controllers: [ChatController],
|
||||
providers: [ChatService],
|
||||
exports: [ChatService],
|
||||
})
|
||||
export class ChatModule {}
|
||||
51
backend-nest/src/modules/chat/chat.service.ts
Normal file
51
backend-nest/src/modules/chat/chat.service.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ChatLog } from '../../entities/chat-log.entity';
|
||||
import { FlagMessageDto } from './dto/flag-message.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ChatService {
|
||||
constructor(
|
||||
@InjectRepository(ChatLog)
|
||||
private readonly chatRepo: Repository<ChatLog>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get recent chat messages for a license
|
||||
*/
|
||||
async getMessages(licenseId: string, limit: number = 100) {
|
||||
const messages = await this.chatRepo.find({
|
||||
where: { license_id: licenseId },
|
||||
order: { created_at: 'DESC' },
|
||||
take: limit,
|
||||
});
|
||||
|
||||
// Return in chronological order (oldest first for display)
|
||||
return { messages: messages.reverse() };
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag or unflag a chat message
|
||||
*/
|
||||
async flagMessage(
|
||||
licenseId: string,
|
||||
messageId: string,
|
||||
userId: string,
|
||||
dto: FlagMessageDto,
|
||||
) {
|
||||
const message = await this.chatRepo.findOne({
|
||||
where: { id: messageId, license_id: licenseId },
|
||||
});
|
||||
|
||||
if (!message) {
|
||||
throw new NotFoundException('Message not found');
|
||||
}
|
||||
|
||||
message.flagged = dto.flagged;
|
||||
message.flagged_by = dto.flagged ? userId : null;
|
||||
message.flag_reason = dto.flagged ? (dto.flag_reason || null) : null;
|
||||
|
||||
return await this.chatRepo.save(message);
|
||||
}
|
||||
}
|
||||
13
backend-nest/src/modules/chat/dto/flag-message.dto.ts
Normal file
13
backend-nest/src/modules/chat/dto/flag-message.dto.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { IsBoolean, IsOptional, IsString } from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
|
||||
export class FlagMessageDto {
|
||||
@ApiProperty({ example: true, description: 'Whether to flag or unflag the message' })
|
||||
@IsBoolean()
|
||||
flagged: boolean;
|
||||
|
||||
@ApiPropertyOptional({ example: 'Inappropriate language', description: 'Reason for flagging' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
flag_reason?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user