Unit tests

This commit is contained in:
Bastian Wagner
2026-02-27 11:03:35 +01:00
parent 5aa97cd8ea
commit f86c9c681a
15 changed files with 166 additions and 45 deletions

View File

@@ -1,9 +1,8 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { CreateSystemDto } from './dto/create-system.dto';
import { UpdateSystemDto } from './dto/update-system.dto';
import { ActivityRepository, KeySystemRepository, UserRepository } from 'src/model/repositories';
import { KeySystemRepository, UserRepository } from 'src/model/repositories';
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';
@@ -14,7 +13,7 @@ export class SystemService {
constructor(
private systemRepo: KeySystemRepository,
private userRepo: UserRepository,
private systemActivityRepo: ActivityRepository,
// private systemActivityRepo: ActivityRepository,
private mailService: MailService,
private readonly configService: ConfigService,
private readonly activityService: ActivityHelperService
@@ -28,15 +27,7 @@ export class SystemService {
const sys = this.systemRepo.create(createSystemDto);
sys.managers = [user];
try {
const res = await this.systemRepo.save(sys);
this.systemActivityRepo.save({
message: `Schließanlage ${(res as any).name} angelegt`,
user: user,
system: res
});
const res = await this.systemRepo.save(sys);
return res;
} catch (e) {
throw new HttpException(e.code, HttpStatus.UNPROCESSABLE_ENTITY);
@@ -78,7 +69,6 @@ export class SystemService {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
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); }