carga codigos del usuario en su perfil

This commit is contained in:
onsaliyo 2021-06-03 18:44:32 +02:00
parent a03582e68d
commit 373662895e
11 changed files with 176 additions and 60 deletions

View File

@ -1,47 +1,48 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { LoginPage } from './login/login.page'; import { LoginPage } from './login/login.page';
const routes: Routes = [ const routes: Routes = [
{ {
path: 'login', path: 'login',
component: LoginPage component: LoginPage
}, },
{ {
path: 'tabs', path: 'tabs',
loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule) loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule)
}, },
{ {
path: 'tabsUser', path: 'tabsUser',
loadChildren: () => import('./tabs-user/tabs-user.module').then(m => m.TabsUserPageModule) loadChildren: () => import('./tabs-user/tabs-user.module').then(m => m.TabsUserPageModule)
}, },
{ {
path: 'view-evento', path: 'view-evento',
loadChildren: () => import('./view-evento/view-evento.module').then( m => m.ViewEventoPageModule) loadChildren: () => import('./view-evento/view-evento.module').then( m => m.ViewEventoPageModule)
}, },
{ {
path: 'galeriamodal', path: 'galeriamodal',
loadChildren: () => import('./galeriamodal/galeriamodal.module').then( m => m.GaleriamodalPageModule) loadChildren: () => import('./galeriamodal/galeriamodal.module').then( m => m.GaleriamodalPageModule)
}, },
{ {
path:'', path:'',
redirectTo: 'login', redirectTo: 'login',
pathMatch: 'full' pathMatch: 'full'
}, },
{ {
path: 'tabs-user', path: 'tabs-user',
loadChildren: () => import('./tabs-user/tabs-user.module').then( m => m.TabsUserPageModule) loadChildren: () => import('./tabs-user/tabs-user.module').then( m => m.TabsUserPageModule)
}, },
{ {
path: 'feed', path: 'feed',
loadChildren: () => import('./feed/feed.module').then( m => m.FeedPageModule) loadChildren: () => import('./feed/feed.module').then( m => m.FeedPageModule)
}, },
{ {
path: 'view-evento-cliente', path: 'view-evento-cliente',
loadChildren: () => import('./view-evento-cliente/view-evento-cliente.module').then( m => m.ViewEventoClientePageModule) loadChildren: () => import('./view-evento-cliente/view-evento-cliente.module').then( m => m.ViewEventoClientePageModule)
}, { },
{
path: 'view-discoteca-cliente', path: 'view-discoteca-cliente',
loadChildren: () => import('./view-discoteca-cliente/view-discoteca-cliente.module').then( m => m.ViewDiscotecaClientePageModule) loadChildren: () => import('./view-discoteca-cliente/view-discoteca-cliente.module').then( m => m.ViewDiscotecaClientePageModule)
}, },
@ -49,18 +50,22 @@ const routes: Routes = [
path: 'reservamodal', path: 'reservamodal',
loadChildren: () => import('./reservamodal/reservamodal.module').then( m => m.ReservamodalPageModule) loadChildren: () => import('./reservamodal/reservamodal.module').then( m => m.ReservamodalPageModule)
}, },
{
path: 'perfil-usuario',
loadChildren: () => import('./perfil-usuario/perfil-usuario.module').then( m => m.PerfilUsuarioPageModule)
},
]; ];
@NgModule({ @NgModule({
imports: [ imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules }) RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
], ],
exports: [RouterModule] exports: [RouterModule]
}) })
export class AppRoutingModule {} export class AppRoutingModule {}

View File

@ -0,0 +1,5 @@
export interface Codigo {
UserID: number,
codigo: string,
numReservas: number
}

View File

@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { PerfilUsuarioPage } from './perfil-usuario.page';
const routes: Routes = [
{
path: '',
component: PerfilUsuarioPage
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class PerfilUsuarioPageRoutingModule {}

View File

@ -0,0 +1,20 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { PerfilUsuarioPageRoutingModule } from './perfil-usuario-routing.module';
import { PerfilUsuarioPage } from './perfil-usuario.page';
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
PerfilUsuarioPageRoutingModule
],
declarations: [PerfilUsuarioPage]
})
export class PerfilUsuarioPageModule {}

View File

@ -0,0 +1,14 @@
<ion-header>
<ion-toolbar>
<ion-title>Mi perfil</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<div *ngIf="codigos?.length>0">
<div *ngFor="let codigo of codigos">
Tu código: {{codigo.codigo}}
</div>
</div>
</ion-content>

View File

@ -0,0 +1,24 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';
import { PerfilUsuarioPage } from './perfil-usuario.page';
describe('PerfilUsuarioPage', () => {
let component: PerfilUsuarioPage;
let fixture: ComponentFixture<PerfilUsuarioPage>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PerfilUsuarioPage ],
imports: [IonicModule.forRoot()]
}).compileComponents();
fixture = TestBed.createComponent(PerfilUsuarioPage);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,25 @@
import { Component, OnInit } from '@angular/core';
import { Codigo } from '../interfaces/codigo';
import { ApiService } from '../services/api.service';
import { LoginService } from '../services/login.service';
@Component({
selector: 'app-perfil-usuario',
templateUrl: './perfil-usuario.page.html',
styleUrls: ['./perfil-usuario.page.scss'],
})
export class PerfilUsuarioPage implements OnInit {
codigos: Codigo[];
constructor(private apiService: ApiService, private loginService: LoginService) { }
ngOnInit() {
this.apiService.getCodigosUsuario(this.loginService.user)
.subscribe(codigos => {
this.codigos = codigos;
console.log(this.codigos);
})
}
}

View File

@ -3,6 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { Observable, throwError, BehaviorSubject } from 'rxjs'; import { Observable, throwError, BehaviorSubject } from 'rxjs';
import { catchError, retry, map, tap } from 'rxjs/operators'; import { catchError, retry, map, tap } from 'rxjs/operators';
import { User } from '../interfaces/user'; import { User } from '../interfaces/user';
import { Codigo } from '../interfaces/codigo'
import { Discoteca } from '../discoteca'; import { Discoteca } from '../discoteca';
import { UserLogin } from '../interfaces/user-login'; import { UserLogin } from '../interfaces/user-login';
import { DiscotecaI } from '../interfaces/discoteca-i'; import { DiscotecaI } from '../interfaces/discoteca-i';
@ -56,6 +57,10 @@ export class ApiService {
return this.http.post<Reservai>(this.baseUrl+"/reserva", reserva); return this.http.post<Reservai>(this.baseUrl+"/reserva", reserva);
} }
getCodigosUsuario(user: User){
return this.http.post<Codigo[]>(this.baseUrl+"/codigosUsuario", user);
}

View File

@ -1,11 +1,12 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import { RouterModule, Routes } from '@angular/router';
import { PerfilUsuarioPage } from '../perfil-usuario/perfil-usuario.page';
import { Tab3Page } from './tab3.page'; import { Tab3Page } from './tab3.page';
const routes: Routes = [ const routes: Routes = [
{ {
path: '', path: '',
component: Tab3Page, component: PerfilUsuarioPage,
} }
]; ];

View File

@ -8,7 +8,7 @@
<ion-tab-button tab="tab3"> <ion-tab-button tab="tab3">
<ion-icon name="accessibility-outline"></ion-icon> <ion-icon name="accessibility-outline"></ion-icon>
<ion-label>Me</ion-label> <ion-label>Mi Perfil</ion-label>
</ion-tab-button> </ion-tab-button>