@pgds/api-interface 1.3.2 → 1.3.4

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.
@@ -24,9 +24,22 @@ export declare class ReqUser {
24
24
  * Returns the organizationIds in the hierarchy of the inputted organizationId
25
25
  * Input must be inside the user's organization hierarchy.
26
26
  * If no organization is inputted, it returns the ids in the user's organization hierarchy.
27
+ * If the organizationId is not in the user's hierarchy, it returns that id without any children. The reason for this is to prevent returning all organizations in the system if the result from this function is an empty array and used in a query.
27
28
  *
28
29
  * @param organizationId The organizationId to get the children of
30
+ * @param toOrganization Where to stop the search
31
+ * @returns {string[]} Organization tree ids in no particular order
32
+ *
33
+ * ```
34
+ * const organizationTreeIds = getOrganizationTreeIds("org1");
35
+ * console.log(organizationTreeIds); // ["org1", "org2", "org3"]
36
+ *
37
+ * const organizationTreeIds = getOrganizationTreeIds("org1", "org2");
38
+ * console.log(organizationTreeIds); // ["org1", "org2"]
39
+ * ```
29
40
  */
30
- getOrganizationTreeIds(organizationId?: string): string[];
41
+ getOrganizationTreeIds(organizationId?: string, toOrganization?: string): string[];
42
+ private getOrganizationTreeFromToIds;
43
+ private getCompleteOrganizationTreeIds;
31
44
  }
32
45
  export {};
@@ -14,10 +14,57 @@ var ReqUser = /** @class */ (function () {
14
14
  * Returns the organizationIds in the hierarchy of the inputted organizationId
15
15
  * Input must be inside the user's organization hierarchy.
16
16
  * If no organization is inputted, it returns the ids in the user's organization hierarchy.
17
+ * If the organizationId is not in the user's hierarchy, it returns that id without any children. The reason for this is to prevent returning all organizations in the system if the result from this function is an empty array and used in a query.
17
18
  *
18
19
  * @param organizationId The organizationId to get the children of
20
+ * @param toOrganization Where to stop the search
21
+ * @returns {string[]} Organization tree ids in no particular order
22
+ *
23
+ * ```
24
+ * const organizationTreeIds = getOrganizationTreeIds("org1");
25
+ * console.log(organizationTreeIds); // ["org1", "org2", "org3"]
26
+ *
27
+ * const organizationTreeIds = getOrganizationTreeIds("org1", "org2");
28
+ * console.log(organizationTreeIds); // ["org1", "org2"]
29
+ * ```
19
30
  */
20
- ReqUser.prototype.getOrganizationTreeIds = function (organizationId) {
31
+ ReqUser.prototype.getOrganizationTreeIds = function (organizationId, toOrganization) {
32
+ if (toOrganization) {
33
+ return this.getOrganizationTreeFromToIds(organizationId, toOrganization);
34
+ }
35
+ else {
36
+ return this.getCompleteOrganizationTreeIds(organizationId);
37
+ }
38
+ };
39
+ ReqUser.prototype.getOrganizationTreeFromToIds = function (fromOrganization, toOrganization) {
40
+ if ((!this.organizationHierarchy[toOrganization] &&
41
+ !Object.values(this.organizationHierarchy).includes(toOrganization)) ||
42
+ (!this.organizationHierarchy[fromOrganization] &&
43
+ !Object.values(this.organizationHierarchy).includes(fromOrganization))) {
44
+ return [toOrganization];
45
+ }
46
+ var stack = [];
47
+ var visited = new Set();
48
+ var result = [];
49
+ stack.push(toOrganization);
50
+ while (stack.length > 0) {
51
+ var currentOrgId = stack.pop();
52
+ if (visited.has(currentOrgId) || currentOrgId === fromOrganization) {
53
+ continue;
54
+ }
55
+ visited.add(currentOrgId);
56
+ for (var _i = 0, _a = Object.entries(this.organizationHierarchy); _i < _a.length; _i++) {
57
+ var _b = _a[_i], childId = _b[0], parentId = _b[1];
58
+ if (childId === currentOrgId && !visited.has(parentId)) {
59
+ stack.push(parentId);
60
+ result.push(currentOrgId);
61
+ }
62
+ }
63
+ }
64
+ result.push(fromOrganization);
65
+ return result;
66
+ };
67
+ ReqUser.prototype.getCompleteOrganizationTreeIds = function (organizationId) {
21
68
  var stack = [];
22
69
  var visited = new Set();
23
70
  var result = [];
@@ -27,6 +74,11 @@ var ReqUser = /** @class */ (function () {
27
74
  else {
28
75
  stack.push(organizationId);
29
76
  }
77
+ if (organizationId !== undefined &&
78
+ organizationId !== this.organizationId &&
79
+ !Object.keys(this.organizationHierarchy).includes(organizationId)) {
80
+ return [];
81
+ }
30
82
  while (stack.length > 0) {
31
83
  var currentOrgId = stack.pop();
32
84
  if (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;IACH,cAAC;AAAD,CAAC,AAtID,IAsIC;AAtIY,0BAAO"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@pgds/api-interface",
3
3
  "description": "Api interface for pgds services",
4
4
  "authors": "Florry",
5
- "version": "1.3.2",
5
+ "version": "1.3.4",
6
6
  "main": "index.js",
7
7
  "types": "types/",
8
8
  "scripts": {
@@ -100,4 +100,4 @@
100
100
  "**/*.js.map"
101
101
  ]
102
102
  }
103
- }
103
+ }