Commit e0483408 authored by mechtelm's avatar mechtelm
Browse files

Add principals/subs in main data view

parent 8c98a8a2
......@@ -3,12 +3,14 @@ import {InjectRepository} from "@nestjs/typeorm";
import {Repository} from "typeorm";
import Staff from "../entities/staff-member.entity";
import {StaffMemberCreateDto, StaffMemberInListDto, StaffMemberMainDto} from "@lib/dto";
import {PrincipalService} from "./principal.service";
@Injectable()
export class StaffService {
constructor(
@InjectRepository(Staff)
private staffRepository: Repository<Staff>,
private principalService: PrincipalService,
) {}
async findAll(): Promise<StaffMemberInListDto[]> {
......@@ -48,7 +50,9 @@ export class StaffService {
idmId: staffMember.idmId,
idmRegistered: staffMember.idmRegistered,
address: staffMember.address,
dateOfBirth: staffMember.dateOfBirth
dateOfBirth: staffMember.dateOfBirth,
principals: await this.principalService.findAllPrincipals(staffMember.id),
subs: await this.principalService.findAllSubs(staffMember.id)
}
} else {
throw new NotFoundException();
......
......@@ -10,5 +10,7 @@
<tr><td>Adresse</td><td>{{mainData.address ? mainData.address.replace('\n', '; ') : '-'}}</td></tr>
<tr><td>Tag der Geburt</td><td>{{mainData.dateOfBirthString}}</td></tr>
<tr><td>Vertrag</td><td>{{mainData.contractData}}</td></tr>
<tr><td>Vorgesetze/r</td><td>{{mainData.allPrincipals}}</td></tr>
<tr><td>Ist Vorgesetze/r von</td><td>{{mainData.allSubs}}</td></tr>
</table>
</div>
import {StaffMemberInListDto, StaffMemberMainDto} from "@lib/dto";
import {PrincipalRelationDto, StaffMemberInListDto, StaffMemberMainDto} from "@lib/dto";
import * as _moment from 'moment';
export class StaffMemberView {
......@@ -49,6 +49,8 @@ export class StaffMember {
sex?: string;
title?: string;
dateOfBirth?: string;
principals?: PrincipalRelationDto[];
subs?: PrincipalRelationDto[];
get fullName(): string {
const returnText = `${this.name}${this.firstName ? ', ' + this.firstName : ''}`;
......@@ -113,6 +115,28 @@ export class StaffMember {
return 'alle'
}
get allPrincipals(): string {
const returnArray: string[] = [];
if (this.principals) {
this.principals.forEach(p => {
returnArray.push(`${p.name}, ${p.firstName}`);
})
return returnArray.join('; ')
}
return ''
}
get allSubs(): string {
const returnArray: string[] = [];
if (this.subs) {
this.subs.forEach(p => {
returnArray.push(`${p.name}, ${p.firstName}`);
})
return returnArray.join('; ')
}
return ''
}
constructor (staffData: StaffMemberMainDto) {
this.id = staffData.id;
this.name = staffData.name;
......@@ -127,6 +151,8 @@ export class StaffMember {
this.address = staffData.address;
this.payrollId = staffData.payrollId;
this.dateOfBirth = staffData.dateOfBirth;
this.principals = staffData.principals;
this.subs = staffData.subs
}
static dateToString(someDate?: _moment.Moment): string {
......
......@@ -42,6 +42,12 @@ export class StaffMemberMainDto {
@ApiProperty()
title?: string;
@ApiProperty()
principals?: PrincipalRelationDto[];
@ApiProperty()
subs?: PrincipalRelationDto[];
}
export class PrincipalRelationDto {
......
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