@dative-gpi/foundation-shared-domain 1.0.56 → 1.0.58

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.
@@ -6,8 +6,10 @@ export class NotificationInfos {
6
6
  title: string;
7
7
  body: string;
8
8
  pageUrl: string;
9
+ audienceId: string;
10
+ audienceScope: Scope;
11
+ organisationId?: string;
9
12
  entityId?: string;
10
- scope: Scope;
11
13
  type: MessageType;
12
14
  criticity: Criticity;
13
15
  timestamp: number;
@@ -19,8 +21,10 @@ export class NotificationInfos {
19
21
  this.title = params.title;
20
22
  this.body = params.body;
21
23
  this.pageUrl = params.pageUrl;
24
+ this.audienceId = params.audienceId;
25
+ this.audienceScope = params.audienceScope as Scope;
26
+ this.organisationId = params.organisationId;
22
27
  this.entityId = params.entityId;
23
- this.scope = params.scope as Scope;
24
28
  this.type = params.type as MessageType;
25
29
  this.criticity = params.criticity as Criticity;
26
30
  this.timestamp = isoToEpoch(params.timestamp);
@@ -35,8 +39,10 @@ export interface NotificationInfosDTO {
35
39
  title: string;
36
40
  body: string;
37
41
  pageUrl: string;
42
+ audienceId: string;
43
+ audienceScope: number;
44
+ organisationId?: string;
38
45
  entityId?: string;
39
- scope: number;
40
46
  type: number;
41
47
  criticity: number;
42
48
  timestamp: string;
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.56",
4
+ "version": "1.0.58",
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": "c77d95e9a7724fa4a39d94b0b2bd0fa9d4fbdefc"
15
+ "gitHead": "ee85735c6816c9c5f6264ac108a05e8bc6b2bec2"
16
16
  }
@@ -0,0 +1,39 @@
1
+ import { type NotificationInfos } from "../models";
2
+ import { Criticity, Scope } from "../enums";
3
+
4
+ export const getFromAudience = (
5
+ notifications: NotificationInfos[],
6
+ application: boolean,
7
+ criticity: Criticity,
8
+ organisationId?: string | null,
9
+ userId?: string | null,
10
+ ): NotificationInfos[] => notifications.filter((n: NotificationInfos) => {
11
+ if (n.acknowledged) {
12
+ return false;
13
+ }
14
+ if (![Criticity.None, n.criticity].includes(criticity)) {
15
+ return false;
16
+ }
17
+ switch (n.audienceScope) {
18
+ case Scope.Organisation :
19
+ case Scope.UserOrganisation: return organisationId && n.organisationId && n.organisationId === organisationId;
20
+ case Scope.User : return userId && n.audienceId === userId;
21
+ case Scope.Application :
22
+ case Scope.Public : return application;
23
+
24
+ }
25
+ return false;
26
+ });
27
+
28
+ export const getForDrawer = (
29
+ notifications: NotificationInfos[],
30
+ organisationId: string,
31
+ userId: string,
32
+ criticity: Criticity = Criticity.None
33
+ ): NotificationInfos[] => getFromAudience(notifications, true, criticity, organisationId, userId);
34
+
35
+ export const getForCard = (
36
+ notifications: NotificationInfos[],
37
+ organisationId: string,
38
+ criticity: Criticity = Criticity.None
39
+ ): NotificationInfos[] => getFromAudience(notifications, false, criticity, organisationId, null);