@openinc/parse-server-opendash 2.4.32 → 2.4.34

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,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.init = init;
7
+ const types_1 = require("../types");
8
+ const parse_1 = __importDefault(require("parse"));
9
+ async function init(name) {
10
+ parse_1.default.Cloud.define(name, async function (request) {
11
+ if (typeof request.user === "undefined") {
12
+ return { success: false, error: "User not found" };
13
+ }
14
+ if (!request.params?.state)
15
+ return { success: false, error: "StateID not provided" };
16
+ const cursor = request.params?.cursor || 0;
17
+ const limit = request.params?.limit || 10;
18
+ const state = new parse_1.default.Query(types_1.Maintenance_Kanban_State).get(request.params?.state);
19
+ const currentPagePipeline = [
20
+ { group: { _id: "ticket", doc: { $first: "$$ROOT" } } }, // Group by ticket to only get the latest state of the ticket
21
+ { match: { state: state } }, // only get tickets with the state provided
22
+ { sort: { createdAt: 1 } }, // sort by createdAt
23
+ { match: { createdAt: { $lt: new Date(cursor) } } }, // only get tickets with createdAt less than the cursor => pagination
24
+ { limit: limit }, // limit the number of tickets recieved
25
+ { replaceRoot: { newRoot: "$doc" } }, // replace the root of the document with the ticket
26
+ ];
27
+ const aggregatedTicketKanbanStates = await new parse_1.default.Query(types_1.Maintenance_Ticket_Kanban_State).aggregate(
28
+ // @ts-expect-error
29
+ currentPagePipeline);
30
+ const totalCountPipeline = [
31
+ { $group: { _id: "ticket" } }, // Group by ticket to only get the latest state of the ticket
32
+ { $match: { state: state } }, // only get tickets with the state provided
33
+ { count: { $sum: 1 } }, // count the number of tickets
34
+ ];
35
+ const totalCount = await new parse_1.default.Query(types_1.Maintenance_Ticket_Kanban_State).aggregate(
36
+ // @ts-expect-error
37
+ totalCountPipeline);
38
+ return {
39
+ success: true,
40
+ ticketsStates: aggregatedTicketKanbanStates ?? [],
41
+ totalCount: totalCount[0]?.count ?? 0,
42
+ };
43
+ }, {
44
+ requireUser: true,
45
+ });
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "2.4.32",
3
+ "version": "2.4.34",
4
4
  "description": "Parse Server Cloud Code for open.DASH",
5
5
  "keywords": [
6
6
  "parse",