Skip to content

Commit

Permalink
Merge pull request #165 from erz-mba-fbi/feature/138-profile-email
Browse files Browse the repository at this point in the history
Feature/138 profile email
  • Loading branch information
caebr authored Apr 29, 2020
2 parents 3bb061e + e19339c commit 1aba81a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ <h5 class="m-0">
<a href="tel:{{ legalPerson.PhoneMobile }}"
>{{ legalPerson.PhoneMobile }}<br /></a
></ng-container>
<ng-container *ngIf="legalPerson.DisplayEmail">
<a href="mailto:{{ legalPerson.DisplayEmail }}">{{
legalPerson.DisplayEmail
<ng-container *ngIf="legalPerson | erzPersonEmail">
<a href="mailto:{{ legalPerson | erzPersonEmail }}">{{
legalPerson | erzPersonEmail
}}</a></ng-container
>
</address>
Expand Down Expand Up @@ -213,17 +213,17 @@ <h5 class="m-0">
<ng-container
*ngIf="
apprenticeshipCompany.apprenticeshipManagerPerson
.DisplayEmail
| erzPersonEmail
"
>
<a
href="mailto:{{
apprenticeshipCompany.apprenticeshipManagerPerson
.DisplayEmail
| erzPersonEmail
}}"
>{{
apprenticeshipCompany.apprenticeshipManagerPerson
.DisplayEmail
| erzPersonEmail
}}</a
></ng-container
>
Expand Down Expand Up @@ -280,15 +280,17 @@ <h5 class="m-0">
></ng-container>
<ng-container
*ngIf="
apprenticeshipCompany.jobTrainerPerson.DisplayEmail
apprenticeshipCompany.jobTrainerPerson | erzPersonEmail
"
>
<a
href="mailto:{{
apprenticeshipCompany.jobTrainerPerson.DisplayEmail
apprenticeshipCompany.jobTrainerPerson
| erzPersonEmail
}}"
>{{
apprenticeshipCompany.jobTrainerPerson.DisplayEmail
apprenticeshipCompany.jobTrainerPerson
| erzPersonEmail
}}</a
></ng-container
>
Expand Down
2 changes: 2 additions & 0 deletions src/app/presence-control/presence-control.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PresenceControlDetailComponent } from './components/presence-control-de
import { PresenceControlEntryComponent } from './components/presence-control-entry/presence-control-entry.component';
import { PresenceControlBackComponent } from './components/presence-control-back/presence-control-back.component';
import { PresenceControlDialogComponent } from './components/presence-control-dialog/presence-control-dialog.component';
import { PersonEmailPipe } from './utils/person-email-pipe';

@NgModule({
declarations: [
Expand All @@ -21,6 +22,7 @@ import { PresenceControlDialogComponent } from './components/presence-control-di
PresenceControlEntryComponent,
PresenceControlBackComponent,
PresenceControlDialogComponent,
PersonEmailPipe,
],
imports: [SharedModule, PresenceControlRoutingModule],
entryComponents: [PresenceControlDialogComponent],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
buildLegalRepresentative,
buildPerson,
buildStudent,
buildPersonWithEmails,
} from 'src/spec-builders';
import { buildTestModuleMetadata } from 'src/spec-helpers';
import {
Expand Down Expand Up @@ -50,11 +51,17 @@ describe('PresenceControlDetailService', () => {
legalRepresentative1 = buildPerson(
legalRepresentatives[0].RepresentativeId
);
legalRepresentative2 = buildPerson(
legalRepresentatives[1].RepresentativeId
legalRepresentative2 = buildPersonWithEmails(
legalRepresentatives[1].RepresentativeId,
'display@email.ch'
);
jobTrainer = buildPersonWithEmails(35468, undefined, 'email1@email.ch');
apprenticeshipManager = buildPersonWithEmails(
38223,
undefined,
'email1@email.ch',
'email2@email.ch'
);
jobTrainer = buildPerson(35468);
apprenticeshipManager = buildPerson(38223);
persons = [
legalRepresentative1,
legalRepresentative2,
Expand Down
56 changes: 56 additions & 0 deletions src/app/presence-control/utils/person-email-pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { PersonEmailPipe } from './person-email-pipe';
import { buildPersonWithEmails } from '../../../spec-builders';

describe('person email pipe', () => {
let personEmailPipe: PersonEmailPipe;

beforeEach(() => {
personEmailPipe = new PersonEmailPipe();
});

it('should return null for a person without any email set', () => {
expect(personEmailPipe.transform(buildPersonWithEmails(12345))).toBeNull();
});

it('should return the first email address if all options have values', () => {
expect(
personEmailPipe.transform(
buildPersonWithEmails(
12345,
'first@email.ch',
'second@email.ch',
'third@email.ch'
)
)
).toBe('first@email.ch');
});

it('should return the first email address with a value ', () => {
expect(
personEmailPipe.transform(
buildPersonWithEmails(
12345,
undefined,
'second@email.ch',
'third@email.ch'
)
)
).toBe('second@email.ch');
});

it('should return the email address with a value - email', () => {
expect(
personEmailPipe.transform(
buildPersonWithEmails(12345, undefined, 'second@email.ch', undefined)
)
).toBe('second@email.ch');
});

it('should return the first email address with a value - email2', () => {
expect(
personEmailPipe.transform(
buildPersonWithEmails(12345, undefined, undefined, 'third@email.ch')
)
).toBe('third@email.ch');
});
});
11 changes: 11 additions & 0 deletions src/app/presence-control/utils/person-email-pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PipeTransform, Pipe } from '@angular/core';
import { Person } from '../../shared/models/person.model';

@Pipe({
name: 'erzPersonEmail',
})
export class PersonEmailPipe implements PipeTransform {
transform(input: Person): Option<string> {
return input.DisplayEmail || input.Email || input.Email2 || null;
}
}
4 changes: 2 additions & 2 deletions src/app/shared/models/person.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const Person = t.type({
// Birthdate: Option(LocalDateTimeFromString),
// CorrespondenceAddress: Option(t.string),
DisplayEmail: Option(t.string),
// Email: Option(t.string),
// Email2: Option(t.string),
Email: Maybe(t.string),
Email2: Maybe(t.string),
FirstName: Option(t.string),
Gender: t.union([t.literal('M'), t.literal('F'), t.literal('X')]),
// HomeTown: Option(t.string),
Expand Down
17 changes: 15 additions & 2 deletions src/spec-builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ export function buildPerson(id: number): Person {
// Birthdate: null,
// CorrespondenceAddress: '',
DisplayEmail: null,
// Email: null,
// Email2: null,
Email: null,
Email2: null,
FirstName: '',
Gender: 'X',
// HomeTown: null,
Expand All @@ -238,3 +238,16 @@ export function buildPerson(id: number): Person {
// HRef: ''
};
}

export function buildPersonWithEmails(
id: number,
displayEmail?: string,
email?: string,
email2?: string
): Person {
const person = buildPerson(id);
person.DisplayEmail = displayEmail || null;
person.Email = email;
person.Email2 = email2;
return person;
}

0 comments on commit 1aba81a

Please sign in to comment.