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,
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { DatabaseModule } from "../database/database.module";
|
||||
import { ManageHelperService } from "./system.helper.service";
|
||||
import { HelperService } from "./system.helper.service";
|
||||
import { CylinderRepository, KeySystemRepository } from "src/model/repositories";
|
||||
import { Cylinder, User } from "src/model/entitites";
|
||||
import { ActivityHelperService } from "./activity.logger.service";
|
||||
import { CacheModule } from "@nestjs/cache-manager";
|
||||
|
||||
@Module({
|
||||
imports: [ DatabaseModule ],
|
||||
providers: [ ManageHelperService, ActivityHelperService ],
|
||||
exports: [ ManageHelperService, ActivityHelperService ],
|
||||
providers: [ HelperService, ActivityHelperService ],
|
||||
exports: [ HelperService, ActivityHelperService ],
|
||||
})
|
||||
|
||||
export class SharedServiceModule {
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import { User, Cylinder, Key } from "src/model/entitites";
|
||||
import { KeySystem } from "src/model/entitites/system.entity";
|
||||
import { KeySystemRepository, CylinderRepository, KeyRepository } from "src/model/repositories";
|
||||
import { Cache } from "@nestjs/cache-manager";
|
||||
|
||||
@Injectable()
|
||||
export class ManageHelperService {
|
||||
export class HelperService {
|
||||
|
||||
constructor(
|
||||
private readonly systemRepository: KeySystemRepository,
|
||||
private readonly cylinderRepository: CylinderRepository,
|
||||
private readonly keyRepo: KeyRepository,
|
||||
private cacheManager: Cache
|
||||
) {}
|
||||
|
||||
|
||||
@@ -35,4 +38,24 @@ export class ManageHelperService {
|
||||
});
|
||||
return keys;
|
||||
}
|
||||
|
||||
async getSystemOfKey(key: Key): Promise<KeySystem> {
|
||||
const k = await this.keyRepo.findOne({
|
||||
where: { id: key.id },
|
||||
relations: ['cylinder', 'cylinder.system'],
|
||||
withDeleted: true,
|
||||
});
|
||||
this.cache()
|
||||
const found = k.cylinder.find(c => c.system != null);
|
||||
return found.system;
|
||||
}
|
||||
|
||||
async cache() {
|
||||
const value = await this.cacheManager.store.keys()
|
||||
console.log(value)
|
||||
}
|
||||
|
||||
async deleteKeyArchiveCache() {
|
||||
await this.cacheManager.del('/key/archive');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user