Guest User

Untitled

a guest
Aug 14th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. Sample input :- array of report id [id1,id2,id3]
  2. sample output :- array
  3. {
  4. id1:"reportid",
  5. reportdetail:"reportdetails",
  6. evidences :[e1,
  7. e2,
  8. . .
  9. ]
  10. feedback :[f1,f2,f3..]
  11. }
  12.  
  13. reportArray.forEach(function(singleReport) {
  14. this part of code is not executing because report array is coming empty always.calling this after for loops ends but because of callbacks the value is still not persist here.
  15.  
  16. });
  17.  
  18.  
  19.  
  20. enter code here
  21. // Get Existing Reports Stored Procedure
  22. function sproc_GetReportsForQueue_Copy(reportObject) {
  23.  
  24. reportObject = [{
  25. state: "AvailableForT1",
  26. reportId: '295398e7-f468-a541-9d12-70dff0809da3',
  27. id: 20055
  28. },
  29. {
  30. state: "AvailableForT1",
  31. reportId: '00e4a1dc-0b4e-7465-901a-5eaebd50fb41',
  32. id: 20055
  33. }
  34. ]
  35. if (!reportObject || !reportObject.length) {
  36. throw "Input parameters are not supplied.";
  37. }
  38. //Initialization
  39. var  collection = getContext().getCollection();
  40. var collectionLink = collection.getSelfLink();
  41. var  response = getContext().getResponse();
  42. var reportArray = [];
  43. var mainArray = new Array();
  44. var feedbackArray = new Array();
  45. var evidenceArray = new Array();
  46.  
  47.  
  48. for (var i = 0; i < reportObject.length; i++) {
  49. //Gets the state and report id
  50. var state = reportObject[i].state;
  51. var reportId = reportObject[i].reportId;
  52. var reportQuery = "SELECT r.id as reportId,r.routingTargetType as routingTargetType,r.createdTimestamp AS createdTimeStamp from r WHERE r.docType='Report' AND r.id ='" + reportId + "' AND ARRAY_CONTAINS(r.reportState,{state: '" + state + "',isCurrent:true},true)";
  53. var evidenceQuery = "SELECT e.reportId as reportId,e.id As evidenceid,{ moderatorId: e.moderatorNotes.moderatorId, comment: e.moderatorNotes.comment,timeStamp:e.moderatorNotes.timestamp } AS comments,udf.GetEvidenceInfo(e.evidenceDetails) AS evidenceDetail FROM e WHERE e.docType='Evidence' AND e.reportId ='" + reportId + "'";
  54. var feedbackQuery = "SELECT f.reportId as reportId,f.targetGamertag,f.textReason from f WHERE f.reportId ='" + reportId + "' and f.docType='Feedback'";
  55.  
  56. //Gets the report
  57.  
  58. var isReportExists = collection.queryDocuments(collection.getSelfLink(), reportQuery,
  59. function(err, documents, options) {
  60. if (err) {
  61. throw err;
  62. }
  63. if  (!documents || !documents.length) {
  64.  
  65. }
  66. if (documents.length > 0) {
  67. reportArray.push(documents);
  68.  
  69. }
  70. }
  71.  
  72. );
  73. if (!isReportExists) {
  74. throw "Unable to fetch the reports from the DB";
  75.  
  76. }
  77.  
  78. //Gets the Evidence
  79. var isGetEvidence = collection.queryDocuments(
  80. collection.getSelfLink(), evidenceQuery,
  81. function(err, Evidences, options) {
  82. if (err) {
  83. throw err;
  84. }
  85. if  (!Evidences || !Evidences.length) {
  86.  
  87. } else {
  88. evidenceArray.push(Evidences);
  89.  
  90. }
  91.  
  92.  
  93.  
  94. }
  95. );
  96. if (!isGetEvidence) {
  97.  
  98.  
  99. }
  100. var isGetFeedback = collection.queryDocuments(
  101. collection.getSelfLink(), feedbackQuery,
  102. function(err, Feedbacks, options) {
  103.  
  104. if (err) {
  105. throw err;
  106. }
  107.  
  108. if  (!Feedbacks || !Feedbacks.length) {} else {
  109. feedbackArray.push({
  110. Feedback: Feedbacks
  111. });
  112.  
  113. }
  114.  
  115.  
  116. }
  117. );
  118. }
  119.  
  120. reportArray.forEach(function(singleReport) {
  121.  
  122.  
  123. });
  124.  
  125.  
  126.  
  127.  
  128. response.setBody();
  129.  
  130. }
Add Comment
Please, Sign In to add comment