Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. 'use strict';
  2. var Q = require('q')
  3. module.exports = function(Funnel) {
  4.  
  5. Funnel.details = function(funnel_id, callback) {
  6. var result = {};
  7. var app = Funnel.app;
  8. var Step = app.models.Step;
  9. var Page = app.models.Page;
  10. var Product = app.models.Product;
  11. var Transition = app.models.Transition;
  12. var Pricingmodel = app.models.PricingModel;
  13. var Variant = app.models.Variant;
  14.  
  15. Funnel.findById(funnel_id)
  16. .then(funnel => {
  17. var steps_ids = funnel.steps;
  18. var products_ids = funnel.products;
  19. var steps = {};
  20. var products = [];
  21. result["name"] = funnel.name;
  22. result["descriptor"] = funnel.descriptor;
  23. result["slug"] = funnel.slug;
  24. result["total_free_shipping_count"] = funnel.total_free_shipping_count;
  25. result["url"] = funnel.url;
  26.  
  27. var promises = steps_ids.map(function (step_id) {
  28. return Step.findById(step_id)
  29. .then(step => {
  30. var step_details = {};
  31. var transition_id = step.transition_id;
  32. var page_id = step.page_id;
  33.  
  34. step_details["id"] = step_id;
  35. step_details["name"] = step.name;
  36. step_details["type"] = step.type;
  37. step_details["description"] = step.description;
  38. step_details["funnel_id"] = step.funnel_id;
  39. return [step_details , transition_id , page_id , step_id];
  40.  
  41. }).then(function(data){
  42. console.log("hereeeeeeeeeeeeee");
  43. console.log(data);
  44. return Transition.findById(data[1])
  45. .then(transition => {
  46. var transition_details = {};
  47. transition_details["name"] = transition.name;
  48. transition_details["signal"] = transition.signal;
  49. transition_details["condition"] = transition.condition;
  50. transition_details["from"] = transition.from;
  51. transition_details["to"] = transition.to;
  52. data[0]["transition"] = transition_details;
  53.  
  54. console.log("transition_details");
  55. console.log(transition_details);
  56. return data
  57. });
  58. }).then(function(data){
  59.  
  60. return Page.findById(data[2])
  61. .then(page => {
  62. var page_details = {};
  63. page_details["name"] = page.name;
  64. page_details["type"] = page.type;
  65. page_details["title"] = page.title;
  66. page_details["status"] = page.status;
  67. page_details["slug"] = page.slug;
  68. page_details["path"] = page.path;
  69. data[0]["page"] = page_details;
  70. console.log("page_details");
  71. console.log(page_details);
  72. return data;
  73. });
  74. }).then(function(data){
  75.  
  76.  
  77. console.log("step_details");
  78. console.log(data[0]);
  79. steps[data[3]] = data[0];
  80. return steps;
  81. }).catch(step_error => {
  82. console.log(step_error);
  83. });
  84. });
  85. return Q.all(promises).then(function (steps) { // [2]
  86. console.log("steps");
  87. console.log(steps);
  88. result["steps"] = steps;
  89. callback(null , result);
  90. })
  91.  
  92.  
  93.  
  94.  
  95. }).catch(funnel_error => {
  96. console.log(funnel_error);
  97. });
  98.  
  99.  
  100. }
  101.  
  102. Funnel.remoteMethod('details', {
  103. accepts: {arg: 'id', type: 'number', required: true},
  104. returns: {arg: 'res', type: 'object'}
  105. });
  106.  
  107. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement