Logging und sowas
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user