@openinc/parse-server-opendash 2.4.33 → 2.4.35

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.
@@ -0,0 +1 @@
1
+ export declare function init(name: string): Promise<void>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.init = init;
4
+ const types_1 = require("../types");
5
+ async function init(name) {
6
+ Parse.Cloud.define(name, async function (request) {
7
+ if (typeof request.user === "undefined") {
8
+ return { success: false, error: "User not found" };
9
+ }
10
+ if (!request.params?.state)
11
+ return { success: false, error: "StateID not provided" };
12
+ const cursor = request.params?.cursor || 0;
13
+ const limit = request.params?.limit || 10;
14
+ const state = new Parse.Query(types_1.Maintenance_Kanban_State).get(request.params?.state);
15
+ 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
22
+ ];
23
+ const aggregatedTicketKanbanStates = await new Parse.Query(types_1.Maintenance_Ticket_Kanban_State).aggregate(
24
+ // @ts-expect-error
25
+ currentPagePipeline);
26
+ const totalCountPipeline = [
27
+ { $group: { _id: "ticket" } }, // Group by ticket to only get the latest state of the ticket
28
+ { $match: { state: state } }, // only get tickets with the state provided
29
+ { count: { $sum: 1 } }, // count the number of tickets
30
+ ];
31
+ const totalCount = await new Parse.Query(types_1.Maintenance_Ticket_Kanban_State).aggregate(
32
+ // @ts-expect-error
33
+ totalCountPipeline);
34
+ return {
35
+ success: true,
36
+ ticketsStates: aggregatedTicketKanbanStates ?? [],
37
+ totalCount: totalCount[0]?.count ?? 0,
38
+ };
39
+ }, {
40
+ requireUser: true,
41
+ });
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "2.4.33",
3
+ "version": "2.4.35",
4
4
  "description": "Parse Server Cloud Code for open.DASH",
5
5
  "keywords": [
6
6
  "parse",