@openinc/parse-server-opendash 2.4.35 → 2.4.37
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.
|
@@ -7,30 +7,31 @@ async function init(name) {
|
|
|
7
7
|
if (typeof request.user === "undefined") {
|
|
8
8
|
return { success: false, error: "User not found" };
|
|
9
9
|
}
|
|
10
|
-
if (!request.params?.state)
|
|
10
|
+
if (!request.params?.state) {
|
|
11
11
|
return { success: false, error: "StateID not provided" };
|
|
12
|
+
}
|
|
12
13
|
const cursor = request.params?.cursor || 0;
|
|
13
14
|
const limit = request.params?.limit || 10;
|
|
14
|
-
const state = new Parse.Query(types_1.Maintenance_Kanban_State).get(request.params?.state);
|
|
15
|
+
const state = await new Parse.Query(types_1.Maintenance_Kanban_State).get(request.params?.state, { useMasterKey: true });
|
|
15
16
|
const currentPagePipeline = [
|
|
16
|
-
{ group: { _id: "ticket", doc: { $first: "$$ROOT" } } }, // Group by ticket to only get the latest state of the ticket
|
|
17
|
-
{ match: { state: state } }, // only get tickets with the state provided
|
|
18
|
-
{ sort: { createdAt: 1 } }, // sort by createdAt
|
|
19
|
-
{ match: { createdAt: { $lt: new Date(cursor) } } }, // only get tickets with createdAt less than the cursor => pagination
|
|
20
|
-
{ limit: limit }, // limit the number of tickets recieved
|
|
21
|
-
{ replaceRoot: { newRoot: "$doc" } }, // replace the root of the document with the ticket
|
|
17
|
+
{ $group: { _id: "ticket", doc: { $first: "$$ROOT" } } }, // Group by ticket to only get the latest state of the ticket
|
|
18
|
+
{ $match: { state: state } }, // only get tickets with the state provided
|
|
19
|
+
{ $sort: { createdAt: 1 } }, // sort by createdAt
|
|
20
|
+
{ $match: { createdAt: { $lt: new Date(cursor) } } }, // only get tickets with createdAt less than the cursor => pagination
|
|
21
|
+
{ $limit: limit }, // limit the number of tickets recieved
|
|
22
|
+
{ $replaceRoot: { newRoot: "$doc" } }, // replace the root of the document with the ticket
|
|
22
23
|
];
|
|
23
|
-
const aggregatedTicketKanbanStates = await new Parse.Query(types_1.Maintenance_Ticket_Kanban_State).aggregate(
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const aggregatedTicketKanbanStates = await new Parse.Query(types_1.Maintenance_Ticket_Kanban_State).aggregate(currentPagePipeline,
|
|
25
|
+
//@ts-expect-error
|
|
26
|
+
{ useMasterKey: true });
|
|
26
27
|
const totalCountPipeline = [
|
|
27
28
|
{ $group: { _id: "ticket" } }, // Group by ticket to only get the latest state of the ticket
|
|
28
29
|
{ $match: { state: state } }, // only get tickets with the state provided
|
|
29
30
|
{ count: { $sum: 1 } }, // count the number of tickets
|
|
30
31
|
];
|
|
31
|
-
const totalCount = await new Parse.Query(types_1.Maintenance_Ticket_Kanban_State).aggregate(
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const totalCount = await new Parse.Query(types_1.Maintenance_Ticket_Kanban_State).aggregate(totalCountPipeline,
|
|
33
|
+
//@ts-expect-error
|
|
34
|
+
{ useMasterKey: true });
|
|
34
35
|
return {
|
|
35
36
|
success: true,
|
|
36
37
|
ticketsStates: aggregatedTicketKanbanStates ?? [],
|