Guest User

Untitled

a guest
Jun 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. this.router.get('/:id', this.controller.show.bind(this.controller));
  2.  
  3. public async show(req: Request, res: Response): Promise<any> {
  4.  
  5. const params = req.params;
  6. const token = req.headers.token;
  7.  
  8. let transaction;
  9.  
  10. try {
  11. transaction = await this.transactionRepo.getTransactionResult(params.id, token);
  12.  
  13. console.log("instead carries on here"); // 2
  14.  
  15. if (transaction.success === false) {
  16. return res.status(404).json({
  17. success: false,
  18. status: 404,
  19. data: transaction,
  20. message: "Failed to retrieve transaction result"
  21. });
  22. }
  23.  
  24. return res.status(200).json({
  25. success: true,
  26. status: 200,
  27. data: transaction,
  28. message: "Successfully retrieved transaction result"
  29. });
  30.  
  31. } catch (err) {
  32.  
  33. //console.log("Does not call this");
  34. return res.status(500).json({
  35. success: false,
  36. status: 400,
  37. data: err,
  38. message: "The server threw an unexpected error",
  39. });
  40. }
  41.  
  42. public async getTransactionResult(transactionId: string, token: string) {
  43.  
  44. const url = this.config.api_url + "/api/transactions/" + transactionId + "/summary";
  45.  
  46. const options = {
  47. uri: url,
  48. headers: {
  49. 'token': token
  50. },
  51. body: {
  52.  
  53. },
  54. json: true,
  55. resolveWithFullResponse: true
  56. }
  57.  
  58.  
  59. let result;
  60. try {
  61.  
  62. result = await request.get(options);
  63.  
  64. if (result.statusCode !== 200) {
  65. return { "success": false, data: result }
  66. }
  67.  
  68. return { "success": true, data: result }
  69.  
  70. } catch (err) {
  71. console.log("CAUGHT ERROR"); // 1
  72. return err;
  73. }
  74.  
  75. }
Add Comment
Please, Sign In to add comment