Logging und sowas
This commit is contained in:
@@ -58,7 +58,7 @@ export class User implements IUser {
|
||||
@DeleteDateColumn()
|
||||
deletedAt: Date;
|
||||
|
||||
@OneToOne(() => UserSettings, (settings) => settings.user, { cascade: true, onDelete: 'CASCADE', onUpdate: 'NO ACTION', })
|
||||
@OneToOne(() => UserSettings, (settings) => settings.user, { cascade: true, onUpdate: 'NO ACTION', })
|
||||
settings: UserSettings;
|
||||
|
||||
accessToken?: string;
|
||||
|
||||
@@ -6,7 +6,7 @@ export class UserSettings {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@OneToOne(() => User, (user) => user.settings)
|
||||
@OneToOne(() => User, (user) => user.settings, { onDelete: 'CASCADE' })
|
||||
@JoinColumn()
|
||||
user: User;
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -13,8 +13,8 @@ export class UserService {
|
||||
private readonly systemActivityRepo: ActivityRepository,
|
||||
private readonly userSettingsRepository: UserSettingsRepository,
|
||||
private readonly helper: HelperService,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
|
||||
|
||||
getAllUsers(): Promise<User[]> {
|
||||
|
||||
@@ -14,6 +14,17 @@ export class ActivityHelperService {
|
||||
private readonly cylinderRepo: CylinderRepository,
|
||||
) {}
|
||||
|
||||
async logSystemRenamed({system, newName, user}: { system: KeySystem, newName: string, user: User}) {
|
||||
let msg = `Schließanlage von ${system.name} zu ${newName} umbenannt`;
|
||||
|
||||
return this.activityRepo.save(
|
||||
this.activityRepo.create({
|
||||
system,
|
||||
user,
|
||||
message: msg,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
async logDeleteKey(user: User, key: Key, system?: KeySystem) {
|
||||
if (!key || !user) { return; }
|
||||
|
||||
Reference in New Issue
Block a user