Zylinder angefangen
This commit is contained in:
@@ -9,6 +9,7 @@ import { UserModule } from './modules/user/user.module';
|
|||||||
import { RoleModule } from './modules/role/role.module';
|
import { RoleModule } from './modules/role/role.module';
|
||||||
import { KeyModule } from './modules/key/key.module';
|
import { KeyModule } from './modules/key/key.module';
|
||||||
import { CustomerModule } from './modules/customer/customer.module';
|
import { CustomerModule } from './modules/customer/customer.module';
|
||||||
|
import { CylinderModule } from './modules/cylinder/cylinder.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -22,6 +23,7 @@ import { CustomerModule } from './modules/customer/customer.module';
|
|||||||
RoleModule,
|
RoleModule,
|
||||||
KeyModule,
|
KeyModule,
|
||||||
CustomerModule,
|
CustomerModule,
|
||||||
|
CylinderModule,
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService, AuthGuard],
|
providers: [AppService, AuthGuard],
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
|
AfterLoad,
|
||||||
Column,
|
Column,
|
||||||
CreateDateColumn,
|
CreateDateColumn,
|
||||||
|
DeleteDateColumn,
|
||||||
Entity,
|
Entity,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
@@ -29,4 +31,16 @@ export class Cylinder {
|
|||||||
|
|
||||||
@UpdateDateColumn({ name: 'updatet_at' })
|
@UpdateDateColumn({ name: 'updatet_at' })
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@DeleteDateColumn()
|
||||||
|
deletedAt: Date;
|
||||||
|
|
||||||
|
keyCount: number;
|
||||||
|
|
||||||
|
@AfterLoad()
|
||||||
|
countKeys() {
|
||||||
|
if (this.keys) {
|
||||||
|
this.keyCount = this.keys.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ export class RoleRepository extends Repository<Role> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getStandardRole(): Promise<Role> {
|
getStandardRole(): Promise<Role> {
|
||||||
return this.findOne({ where: { name: 'develop' } });
|
return this.findOne({ where: { name: 'user' } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
api/src/modules/cylinder/cylinder.controller.ts
Normal file
21
api/src/modules/cylinder/cylinder.controller.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { Controller, Delete, Get, Param, Req, UseGuards } from '@nestjs/common';
|
||||||
|
import { AuthGuard } from 'src/core/guards/auth.guard';
|
||||||
|
import { CylinderService } from './cylinder.service';
|
||||||
|
import { AuthenticatedRequest } from 'src/model/interface/authenticated-request.interface';
|
||||||
|
import { Cylinder } from 'src/model/entitites';
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@Controller('cylinder')
|
||||||
|
export class CylinderController {
|
||||||
|
constructor(private service: CylinderService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
getCylinders(@Req() req: AuthenticatedRequest): Promise<Cylinder[]> {
|
||||||
|
return this.service.getCylinders(req.user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':id')
|
||||||
|
deleteKey(@Req() req: AuthenticatedRequest, @Param() id: string) {
|
||||||
|
return this.service.deleteKey(req.user, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
api/src/modules/cylinder/cylinder.module.ts
Normal file
12
api/src/modules/cylinder/cylinder.module.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { CylinderController } from './cylinder.controller';
|
||||||
|
import { CylinderService } from './cylinder.service';
|
||||||
|
import { AuthModule } from '../auth/auth.module';
|
||||||
|
import { DatabaseModule } from 'src/shared/database/database.module';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [CylinderController],
|
||||||
|
providers: [CylinderService],
|
||||||
|
imports: [AuthModule, DatabaseModule],
|
||||||
|
})
|
||||||
|
export class CylinderModule {}
|
||||||
30
api/src/modules/cylinder/cylinder.service.ts
Normal file
30
api/src/modules/cylinder/cylinder.service.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Cylinder, User } from 'src/model/entitites';
|
||||||
|
import { CylinderRepository, KeyRepository } from 'src/model/repositories';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CylinderService {
|
||||||
|
constructor(
|
||||||
|
private readonly cylinderRepo: CylinderRepository,
|
||||||
|
private readonly keyRepo: KeyRepository,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async getCylinders(user: User): Promise<Cylinder[]> {
|
||||||
|
const c = await this.cylinderRepo.find({
|
||||||
|
where: { system: { managers: { id: user.id } } },
|
||||||
|
order: { name: { direction: 'ASC' } },
|
||||||
|
relations: ['system', 'keys'],
|
||||||
|
});
|
||||||
|
c.map((cc) => (cc.keys = []));
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteKey(user: User, id: string) {
|
||||||
|
const cylinder = await this.cylinderRepo.findOneOrFail({
|
||||||
|
where: { id: id, system: { managers: { id: user.id } } },
|
||||||
|
relations: ['keys'],
|
||||||
|
});
|
||||||
|
await this.keyRepo.softRemove(cylinder.keys);
|
||||||
|
return this.cylinderRepo.softRemove(cylinder);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,11 +45,6 @@ export class KeyController {
|
|||||||
return this.service.deleteKey(req.user, id);
|
return this.service.deleteKey(req.user, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('cylinder')
|
|
||||||
getCylinders(@Req() req: AuthenticatedRequest) {
|
|
||||||
return this.service.getUsersCylinders(req.user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('system')
|
@Post('system')
|
||||||
createKeySystem(
|
createKeySystem(
|
||||||
@Req() req: AuthenticatedRequest,
|
@Req() req: AuthenticatedRequest,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
} from 'src/model/repositories';
|
} from 'src/model/repositories';
|
||||||
import { KeyHandoutRepository } from 'src/model/repositories/key-handout.repository';
|
import { KeyHandoutRepository } from 'src/model/repositories/key-handout.repository';
|
||||||
import { IsNull, Not } from 'typeorm';
|
import { IsNull, Not } from 'typeorm';
|
||||||
import { faker } from '@faker-js/faker';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class KeyService {
|
export class KeyService {
|
||||||
@@ -20,27 +19,7 @@ export class KeyService {
|
|||||||
private readonly systemRepo: KeySystemRepository,
|
private readonly systemRepo: KeySystemRepository,
|
||||||
private activityRepo: KeyActivityRepository,
|
private activityRepo: KeyActivityRepository,
|
||||||
private handoverRepo: KeyHandoutRepository,
|
private handoverRepo: KeyHandoutRepository,
|
||||||
) {
|
) {}
|
||||||
this.create()
|
|
||||||
}
|
|
||||||
|
|
||||||
async create() {
|
|
||||||
const c = await this.cylinderRepository.findOneBy({ name: 'DevCylinder1' });
|
|
||||||
|
|
||||||
const keys = [];
|
|
||||||
for (let x = 0; x < 1000; x++) {
|
|
||||||
keys.push(
|
|
||||||
this.keyrepository.create({
|
|
||||||
name: faker.commerce.productName(),
|
|
||||||
nr: faker.commerce.isbn(),
|
|
||||||
cylinder: c,
|
|
||||||
createdAt: new Date(faker.date.past())
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
await this.keyrepository.save(keys);
|
|
||||||
console.log("edn")
|
|
||||||
}
|
|
||||||
|
|
||||||
async getUsersKeys(user: User): Promise<Key[]> {
|
async getUsersKeys(user: User): Promise<Key[]> {
|
||||||
return this.keyrepository.find({
|
return this.keyrepository.find({
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ import { LayoutComponent } from './core/layout/layout.component';
|
|||||||
import { DashboardComponent } from './modules/dashboard/dashboard.component';
|
import { DashboardComponent } from './modules/dashboard/dashboard.component';
|
||||||
import { AllUsersComponent } from './modules/admin/all-users/all-users.component';
|
import { AllUsersComponent } from './modules/admin/all-users/all-users.component';
|
||||||
import { KeysComponent } from './modules/keys/keys.component';
|
import { KeysComponent } from './modules/keys/keys.component';
|
||||||
|
import { CylinderComponent } from './modules/cylinder/cylinder.component';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{ path: '', component: LayoutComponent, canActivate: [AuthenticatedGuard], children: [
|
{ path: '', component: LayoutComponent, canActivate: [AuthenticatedGuard], children: [
|
||||||
{ path: '', component: DashboardComponent },
|
{ path: '', component: DashboardComponent },
|
||||||
{ path: 'users', component: AllUsersComponent },
|
{ path: 'users', component: AllUsersComponent },
|
||||||
{ path: 'keys', component: KeysComponent }
|
{ path: 'keys', component: KeysComponent },
|
||||||
|
{ path: 'cylinders', component: CylinderComponent }
|
||||||
]},
|
]},
|
||||||
{ path: 'login', component: LoginComponent},
|
{ path: 'login', component: LoginComponent},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<mat-drawer #drawer class="main_sidenav" mode="side" opened="true" style="border-right: 1px solid #dfdfdf">
|
<mat-drawer #drawer class="main_sidenav" mode="side" opened="true" style="border-right: 1px solid #dfdfdf">
|
||||||
<button mat-button routerLink="/" routerLinkActive="mat-elevation-z1" [routerLinkActiveOptions]="{exact: true}">Home</button>
|
<button mat-button routerLink="/" routerLinkActive="mat-elevation-z1" [routerLinkActiveOptions]="{exact: true}">Home</button>
|
||||||
<button mat-button routerLink="/keys" routerLinkActive="mat-elevation-z1">Schlüssel</button>
|
<button mat-button routerLink="/keys" routerLinkActive="mat-elevation-z1">Schlüssel</button>
|
||||||
|
<button mat-button routerLink="/cylinders" routerLinkActive="mat-elevation-z1">Zylinder</button>
|
||||||
<button mat-button routerLink="/users" routerLinkActive="mat-elevation-z1">Alle User</button>
|
<button mat-button routerLink="/users" routerLinkActive="mat-elevation-z1">Alle User</button>
|
||||||
</mat-drawer>
|
</mat-drawer>
|
||||||
|
|
||||||
|
|||||||
5
client/src/app/modules/cylinder/cylinder.component.html
Normal file
5
client/src/app/modules/cylinder/cylinder.component.html
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<ag-grid-angular
|
||||||
|
style="width: 100%; height: 100%;"
|
||||||
|
(gridReady)="onGridReady($event)"
|
||||||
|
[gridOptions]="gridOptions!"
|
||||||
|
/>
|
||||||
23
client/src/app/modules/cylinder/cylinder.component.spec.ts
Normal file
23
client/src/app/modules/cylinder/cylinder.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { CylinderComponent } from './cylinder.component';
|
||||||
|
|
||||||
|
describe('CylinderComponent', () => {
|
||||||
|
let component: CylinderComponent;
|
||||||
|
let fixture: ComponentFixture<CylinderComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
imports: [CylinderComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(CylinderComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
50
client/src/app/modules/cylinder/cylinder.component.ts
Normal file
50
client/src/app/modules/cylinder/cylinder.component.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { Component, inject } from '@angular/core';
|
||||||
|
import { HELPER } from '../../shared/helper.service';
|
||||||
|
import { GridApi, GridOptions, GridReadyEvent } from 'ag-grid-community';
|
||||||
|
import { AgGridAngular } from 'ag-grid-angular';
|
||||||
|
import { ApiService } from '../../shared/api.service';
|
||||||
|
import { DatePipe } from '@angular/common';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-cylinder',
|
||||||
|
standalone: true,
|
||||||
|
imports: [AgGridAngular],
|
||||||
|
providers: [DatePipe],
|
||||||
|
templateUrl: './cylinder.component.html',
|
||||||
|
styleUrl: './cylinder.component.scss'
|
||||||
|
})
|
||||||
|
export class CylinderComponent {
|
||||||
|
private api: ApiService = inject(ApiService);
|
||||||
|
private datePipe = inject(DatePipe);
|
||||||
|
|
||||||
|
gridApi!: GridApi;
|
||||||
|
|
||||||
|
gridOptions: GridOptions = HELPER.getGridOptions();
|
||||||
|
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
this.gridOptions.columnDefs = [
|
||||||
|
{ field: 'name', headerName: 'Name', sort: 'asc', flex: 1 },
|
||||||
|
{ field: 'system.name', headerName: 'System', flex: 1 },
|
||||||
|
{ field: 'keyCount', headerName: 'Anzahl Schlüssel', flex: 0, type: 'number' },
|
||||||
|
{ field: 'createdAt', headerName: 'Angelegt', cellRenderer: (data: any) => data.value ? this.datePipe.transform(new Date(data.value)) : '-' },
|
||||||
|
{ field: 'updatedAt', headerName: 'Upgedated', cellRenderer: (data: any) => data.value ? this.datePipe.transform(new Date(data.value)) : '-' },
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
loadCylinders() {
|
||||||
|
this.api.getCylinders().subscribe({
|
||||||
|
next: n => {
|
||||||
|
this.gridApi.setGridOption("rowData", n);
|
||||||
|
this.gridApi.setGridOption("loading", false);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onGridReady(params: GridReadyEvent) {
|
||||||
|
this.gridApi = params.api;
|
||||||
|
this.loadCylinders();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,10 +33,6 @@ export class ApiService {
|
|||||||
return this.http.put<IKey>('api/key', key);
|
return this.http.put<IKey>('api/key', key);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCylinders(): Observable<any[]> {
|
|
||||||
return this.http.get<any[]>('api/key/cylinder');
|
|
||||||
}
|
|
||||||
|
|
||||||
createKey(key: any) {
|
createKey(key: any) {
|
||||||
return this.http.post<IKey>('api/key', key);
|
return this.http.post<IKey>('api/key', key);
|
||||||
}
|
}
|
||||||
@@ -72,4 +68,8 @@ export class ApiService {
|
|||||||
restoreKey(id: string) {
|
restoreKey(id: string) {
|
||||||
return this.http.put(`api/key/${id}/restore`, null);
|
return this.http.put(`api/key/${id}/restore`, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCylinders(): Observable<any[]> {
|
||||||
|
return this.http.get<any[]>('api/cylinder');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user