create cylinder

This commit is contained in:
Bastian Wagner
2025-01-02 16:53:16 +01:00
parent 5c6516095b
commit a47bbe29fe
11 changed files with 175 additions and 9 deletions

View File

@@ -1,12 +1,13 @@
import { Injectable } from '@nestjs/common';
import { Cylinder, User } from 'src/model/entitites';
import { CylinderRepository, KeyRepository } from 'src/model/repositories';
import { ActivityRepository, CylinderRepository, KeyRepository } from 'src/model/repositories';
@Injectable()
export class CylinderService {
constructor(
private readonly cylinderRepo: CylinderRepository,
private readonly keyRepo: KeyRepository,
private systemActivityRepo: ActivityRepository,
) {}
async getCylinders(user: User): Promise<Cylinder[]> {
@@ -40,7 +41,14 @@ export class CylinderService {
return this.cylinderRepo.save(original);
}
createCylinder(user: User, cylinder: Partial<Cylinder>) {
return this.cylinderRepo.save(this.cylinderRepo.create(cylinder));
async createCylinder(user: User, cylinder: Partial<Cylinder>) {
const c = await this.cylinderRepo.save(this.cylinderRepo.create(cylinder));
this.systemActivityRepo.save({
message: `Zylinder ${(c as any).name} angelegt`,
user: user,
system: (c as any).system
});
return c
}
}

View File

@@ -1,19 +1,31 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { CreateSystemDto } from './dto/create-system.dto';
import { UpdateSystemDto } from './dto/update-system.dto';
import { KeySystemRepository, UserRepository } from 'src/model/repositories';
import { ActivityRepository, KeySystemRepository, UserRepository } from 'src/model/repositories';
import { User } from 'src/model/entitites';
import { IUser } from 'src/model/interface';
@Injectable()
export class SystemService {
constructor(private systemRepo: KeySystemRepository, private userRepo: UserRepository) {}
constructor(
private systemRepo: KeySystemRepository,
private userRepo: UserRepository,
private systemActivityRepo: ActivityRepository,
) {}
async create(user: User, createSystemDto: CreateSystemDto) {
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
});
return res;
} catch (e) {
throw new HttpException(e.code, HttpStatus.UNPROCESSABLE_ENTITY);