update-user.service.js
4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require('@angular/core');
var http_1 = require('@angular/http');
var router_1 = require('@angular/router');
var Observable_1 = require('rxjs/Observable');
require('rxjs/add/operator/map');
require('rxjs/add/operator/catch');
//import { AppSettings, User } from '../model/data-model';
var UpdateUserService = (function () {
function UpdateUserService(http, router) {
//if (this.currentUser == null) {
// var user = localStorage.getItem("currentUser");
this.http = http;
this.router = router;
// if (user != null) {
// this.currentUser = JSON.parse(user);
// this.loggedIn = true;
// }
//}
this.userId = 0;
this.firstName = "";
this.lastName = "";
this.emailId = "";
}
UpdateUserService.prototype.extractData = function (res) {
var body = res.json();
return body || {};
};
UpdateUserService.prototype.handleError = function (error) {
// In a real world app, we might use a remote logging infrastructure
var errMsg;
if (error instanceof http_1.Response) {
var body = error.json() || '';
var err = body.error || JSON.stringify(body);
errMsg = error.status + " - " + (error.statusText || '') + " " + err;
}
else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable_1.Observable.throw(errMsg);
};
UpdateUserService.prototype.UpdateUserProfile = function (applicationName, strFirstName, strLastName, strEmailID) {
console.log('inside application service');
var usrID;
usrID = 1;
var headers = new http_1.Headers({ 'Content-Type': 'application/json' });
//let headers = new Headers();
//headers.append('Content-type', 'application/x-www-form-urlencoded');
var options = new http_1.RequestOptions({ headers: headers });
var body = JSON.stringify({ userId: usrID, emailId: strEmailID, firstName: strFirstName, lastName: strLastName });
console.log(body);
return this.http.post('http://localhost:85/AIAHTML5.Server/api/updateprofile', body, options)
.map(this.extractData)
.catch(this.handleError);
};
UpdateUserService.prototype.UpdateUserProfile2 = function (applicationName, strFirstName, strLastName, strEmailID) {
console.log('inside update-user service -2');
var usrID;
usrID = 1;
//let headers = new Headers({ 'Content-Type': 'application/json' });
var headers = new http_1.Headers();
headers.append('Content-type', 'application/x-www-form-urlencoded');
var options = new http_1.RequestOptions({ headers: headers });
var body = 'userId=' + usrID + '&emailId=' + strEmailID + '&firstName=' + strFirstName + '&lastName=' + strLastName;
console.log(body);
var urlSearchParams = new http_1.URLSearchParams();
urlSearchParams.append('userId', usrID.toString());
urlSearchParams.append('firstName', strFirstName);
urlSearchParams.append('lastName', strLastName);
urlSearchParams.append('emailId', strEmailID);
var body2 = urlSearchParams.toString();
return this.http.post('http://localhost:85/AIAHTML5.Server/api/updateprofile', body, options)
.map(function (response) {
console.log(response);
var body = response.json();
console.log(body);
})
.catch(this.logError);
};
UpdateUserService.prototype.extractData2 = function (res) {
var body = res.json();
console.log('ServiceResult: ' + body);
return body || {};
};
UpdateUserService.prototype.logError = function (error) {
console.log('ServiceError: ' + err);
};
UpdateUserService = __decorate([
core_1.Injectable(),
__metadata('design:paramtypes', [http_1.Http, router_1.Router])
], UpdateUserService);
return UpdateUserService;
}());
exports.UpdateUserService = UpdateUserService;
//# sourceMappingURL=update-user.service.js.map