You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

  1. //
  2. // OrderHistoryService.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon Devik Kim on 14/05/2019.
  6. //Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class OrderHistoryService: OrderHistoryServiceType {
  10. func fetchOrderHistory(
  11. from startDate: String,
  12. to endDate: String,
  13. success: @escaping([Order]?) -> Void,
  14. failure: @escaping(Error) -> Void
  15. ) {
  16. guard let userId = GMEDB.shared.user.string(.userId) else {
  17. let error = NSError.init(
  18. domain: "Network",
  19. code: 0,
  20. userInfo: [NSLocalizedDescriptionKey : "no exist email"])
  21. failure(error)
  22. return
  23. }
  24. let parameter = [
  25. "userId": userId,
  26. "startDate": startDate,
  27. "endDate": endDate
  28. ]
  29. let url = baseUrlWithoutVersion + "v2/reward/productOrderedList"
  30. // let url = baseUrlWithoutVersion + "v2/reward/productOrderd"
  31. auth.request(
  32. method: .post,
  33. url: url,
  34. params: parameter,
  35. success: { (response: OrderContainer) in
  36. if (response.errorCode ?? "") == "1" {
  37. let error = NSError.init(
  38. domain: "Network",
  39. code: 0,
  40. userInfo: [NSLocalizedDescriptionKey :
  41. response.message ?? ""])
  42. failure(error)
  43. } else {
  44. let model = response.data
  45. success(model)
  46. }
  47. },
  48. failure: { failure($0) }
  49. )
  50. }
  51. }