Guest User

Untitled

a guest
Jun 30th, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. C:wampwwwngapp>ng build --prod
  2. 10% building modules 3/3 modules 0 activeWarning: Can't resolve all parameters for LoginService in C:/wamp/www/ngapp/sr
  3. c/app/abstract/login.service.ts: ([object Object], ?). This will become an error in Angular v6.x
  4. Warning: Can't resolve all parameters for UserService in C:/wamp/www/ngapp/src/app/abstract/user.service.ts: ([object Ob
  5. ject], ?). This will become an error in Angular v6.x
  6.  
  7. Date: 2018-06-30T06:40:13.988Z
  8. Hash: 72312a1071e597367666
  9. Time: 10125ms
  10. chunk {scripts} scripts.385b291e179030219400.js (scripts) 136 kB [rendered]
  11. chunk {0} runtime.a66f828dca56eeb90e02.js (runtime) 1.05 kB [entry] [rendered]
  12. chunk {1} styles.14764545cc77d1b25789.css (styles) 159 kB [initial] [rendered]
  13. chunk {2} polyfills.207dcc605630215505f5.js (polyfills) 130 bytes [initial] [rendered]
  14. chunk {3} main.f58b96bf9bf614ca37d4.js (main) 128 bytes [initial] [rendered]
  15.  
  16. ERROR in : Can't resolve all parameters for UserService in C:/wamp/www/ngapp/src/app/abstract/user.service.ts: ([object
  17. Object], ?).
  18.  
  19. import { Injectable, forwardRef, Inject } from '@angular/core';
  20. //import { Http } from '@angular/http';
  21. import { HttpClient } from '@angular/common/http';
  22. import { catchError, map, retry } from 'rxjs/operators';
  23. import { throwError } from 'rxjs';
  24. import { NotFoundError } from '../errors/notfound-error';
  25. import { Unauthorized } from '../errors/unauthorized-error';
  26. import { AppError } from '../errors/app-error';
  27. import * as GLOBAL from 'globals';
  28.  
  29.  
  30. interface Credentials {
  31. username: string,
  32. password: string
  33. }
  34.  
  35. @Injectable({
  36. providedIn: 'root'
  37. })
  38.  
  39. export abstract class LoginService {
  40.  
  41.  
  42. // readonly USER_NOT_FOUND = 404;
  43. // readonly UNAUTHENTICATED = 401;
  44.  
  45. private http: HttpClient;
  46.  
  47. constructor(@Inject(forwardRef(() => HttpClient)) http:HttpClient, private url: string) {
  48. this.http = http;
  49. }
  50.  
  51. check(credential: Credentials, url?) {
  52. url = url ? url : this.url;
  53.  
  54. return this.http.post(url, credential)
  55. .pipe(
  56. //map((response) => { console.log(response.json()); return response.json() }),
  57. map((response) => { return response }),
  58. retry(0),
  59. catchError((error: Response) => { return this.handleError(error) })
  60. );
  61. }
  62.  
  63. isUserExists(user: {username: string}, url?){
  64.  
  65. url = url ? url : this.url;
  66.  
  67. return this.http.post(url, user)//, {observe: 'response'})
  68. .pipe(
  69. map(response => { return response;}),
  70. catchError( error => this.handleError(error))
  71. )
  72. }
  73.  
  74. private handleError(error: any) {
  75. //console.log("handleError: ", error);
  76. if (error.status as number === GLOBAL.USER_NOT_FOUND) {
  77. return throwError(new NotFoundError(error));
  78. }
  79. else if (error.status as number === GLOBAL.UNAUTHENTICATED) {
  80. let e = new Unauthorized(error);
  81. return throwError(e);
  82. }
  83. else {
  84. return throwError(new AppError(error));
  85. }
  86. }
  87. }
  88.  
  89. import { Injectable } from '@angular/core';
  90. import { HttpClient } from '@angular/common/http';
  91. import { LoginService } from '../abstract/login.service';
  92. //import { Http } from '@angular/http';
  93.  
  94. @Injectable({
  95. providedIn: 'root'
  96. })
  97.  
  98. export class AuthService extends LoginService {
  99.  
  100. constructor(http: HttpClient) {
  101. super(http, "http://demo1601932.mockable.io/login-invalid");
  102. }
  103.  
  104. isUserExists(user: {username: string}){
  105. let url;
  106.  
  107. if (user.username == "cust@ngapp.com")
  108. url = "http://demo1601932.mockable.io/user-valid";
  109. else
  110. url = "http://demo1601932.mockable.io/user-invalid";
  111.  
  112. return super.isUserExists(user, url);
  113. }
  114.  
  115. check(user){
  116.  
  117. let url;
  118.  
  119. if (user.username == "cust@ngapp.com" && user.password == "cust1234")
  120. url = "https://demo1601932.mockable.io/login-valid";
  121. else
  122. url = "https://demo1601932.mockable.io/login-invalid";
  123.  
  124. return super.check(user, url);
  125. }
  126. }
  127.  
  128. import { Injectable, forwardRef, Inject } from '@angular/core';
  129. import { HttpClient } from '@angular/common/http';
  130. import { catchError, map, retry } from 'rxjs/operators';
  131. import { throwError } from 'rxjs';
  132. import { NotFoundError } from '../errors/notfound-error';
  133. import { Unauthorized } from '../errors/unauthorized-error';
  134. import { AppError } from '../errors/app-error';
  135. import * as GLOBAL from 'globals';
  136.  
  137. @Injectable({
  138. providedIn: 'root'
  139. })
  140. export class UserService {
  141.  
  142. private http: HttpClient;
  143.  
  144. constructor(@Inject(forwardRef(() => HttpClient)) http:HttpClient, private url: string) {
  145. this.http = http;
  146. }
  147.  
  148. getAll(url? : string){
  149.  
  150. url = url ? url : this.url;
  151.  
  152. return this.http.get(url).pipe(
  153. map(response => { return response;}),
  154. catchError( error => this.handleError(error))
  155. )
  156. }
  157.  
  158. getUser(uid, url? : string){
  159. url = url ? url : this.url;
  160.  
  161. return this.http.get(url + "/" + uid)
  162. .pipe(
  163. retry(2),
  164. catchError( error => this.handleError(error))
  165. )
  166. }
  167.  
  168. create(user, url? : string){
  169. url = url ? url : this.url;
  170.  
  171. return this.http.put(url, user).pipe(
  172. map(response => { return response;}),
  173. catchError( error => this.handleError(error))
  174. )
  175. }
  176.  
  177. update(uid, data, url? : string){
  178. url = url ? url : this.url;
  179.  
  180. return this.http.patch(url + '/'+ uid, data, { observe: "response"}).pipe(
  181. map(response => {
  182. // console.log('Headers', response.headers.keys());
  183. // console.log('Body', response.body);
  184. return response.body;
  185. }),
  186. retry(1),
  187. catchError( error => this.handleError(error))
  188. )
  189. }
  190.  
  191. private handleError(error: any) {
  192. //console.log("handleError: ", error);
  193. if (error.status as number === GLOBAL.USER_NOT_FOUND) {
  194. return throwError(new NotFoundError(error));
  195. }
  196. else if (error.status as number === GLOBAL.UNAUTHENTICATED) {
  197. let e = new Unauthorized(error);
  198. return throwError(e);
  199. }
  200. else {
  201. return throwError(new AppError(error));
  202. }
  203. }
  204. }
  205.  
  206. import { Injectable } from '@angular/core';
  207. import { HttpClient } from '@angular/common/http';
  208. import { UserService } from '../abstract/user.service';
  209.  
  210. @Injectable({
  211. providedIn: 'root'
  212. })
  213.  
  214. export class CustomersService extends UserService {
  215.  
  216. constructor(http: HttpClient) {
  217. super(http, "http://demo1601932.mockable.io/customers/");
  218. }
  219.  
  220. getAll(){
  221. return super.getAll("http://demo1601932.mockable.io/customers/get");
  222. }
  223.  
  224. get(uid){
  225. return super.getUser(uid, "http://demo1601932.mockable.io/customer/get");
  226. }
  227.  
  228. create(user){
  229. return super.create(user, "http://demo1601932.mockable.io/customers");
  230. }
  231.  
  232. update(uid, userData){
  233. return super.update(uid, userData, "http://demo1601932.mockable.io/customers");
  234. }
  235.  
  236. //Admin
  237. getall4Admin(){
  238. return super.getAll("https://jsonplaceholder.typicode.com/users");
  239. }
  240.  
  241. get4Admin(uid){
  242. return super.getUser(uid, "https://jsonplaceholder.typicode.com/users");
  243. }
  244. }
Add Comment
Please, Sign In to add comment