Commit 80a3e93f authored by Heber Cordova's avatar Heber Cordova

feat: added auth config

parent 606adc58
......@@ -7,7 +7,7 @@
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"server": "json-server-auth --port 3000 --watch ./server/db.json"
"server": "json-server-auth --port 3000 --watch ./server/db.json -r ./server/routes.json"
},
"private": true,
"dependencies": {
......
......@@ -30,19 +30,20 @@
],
"agents": [
{
"name": "Heber ",
"lastname": "Cordova Jimenez",
"name": "Julio",
"lastname": "Garcia",
"detail": "",
"email": "hcordova@gmail.com",
"password": "heber123",
"userId": 2,
"id": 1
}
],
"passengers": [
{
"name": "Heber",
"name": "Roberto",
"secondName": "",
"lastname": "Cordova",
"lastname": "Loayza",
"country": "Peru",
"city": "Lima",
"address": "Calle 123",
......@@ -362,4 +363,4 @@
"name": "Primera Clase"
}
]
}
\ No newline at end of file
}
{
"/passengers/*": "/664/passengers/*",
"/supervisors/*": "/664/supervisors/*",
"/agents/*": "/664/agents/*"
}
......@@ -6,6 +6,11 @@ import { HomePageComponent as SupervisorHomePageComponent } from './supervisor/p
import { SignInComponent } from './security/pages/sign-in/sign-in.component';
const routes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: 'sign-in',
},
{
path: 'passengers',
component: PassengerHomePageComponent,
......
// To parse this data:
//
// import { Convert, AgentAuthorize } from "./file";
//
// const agentAuthorize = Convert.toAgentAuthorize(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface AgentAuthorize {
name: string;
lastname: string;
detail: string;
email: string;
password: string;
userId: number;
id: number;
user: User;
}
export interface User {
id: number;
email: string;
password: string;
role: string;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toAgentAuthorize(json: string): AgentAuthorize {
return cast(JSON.parse(json), r("AgentAuthorize"));
}
public static agentAuthorizeToJson(value: AgentAuthorize): string {
return JSON.stringify(uncast(value, r("AgentAuthorize")), null, 2);
}
}
function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
const prettyTyp = prettyTypeName(typ);
const parentText = parent ? ` on ${parent}` : '';
const keyText = key ? ` for key "${key}"` : '';
throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
}
function prettyTypeName(typ: any): string {
if (Array.isArray(typ)) {
if (typ.length === 2 && typ[0] === undefined) {
return `an optional ${prettyTypeName(typ[1])}`;
} else {
return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
}
} else if (typeof typ === "object" && typ.literal !== undefined) {
return typ.literal;
} else {
return typeof typ;
}
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key, parent);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val, key, parent);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue(l("Date"), val, key, parent);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue(l(ref || "object"), val, key, parent);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key, ref);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val, key, parent);
}
if (typ === false) return invalidValue(typ, val, key, parent);
let ref: any = undefined;
while (typeof typ === "object" && typ.ref !== undefined) {
ref = typ.ref;
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val, key, parent);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function l(typ: any) {
return { literal: typ };
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"AgentAuthorize": o([
{ json: "name", js: "name", typ: "" },
{ json: "lastname", js: "lastname", typ: "" },
{ json: "detail", js: "detail", typ: "" },
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
{ json: "userId", js: "userId", typ: 0 },
{ json: "id", js: "id", typ: 0 },
{ json: "user", js: "user", typ: r("User") },
], false),
"User": o([
{ json: "id", js: "id", typ: 0 },
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
{ json: "role", js: "role", typ: "" },
], false),
};
// To parse this data:
//
// import { Convert, PassengerAuthorize } from "./file";
//
// const passengerAuthorize = Convert.toPassengerAuthorize(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface PassengerAuthorize {
name: string;
secondName: string;
lastname: string;
country: string;
city: string;
address: string;
phone: string;
email: string;
password: string;
userId: number;
id: number;
user: User;
}
export interface User {
id: number;
email: string;
password: string;
role: string;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toPassengerAuthorize(json: string): PassengerAuthorize {
return cast(JSON.parse(json), r("PassengerAuthorize"));
}
public static passengerAuthorizeToJson(value: PassengerAuthorize): string {
return JSON.stringify(uncast(value, r("PassengerAuthorize")), null, 2);
}
}
function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
const prettyTyp = prettyTypeName(typ);
const parentText = parent ? ` on ${parent}` : '';
const keyText = key ? ` for key "${key}"` : '';
throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
}
function prettyTypeName(typ: any): string {
if (Array.isArray(typ)) {
if (typ.length === 2 && typ[0] === undefined) {
return `an optional ${prettyTypeName(typ[1])}`;
} else {
return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
}
} else if (typeof typ === "object" && typ.literal !== undefined) {
return typ.literal;
} else {
return typeof typ;
}
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key, parent);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val, key, parent);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue(l("Date"), val, key, parent);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue(l(ref || "object"), val, key, parent);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key, ref);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val, key, parent);
}
if (typ === false) return invalidValue(typ, val, key, parent);
let ref: any = undefined;
while (typeof typ === "object" && typ.ref !== undefined) {
ref = typ.ref;
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val, key, parent);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function l(typ: any) {
return { literal: typ };
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"PassengerAuthorize": o([
{ json: "name", js: "name", typ: "" },
{ json: "secondName", js: "secondName", typ: "" },
{ json: "lastname", js: "lastname", typ: "" },
{ json: "country", js: "country", typ: "" },
{ json: "city", js: "city", typ: "" },
{ json: "address", js: "address", typ: "" },
{ json: "phone", js: "phone", typ: "" },
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
{ json: "userId", js: "userId", typ: 0 },
{ json: "id", js: "id", typ: 0 },
{ json: "user", js: "user", typ: r("User") },
], false),
"User": o([
{ json: "id", js: "id", typ: 0 },
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
{ json: "role", js: "role", typ: "" },
], false),
};
// To parse this data:
//
// import { Convert, Supervisor } from "./file";
//
// const supervisor = Convert.toSupervisor(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface SupervisorAuthorize {
id: number;
name: string;
lastname: string;
detail: string;
userId: number;
user: User;
}
export interface User {
id: number;
email: string;
password: string;
role: string;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toSupervisor(json: string): SupervisorAuthorize {
return cast(JSON.parse(json), r("Supervisor"));
}
public static supervisorToJson(value: SupervisorAuthorize): string {
return JSON.stringify(uncast(value, r("Supervisor")), null, 2);
}
}
function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
const prettyTyp = prettyTypeName(typ);
const parentText = parent ? ` on ${parent}` : '';
const keyText = key ? ` for key "${key}"` : '';
throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
}
function prettyTypeName(typ: any): string {
if (Array.isArray(typ)) {
if (typ.length === 2 && typ[0] === undefined) {
return `an optional ${prettyTypeName(typ[1])}`;
} else {
return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
}
} else if (typeof typ === "object" && typ.literal !== undefined) {
return typ.literal;
} else {
return typeof typ;
}
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key, parent);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) {}
}
return invalidValue(typs, val, key, parent);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue(l("Date"), val, key, parent);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue(l(ref || "object"), val, key, parent);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key, ref);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val, key, parent);
}
if (typ === false) return invalidValue(typ, val, key, parent);
let ref: any = undefined;
while (typeof typ === "object" && typ.ref !== undefined) {
ref = typ.ref;
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val, key, parent);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function l(typ: any) {
return { literal: typ };
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"Supervisor": o([
{ json: "id", js: "id", typ: 0 },
{ json: "name", js: "name", typ: "" },
{ json: "lastname", js: "lastname", typ: "" },
{ json: "detail", js: "detail", typ: "" },
{ json: "userId", js: "userId", typ: 0 },
{ json: "user", js: "user", typ: r("User") },
], false),
"User": o([
{ json: "id", js: "id", typ: 0 },
{ json: "email", js: "email", typ: "" },
{ json: "password", js: "password", typ: "" },
{ json: "role", js: "role", typ: "" },
], false),
};
export interface UserLogged {
id: number;
name: string;
lastname: string;
email: string;
token: string;
role: string;
}
......@@ -4,6 +4,10 @@ import { SecurityService } from '../../services/security.service';
import { SecurityCredentials } from '../../models/security-credentials.interface';
import { SecurityResponse } from '../../models/security-response.interface';
import { Router } from '@angular/router';
import { UserLogged } from '../../models/user-logged.interface';
import { SupervisorAuthorize } from '../../models/supervisor-authorize.interface';
import { AgentAuthorize } from '../../models/agent-authorize.interface';
import { PassengerAuthorize } from '../../models/passenger-authorize.interface';
@Component({
selector: 'app-sign-in',
......@@ -58,19 +62,71 @@ export class SignInComponent {
const credentials: SecurityCredentials = this.signInForm.value;
this.securityService.login(credentials)
.subscribe(securityResponse => {
switch(securityResponse.user.role) {
case 'supervisor':
this.router.navigate(['/supervisors']);
break;
case 'agent':
this.router.navigate(['/agents']);
break;
case 'passenger':
this.router.navigate(['/passengers']);
break;
}
}, error => this.showError = true);
this.redirectAndSaveLocalStorage(securityResponse);
});
} else this.showError = true;
}
redirectAndSaveLocalStorage(securityResponse: SecurityResponse): void {
switch(securityResponse.user.role) {
case 'supervisor':
this.securityService.getSupervisorByUserId(securityResponse.user.id)
.subscribe(supervisors => {
this.supervisorSaveLocalStorage(supervisors[0], securityResponse);
this.router.navigate(['/supervisors']);
});
break;
case 'agent':
this.securityService.getAgentByUserId(securityResponse.user.id)
.subscribe(agents => {
this.agentSaveLocalStorage(agents[0], securityResponse);
this.router.navigate(['/agents']);
});
break;
case 'passenger':
this.securityService.getPassengerByUserId(securityResponse.user.id)
.subscribe(passengers => {
this.passengerSaveLocalStorage(passengers[0], securityResponse);
this.router.navigate(['/passengers']);
});
break;
}
}
supervisorSaveLocalStorage(supervisor: SupervisorAuthorize, securityResponse: SecurityResponse): void {
const userLogged: UserLogged = {
id: supervisor.id,
name: supervisor.name,
lastname: supervisor.lastname,
email: supervisor.user.email,
role: supervisor.user.role,
token: securityResponse.accessToken
}
localStorage.setItem('userLogged', JSON.stringify(userLogged));
}
agentSaveLocalStorage(agent: AgentAuthorize, securityResponse: SecurityResponse): void {
const userLogged: UserLogged = {
id: agent.id,
name: agent.name,
lastname: agent.lastname,
email: agent.user.email,
role: agent.user.role,
token: securityResponse.accessToken
}
localStorage.setItem('userLogged', JSON.stringify(userLogged));
}
passengerSaveLocalStorage(passenger: PassengerAuthorize, securityResponse: SecurityResponse): void {
const userLogged: UserLogged = {
id: passenger.id,
name: passenger.name,
lastname: passenger.lastname,
email: passenger.user.email,
role: passenger.user.role,
token: securityResponse.accessToken
}
localStorage.setItem('userLogged', JSON.stringify(userLogged));
}
}
......@@ -3,15 +3,43 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { SecurityCredentials } from '../models/security-credentials.interface';
import { SecurityResponse } from '../models/security-response.interface';
import { Observable } from 'rxjs';
import { Observable, of, tap } from 'rxjs';
import { SupervisorAuthorize } from '../models/supervisor-authorize.interface';
import { Passenger } from 'src/app/agent/interfaces/passenger.interface';
import { PassengerAuthorize } from '../models/passenger-authorize.interface';
import { AgentAuthorize } from '../models/agent-authorize.interface';
import { UserLogged } from '../models/user-logged.interface';
import { Router } from '@angular/router';
@Injectable({providedIn: 'root'})
export class SecurityService {
constructor(private http: HttpClient) { }
constructor(private http: HttpClient, private router: Router) { }
URL_BASE: string = 'http://localhost:3000/';
get currentUser(): UserLogged | null {
const userLogged: UserLogged | null = JSON.parse(localStorage.getItem('userLogged') || 'null');
return userLogged;
}
login(securityCredentials: SecurityCredentials): Observable<SecurityResponse> {
return this.http.post<SecurityResponse>(this.URL_BASE + 'signin', securityCredentials);
}
loguot(): void {
localStorage.removeItem('userLogged');
this.router.navigate(['/sign-in']);
}
getSupervisorByUserId(userId: number): Observable<SupervisorAuthorize[]> {
return this.http.get<SupervisorAuthorize[]>(this.URL_BASE + 'supervisors?userId=' + userId + '&_expand=user');
}
getPassengerByUserId(userId: number): Observable<PassengerAuthorize[]> {
return this.http.get<PassengerAuthorize[]>(this.URL_BASE + 'passengers?userId=' + userId + '&_expand=user');
}
getAgentByUserId(userId: number): Observable<AgentAuthorize[]> {
return this.http.get<AgentAuthorize[]>(this.URL_BASE + 'agents?userId=' + userId + '&_expand=user');
}
}
......@@ -11,7 +11,7 @@
</div>
<div class="d-flex align-items-center">
<div class="user">
<span>hcordova</span>
<span>{{ username }}</span>
<i class="bi bi-caret-down-fill"></i>
</div>
<button class="btn">
......
import { Component, EventEmitter, Output } from '@angular/core';
import { Router } from '@angular/router';
import { SecurityService } from 'src/app/security/services/security.service';
@Component({
selector: 'shared-navigation-user',
......@@ -11,12 +12,20 @@ export class NavigationUserComponent {
@Output()
public toggleSidebarEvent: EventEmitter<void> = new EventEmitter<void>();
constructor(private router: Router) { }
constructor(private router: Router,
private securityService: SecurityService) { }
toggleSidebar():void {
this.toggleSidebarEvent.emit();
}
get username(): any {
const userLogged = this.securityService.currentUser;
if (userLogged) {
return `${userLogged.name.toLowerCase().substring(0, 1)}${userLogged.lastname.toLowerCase()}`
} return null;
}
goToLogin(): void {
this.router.navigate(['/sign-in']);
}
......
Markdown is supported
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