Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #library#
- import { Http, Headers, RequestOptions } from '@angular/http';
- #rest-api#
- addRegister(dataRegister){
- return new Promise((resolve, reject) => {
- let header = new Headers();
- header.set('Content-Type', 'application/json');
- let options = new RequestOptions({
- headers: header
- });
- this.http.post(this.apiUrl+'/api/register', JSON.stringify(dataRegister), options)
- .map(res => res.json())
- .subscribe(res => {
- resolve(res);
- }, (err) => {
- reject(err);
- });
- });
- }
- #raw json seng dikirim#
- userRegister = {
- params: {
- api_key: '.tC7HQ34TUW67P18PEA0DM5U8Y0A6AYB6BIO2MSVH0e64e270572656fd408677cb0fa4d3e4',
- params: [],
- vals: {
- name: '',
- phone: '',
- email: '',
- ktp: '',
- foto_ktp: '',
- npwp: '',
- foto_npwp: '',
- password:'',
- password2 : '',
- company_type : 'INDIVIDUAL'
- }
- }
- };
- #pemanggilan rest-api + lain-lain#
- saveUserRegister() {
- this.formatNumberPhone();
- console.log(this.userRegister.params.vals.phone);
- if(!this.restApiProvider.checkEmail(this.userRegister.params.vals.email)){
- this.restApiProvider.alertOK("Gagal input","Alamat email tidak valid");
- return false;
- }
- if(this.userRegister.params.vals.foto_ktp == ""){
- this.restApiProvider.alertOK("Gagal input","Foto KTP belum ada");
- return false;
- }
- if(this.userRegister.params.vals.foto_npwp == ""){
- this.restApiProvider.alertOK("Gagal input","Foto NPWP belum ada");
- return false;
- }
- this.restApiProvider.showLoader("Sedang memuat...");
- this.restApiProvider.addRegister(this.userRegister).then((result) => {
- console.log(result);
- this.dataRegister = result;
- this.dataRegisterError = result['error'];
- this.dataRegisterResult = result['result'];
- this.restApiProvider.loading.dismiss();
- if ( this.dataRegisterError != null) {
- this.restApiProvider.alertOK("Registrasi gagal", "Proses registrasi anda gagal");
- this.restApiProvider.alertOK("Registrasi gagal", this.dataRegisterError.data.message);
- } else if (this.dataRegisterResult != null) {
- this.showAlert(
- this.dataRegister.result.rec.contact_name,
- this.dataRegister.result.rec.email,
- this.dataRegister.result.rec.phone,
- this.dataRegister.result.rec.ktp,
- this.dataRegister.result.rec.npwp,
- this.dataRegister.result.rec.totp
- );
- }
- }, (err) => {
- console.log(err);
- this.restApiProvider.loading.dismiss();
- this.restApiProvider.alertOK("Registrasi gagal", "Cek koneksi internet anda");
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement