Dashboard

This commit is contained in:
Bastian Wagner
2025-01-02 15:55:56 +01:00
parent efbfc2eb01
commit 5c6516095b
24 changed files with 490 additions and 36 deletions

View File

@@ -2,6 +2,7 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { Customer, Cylinder, Key, User } from 'src/model/entitites';
import { IUser } from 'src/model/interface';
import {
ActivityRepository,
CylinderRepository,
KeyActivityRepository,
KeyRepository,
@@ -18,6 +19,7 @@ export class KeyService {
private readonly systemRepo: KeySystemRepository,
private activityRepo: KeyActivityRepository,
private handoverRepo: KeyHandoutRepository,
private systemActivityRepo: ActivityRepository,
) {}
async getUsersKeys(user: User): Promise<Key[]> {
@@ -74,19 +76,30 @@ export class KeyService {
async handoverKey(user: IUser, data: any, keyID: string) {
const key: Key = await this.keyrepository.findOneOrFail({
where: { id: keyID, cylinder: { system: { managers: { id: user.id } } } },
relations: [ 'cylinder', 'cylinder.system' ]
});
key.handedOut = data.direction == 'out';
this.keyrepository.save(key);
return this.handoverRepo.save(
const res = await this.handoverRepo.save(
this.handoverRepo.create({
customer: data.customer,
direction: data.direction,
timestamp: data.timestamp,
key: key,
user: user as any
}),
);
const msg = `Schlüssel ${key.nr} ${res.direction == 'out' ? 'ausgegeben an ' : 'zurückgegeben von '}${res.customer.name}`
this.systemActivityRepo.save(
this.systemActivityRepo.create({
system: key.cylinder[0].system,
user: user as any,
message: msg,
}))
return res;
}
getKeyHandovers(user: User, keyID: string) {
@@ -121,8 +134,14 @@ export class KeyService {
}
}
createKey(user: User, key: any) {
return this.keyrepository.save(this.keyrepository.create(key));
async createKey(user: User, key: any) {
const k = await this.keyrepository.save(this.keyrepository.create(key));
this.systemActivityRepo.save({
message: `Schlüssel ${(k as any).nr} angelegt`,
user: user,
system: (k as any).cylinder[0].system
});
return k;
}
async deleteKey(user: User, id: string) {