Advertisement
Guest User

example_post

a guest
Dec 17th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. #library#
  2. import { Http, Headers, RequestOptions } from '@angular/http';
  3.  
  4. #rest-api#
  5. addRegister(dataRegister){
  6. return new Promise((resolve, reject) => {
  7.  
  8. let header = new Headers();
  9. header.set('Content-Type', 'application/json');
  10. let options = new RequestOptions({
  11. headers: header
  12. });
  13.  
  14. this.http.post(this.apiUrl+'/api/register', JSON.stringify(dataRegister), options)
  15. .map(res => res.json())
  16. .subscribe(res => {
  17. resolve(res);
  18. }, (err) => {
  19. reject(err);
  20. });
  21. });
  22. }
  23.  
  24. #raw json seng dikirim#
  25. userRegister = {
  26. params: {
  27. api_key: '.tC7HQ34TUW67P18PEA0DM5U8Y0A6AYB6BIO2MSVH0e64e270572656fd408677cb0fa4d3e4',
  28. params: [],
  29. vals: {
  30. name: '',
  31. phone: '',
  32. email: '',
  33. ktp: '',
  34. foto_ktp: '',
  35. npwp: '',
  36. foto_npwp: '',
  37. password:'',
  38. password2 : '',
  39. company_type : 'INDIVIDUAL'
  40. }
  41. }
  42. };
  43.  
  44. #pemanggilan rest-api + lain-lain#
  45. saveUserRegister() {
  46. this.formatNumberPhone();
  47. console.log(this.userRegister.params.vals.phone);
  48.  
  49. if(!this.restApiProvider.checkEmail(this.userRegister.params.vals.email)){
  50. this.restApiProvider.alertOK("Gagal input","Alamat email tidak valid");
  51. return false;
  52. }
  53.  
  54. if(this.userRegister.params.vals.foto_ktp == ""){
  55. this.restApiProvider.alertOK("Gagal input","Foto KTP belum ada");
  56. return false;
  57. }
  58.  
  59. if(this.userRegister.params.vals.foto_npwp == ""){
  60. this.restApiProvider.alertOK("Gagal input","Foto NPWP belum ada");
  61. return false;
  62. }
  63.  
  64. this.restApiProvider.showLoader("Sedang memuat...");
  65. this.restApiProvider.addRegister(this.userRegister).then((result) => {
  66. console.log(result);
  67.  
  68. this.dataRegister = result;
  69. this.dataRegisterError = result['error'];
  70. this.dataRegisterResult = result['result'];
  71.  
  72. this.restApiProvider.loading.dismiss();
  73. if ( this.dataRegisterError != null) {
  74. this.restApiProvider.alertOK("Registrasi gagal", "Proses registrasi anda gagal");
  75. this.restApiProvider.alertOK("Registrasi gagal", this.dataRegisterError.data.message);
  76. } else if (this.dataRegisterResult != null) {
  77. this.showAlert(
  78. this.dataRegister.result.rec.contact_name,
  79. this.dataRegister.result.rec.email,
  80. this.dataRegister.result.rec.phone,
  81. this.dataRegister.result.rec.ktp,
  82. this.dataRegister.result.rec.npwp,
  83. this.dataRegister.result.rec.totp
  84. );
  85. }
  86. }, (err) => {
  87. console.log(err);
  88. this.restApiProvider.loading.dismiss();
  89. this.restApiProvider.alertOK("Registrasi gagal", "Cek koneksi internet anda");
  90. });
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement