@openinc/parse-server-opendash 2.4.54 → 2.4.59

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.
Files changed (87) hide show
  1. package/dist/config.js +9 -0
  2. package/dist/featuremap.json +7 -5
  3. package/dist/functions/openinc-deregister-permission.d.ts +5 -0
  4. package/dist/functions/openinc-deregister-permission.js +61 -0
  5. package/dist/functions/openinc-register-permission.d.ts +10 -0
  6. package/dist/functions/openinc-register-permission.js +51 -0
  7. package/dist/helper/catchError.d.ts +7 -0
  8. package/dist/helper/catchError.js +24 -0
  9. package/dist/helper/removeShorltyPreviousEntry.d.ts +2 -0
  10. package/dist/helper/removeShorltyPreviousEntry.js +23 -0
  11. package/dist/hooks/Company.js +1 -0
  12. package/dist/hooks/Contact.js +1 -0
  13. package/dist/hooks/{Maintenance_Article.js → Documentation_Category.js} +2 -2
  14. package/dist/hooks/Documentation_Document.js +17 -0
  15. package/dist/hooks/{Maintenance_File.js → Knowledge_Chat.js} +2 -2
  16. package/dist/hooks/Knowledge_ChatMessage.d.ts +1 -0
  17. package/dist/hooks/{Maintenance_Schedule.js → Knowledge_ChatMessage.js} +2 -2
  18. package/dist/hooks/Maintenance_Downtime.js +16 -2
  19. package/dist/hooks/Maintenance_Duedate.js +16 -1
  20. package/dist/hooks/Maintenance_Frequency.js +16 -1
  21. package/dist/hooks/Maintenance_Priority.js +16 -2
  22. package/dist/hooks/Maintenance_Restriction.js +16 -1
  23. package/dist/hooks/Maintenance_Schedule_Execution.js +48 -2
  24. package/dist/hooks/Maintenance_Schedule_Template.d.ts +1 -0
  25. package/dist/hooks/Maintenance_Schedule_Template.js +17 -0
  26. package/dist/hooks/Maintenance_Ticket_Assignment.d.ts +1 -0
  27. package/dist/hooks/Maintenance_Ticket_Assignment.js +17 -0
  28. package/dist/hooks/Maintenance_Ticket_Issuecategory.js +16 -2
  29. package/dist/hooks/Maintenance_Ticket_Kanban_State.js +24 -7
  30. package/dist/hooks/Maintenance_Ticket_Source.js +16 -0
  31. package/dist/hooks/Maintenance_Ticket_Title.d.ts +1 -0
  32. package/dist/hooks/Maintenance_Ticket_Title.js +33 -0
  33. package/dist/hooks/Notification.js +1 -0
  34. package/dist/index.js +1 -0
  35. package/dist/types/Contact.d.ts +0 -3
  36. package/dist/types/Contact.js +0 -6
  37. package/dist/types/Documentation_Category.d.ts +16 -0
  38. package/dist/types/Documentation_Category.js +23 -0
  39. package/dist/types/Documentation_Document.d.ts +30 -0
  40. package/dist/types/Documentation_Document.js +47 -0
  41. package/dist/types/Maintenance_Media.d.ts +3 -3
  42. package/dist/types/Maintenance_Media.js +4 -4
  43. package/dist/types/Maintenance_Schedule_Execution.d.ts +7 -4
  44. package/dist/types/Maintenance_Schedule_Execution.js +6 -0
  45. package/dist/types/Maintenance_Schedule_Execution_Step.d.ts +20 -28
  46. package/dist/types/Maintenance_Schedule_Execution_Step.js +16 -34
  47. package/dist/types/Maintenance_Schedule_Step.d.ts +11 -23
  48. package/dist/types/Maintenance_Schedule_Step.js +14 -38
  49. package/dist/types/Maintenance_Schedule_Template.d.ts +32 -0
  50. package/dist/types/Maintenance_Schedule_Template.js +47 -0
  51. package/dist/types/Maintenance_Source_File.d.ts +3 -3
  52. package/dist/types/Maintenance_Ticket.d.ts +0 -3
  53. package/dist/types/Maintenance_Ticket.js +0 -3
  54. package/dist/types/Maintenance_Ticket_Assignment.d.ts +32 -0
  55. package/dist/types/Maintenance_Ticket_Assignment.js +47 -0
  56. package/dist/types/Maintenance_Ticket_Title.d.ts +25 -0
  57. package/dist/types/Maintenance_Ticket_Title.js +35 -0
  58. package/dist/types/Notification.d.ts +3 -0
  59. package/dist/types/Notification.js +6 -0
  60. package/dist/types/Report.d.ts +9 -0
  61. package/dist/types/Report.js +18 -0
  62. package/dist/types/index.d.ts +10 -6
  63. package/dist/types/index.js +12 -8
  64. package/package.json +5 -3
  65. package/schema/Contact.json +0 -4
  66. package/schema/Documentation_Category.json +40 -0
  67. package/schema/Documentation_Document.json +57 -0
  68. package/schema/Maintenance_Media.json +2 -2
  69. package/schema/Maintenance_Schedule_Execution.json +5 -1
  70. package/schema/Maintenance_Schedule_Execution_Step.json +24 -28
  71. package/schema/Maintenance_Schedule_Step.json +9 -22
  72. package/schema/{Maintenance_Schedule.json → Maintenance_Schedule_Template.json} +19 -21
  73. package/schema/Maintenance_Source_File.json +1 -1
  74. package/schema/Maintenance_Ticket.json +0 -5
  75. package/schema/{Maintenance_Article.json → Maintenance_Ticket_Assignment.json} +20 -17
  76. package/schema/{Maintenance_File.json → Maintenance_Ticket_Title.json} +18 -15
  77. package/schema/Notification.json +5 -0
  78. package/schema/Report.json +13 -0
  79. package/dist/types/Maintenance_Article.d.ts +0 -31
  80. package/dist/types/Maintenance_Article.js +0 -44
  81. package/dist/types/Maintenance_File.d.ts +0 -24
  82. package/dist/types/Maintenance_File.js +0 -35
  83. package/dist/types/Maintenance_Schedule.d.ts +0 -36
  84. package/dist/types/Maintenance_Schedule.js +0 -56
  85. /package/dist/hooks/{Maintenance_Article.d.ts → Documentation_Category.d.ts} +0 -0
  86. /package/dist/hooks/{Maintenance_File.d.ts → Documentation_Document.d.ts} +0 -0
  87. /package/dist/hooks/{Maintenance_Schedule.d.ts → Knowledge_Chat.d.ts} +0 -0
package/dist/config.js CHANGED
@@ -242,6 +242,15 @@ const options = {
242
242
  default: "false",
243
243
  description: "This will force the schema to be updated on startup including removing fields and classes, which is a destructive operation and can result in data loss.",
244
244
  },
245
+ FORCE_DELETE_CLASS: {
246
+ env: "OPENINC_PARSE_FORCE_DELETE_CLASS",
247
+ type: "boolean",
248
+ required: false,
249
+ secret: false,
250
+ public: false,
251
+ default: "false",
252
+ description: "This will work as FORCE_SCHEMA and will also delete entries in non-empty classes. Just a safety hook.",
253
+ },
245
254
  EMAIL_TEMPLATE_DIR: {
246
255
  env: "OPENINC_PARSE_EMAIL_TEMPLATE_DIR",
247
256
  type: "string",
@@ -15,6 +15,9 @@
15
15
  "OD3_Core_Email": "CORE",
16
16
  "OD3_Core_Token": "CORE",
17
17
  "OD3_Dashboard": "MONITORING",
18
+ "OD3_Documentation_Category": "DOCUMENTATION",
19
+ "OD3_Documentation_Document": "DOCUMENTATION",
20
+ "OD3_Group": "CORE",
18
21
  "OD3_GTFS_Agency": "GTFS",
19
22
  "OD3_GTFS_Bikes_Allowed": "GTFS",
20
23
  "OD3_GTFS_Calendar": "GTFS",
@@ -28,7 +31,6 @@
28
31
  "OD3_GTFS_Trip": "GTFS",
29
32
  "OD3_GTFS_Wheelchair_Accessible": "GTFS",
30
33
  "OD3_GTFS_Wheelchair_Boarding": "GTFS",
31
- "OD3_Group": "CORE",
32
34
  "OD3_Knowledge_Article": "KNOWLEDGE",
33
35
  "OD3_Knowledge_Category": "KNOWLEDGE",
34
36
  "OD3_Knowledge_Chat": "KNOWLEDGE",
@@ -38,13 +40,10 @@
38
40
  "OD3_Knowledge_Video": "KNOWLEDGE",
39
41
  "OD3_Language": "CORE",
40
42
  "OD3_Log": "CORE",
41
- "OD3_MIAAS_MDSEndpoint": "MIAAS",
42
43
  "OD3_MailTemplate": "MONITORING",
43
- "OD3_Maintenance_Article": "MAINTENANCE",
44
44
  "OD3_Maintenance_DailySchedule": "MAINTENANCE",
45
45
  "OD3_Maintenance_Downtime": "MAINTENANCE",
46
46
  "OD3_Maintenance_Duedate": "MAINTENANCE",
47
- "OD3_Maintenance_File": "MAINTENANCE",
48
47
  "OD3_Maintenance_Frequency": "MAINTENANCE",
49
48
  "OD3_Maintenance_Issuecategory": "MAINTENANCE",
50
49
  "OD3_Maintenance_Item": "MAINTENANCE",
@@ -55,17 +54,20 @@
55
54
  "OD3_Maintenance_Order": "MAINTENANCE",
56
55
  "OD3_Maintenance_Priority": "MAINTENANCE",
57
56
  "OD3_Maintenance_Restriction": "MAINTENANCE",
58
- "OD3_Maintenance_Schedule": "MAINTENANCE",
59
57
  "OD3_Maintenance_Schedule_Execution": "MAINTENANCE",
60
58
  "OD3_Maintenance_Schedule_Execution_Step": "MAINTENANCE",
61
59
  "OD3_Maintenance_Schedule_Step": "MAINTENANCE",
60
+ "OD3_Maintenance_Schedule_Template": "MAINTENANCE",
62
61
  "OD3_Maintenance_SourceMeta": "MAINTENANCE",
63
62
  "OD3_Maintenance_Source_File": "MAINTENANCE",
64
63
  "OD3_Maintenance_Ticket": "MAINTENANCE",
64
+ "OD3_Maintenance_Ticket_Assignment": "MAINTENANCE",
65
65
  "OD3_Maintenance_Ticket_Issuecategory": "MAINTENANCE",
66
66
  "OD3_Maintenance_Ticket_Kanban_State": "MAINTENANCE",
67
67
  "OD3_Maintenance_Ticket_Kanban_State_Current": "MAINTENANCE",
68
68
  "OD3_Maintenance_Ticket_Source": "MAINTENANCE",
69
+ "OD3_Maintenance_Ticket_Title": "MAINTENANCE",
70
+ "OD3_MIAAS_MDSEndpoint": "MIAAS",
69
71
  "OD3_Monitoring_DataHierachies": "MONITORING",
70
72
  "OD3_Monitoring_Jobs": "MONITORING",
71
73
  "OD3_Monitoring_ReportImage": "MONITORING",
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This function deregisters a permission in the database on a tenant level.
3
+ * @param name The function name derived from the file name
4
+ */
5
+ export declare function init(name: string): Promise<void>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.init = init;
4
+ const types_1 = require("../types");
5
+ /**
6
+ * This function deregisters a permission in the database on a tenant level.
7
+ * @param name The function name derived from the file name
8
+ */
9
+ async function init(name) {
10
+ Parse.Cloud.define(name, async function (request) {
11
+ if (typeof request.user === "undefined") {
12
+ return { success: false, error: "User is not provided." };
13
+ }
14
+ //Get the current user
15
+ const user = request.user;
16
+ if (!user) {
17
+ return { success: false, error: "User is required." };
18
+ }
19
+ //Get the tenant of the current user
20
+ const tenant = user.get("tenant");
21
+ const permissionKey = request.params.permissionKey;
22
+ if (!permissionKey) {
23
+ return { success: false, error: "Permission key is required." };
24
+ }
25
+ //Find the permission with key permissionKey and delete it
26
+ const permissions = await new Parse.Query(types_1.Permission)
27
+ .equalTo("key", permissionKey)
28
+ .equalTo("tenant", tenant)
29
+ .find({ useMasterKey: true });
30
+ const role = await new Parse.Query(Parse.Role)
31
+ .equalTo("name", "od-tenant-admin-" + tenant.id)
32
+ .first({ useMasterKey: true });
33
+ // Check if the permission can be written publically or by the current user or the tenant role
34
+ const filteredpermissions = permissions.filter((permission) => {
35
+ const acl = permission.getACL();
36
+ return acl?.getPublicWriteAccess() ||
37
+ acl?.getWriteAccess(user.id) ||
38
+ typeof role !== "undefined"
39
+ ? acl?.getRoleWriteAccess(role)
40
+ : false;
41
+ });
42
+ if (permissions.length === 0) {
43
+ console.info(`Permissions with key ${permissionKey} not found.`);
44
+ }
45
+ else {
46
+ console.info(`Permission with key ${permissionKey} found. Deleting...`);
47
+ for await (const permission of filteredpermissions) {
48
+ await permission.destroy({ useMasterKey: true });
49
+ }
50
+ }
51
+ return { success: true };
52
+ }, {
53
+ requireUser: true,
54
+ fields: {
55
+ permissionKey: {
56
+ required: true,
57
+ type: String,
58
+ },
59
+ },
60
+ });
61
+ }
@@ -0,0 +1,10 @@
1
+ export interface PermissionInterface {
2
+ label: string;
3
+ description: string;
4
+ key: string;
5
+ }
6
+ /**
7
+ * This function registers a new permission in the database on a tenant level.
8
+ * @param name The function name derived from the file name
9
+ */
10
+ export declare function init(name: string): Promise<void>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.init = init;
4
+ const types_1 = require("../types");
5
+ /**
6
+ * This function registers a new permission in the database on a tenant level.
7
+ * @param name The function name derived from the file name
8
+ */
9
+ async function init(name) {
10
+ Parse.Cloud.define(name, async function (request) {
11
+ if (typeof request.user === "undefined") {
12
+ return { success: false, error: "User is not provided." };
13
+ }
14
+ //Get the current user
15
+ const user = request.user;
16
+ if (!user) {
17
+ return { success: false, error: "User is required." };
18
+ }
19
+ //Get the tenant of the current user
20
+ const tenant = user.get("tenant");
21
+ const permission = request.params
22
+ .permission;
23
+ //Check if the Permission with key already exists
24
+ const existingpermission = await new Parse.Query(types_1.Permission)
25
+ .equalTo("key", permission.key)
26
+ .equalTo("tenant", tenant)
27
+ .find({ useMasterKey: true });
28
+ //If the permission does not exist, create it
29
+ if (existingpermission.length === 0) {
30
+ console.log(`Permission with key ${permission.key} does not exist. Will be created.`);
31
+ const newPermission = new types_1.Permission();
32
+ newPermission.set("label", permission.label);
33
+ newPermission.set("description", permission.description);
34
+ newPermission.set("key", permission.key);
35
+ newPermission.set("tenant", tenant);
36
+ await newPermission.save({}, { useMasterKey: true });
37
+ }
38
+ else {
39
+ console.log(`Permission with key ${permission.key} already exists. Continue.`);
40
+ }
41
+ return { success: true };
42
+ }, {
43
+ requireUser: true,
44
+ fields: {
45
+ permission: {
46
+ required: true,
47
+ type: Object,
48
+ },
49
+ },
50
+ });
51
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Catch errors from a promise and return them as an array or the result
3
+ * @param promise A promise to catch errors from
4
+ * @param errorsToCatch An array of error classes to catch. If not provided, all errors will be caught.
5
+ * @returns The promise result or an array with the error
6
+ */
7
+ export declare function catchError<T, E extends new (Message?: string) => Error>(promise: Promise<T>, errorsToCatch?: E[]): Promise<[undefined, T] | [InstanceType<E>]>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.catchError = catchError;
4
+ /**
5
+ * Catch errors from a promise and return them as an array or the result
6
+ * @param promise A promise to catch errors from
7
+ * @param errorsToCatch An array of error classes to catch. If not provided, all errors will be caught.
8
+ * @returns The promise result or an array with the error
9
+ */
10
+ async function catchError(promise, errorsToCatch) {
11
+ try {
12
+ const data = await promise;
13
+ return [undefined, data];
14
+ }
15
+ catch (error) {
16
+ if (errorsToCatch === undefined) {
17
+ return [error];
18
+ }
19
+ if (errorsToCatch.some((e) => error instanceof e)) {
20
+ return [error];
21
+ }
22
+ throw error;
23
+ }
24
+ }
@@ -0,0 +1,2 @@
1
+ export declare function removeShortlyPreviousEntry<T extends Parse.Object>(entry: T, onQuery: (query: Parse.Query<T>) => Parse.Query<T>, overrideTime?: number): Promise<void>;
2
+ export declare function removeEqualSaved<T extends Parse.Object>(entry: T, onQuery: (query: Parse.Query<T>) => Parse.Query<T>, isEqual: (frist: T, second: T) => boolean): Promise<T>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeShortlyPreviousEntry = removeShortlyPreviousEntry;
4
+ exports.removeEqualSaved = removeEqualSaved;
5
+ async function removeShortlyPreviousEntry(entry, onQuery, overrideTime = 300) {
6
+ const query = onQuery(new Parse.Query(entry.className));
7
+ const object = await query.first({ useMasterKey: true });
8
+ const lastEntryTime = object?.get("createdAt")?.getTime();
9
+ const currentTime = new Date().getTime();
10
+ const timeDifferenceInSeconds = (currentTime - lastEntryTime) / 1000;
11
+ if (timeDifferenceInSeconds <= overrideTime) {
12
+ await object?.destroy({ useMasterKey: true });
13
+ }
14
+ }
15
+ async function removeEqualSaved(entry, onQuery, isEqual) {
16
+ const query = onQuery(new Parse.Query(entry.className));
17
+ const object = await query.first({ useMasterKey: true });
18
+ if (object && isEqual(entry, object)) {
19
+ await entry.destroy({ useMasterKey: true });
20
+ return object;
21
+ }
22
+ return entry;
23
+ }
@@ -7,6 +7,7 @@ async function init() {
7
7
  (0, __1.beforeSaveHook)(types_1.Company, async (request) => {
8
8
  const { object, original, user } = request;
9
9
  await (0, __1.defaultHandler)(request);
10
+ await (0, __1.defaultAclHandler)(request);
10
11
  // TODO
11
12
  });
12
13
  (0, __1.afterSaveHook)(types_1.Company, async ({ object, original, user }) => {
@@ -7,6 +7,7 @@ async function init() {
7
7
  (0, __1.beforeSaveHook)(types_1.Contact, async (request) => {
8
8
  const { object, original, user } = request;
9
9
  await (0, __1.defaultHandler)(request);
10
+ await (0, __1.defaultAclHandler)(request);
10
11
  // TODO
11
12
  });
12
13
  (0, __1.afterSaveHook)(types_1.Contact, async ({ object, original, user }) => {
@@ -4,13 +4,13 @@ exports.init = init;
4
4
  const __1 = require("..");
5
5
  const types_1 = require("../types");
6
6
  async function init() {
7
- (0, __1.beforeSaveHook)(types_1.Maintenance_Article, async (request) => {
7
+ (0, __1.beforeSaveHook)(types_1.Documentation_Category, async (request) => {
8
8
  const { object, original, user } = request;
9
9
  await (0, __1.defaultHandler)(request);
10
10
  await (0, __1.defaultAclHandler)(request);
11
11
  // TODO
12
12
  });
13
- (0, __1.afterSaveHook)(types_1.Maintenance_Article, async (request) => {
13
+ (0, __1.afterSaveHook)(types_1.Documentation_Category, async (request) => {
14
14
  const { object, original, user } = request;
15
15
  // TODO
16
16
  });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.init = init;
4
+ const __1 = require("..");
5
+ const types_1 = require("../types");
6
+ async function init() {
7
+ (0, __1.beforeSaveHook)(types_1.Documentation_Document, async (request) => {
8
+ const { object, original, user } = request;
9
+ await (0, __1.defaultHandler)(request);
10
+ await (0, __1.defaultAclHandler)(request);
11
+ // TODO
12
+ });
13
+ (0, __1.afterSaveHook)(types_1.Documentation_Document, async (request) => {
14
+ const { object, original, user } = request;
15
+ // TODO
16
+ });
17
+ }
@@ -4,13 +4,13 @@ exports.init = init;
4
4
  const __1 = require("..");
5
5
  const types_1 = require("../types");
6
6
  async function init() {
7
- (0, __1.beforeSaveHook)(types_1.Maintenance_File, async (request) => {
7
+ (0, __1.beforeSaveHook)(types_1.Knowledge_Chat, async (request) => {
8
8
  const { object, original, user } = request;
9
9
  await (0, __1.defaultHandler)(request);
10
10
  await (0, __1.defaultAclHandler)(request);
11
11
  // TODO
12
12
  });
13
- (0, __1.afterSaveHook)(types_1.Maintenance_File, async (request) => {
13
+ (0, __1.afterSaveHook)(types_1.Knowledge_Chat, async (request) => {
14
14
  const { object, original, user } = request;
15
15
  // TODO
16
16
  });
@@ -0,0 +1 @@
1
+ export declare function init(): Promise<void>;
@@ -4,13 +4,13 @@ exports.init = init;
4
4
  const __1 = require("..");
5
5
  const types_1 = require("../types");
6
6
  async function init() {
7
- (0, __1.beforeSaveHook)(types_1.Maintenance_Schedule, async (request) => {
7
+ (0, __1.beforeSaveHook)(types_1.Knowledge_ChatMessage, async (request) => {
8
8
  const { object, original, user } = request;
9
9
  await (0, __1.defaultHandler)(request);
10
10
  await (0, __1.defaultAclHandler)(request);
11
11
  // TODO
12
12
  });
13
- (0, __1.afterSaveHook)(types_1.Maintenance_Schedule, async (request) => {
13
+ (0, __1.afterSaveHook)(types_1.Knowledge_ChatMessage, async (request) => {
14
14
  const { object, original, user } = request;
15
15
  // TODO
16
16
  });
@@ -2,16 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
4
  const __1 = require("..");
5
+ const removeShorltyPreviousEntry_1 = require("../helper/removeShorltyPreviousEntry");
5
6
  const types_1 = require("../types");
6
7
  async function init() {
7
8
  (0, __1.beforeSaveHook)(types_1.Maintenance_Downtime, async (request) => {
8
9
  const { object, original, user } = request;
9
10
  await (0, __1.defaultHandler)(request);
10
11
  await (0, __1.defaultAclHandler)(request);
11
- // TODO
12
+ // Remove previous entry if it was created within 5 minutes
13
+ await (0, removeShorltyPreviousEntry_1.removeShortlyPreviousEntry)(object, (query) => {
14
+ query.equalTo("ticket", object.get("ticket"));
15
+ query.descending("createdAt");
16
+ return query;
17
+ });
12
18
  });
13
19
  (0, __1.afterSaveHook)(types_1.Maintenance_Downtime, async (request) => {
14
20
  const { object, original, user } = request;
15
- // TODO
21
+ // Remove entry if it has the same values as the previous entry so its simply reverted to the already existing entry
22
+ await (0, removeShorltyPreviousEntry_1.removeEqualSaved)(object, (query) => {
23
+ query.includeAll();
24
+ query.equalTo("ticket", object.get("ticket"));
25
+ query.notEqualTo("objectId", object.id);
26
+ return query;
27
+ }, (first, second) => {
28
+ return first.get("value") === second.get("value");
29
+ });
16
30
  });
17
31
  }
@@ -2,16 +2,31 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
4
  const __1 = require("..");
5
+ const removeShorltyPreviousEntry_1 = require("../helper/removeShorltyPreviousEntry");
5
6
  const types_1 = require("../types");
6
7
  async function init() {
7
8
  (0, __1.beforeSaveHook)(types_1.Maintenance_Duedate, async (request) => {
8
9
  const { object, original, user } = request;
9
10
  await (0, __1.defaultHandler)(request);
10
11
  await (0, __1.defaultAclHandler)(request);
11
- // TODO
12
+ // Remove previous entry if it was created within 5 minutes
13
+ await (0, removeShorltyPreviousEntry_1.removeShortlyPreviousEntry)(object, (query) => {
14
+ query.equalTo("ticket", object.get("ticket"));
15
+ query.descending("createdAt");
16
+ return query;
17
+ });
12
18
  });
13
19
  (0, __1.afterSaveHook)(types_1.Maintenance_Duedate, async (request) => {
14
20
  const { object, original, user } = request;
21
+ // Remove entry if it has the same values as the previous entry so its simply reverted to the already existing entry
22
+ await (0, removeShorltyPreviousEntry_1.removeEqualSaved)(object, (query) => {
23
+ query.includeAll();
24
+ query.equalTo("ticket", object.get("ticket"));
25
+ query.notEqualTo("objectId", object.id);
26
+ return query;
27
+ }, (first, second) => {
28
+ return first.get("end")?.getTime() === second.get("end")?.getTime();
29
+ });
15
30
  // TODO
16
31
  });
17
32
  }
@@ -2,16 +2,31 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
4
  const __1 = require("..");
5
+ const removeShorltyPreviousEntry_1 = require("../helper/removeShorltyPreviousEntry");
5
6
  const types_1 = require("../types");
6
7
  async function init() {
7
8
  (0, __1.beforeSaveHook)(types_1.Maintenance_Frequency, async (request) => {
8
9
  const { object, original, user } = request;
9
10
  await (0, __1.defaultHandler)(request);
10
11
  await (0, __1.defaultAclHandler)(request);
11
- // TODO
12
+ // Remove previous entry if it was created within 5 minutes
13
+ await (0, removeShorltyPreviousEntry_1.removeShortlyPreviousEntry)(object, (query) => {
14
+ query.equalTo("ticket", object.get("ticket"));
15
+ query.descending("createdAt");
16
+ return query;
17
+ });
12
18
  });
13
19
  (0, __1.afterSaveHook)(types_1.Maintenance_Frequency, async (request) => {
14
20
  const { object, original, user } = request;
21
+ // Remove entry if it has the same values as the previous entry so its simply reverted to the already existing entry
22
+ await (0, removeShorltyPreviousEntry_1.removeEqualSaved)(object, (query) => {
23
+ query.includeAll();
24
+ query.equalTo("ticket", object.get("ticket"));
25
+ query.notEqualTo("objectId", object.id);
26
+ return query;
27
+ }, (first, second) => {
28
+ return first.get("value") === second.get("value");
29
+ });
15
30
  // TODO
16
31
  });
17
32
  }
@@ -2,16 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
4
  const __1 = require("..");
5
+ const removeShorltyPreviousEntry_1 = require("../helper/removeShorltyPreviousEntry");
5
6
  const types_1 = require("../types");
6
7
  async function init() {
7
8
  (0, __1.beforeSaveHook)(types_1.Maintenance_Priority, async (request) => {
8
9
  const { object, original, user } = request;
9
10
  await (0, __1.defaultHandler)(request);
10
11
  await (0, __1.defaultAclHandler)(request);
11
- // TODO
12
+ // Remove previous entry if it was created within 5 minutes
13
+ await (0, removeShorltyPreviousEntry_1.removeShortlyPreviousEntry)(object, (query) => {
14
+ query.equalTo("ticket", object.get("ticket"));
15
+ query.descending("createdAt");
16
+ return query;
17
+ });
12
18
  });
13
19
  (0, __1.afterSaveHook)(types_1.Maintenance_Priority, async (request) => {
14
20
  const { object, original, user } = request;
15
- // TODO
21
+ // Remove entry if it has the same values as the previous entry so its simply reverted to the already existing entry
22
+ await (0, removeShorltyPreviousEntry_1.removeEqualSaved)(object, (query) => {
23
+ query.includeAll();
24
+ query.equalTo("ticket", object.get("ticket"));
25
+ query.notEqualTo("objectId", object.id);
26
+ return query;
27
+ }, (first, second) => {
28
+ return first.get("value") === second.get("value");
29
+ });
16
30
  });
17
31
  }
@@ -2,16 +2,31 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
4
  const __1 = require("..");
5
+ const removeShorltyPreviousEntry_1 = require("../helper/removeShorltyPreviousEntry");
5
6
  const types_1 = require("../types");
6
7
  async function init() {
7
8
  (0, __1.beforeSaveHook)(types_1.Maintenance_Restriction, async (request) => {
8
9
  const { object, original, user } = request;
9
10
  await (0, __1.defaultHandler)(request);
10
11
  await (0, __1.defaultAclHandler)(request);
11
- // TODO
12
+ // Remove previous entry if it was created within 5 minutes
13
+ await (0, removeShorltyPreviousEntry_1.removeShortlyPreviousEntry)(object, (query) => {
14
+ query.equalTo("ticket", object.get("ticket"));
15
+ query.descending("createdAt");
16
+ return query;
17
+ });
12
18
  });
13
19
  (0, __1.afterSaveHook)(types_1.Maintenance_Restriction, async (request) => {
14
20
  const { object, original, user } = request;
21
+ // Remove entry if it has the same values as the previous entry so its simply reverted to the already existing entry
22
+ await (0, removeShorltyPreviousEntry_1.removeEqualSaved)(object, (query) => {
23
+ query.includeAll();
24
+ query.equalTo("ticket", object.get("ticket"));
25
+ query.notEqualTo("objectId", object.id);
26
+ return query;
27
+ }, (first, second) => {
28
+ return first.get("value") === second.get("value");
29
+ });
15
30
  // TODO
16
31
  });
17
32
  }
@@ -2,16 +2,62 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.init = init;
4
4
  const __1 = require("..");
5
+ const catchError_1 = require("../helper/catchError");
5
6
  const types_1 = require("../types");
6
7
  async function init() {
7
8
  (0, __1.beforeSaveHook)(types_1.Maintenance_Schedule_Execution, async (request) => {
8
9
  const { object, original, user } = request;
9
10
  await (0, __1.defaultHandler)(request);
10
11
  await (0, __1.defaultAclHandler)(request);
11
- // TODO
12
12
  });
13
13
  (0, __1.afterSaveHook)(types_1.Maintenance_Schedule_Execution, async (request) => {
14
14
  const { object, original, user } = request;
15
- // TODO
15
+ const tenant = object.get("tenant")
16
+ ? object.get("tenant")
17
+ : Parse.User.current()
18
+ ? Parse.User.current().get("tenant")
19
+ : undefined;
20
+ if (typeof object.origin === "undefined" || typeof tenant === "undefined") {
21
+ return;
22
+ }
23
+ const [fetchedOriginError, fetchedOrigin] = await (0, catchError_1.catchError)(new Parse.Query(types_1.Maintenance_Schedule_Template)
24
+ .includeAll()
25
+ .get(object.origin.id, {
26
+ useMasterKey: true,
27
+ }));
28
+ if (typeof fetchedOrigin === "undefined") {
29
+ return;
30
+ }
31
+ const [stepserror, steps] = await (0, catchError_1.catchError)(fetchedOrigin
32
+ .get("steps")
33
+ .query()
34
+ .includeAll()
35
+ .find({ useMasterKey: true }));
36
+ if (stepserror) {
37
+ throw stepserror;
38
+ }
39
+ //For every step create a new step object and save as Maintenance_Schedule_Execution_Step
40
+ for await (const step of steps) {
41
+ const [roleserror, roles] = await (0, catchError_1.catchError)(step.relation("roles").query().find({ useMasterKey: true }));
42
+ const [mediaerror, media] = await (0, catchError_1.catchError)(step.relation("media").query().find({ useMasterKey: true }));
43
+ const executionstep = new types_1.Maintenance_Schedule_Execution_Step({
44
+ done: false,
45
+ comment: "",
46
+ scheduleexecution: object,
47
+ tenant: tenant,
48
+ description: step.get("description"),
49
+ title: step.get("title"),
50
+ fields: step.get("data"),
51
+ });
52
+ const mediarelation = executionstep.relation("media");
53
+ if (typeof media !== "undefined") {
54
+ mediarelation.add(media);
55
+ }
56
+ const rolesrelation = executionstep.relation("roles");
57
+ if (typeof roles !== "undefined") {
58
+ rolesrelation.add(roles);
59
+ }
60
+ const [stepsaveerror, stepsaveobject] = await (0, catchError_1.catchError)(executionstep.save(null, { useMasterKey: true }));
61
+ }
16
62
  });
17
63
  }
@@ -0,0 +1 @@
1
+ export declare function init(): Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.init = init;
4
+ const __1 = require("..");
5
+ const types_1 = require("../types");
6
+ async function init() {
7
+ (0, __1.beforeSaveHook)(types_1.Maintenance_Schedule_Template, async (request) => {
8
+ const { object, original, user } = request;
9
+ await (0, __1.defaultHandler)(request);
10
+ await (0, __1.defaultAclHandler)(request);
11
+ // TODO
12
+ });
13
+ (0, __1.afterSaveHook)(types_1.Maintenance_Schedule_Template, async (request) => {
14
+ const { object, original, user } = request;
15
+ // TODO
16
+ });
17
+ }
@@ -0,0 +1 @@
1
+ export declare function init(): Promise<void>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.init = init;
4
+ const __1 = require("..");
5
+ const types_1 = require("../types");
6
+ async function init() {
7
+ (0, __1.beforeSaveHook)(types_1.Maintenance_Ticket_Assignment, async (request) => {
8
+ const { object, original, user } = request;
9
+ await (0, __1.defaultHandler)(request);
10
+ await (0, __1.defaultAclHandler)(request);
11
+ // TODO
12
+ });
13
+ (0, __1.afterSaveHook)(types_1.Maintenance_Ticket_Assignment, async (request) => {
14
+ const { object, original, user } = request;
15
+ // TODO
16
+ });
17
+ }