Lost Keys
This commit is contained in:
@@ -2,11 +2,13 @@ import { Injectable } from "@nestjs/common";
|
||||
import { Key, KeyHandout, User } from "src/model/entitites";
|
||||
import { KeySystem } from "src/model/entitites/system.entity";
|
||||
import { ActivityRepository, CylinderRepository, KeyRepository } from "src/model/repositories";
|
||||
import { HelperService } from "./system.helper.service";
|
||||
|
||||
@Injectable()
|
||||
export class ActivityHelperService {
|
||||
|
||||
constructor(
|
||||
private readonly helper: HelperService,
|
||||
private readonly activityRepo: ActivityRepository,
|
||||
private readonly keyRepository: KeyRepository,
|
||||
private readonly cylinderRepo: CylinderRepository,
|
||||
@@ -54,8 +56,8 @@ export class ActivityHelperService {
|
||||
}))
|
||||
}
|
||||
|
||||
async logKeyRenamed(user: User, key: Key, system: KeySystem) {
|
||||
let msg = `Schlüssel ${key.nr} in ${key.name} umbenannt`;
|
||||
async logKeyRenamed(user: User, key: Key, system: KeySystem, oldName?: string) {
|
||||
let msg = `Schlüssel ${key.nr} ${oldName ? 'von ' + oldName + ' in ' : ''}in ${key.name} umbenannt`;
|
||||
this.activityRepo.save(
|
||||
this.activityRepo.create({
|
||||
system,
|
||||
@@ -64,6 +66,31 @@ export class ActivityHelperService {
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs when a key is reported as lost or misplaced in the system.
|
||||
*
|
||||
* @param user - The user who reported the key as lost
|
||||
* @param key - The key that was reported as lost
|
||||
* @param system - The key system the lost key belongs to
|
||||
* @param lostDate - The date when the key was reported as lost
|
||||
*/
|
||||
async logKeyLostUpdate(user: User, key: Key,lostDate: Date | string) {
|
||||
const sys = await this.helper.getSystemOfKey(key);
|
||||
let msg;
|
||||
if (lostDate == null) {
|
||||
msg = `Schlüssel ${key.nr} als gefunden gemeldet`;
|
||||
} else {
|
||||
msg = `Schlüssel ${key.nr} als verloren gemeldet`
|
||||
}
|
||||
this.activityRepo.save(
|
||||
this.activityRepo.create({
|
||||
system: sys,
|
||||
user,
|
||||
message: msg,
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
logKeyHandover(user: User, key: Key, system: KeySystem, handover: KeyHandout) {
|
||||
|
||||
const msg = `Schlüssel ${key.nr} ${handover.direction == 'out' ? 'ausgegeben an ' : 'zurückgegeben von '}${handover.customer.name}`
|
||||
@@ -75,4 +102,17 @@ export class ActivityHelperService {
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
async logKeyRestored(user: User, key: Key) {
|
||||
let msg = `Schlüssel ${key.nr} wiederhergestellt`;
|
||||
|
||||
const system: KeySystem = await this.helper.getSystemOfKey(key);
|
||||
|
||||
this.activityRepo.save(
|
||||
this.activityRepo.create({
|
||||
system,
|
||||
user,
|
||||
message: msg,
|
||||
}))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user