Browse Source

Get user info API connection

master
kj1352 5 years ago
parent
commit
b9e764a011
4 changed files with 32 additions and 10 deletions
  1. +0
    -2
      src/app/orders/orders.component.ts
  2. +3
    -2
      src/app/profile/profile.page.html
  3. +17
    -6
      src/app/profile/profile.page.ts
  4. +12
    -0
      src/app/services/auth.service.ts

+ 0
- 2
src/app/orders/orders.component.ts View File

@@ -38,7 +38,6 @@ export class OrdersComponent implements OnInit {
submitFeedbackForOrder() {
this.tempReview.app_user.user_id = this.userInfo.id;
this.selectedOrder.rating = this.tempReview;
console.log(this.selectedOrder);
this.orderService.updateOrder(this.selectedOrder).then(() => {
this.selectedOrder = null;
this.tempReview = {
@@ -64,7 +63,6 @@ export class OrdersComponent implements OnInit {
});
this.orderService.getAllOrderStatus().then((data) => {
console.log(data);
this.allOrderStatus = data;
}, (err) => {
console.log(err);


+ 3
- 2
src/app/profile/profile.page.html View File

@@ -4,9 +4,9 @@
<figure class="profile-image">
<img src="assets/custom/name.svg" alt="">
</figure>
<div class="content">
<div class="content" *ngIf="userInfo">
<h5>
<span> {{ userInfo.name }} </span>
<span> {{ userInfo.name }} ({{ userInfo.username }}) </span>
<!-- <input *ngIf="showEdit" type="text" [(ngModel)]="userInfo.name"> -->

<button *ngIf="!showEdit" (click)="showEdit = true"> Edit </button>
@@ -20,6 +20,7 @@
<span *ngIf="!showEdit"> {{ userInfo.email }} </span>
<input *ngIf="showEdit" type="tel" [(ngModel)]="userInfo.email">
</p>

</div>
</div>
<div class="location-details">


+ 17
- 6
src/app/profile/profile.page.ts View File

@@ -21,8 +21,7 @@ export class ProfilePage implements OnInit {
private toastService: ToastService
) { }

ngOnInit() {
this.userInfo = JSON.parse(localStorage.userInfo)['User Info'];
ngOnInit() {
}
updateUserInfo() {
@@ -33,16 +32,28 @@ export class ProfilePage implements OnInit {
email: this.userInfo.email,
}
this.authService.updateUser(tempUserInfo).then((data) => {
console.log(data);
this.authService.updateUser(tempUserInfo).then(() => {
this.toastService.presentToast("Updated!", "success");
}, (err) => {
console.log(err);
}, () => {
this.toastService.presentToast("Failed to update", "danger");
});
}

ionViewDidEnter() {
this.userInfo = JSON.parse(localStorage.userInfo)['User Info'];
this.authService.getUserDetails(this.userInfo.id).then((data: any) => {
this.userInfo.mobile = data.mobile;
this.userInfo.email = data.email;

let info = JSON.parse(localStorage.userInfo);
info['User Info'] = this.userInfo;
localStorage.userInfo = JSON.stringify(info);
}, () => {
this.toastService.presentToast("Failed to get user data");
});

this.selected_tab = '';
setTimeout(() => {
this.selected_tab = 'MY ORDERS';


+ 12
- 0
src/app/services/auth.service.ts View File

@@ -46,4 +46,16 @@ export class AuthService {
return this.http.put(URL + '/api/maioraservice/user/v1/update', userData, httpOptions).toPromise();
}

getUserDetails(userId: string) {
const httpOptions = {
headers: new HttpHeaders({
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.access_Token
})
};
return this.http.get(URL + '/api/maioraservice/user/v1/user_id/' + userId + '/', httpOptions).toPromise();
}
}

Loading…
Cancel
Save