User.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import { appApi } from 'src/boot/axios.js'
  2. import { User, UserList } from 'src/models/User.js'
  3. import APIRepository from '../classes/APIRepository.js'
  4. export default class UserAPI extends APIRepository {
  5. constructor() {
  6. super('user', appApi, '/uma/users', User)
  7. this.APIAdresses = {
  8. base: '/uma/users',
  9. exportReport: '/uma/users/export_report',
  10. verify: '/uma/users/verify',
  11. current: '/uma/users/current',
  12. byId: (id) => '/uma/users/' + id,
  13. changeRole: (id) => '/uma/users/' + id + '/change_role'
  14. }
  15. this.CacheList = {
  16. base: this.name + this.APIAdresses.base,
  17. current: this.name + this.APIAdresses.current,
  18. verify: this.name + this.APIAdresses.verify,
  19. byId: (id) => this.name + this.APIAdresses.byId(id),
  20. changeRole: (id) => this.name + this.APIAdresses.changeRole(id)
  21. }
  22. }
  23. index(data) {
  24. return this.sendRequest({
  25. apiMethod: 'get',
  26. api: this.api,
  27. request: this.APIAdresses.base,
  28. data: this.getNormalizedSendData({
  29. role: null, // String
  30. per_page: 10, // Number
  31. page: 1 // Number
  32. }, data),
  33. resolveCallback: (response) => {
  34. const paginate = response.data
  35. const results = response.data.results
  36. delete paginate.results
  37. return {
  38. list: new UserList(results),
  39. paginate
  40. // {
  41. // "count": 1,
  42. // "num_pages": 1,
  43. // "per_page": 10,
  44. // "current": 1,
  45. // "next": null,
  46. // "previous": null,
  47. // }
  48. }
  49. },
  50. rejectCallback: (error) => {
  51. return error
  52. }
  53. })
  54. }
  55. exportReport(data) {
  56. return this.sendRequest({
  57. apiMethod: 'get',
  58. api: this.api,
  59. request: this.APIAdresses.exportReport,
  60. data,
  61. responseType: 'blob',
  62. resolveCallback: (response) => {
  63. return response.data // xlsxData
  64. },
  65. rejectCallback: (error) => {
  66. return error
  67. }
  68. })
  69. }
  70. updateCurrent(data = {}) {
  71. return this.sendRequest({
  72. apiMethod: 'put',
  73. api: this.api,
  74. request: this.APIAdresses.current,
  75. data: this.getNormalizedSendData({
  76. firstname: '', // String
  77. lastname: '', // String
  78. gender: 'MALE', // String
  79. marital_status: 'UNKNOWN', // String
  80. birthdate: null, // String
  81. national_code: '', // String
  82. has_seminary_education: false, // Boolean
  83. last_academic_degree: 'UNDER_DIPLOMA', // String
  84. last_academic_degree_field: null, // String
  85. last_academy_name: null, // String
  86. educational_status: null, // String
  87. phone_number: null, // String
  88. on_social_network_mobile_number: null, // String
  89. on_call_mobile_number: null, // String
  90. mobile_number: null, // String
  91. email: '', // String
  92. is_abroad_birth_address: 'False', // String
  93. is_abroad_living_address: 'False', // String
  94. birth_country: 'ایران', // String
  95. living_country: 'ایران', // String
  96. birth_province: null, // String
  97. living_province: null, // String
  98. birth_city: null, // String
  99. living_city: null, // String
  100. living_address: null, // String
  101. living_postal_code: null, // String
  102. living_address_additional_info: null // String
  103. }, data),
  104. resolveCallback: (response) => {
  105. return new User(response.data)
  106. },
  107. rejectCallback: (error) => {
  108. return error
  109. }
  110. })
  111. }
  112. getCurrent() {
  113. return this.sendRequest({
  114. apiMethod: 'get',
  115. api: this.api,
  116. request: this.APIAdresses.current,
  117. resolveCallback: (response) => {
  118. return new User(response.data)
  119. },
  120. rejectCallback: (error) => {
  121. return error
  122. }
  123. })
  124. }
  125. updateByAdmin(data = {}) {
  126. return this.sendRequest({
  127. apiMethod: 'put',
  128. api: this.api,
  129. request: this.APIAdresses.byId(data.id),
  130. data: this.getNormalizedSendData({
  131. firstname: '', // String
  132. lastname: '', // String
  133. gender: 'MALE', // String
  134. marital_status: 'UNKNOWN', // String
  135. birthdate: null, // String
  136. national_code: '', // String
  137. is_active: false, // Boolean
  138. has_seminary_education: false, // Boolean
  139. last_academic_degree: 'UNDER_DIPLOMA', // String
  140. last_academic_degree_field: null, // String
  141. last_academy_name: null, // String
  142. educational_status: null, // String
  143. phone_number: null, // String
  144. on_social_network_mobile_number: null, // String
  145. mobile_number: null, // String
  146. email: '', // String
  147. is_abroad_birth_address: 'False', // String
  148. is_abroad_living_address: 'False', // String
  149. birth_country: 'ایران', // String
  150. living_country: 'ایران', // String
  151. birth_province: null, // String
  152. living_province: null, // String
  153. birth_city: null, // String
  154. living_city: null, // String
  155. living_address: null, // String
  156. living_postal_code: null, // String
  157. living_address_additional_info: null // String
  158. }, data),
  159. resolveCallback: (response) => {
  160. return new User(response.data)
  161. },
  162. rejectCallback: (error) => {
  163. return error
  164. }
  165. })
  166. }
  167. }