blob: 7a9bed80f3e76c797b65c498742dfb4d37225a02 [file] [log] [blame]
Michael Landodd603392017-07-12 00:54:52 +03001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
ys969316a9fce2020-01-19 13:50:02 +020010 *
Michael Landodd603392017-07-12 00:54:52 +030011 * http://www.apache.org/licenses/LICENSE-2.0
ys969316a9fce2020-01-19 13:50:02 +020012 *
Michael Landodd603392017-07-12 00:54:52 +030013 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
Michael Landoed64b5e2017-06-09 03:19:04 +030020'use strict';
Michael Landoed64b5e2017-06-09 03:19:04 +030021
22export enum UserRole {
23 ADMIN,
ys969316a9fce2020-01-19 13:50:02 +020024 DESIGNER
Michael Landoed64b5e2017-06-09 03:19:04 +030025}
26
ys969316a9fce2020-01-19 13:50:02 +020027// tslint:disable-next-line:interface-name
Michael Landoed64b5e2017-06-09 03:19:04 +030028export interface IUserManager {
ys969316a9fce2020-01-19 13:50:02 +020029 isInEditMode: boolean;
30 filterTerm: string;
Michael Landoed64b5e2017-06-09 03:19:04 +030031}
32
ys969316a9fce2020-01-19 13:50:02 +020033// tslint:disable-next-line:interface-name
Michael Landoed64b5e2017-06-09 03:19:04 +030034export interface IUserProperties extends IUserManager {
ys969316a9fce2020-01-19 13:50:02 +020035 firstName: string;
36 lastName: string;
37 userId: string;
38 email: string;
39 role: string;
40 tempRole: string;
41 lastLoginTime: string;
42 status: string;
Michael Landoed64b5e2017-06-09 03:19:04 +030043}
44
ys969316a9fce2020-01-19 13:50:02 +020045// tslint:disable-next-line:interface-name
Michael Landoed64b5e2017-06-09 03:19:04 +030046export interface IUser {
ys969316a9fce2020-01-19 13:50:02 +020047 userInfo: IUserProperties;
48 getRole(): UserRole;
49 getRoleToView(): string;
50 getName(): string;
51 getFirstName(): string;
52 getLastName(): string;
Michael Landoed64b5e2017-06-09 03:19:04 +030053}
54
55export class User implements IUser {
56
ys969316a9fce2020-01-19 13:50:02 +020057 constructor(public userInfo: IUserProperties) {
Michael Landoed64b5e2017-06-09 03:19:04 +030058 }
59
60 public getLastName = () => {
Tal Gitelman51d50f02017-12-10 18:55:03 +020061 return this.userInfo.lastName;
ys969316a9fce2020-01-19 13:50:02 +020062 }
Michael Landoed64b5e2017-06-09 03:19:04 +030063
64 public getFirstName = () => {
Tal Gitelman51d50f02017-12-10 18:55:03 +020065 return this.userInfo.firstName;
ys969316a9fce2020-01-19 13:50:02 +020066 }
Michael Landoed64b5e2017-06-09 03:19:04 +030067
68 public getName = () => {
Tal Gitelman51d50f02017-12-10 18:55:03 +020069 return this.userInfo.firstName + ' ' + this.userInfo.lastName;
ys969316a9fce2020-01-19 13:50:02 +020070 }
Michael Landoed64b5e2017-06-09 03:19:04 +030071
72 public getLastLogin = () => {
ys969316a9fce2020-01-19 13:50:02 +020073 if (!this.userInfo.lastLoginTime || this.userInfo.lastLoginTime === '0') {
74 return '';
Michael Landoed64b5e2017-06-09 03:19:04 +030075 } else {
Tal Gitelman51d50f02017-12-10 18:55:03 +020076 return this.userInfo.lastLoginTime;
Michael Landoed64b5e2017-06-09 03:19:04 +030077 }
ys969316a9fce2020-01-19 13:50:02 +020078 }
Michael Landoed64b5e2017-06-09 03:19:04 +030079
ys969316a9fce2020-01-19 13:50:02 +020080 public getRole = (): UserRole => {
81 let role: UserRole;
Tal Gitelman51d50f02017-12-10 18:55:03 +020082 switch (UserRole[this.userInfo.role.toUpperCase()]) {
Michael Landoed64b5e2017-06-09 03:19:04 +030083 case UserRole.ADMIN:
84 role = UserRole.ADMIN;
85 break;
86 case UserRole.DESIGNER:
87 role = UserRole.DESIGNER;
88 break;
Michael Landoed64b5e2017-06-09 03:19:04 +030089 }
90 return role;
ys969316a9fce2020-01-19 13:50:02 +020091 }
Michael Landoed64b5e2017-06-09 03:19:04 +030092
ys969316a9fce2020-01-19 13:50:02 +020093 public getRoleToView = (): string => {
94 const role: string = this.userInfo.role.toLowerCase().replace('governor', 'governance_Rep');
Michael Landoed64b5e2017-06-09 03:19:04 +030095 return role.charAt(0).toUpperCase() + role.slice(1).replace('_', ' ');
96 }
97}