@dative-gpi/foundation-shared-domain 1.0.165 → 1.0.167-map-edit

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.
@@ -9,7 +9,6 @@ export class NotificationInfos {
9
9
  body: string;
10
10
  pageUrl: string;
11
11
  audiences: NotificationAudience[];
12
- organisationId?: string;
13
12
  type: MessageType;
14
13
  criticity: Criticity;
15
14
  imageId: string | null;
@@ -28,7 +27,6 @@ export class NotificationInfos {
28
27
  this.icon = params.icon;
29
28
  this.color = params.color;
30
29
  this.audiences = params.audiences.map((a: NotificationAudience) => new NotificationAudience(a));
31
- this.organisationId = params.organisationId;
32
30
  this.type = params.type as MessageType;
33
31
  this.criticity = params.criticity as Criticity;
34
32
  this.timestamp = isoToEpoch(params.timestamp);
@@ -44,7 +42,6 @@ export interface NotificationInfosDTO {
44
42
  body: string;
45
43
  pageUrl: string;
46
44
  audiences: NotificationAudience[];
47
- organisationId?: string;
48
45
  imageId: string | null;
49
46
  icon: string;
50
47
  color: string;
@@ -1,33 +1,36 @@
1
1
  export class OrganisationInfos {
2
- id: string;
3
- organisationTypeId: string;
4
- imageId: string | null;
5
- label: string;
6
- userOrganisationsCount: number;
7
- adminId: string | null;
8
- adminName: string | null;
2
+ id: string;
3
+ organisationTypeId: string;
4
+ imageId: string | null;
5
+ label: string;
6
+ userOrganisationsCount: number;
7
+ adminId: string | null;
8
+ adminName: string | null;
9
+ currentUserOrganisationId: string | null;
9
10
 
10
- constructor(params: OrganisationInfosDTO) {
11
- this.id = params.id;
12
- this.organisationTypeId = params.organisationTypeId;
13
- this.imageId = params.imageId;
14
- this.label = params.label;
15
- this.userOrganisationsCount = params.userOrganisationsCount;
16
- this.adminId = params.adminId;
17
- this.adminName = params.adminName;
18
- }
11
+ constructor(params: OrganisationInfosDTO) {
12
+ this.id = params.id;
13
+ this.organisationTypeId = params.organisationTypeId;
14
+ this.imageId = params.imageId;
15
+ this.label = params.label;
16
+ this.userOrganisationsCount = params.userOrganisationsCount;
17
+ this.adminId = params.adminId;
18
+ this.adminName = params.adminName;
19
+ this.currentUserOrganisationId = params.currentUserOrganisationId;
20
+ }
19
21
  }
20
22
 
21
23
  export interface OrganisationInfosDTO {
22
- id: string;
23
- organisationTypeId: string;
24
- imageId: string | null;
25
- label: string;
26
- userOrganisationsCount: number;
27
- adminId: string | null;
28
- adminName: string | null;
24
+ id: string;
25
+ organisationTypeId: string;
26
+ imageId: string | null;
27
+ label: string;
28
+ userOrganisationsCount: number;
29
+ adminId: string | null;
30
+ adminName: string | null;
31
+ currentUserOrganisationId: string | null;
29
32
  }
30
33
 
31
34
  export interface OrganisationFilters {
32
- search?: string | null;
35
+ search?: string | null;
33
36
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-shared-domain",
3
3
  "sideEffects": false,
4
- "version": "1.0.165",
4
+ "version": "1.0.167-map-edit",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -12,5 +12,5 @@
12
12
  "peerDependencies": {
13
13
  "date-fns": "^3.6.0"
14
14
  },
15
- "gitHead": "0481543beb9ab42475891298793dc397c2428a19"
15
+ "gitHead": "725635256ebf2bb6450c38e5a3077fb907ea550c"
16
16
  }
@@ -0,0 +1,45 @@
1
+ import { AggregationType } from '@dative-gpi/foundation-shared-domain/enums';
2
+
3
+ type ReducerFn = (prev: number, curr: number, index: number, array: number[]) => number;
4
+
5
+ const reducers: Partial<Record<AggregationType, ReducerFn>> = {
6
+ [AggregationType.Sum]: (a, b) => a + b,
7
+ [AggregationType.First]: (a) => a,
8
+ [AggregationType.Last]: (_, b) => b,
9
+ [AggregationType.Difference]: (a, b) => b - a,
10
+ [AggregationType.Maximum]: (a, b) => Math.max(a, b),
11
+ [AggregationType.Minimum]: (a, b) => Math.min(a, b),
12
+ };
13
+
14
+ const aggregationFactory = (type: AggregationType): ReducerFn => {
15
+ const reducer = reducers[type];
16
+ if (!reducer) {
17
+ throw new Error(`Aggregation "${type}" must be handled explicitly.`);
18
+ }
19
+ return reducer;
20
+ }
21
+
22
+ export const computeAggregation = (type: AggregationType, values: number[]): number => {
23
+ if (!values.length) {
24
+ throw new Error('Cannot aggregate empty array.');
25
+ }
26
+
27
+ switch (type) {
28
+ case AggregationType.Mean:
29
+ const sum = values.reduce((a, b) => a + b, 0);
30
+ return sum / values.length;
31
+
32
+ case AggregationType.Median:
33
+ const sorted = [...values].sort((a, b) => a - b);
34
+ const mid = Math.floor(sorted.length / 2);
35
+ return sorted.length % 2 === 0
36
+ ? (sorted[mid - 1] + sorted[mid]) / 2
37
+ : sorted[mid];
38
+
39
+ case AggregationType.Cardinal:
40
+ return values.length;
41
+
42
+ default:
43
+ return values.reduce(aggregationFactory(type));
44
+ }
45
+ }
package/tools/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./aggregationTools";
1
2
  export * from "./autoRefresh";
2
3
  export * from "./datesTools";
3
4
  export * from "./enumTools";