From 660f19932cc92e53d0fcec5e633935710b93ab02 Mon Sep 17 00:00:00 2001 From: onsaliyo Date: Thu, 18 Mar 2021 18:04:58 +0100 Subject: [PATCH] Si el usuario es tipo 0 (gestor de discoteca) muestra la discoteca asociada al gestor en la BD --- src/app/api.service.ts | 11 +++++++++-- src/app/discoteca-i.ts | 4 ++++ src/app/login.service.ts | 10 +++++++--- src/app/tab1/tab1.service.ts | 24 ++++++++++++++++++++---- src/app/user.ts | 2 +- 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/app/api.service.ts b/src/app/api.service.ts index b3c7cf4..58e806e 100644 --- a/src/app/api.service.ts +++ b/src/app/api.service.ts @@ -5,6 +5,7 @@ import { catchError, retry, map, tap } from 'rxjs/operators'; import { User } from './user'; import { Discoteca } from './discoteca'; import { UserLogin } from './user-login'; +import { DiscotecaI } from './discoteca-i'; @Injectable({ @@ -12,7 +13,7 @@ import { UserLogin } from './user-login'; }) export class ApiService { - + baseUrl = "http://localhost:3307/api/consultas"; constructor(private http: HttpClient) { @@ -21,10 +22,16 @@ export class ApiService { validateUser(user: UserLogin): Observable{ - return this.http.post("http://localhost:3307/api/consultas/users", user) + return this.http.post(this.baseUrl+"/users", user) } + getUserDiscoteca(discotecaId: number): Observable{ + + return this.http.post(this.baseUrl+"/discoteca", { "id": discotecaId}); + + } + diff --git a/src/app/discoteca-i.ts b/src/app/discoteca-i.ts index 522adda..a3274f1 100644 --- a/src/app/discoteca-i.ts +++ b/src/app/discoteca-i.ts @@ -1,2 +1,6 @@ export interface DiscotecaI { + discotecaId: number, + nombre: string, + telefono: number, + localizacion: string } diff --git a/src/app/login.service.ts b/src/app/login.service.ts index 6e8f283..8652c71 100644 --- a/src/app/login.service.ts +++ b/src/app/login.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { VirtualTimeScheduler } from 'rxjs'; import { ApiService } from './api.service'; +import { Tab1Service } from './tab1/tab1.service'; import { User } from './user'; import { UserLogin } from './user-login'; @@ -13,10 +14,10 @@ export class LoginService { user: User; - constructor(private apiService: ApiService, private router: Router) { + constructor(private apiService: ApiService, private router: Router, private tab1service: Tab1Service) { this.user = { id: 0, - discotecaId: 0, + discotecaID: 0, userType: 0, username: '', }; @@ -31,8 +32,11 @@ export class LoginService { this.apiService.validateUser(userlogin) .subscribe(user => { - this.user = user; + this.user = user[0]; console.log(this.user); + console.log(this.user.discotecaID); + this.tab1service.getDiscoteca(this.user.discotecaID); + }) } diff --git a/src/app/tab1/tab1.service.ts b/src/app/tab1/tab1.service.ts index 8bb4d48..1b98cd3 100644 --- a/src/app/tab1/tab1.service.ts +++ b/src/app/tab1/tab1.service.ts @@ -5,6 +5,9 @@ import { Discoteca } from '../discoteca' import { Evento } from '../evento'; import { FormControl, FormGroup } from '@angular/forms'; import { NumericValueAccessor } from '@ionic/angular'; +import { DiscotecaI } from '../discoteca-i'; +import { ApiService } from '../api.service'; +import { Router } from '@angular/router'; @Injectable({ @@ -13,13 +16,14 @@ import { NumericValueAccessor } from '@ionic/angular'; export class Tab1Service implements OnInit{ discoteca: Discoteca; + discotecaI: DiscotecaI; galeria: string[]; eventos: Evento[]; eventoForms: FormGroup[]; eventoIndex: number; editarEvento: boolean; - constructor() { + constructor(private apiService: ApiService, private router: Router) { } @@ -29,9 +33,9 @@ export class Tab1Service implements OnInit{ initValues(): void{ this.discoteca = new Discoteca(); - this.discoteca.setNombre('Barraca'); - this.discoteca.setTelefono(666666666); - this.discoteca.setLocalizacion('Calle del Barquillo'); + this.discoteca.setNombre(this.discotecaI.nombre); + this.discoteca.setTelefono(this.discotecaI.telefono); + this.discoteca.setLocalizacion(this.discotecaI.localizacion); this.galeria = []; this.initEventos(); this.editarEvento = false; @@ -73,4 +77,16 @@ export class Tab1Service implements OnInit{ return this.eventos[eventoIndex]; } + getDiscoteca(discotecaId: number){ + if (discotecaId != 0){ + this.apiService.getUserDiscoteca(discotecaId) + .subscribe(discoteca => { + this.discotecaI = discoteca[0]; + console.log(this.discotecaI); + this.initValues(); + this.router.navigate(['/tabs/tab1/perfil-discoteca']); + }) + } + } + } diff --git a/src/app/user.ts b/src/app/user.ts index 78fb1f5..f40b02f 100644 --- a/src/app/user.ts +++ b/src/app/user.ts @@ -1,6 +1,6 @@ export interface User { id: number; - discotecaId: number; + discotecaID: number; userType: number; username: string; }