From e31ded9eb92ddf0643595440bb7ab18eacfc9c9e Mon Sep 17 00:00:00 2001 From: onsaliyo Date: Sat, 22 May 2021 16:13:00 +0200 Subject: [PATCH] creacion de reservas con su codigo unico --- src/app/interfaces/reservai.ts | 1 + src/app/interfaces/user.ts | 2 +- src/app/services/api.service.ts | 5 ++ src/app/services/login.service.ts | 2 +- .../view-evento-cliente.page.html | 5 +- .../view-evento-cliente.page.ts | 51 +++++++++++++++---- 6 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/app/interfaces/reservai.ts b/src/app/interfaces/reservai.ts index 91b40f4..13aafad 100644 --- a/src/app/interfaces/reservai.ts +++ b/src/app/interfaces/reservai.ts @@ -2,6 +2,7 @@ export interface Reservai { UserID: number, EventoID: number, codigoDescuento: string, + codigoUnico: string, codigoUnicoID: number, descuentoPorciento: number } diff --git a/src/app/interfaces/user.ts b/src/app/interfaces/user.ts index f40b02f..527d35e 100644 --- a/src/app/interfaces/user.ts +++ b/src/app/interfaces/user.ts @@ -1,5 +1,5 @@ export interface User { - id: number; + userID: number; discotecaID: number; userType: number; username: string; diff --git a/src/app/services/api.service.ts b/src/app/services/api.service.ts index 8d2d383..d4553f4 100644 --- a/src/app/services/api.service.ts +++ b/src/app/services/api.service.ts @@ -7,6 +7,7 @@ import { Discoteca } from '../discoteca'; import { UserLogin } from '../interfaces/user-login'; import { DiscotecaI } from '../interfaces/discoteca-i'; import { Eventoi } from '../interfaces/eventoi'; +import { Reservai } from '../interfaces/reservai'; @Injectable({ @@ -51,6 +52,10 @@ export class ApiService { } + creaReserva(reserva: Reservai): Observable{ + return this.http.post(this.baseUrl+"/reserva", reserva); + } + diff --git a/src/app/services/login.service.ts b/src/app/services/login.service.ts index ad5d36e..028ee52 100644 --- a/src/app/services/login.service.ts +++ b/src/app/services/login.service.ts @@ -17,7 +17,7 @@ export class LoginService { constructor(private apiService: ApiService, private router: Router, private tab1service: Tab1Service, private feedService: FeedService) { this.user = { - id: 0, + userID: 0, discotecaID: 0, userType: 0, username: '', diff --git a/src/app/view-evento-cliente/view-evento-cliente.page.html b/src/app/view-evento-cliente/view-evento-cliente.page.html index 3d0724c..7792735 100644 --- a/src/app/view-evento-cliente/view-evento-cliente.page.html +++ b/src/app/view-evento-cliente/view-evento-cliente.page.html @@ -27,10 +27,13 @@ - + Reserva + + Código de descuento: + diff --git a/src/app/view-evento-cliente/view-evento-cliente.page.ts b/src/app/view-evento-cliente/view-evento-cliente.page.ts index 5a0935d..38fa5bc 100644 --- a/src/app/view-evento-cliente/view-evento-cliente.page.ts +++ b/src/app/view-evento-cliente/view-evento-cliente.page.ts @@ -5,8 +5,10 @@ import { DiscotecaI } from '../interfaces/discoteca-i'; import { Eventoi } from '../interfaces/eventoi'; import { Reservai } from '../interfaces/reservai'; import { ReservamodalPage } from '../reservamodal/reservamodal.page'; +import { ApiService } from '../services/api.service'; import { CodigoreservaService } from '../services/codigoreserva.service'; import { FeedService } from '../services/feed.service'; +import { LoginService } from '../services/login.service'; @Component({ selector: 'app-view-evento-cliente', @@ -19,29 +21,58 @@ export class ViewEventoClientePage implements OnInit { discoteca: DiscotecaI; reserva: Reservai; codigoReserva: string; + reservaRealizada: boolean; constructor(private feedService: FeedService, private modalController: ModalController, - private codigoReservaService: CodigoreservaService) { } + private codigoReservaService: CodigoreservaService, private loginService: LoginService, private apiService: ApiService) { } ngOnInit() { + this.reservaRealizada = false; this.evento = this.feedService.getEventoByIndex(this.feedService.eventoIndex); this.discoteca = this.feedService.discotecaEvento; } generarCodigo(){ - this.codigoReserva = stringify(this.codigoReservaService.generarAleatorio()); - console.log(this.codigoReserva); + return stringify(this.codigoReservaService.generarAleatorio()); + } + + initReserva(){ + this.reserva = { + UserID: this.loginService.user.userID, + EventoID: this.evento.id, + codigoDescuento: null, + codigoUnico: '', + codigoUnicoID: null, + descuentoPorciento: null + } } openReserva(){ - this.modalController.create({ - component: ReservamodalPage, - componentProps : { - codigo: this.codigoReserva + this.initReserva(); + this.reserva.codigoDescuento = (document.getElementById("codigoDescuento")).value; + this.reserva.codigoUnico = this.generarCodigo(); + this.creaReserva(this.reserva); + } + + creaReserva(reserva){ + this.apiService.creaReserva(reserva) + .subscribe( + data => { + console.log(data); + this.reserva = data; + this.reservaRealizada = true; + this.modalController.create({ + component: ReservamodalPage, + componentProps : { + codigo: this.reserva.codigoUnico + } + + }).then(modal => modal.present()); + }, + error => { + console.log(error); } - - }).then(modal => modal.present()); - + ) } }