@openinc/parse-server-opendash 2.4.84 → 2.4.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,16 +39,71 @@ async function handleRequest(request) {
39
39
  const ticketQuery = request.params.junction === "or"
40
40
  ? Parse.Query.or(...queries)
41
41
  : Parse.Query.and(...queries);
42
- // fetch all tickets for sorting by data
43
- const tickets = await ticketQuery
44
- .limit(1000000000)
45
- .find({ useMasterKey: true });
46
- // get total count of tickets before applying pagination
47
- const totalCount = tickets.length;
48
42
  //Log the time taken to fetch the data in seconds
49
43
  console.log(`Function openinc-openservice-ticket-data runs for: ${(new Date().getTime() - time) / 1000}s. Next: Fetch ticket data`);
44
+ // fetch all tickets for sorting by data
45
+ const ticketData = await ticketQuery.limit(1000000000).map(async (ticket) => {
46
+ let assignedusers = [];
47
+ let assignedroles = [];
48
+ if (typeof ticket.assignedusers !== "undefined") {
49
+ assignedusers = await ticket.assignedusers
50
+ .query()
51
+ .find({ useMasterKey: true });
52
+ }
53
+ if (typeof ticket.assignedroles !== "undefined") {
54
+ assignedroles = await ticket.assignedroles
55
+ .query()
56
+ .find({ useMasterKey: true });
57
+ }
58
+ const downtimes = getDowntime(ticket);
59
+ const duedate = getDueDate(ticket);
60
+ const frequency = getFrequency(ticket);
61
+ const restriction = getRestriction(ticket);
62
+ const issuecategory = getIssueCategory(ticket);
63
+ const priority = getPriority(ticket);
64
+ const source = getTicketSource(ticket);
65
+ const state = getState(ticket);
66
+ const dailySchedule = getDailySchedule(ticket);
67
+ const messages = getMessages(ticket);
68
+ const dataPromises = await Promise.all([
69
+ downtimes,
70
+ duedate,
71
+ frequency,
72
+ restriction,
73
+ issuecategory,
74
+ priority,
75
+ source,
76
+ state,
77
+ dailySchedule,
78
+ messages,
79
+ ]);
80
+ return {
81
+ ticket: ticket,
82
+ downtime: dataPromises[0].length > 0 ? dataPromises[0][0] : undefined,
83
+ duedate: dataPromises[1].length > 0 ? dataPromises[1][0] : undefined,
84
+ frequency: dataPromises[2].length > 0 ? dataPromises[2][0] : undefined,
85
+ restriction: dataPromises[3].length > 0 ? dataPromises[3][0] : undefined,
86
+ issuecategory: dataPromises[4].length > 0
87
+ ? dataPromises[4][0]?.get("issuecategory")
88
+ : undefined,
89
+ priority: dataPromises[5].length > 0 ? dataPromises[5][0] : undefined,
90
+ source: dataPromises[6].length > 0
91
+ ? dataPromises[6][0]?.get("source")
92
+ : undefined,
93
+ state: dataPromises[7].length > 0
94
+ ? dataPromises[7][0]?.get("state")
95
+ : undefined,
96
+ dailySchedule: dataPromises[8],
97
+ messages: dataPromises[9].messages,
98
+ messageBodies: dataPromises[9].messageBodies,
99
+ assignedTo: [...assignedusers, ...assignedroles],
100
+ };
101
+ }, { useMasterKey: true });
102
+ // .find({ useMasterKey: true });
103
+ // get total count of tickets before applying pagination
104
+ const totalCount = ticketData.length;
50
105
  // fetch ticket data for those tickets
51
- const ticketData = await getTicketData(tickets);
106
+ // const ticketData = await getTicketData(tickets);
52
107
  //Log the time taken to fetch the data in seconds
53
108
  console.log(`Function openinc-openservice-ticket-data runs for: ${(new Date().getTime() - time) / 1000}s. Next: Sorting and Pagination`);
54
109
  // apply sorting
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "2.4.84",
3
+ "version": "2.4.85",
4
4
  "description": "Parse Server Cloud Code for open.DASH",
5
5
  "keywords": [
6
6
  "parse",