From 48d2ffc8d7916f18fddbb206becc00525b696a4d Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Fri, 16 Jul 2021 15:24:14 +0200 Subject: [PATCH] Add UserNamePipe (#429) --- angular/src/pipes/user-name.pipe.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 angular/src/pipes/user-name.pipe.ts diff --git a/angular/src/pipes/user-name.pipe.ts b/angular/src/pipes/user-name.pipe.ts new file mode 100644 index 0000000000..43397528d6 --- /dev/null +++ b/angular/src/pipes/user-name.pipe.ts @@ -0,0 +1,22 @@ +import { + Pipe, + PipeTransform, +} from '@angular/core'; + +interface User { + name?: string; + email: string; +} + +@Pipe({ + name: 'userName', +}) +export class UserNamePipe implements PipeTransform { + transform(user?: User): string { + if (user == null) { + return null; + } + + return user.name == null || user.name.trim() === '' ? user.email : user.name; + } +}