Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. export class BaseModel {
  2. constructor (http: Http) {}
  3.  
  4. fetch() {
  5. let params = {
  6. "includes": this.includes,
  7. "page": page,
  8. "filters" : this.filters,
  9. "order" : this.orderDirection + this.orderColumn
  10. };
  11.  
  12. return this.api.get("/"+this.endpoint, params)
  13. .map(
  14. (response: any) => {
  15. let total = response.meta.total;
  16. let current = response.meta.current;
  17.  
  18. let min = current - 5;
  19. let max = current + 5;
  20.  
  21. if (min < 1) {
  22. min = 1;
  23. }
  24.  
  25. if (max > total) {
  26. max = total;
  27. }
  28. else if (max < 10) {
  29. if(total < 10) {
  30. max = total;
  31. }else {
  32. max = 10;
  33. }
  34. }
  35.  
  36. let pages : number[] = [];
  37.  
  38. for (let i = min; i <= max; i++) {
  39. pages.push(i);
  40. }
  41.  
  42. this.pages = pages;
  43.  
  44. return response
  45. }
  46. );
  47. }
  48. }
  49.  
  50. export class User extends BaseModel {
  51.  
  52. public id : number;
  53. public username : string;
  54. public email : string;
  55. public password : string;
  56. public passwordConfirmation : string;
  57. public details : UserDetail = new UserDetail();
  58. public type : string;
  59. public status : string;
  60. public profileImage : string;
  61. public profileImageUrl : string;
  62. public crop : Object = {};
  63. public lastLogin : string;
  64. public numberOfLogin : string;
  65. public joinDate : string;
  66. public registerType : string = "web";
  67.  
  68. public static create(response : any) {
  69.  
  70. if (response === undefined || response === null) {
  71. return response;
  72. }
  73.  
  74. let details = new UserDetail();
  75.  
  76. if (response.details) {
  77. details = UserDetail.create(response.details);
  78. }
  79.  
  80. let user = new User(); //error parameter required
  81. user.id = response.id;
  82. user.username = response.username;
  83. user.email = response.email;
  84. user.status = response.status;
  85. user.type = response.type;
  86. user.details.id = response.details.id;
  87. user.details = details;
  88. user.profileImageUrl = response.profile_image_url;
  89. user.joinDate = response.created_at;
  90. user.registerType = response.register_type;
  91.  
  92. return user;
  93. }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement