Compare commits
2 Commits
024f768da9
...
e31ded9eb9
Author | SHA1 | Date |
---|---|---|
onsaliyo | e31ded9eb9 | |
onsaliyo | 9817883235 |
|
@ -2,6 +2,7 @@ export interface Reservai {
|
|||
UserID: number,
|
||||
EventoID: number,
|
||||
codigoDescuento: string,
|
||||
codigoUnico: string,
|
||||
codigoUnicoID: number,
|
||||
descuentoPorciento: number
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export interface User {
|
||||
id: number;
|
||||
userID: number;
|
||||
discotecaID: number;
|
||||
userType: number;
|
||||
username: string;
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
</ion-header>
|
||||
|
||||
<ion-content>
|
||||
|
||||
{{codigoReserva}}
|
||||
</ion-content>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { NavParams } from '@ionic/angular';
|
||||
|
||||
@Component({
|
||||
selector: 'app-reservamodal',
|
||||
|
@ -7,9 +8,11 @@ import { Component, OnInit } from '@angular/core';
|
|||
})
|
||||
export class ReservamodalPage implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
codigoReserva: string;
|
||||
constructor(private navParams: NavParams) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.codigoReserva = this.navParams.get('codigo');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Reservai>{
|
||||
return this.http.post<Reservai>(this.baseUrl+"/reserva", reserva);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CodigoreservaService } from './codigoreserva.service';
|
||||
|
||||
describe('CodigoreservaService', () => {
|
||||
let service: CodigoreservaService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(CodigoreservaService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,27 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CodigoreservaService {
|
||||
|
||||
codigo: string;
|
||||
length: number;
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
generarAleatorio(){
|
||||
this.length = 7;
|
||||
var result = [];
|
||||
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
var charactersLength = characters.length;
|
||||
for ( var i = 0; i < this.length; i++ ) {
|
||||
result.push(characters.charAt(Math.floor(Math.random() *
|
||||
charactersLength)));
|
||||
}
|
||||
return result.join("");
|
||||
}
|
||||
|
||||
}
|
|
@ -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: '',
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
Reserva
|
||||
</ion-button>
|
||||
</ion-row>
|
||||
<ion-row>
|
||||
<span>Código de descuento: </span><input type="text" id="codigoDescuento">
|
||||
</ion-row>
|
||||
</div>
|
||||
</ion-grid>
|
||||
</ion-content>
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
import { stringify } from '@angular/compiler/src/util';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ModalController } from '@ionic/angular';
|
||||
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',
|
||||
|
@ -16,19 +20,59 @@ export class ViewEventoClientePage implements OnInit {
|
|||
evento: Eventoi;
|
||||
discoteca: DiscotecaI;
|
||||
reserva: Reservai;
|
||||
constructor(private feedService: FeedService, private modalController: ModalController) { }
|
||||
codigoReserva: string;
|
||||
reservaRealizada: boolean;
|
||||
|
||||
constructor(private feedService: FeedService, private modalController: ModalController,
|
||||
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(){
|
||||
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,
|
||||
|
||||
}).then(modal => modal.present());
|
||||
this.initReserva();
|
||||
this.reserva.codigoDescuento = (<HTMLInputElement>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);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue