Boa noite professor tudo bem ? Estou tendo um problema com o webservice, toda vez que eu realizo um agendamento o servidor acaba caindo... me devolvendo essa mensagem de erro:
$ npm start
> api@1.0.0 start C:\dev\workspace\aluracar-webservice
> node server.js
Servidor rodando em http://localhost:8080
Agendamento recebido: {"nomeCliente":"Jorge","enderecoCliente":"Rua Teste","emailCliente":"teste@gmail.com","modeloCarro":"Onix 1.6","precoTotal":35000}
C:\dev\workspace\aluracar-webservice\api.js:67
const agendamentoId = agendamento.emailCliente + agendamento.data.substr(0, 10);
^
TypeError: Cannot read property 'substr' of undefined
at enviaNotificacao (C:\dev\workspace\aluracar-webservice\api.js:67:75)
at Timeout.setTimeout [as _onTimeout] (C:\dev\workspace\aluracar-webservice\api.js:46:30)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! api@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the api@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\jorge.pinto\AppData\Roaming\npm-cache\_logs\2018-03-01T22_31_32_833Z-debug.log
jorge.pinto@SPCBR475 MINGW64 /c/dev/workspace/aluracar-webservice
cadastro.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController, Alert } from 'ionic-angular';
import { Carro } from '../../modelos/carro';
import { AgendamentosServiceProvider } from '../../providers/agendamentos-service/agendamentos-service';
import { HomePage } from '../home/home';
@IonicPage()
@Component({
selector: 'page-cadastro',
templateUrl: 'cadastro.html',
})
export class CadastroPage {
public carro: Carro;
public precoTotal: number;
public nome: string = '';
public endereco: string = '';
public email: string = '';
public data: string = new Date().toISOString();
private _alerta: Alert;
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private _agendamentosService: AgendamentosServiceProvider,
private _alertCtrl: AlertController) {
this.carro = this.navParams.get('carroSelecionado');
this.precoTotal = this.navParams.get('precoTotal');
}
agenda() {
console.log(this.nome);
console.log(this.endereco);
console.log(this.email);
console.log(this.carro.nome);
console.log(this.precoTotal);
let agendamento = {
nomeCliente: this.nome,
enderecoCliente: this.endereco,
emailCliente: this.email,
modeloCarro: this.carro.nome,
precoTotal: this.precoTotal
}
this._alerta = this._alertCtrl.create({
title: 'Aviso',
buttons: [
{
text: 'Ok',
handler: () => {
this.navCtrl.setRoot(HomePage);
}
}
]
});
this._agendamentosService.agenda(agendamento)
.subscribe(
() => {
this._alerta.setSubTitle('Agedamento realizado !');
this._alerta.present();
},
() => {
this._alerta.setSubTitle('Falha ao realizar o agendamento, tente novamente mais tarde !');
this._alerta.present();
}
);
}
}
cadastro.html
<ion-header>
<ion-navbar>
<ion-title>Cadastro</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<h2>{{carro.nome}}</h2>
<p>R$ {{precoTotal}}</p>
<form (ngSubmit)="agenda()" #formulario="ngForm">
<ion-item>
<ion-label stacked>Nome:</ion-label>
<ion-input name="nome" [(ngModel)]="nome"></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>Endereço:</ion-label>
<ion-input name="endereco" [(ngModel)]="endereco"></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>E-mail:</ion-label>
<ion-input name="email" [(ngModel)]="email"></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>Data:</ion-label>
<ion-datetime name="data" displayFormat="DD/MM/YY" [(ngModel)]="data"></ion-datetime>
</ion-item>
</form>
<ion-fab top right edge>
<button ion-fab (click)="formulario.ngSubmit.emit()">
<ion-icon name="send"></ion-icon>
</button>
</ion-fab>
</ion-content>