Logging und sowas

This commit is contained in:
Bastian Wagner
2026-02-20 10:28:48 +01:00
parent 29bfffc505
commit 4e051a1f40
14 changed files with 87 additions and 22 deletions

View File

@@ -1,4 +1,6 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateSystemDto } from './create-system.dto';
export class UpdateSystemDto extends PartialType(CreateSystemDto) {}
export class UpdateSystemDto extends PartialType(CreateSystemDto) {
id: string;
}

View File

@@ -48,9 +48,9 @@ export class SystemController {
return this.systemService.findOne(id);
}
@Put(':id')
update(@Param('id') id: string, @Body() updateSystemDto: UpdateSystemDto) {
return this.systemService.update(id, updateSystemDto);
@Put()
update(@Req() req: AuthenticatedRequest, @Body() updateSystemDto: UpdateSystemDto) {
return this.systemService.update(req.user, updateSystemDto);
}
@Delete(':id')

View File

@@ -5,10 +5,11 @@ import { AuthModule } from '../auth/auth.module';
import { DatabaseModule } from 'src/shared/database/database.module';
import { MailModule } from '../mail/mail.module';
import { ConfigService } from '@nestjs/config';
import { SharedServiceModule } from 'src/shared/service/shared.service.module';
@Module({
controllers: [SystemController],
providers: [SystemService, ConfigService],
imports: [AuthModule, DatabaseModule, MailModule],
imports: [AuthModule, DatabaseModule, MailModule, SharedServiceModule],
})
export class SystemModule {}

View File

@@ -6,6 +6,7 @@ import { User } from 'src/model/entitites';
import { IUser } from 'src/model/interface';
import { MailService } from '../mail/mail.service';
import { ConfigService } from '@nestjs/config';
import { ActivityHelperService } from 'src/shared/service/activity.logger.service';
@Injectable()
export class SystemService {
@@ -14,7 +15,8 @@ export class SystemService {
private userRepo: UserRepository,
private systemActivityRepo: ActivityRepository,
private mailService: MailService,
private readonly configService: ConfigService
private readonly configService: ConfigService,
private readonly activityService: ActivityHelperService
) {}
get isDevelopMode(): boolean {
@@ -59,12 +61,21 @@ export class SystemService {
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
update(id: string, updateSystemDto: UpdateSystemDto) {
throw new HttpException(
`This action updates a #${id} system but is not implemented`,
HttpStatus.NOT_IMPLEMENTED,
);
return `This action updates a #${id} system`;
async update(user: User, updateSystemDto: UpdateSystemDto) {
if (!user || !user.id || !updateSystemDto.id) { throw new HttpException('forbidden', HttpStatus.FORBIDDEN); }
console.log(updateSystemDto);
const system = await this.systemRepo.findOne({ where: { id: updateSystemDto.id, managers: { id: user.id } }, withDeleted: true });
if (!system) { throw new HttpException('forbidden', HttpStatus.FORBIDDEN); }
if (system.name !== updateSystemDto.name) {
await this.activityService.logSystemRenamed({ system, newName: updateSystemDto.name, user })
system.name = updateSystemDto.name;
}
return true;
}
async remove(id: string) {