Commit 3090f93a authored by mechtelm's avatar mechtelm
Browse files

Introduce staff member's main data

parent 21e80984
import { Injectable } from '@nestjs/common';
import {Injectable, NotFoundException} from '@nestjs/common';
import {InjectRepository} from "@nestjs/typeorm";
import {Repository} from "typeorm";
import Staff from "../entities/staff-member.entity";
import {StaffMemberInListDto, UserInListDto} from "../../../../../../libs/dto/src";
import {StaffMemberInListDto, StaffMemberMainDto, UserFullDto, UserInListDto} from "../../../../../../libs/dto/src";
@Injectable()
export class StaffService {
......@@ -30,4 +30,25 @@ export class StaffService {
});
return returnStaff;
}
async findOneMain(id: number): Promise<StaffMemberMainDto> {
const staffMember = await this.staffRepository.findOne(id);
if (staffMember) {
return <StaffMemberMainDto>{
id: staffMember.id,
name: staffMember.name,
firstName: staffMember.firstName,
canonicalName: staffMember.canonicalName,
contractStart: staffMember.contractStart,
contractEnd: staffMember.contractEnd,
contractType: staffMember.contractType,
payrollNumber: staffMember.payrollNumber,
idmId: staffMember.idmId,
idmRegistered: staffMember.idmRegistered,
address: staffMember.address
}
} else {
throw new NotFoundException();
}
}
}
import {Controller, Get, UseGuards} from '@nestjs/common';
import {Controller, Get, Param, UseGuards} from '@nestjs/common';
import {JwtAuthGuard} from "../auth/jwt-auth.guard";
import {IsAdminGuard} from "../app-admin/is-admin.guard";
import {ApiBearerAuth, ApiCreatedResponse, ApiTags} from "@nestjs/swagger";
import {StaffMemberInListDto, UserInListDto} from "../../../../../libs/dto/src";
import {StaffMemberInListDto, StaffMemberMainDto, UserInListDto} from "../../../../../libs/dto/src";
import {StaffService} from "../database/services/staff.service";
@Controller('staff')
......@@ -22,4 +22,14 @@ export class StaffController {
return this.staffService.findAll();
}
@Get(':id/main')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiCreatedResponse({
type: StaffMemberMainDto,
})
@ApiTags('staff')
async findOneMain(@Param('id') id: number): Promise<StaffMemberMainDto> {
return this.staffService.findOneMain(id);
}
}
......@@ -2,7 +2,7 @@ import { catchError } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Injectable, Inject } from '@angular/core';
import {StaffMemberInListDto} from "../../../../../libs/dto/src";
import {StaffMemberInListDto, StaffMemberMainDto} from "../../../../../libs/dto/src";
@Injectable({
providedIn: 'root'
......@@ -20,4 +20,12 @@ export class BackendService {
catchError(() => [])
);
}
getStaffMemberMainData(id: number): Observable <StaffMemberMainDto | null> {
return this.http
.get<StaffMemberMainDto>(`${this.serverUrl}staff/${id}/main`)
.pipe(
catchError(async () => null)
);
}
}
<p>main-data works!</p>
<div fxLayout="column">
<div fxLayout="row" fxLayoutAlign="space-between center">
<div fxFlex="30%">Name: {{staffMemberData.name}}</div>
<div fxFlex="40%">Vorname: {{staffMemberData.firstName}}</div>
<button mat-button *ngIf="appService.authData.isPersonalAdmin"><mat-icon>edit</mat-icon></button>
</div>
<div *ngIf="staffMemberData.idmId" fxLayout="row" fxLayoutAlign="space-between center">
<div>Kennung im HU-Identitätsmanagement: {{staffMemberData.idmId}}</div>
<div *ngIf="staffMemberData.idmRegistered">Registriert am {{staffMemberData.idmRegistered}}</div>
<div *ngIf="!staffMemberData.idmRegistered">Nicht registriert.</div>
<button mat-button *ngIf="appService.authData.isCmsAdmin" matTooltip="Registrieren"><mat-icon>manage_accounts</mat-icon></button>
</div>
<div *ngIf="!staffMemberData.idmId" fxLayout="row" fxLayoutAlign="space-between center">
<div>Kennung im HU-Identitätsmanagement nicht zugewiesen</div>
<button mat-button *ngIf="appService.authData.isPersonalAdmin"
(click)="selectIdmId()"
matTooltip="Kennung zuweisen"><mat-icon>verified</mat-icon></button>
</div>
</div>
import { Component, OnInit } from '@angular/core';
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from "rxjs";
import {StaffListService} from "../staff-list.service";
import {BackendService} from "../backend.service";
import {StaffMemberMainDto} from "../../../../../../libs/dto/src";
import {AppService} from "../../app.service";
@Component({
selector: 'studio-lite-main-data',
templateUrl: './main-data.component.html',
styleUrls: ['./main-data.component.scss']
})
export class MainDataComponent implements OnInit {
export class MainDataComponent implements OnInit, OnDestroy {
private staffMemberIdChangedSubscription: Subscription | undefined;
public staffMemberData: StaffMemberMainDto = {
id: 0,
name: ''
}
constructor() { }
constructor(
public appService: AppService,
public staffListService: StaffListService,
private backendService: BackendService
) { }
ngOnInit(): void {
setTimeout(() => {
this.staffMemberIdChangedSubscription = this.staffListService.selectedStaffMember$.subscribe(() => {
this.backendService.getStaffMemberMainData(
this.staffListService.selectedStaffMember$.getValue()).subscribe(staffMemberData => {
if (staffMemberData) {
this.staffMemberData = staffMemberData;
} else {
this.staffMemberData = {
id: 0,
name: ''
}
}
})
})
})
}
selectIdmId(): void {
}
ngOnDestroy(): void {
if (this.staffMemberIdChangedSubscription) this.staffMemberIdChangedSubscription.unsubscribe();
}
}
export {StaffMemberMainDto} from "./lib/staff/staff-member-main-dto";
export {StaffMemberInListDto} from "./lib/staff/staff-member-in-list-dto";
export {StaffMemberMetadataDto} from "./lib/staff/staff-member-metadata-dto";
export {AuthDataDto} from "./lib/auth-data-dto";
......
import { ApiProperty } from '@nestjs/swagger';
export class StaffMemberMainDto {
@ApiProperty()
id!: number;
@ApiProperty()
name!: string;
@ApiProperty()
firstName?: string;
@ApiProperty()
idmId?: string;
@ApiProperty()
idmRegistered?: string;
@ApiProperty()
canonicalName?: string;
@ApiProperty()
contractStart?: string;
@ApiProperty()
contractEnd?: string;
@ApiProperty()
contractType?: string;
@ApiProperty()
payrollNumber?: string;
@ApiProperty()
address?: string;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment