Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. module Api
  2. module V1Test
  3. class BeneficiaryUsersController < TestApiController
  4.  
  5. def index
  6. if token == 'email_updated@example.com'
  7. return render json: { error_code: :email_updated }, status: 403
  8. else
  9. data = {"data": [],"meta":{"has_maxed_beneficiaries":false}}
  10. data[:data] << mock_data_user_json(
  11. email: 'beneficiary_user1@example.com', is_destroyable: true
  12. )
  13.  
  14.  
  15. data[:data] << mock_data_user_json(email: 'beneficiary_user1@example.com', id: 2)
  16. data[:data] << mock_data_user_json(
  17. is_inactive_beneficiary: true,
  18. email: 'beneficiary_user4@example.com', id: 4,
  19. has_no_account_access_and_is_managed_by_parent: false
  20. )
  21.  
  22. data[:data] << mock_data_user_json(
  23. is_inactive_beneficiary: true,
  24. email: 'beneficiary_user5@example.com', id: 5,
  25. has_no_account_access_and_is_managed_by_parent: true
  26. )
  27. data[:data] << mock_data_user_json(email: 'beneficiary_user2@example.com', id: 3)
  28.  
  29. response_success(data)
  30. end
  31. end
  32.  
  33. def update
  34. data = {
  35. "data": {
  36. "id": "1",
  37. "type": "beneficiary_user",
  38. "attributes": current_user.as_json.merge(params[:beneficiary_user].as_json)
  39. },
  40. "meta": { "notice": I18n.t("controllers.action_messages.update") }
  41. }
  42. response_success(data)
  43. end
  44.  
  45. def sign_up
  46. if valid_email?
  47. data = {
  48. id: 1, type: :beneficiary_user,
  49. attributes: current_user.as_json
  50. }
  51.  
  52. response_success(data: data)
  53. end
  54. end
  55.  
  56. def search_by_government_id
  57. if params[:government_id] == '811111112'
  58. data = {
  59. "status":true,
  60. "data":{
  61. "id":95137, "first_name": "MARIA","second_first_name": nil,"last_name": "SALAS",
  62. "second_last_name": "CHAVARRIA","gender": "female","government_id": "811111112"
  63. }
  64. }
  65.  
  66. response_success data
  67. elsif params[:government_id] == '811111111' # unactive user
  68. data = {
  69. "status": true,
  70. "beneficiary_id": 15,
  71. "title": "¿Querés activar nuevamente tu cuenta?",
  72. "body": "Enviaremos un mensaje a tu correo para que activés tu cuenta",
  73. "button": "Activar Cuenta"
  74. }
  75. response_success data
  76. elsif params[:government_id] == '111111111' # registered
  77. data = {
  78. "status": true,
  79. "errors": I18n.t('activerecord.errors.messages.government_id_user_exists'),
  80. "user_id": 107
  81. }
  82.  
  83. response_success data
  84. else
  85. response_error('errors')
  86. end
  87. end
  88.  
  89. def validate_email
  90. status = false
  91. status = true if valid_email?
  92.  
  93. response_success(status: status, errors: I18n.t('activerecord.errors.messages.taken'))
  94. end
  95.  
  96. def find_by_email
  97. if valid_email?
  98. # confirmed
  99. data = user_data.as_json
  100. else
  101. # not confirmed yet
  102. data = user_data.as_json.merge(authentication_token: nil)
  103. end
  104.  
  105. data = {id: 1, type: :beneficiary_user, attributes: data}
  106.  
  107. response_success(data: data)
  108. end
  109.  
  110. def destroy
  111. if params[:id].to_i == 1
  112. render_nothing
  113. else
  114. response_error(I18n.t('controllers.beneficiary_users.error_destroy'))
  115. end
  116. end
  117.  
  118. def find_blocked_beneficiary
  119. if params[:government_id] == '811111111'
  120. response_success(data: mock_data_user_json)
  121. else
  122. response_error(I18n.t('activerecord.errors.messages.user_not_found'))
  123. end
  124. end
  125.  
  126. def create
  127. if ['811111111', '811111112', '811111114'].include?(params[:beneficiary_user][:government_id])
  128. render json: {
  129. data: user_data.as_json, meta: { notice: 'success' }
  130. }, status: 200
  131. elsif ['811111113'].include?(params[:government_id])
  132. response_error('payment_errors')
  133. else
  134. response_error('errors')
  135. end
  136. end
  137.  
  138. def confirm
  139. if params[:confirmation_token] == 'token_ok_1234'
  140. response_success(data: mock_data_user_json(subscription_setting: nil))
  141. elsif params[:confirmation_token] == 'token_ok_1111'
  142. response_success(data: mock_data_sponsored_membership_json())
  143. else
  144. response_error(I18n.t('errors.messages.not_found_token'))
  145. end
  146. end
  147.  
  148. def transform_inactive_beneficiary_into_affiliate
  149. data = {
  150. "status": true,
  151. "email": "1.evan_schamberger@hahnfarrell.co"
  152. }
  153. response_success data
  154. end
  155.  
  156. def confirm_user
  157. if params[:government_id] == '811111111'
  158. response_success(data: user_data.as_json)
  159. else
  160. response_error(I18n.t('errors.messages.not_found_token'))
  161. end
  162. end
  163.  
  164. def update_password
  165. if params[:beneficiary_user][:current_password] == 'A12345678'
  166. render_nothing
  167. else
  168. response_error('errors')
  169. end
  170. end
  171.  
  172. def update_email
  173. if params[:current_email] == 'beneficiary@example.com'
  174. data = {
  175. affiliate: {
  176. "email": "test@test.cr"
  177. },
  178. status: 200
  179. }
  180. response_success data
  181. else
  182. response_error('errors')
  183. end
  184. end
  185.  
  186. def update_beneficiary_email
  187. if params[:email] == 'error@example.com'
  188. return render json: {
  189. errors: I18n.t('activerecord.errors.messages.taken')
  190. }, status: 422
  191. else
  192. render json: { beneficiary: { email: params[:email] }, status: 200 }
  193. end
  194. end
  195.  
  196. def profile
  197. data = {
  198. id: 1, type: :beneficiary_user,
  199. attributes: user_data
  200. }
  201. response_success(data: data)
  202. end
  203.  
  204. def subscribe_receive_information
  205. data = {
  206. id: 1, type: :beneficiary_user,
  207. attributes: user_data
  208. }
  209. response_success(data: data)
  210. end
  211. end
  212.  
  213. end
  214. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement