@dative-gpi/foundation-shared-domain 1.0.156 → 1.0.157-notif-update

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.
@@ -2,6 +2,7 @@ export enum Scope {
2
2
  None = 0,
3
3
  Public = 0b1111,
4
4
  Application = 0b1000,
5
+ OrganisationType = 0b10000,
5
6
  Organisation = 0b0100,
6
7
  User = 0b0010,
7
8
  UserOrganisation = 0b0001
@@ -1,2 +1,3 @@
1
+ export * from "./notificationAudience";
1
2
  export * from "./notificationDetails";
2
3
  export * from "./notificationInfos";
@@ -0,0 +1,23 @@
1
+ import type { Scope } from "../../enums";
2
+
3
+ export class NotificationAudience {
4
+ id: string;
5
+ notificationId: string;
6
+ targetId: string;
7
+ targetScope: Scope;
8
+
9
+
10
+ constructor(params: NotificationAudienceDTO) {
11
+ this.id = params.id;
12
+ this.notificationId = params.notificationId;
13
+ this.targetId = params.targetId;
14
+ this.targetScope = params.targetScope as Scope;
15
+ }
16
+ }
17
+
18
+ export interface NotificationAudienceDTO {
19
+ id: string;
20
+ notificationId: string;
21
+ targetId: string;
22
+ targetScope: number;
23
+ }
@@ -2,16 +2,15 @@ import { type MessageType } from "../../enums/messages";
2
2
  import { isoToEpoch } from "../../tools/datesTools";
3
3
  import { Scope } from "../../enums/applications";
4
4
  import { Criticity } from "../../enums/alerts";
5
+ import { NotificationAudience } from "./notificationAudience";
5
6
 
6
7
  export class NotificationInfos {
7
8
  id: string;
8
9
  title: string;
9
10
  body: string;
10
11
  pageUrl: string;
11
- audienceId: string;
12
- audienceScope: Scope;
12
+ audiences: NotificationAudience[];
13
13
  organisationId?: string;
14
- entityId?: string;
15
14
  type: MessageType;
16
15
  criticity: Criticity;
17
16
  timestamp: number;
@@ -23,10 +22,8 @@ export class NotificationInfos {
23
22
  this.title = params.title;
24
23
  this.body = params.body;
25
24
  this.pageUrl = params.pageUrl;
26
- this.audienceId = params.audienceId;
27
- this.audienceScope = params.audienceScope as Scope;
25
+ this.audiences = params.audiences.map((a: NotificationAudience) => new NotificationAudience(a));
28
26
  this.organisationId = params.organisationId;
29
- this.entityId = params.entityId;
30
27
  this.type = params.type as MessageType;
31
28
  this.criticity = params.criticity as Criticity;
32
29
  this.timestamp = isoToEpoch(params.timestamp);
@@ -40,7 +37,7 @@ export class NotificationInfos {
40
37
  application: boolean,
41
38
  criticity: Criticity,
42
39
  organisationId?: string | null,
43
- userId?: string | null,
40
+ userId?: string | null
44
41
  ): NotificationInfos[] => notifications.filter((n: NotificationInfos) => {
45
42
  if (n.acknowledged) {
46
43
  return false;
@@ -48,13 +45,16 @@ export class NotificationInfos {
48
45
  if (![Criticity.None, n.criticity].includes(criticity)) {
49
46
  return false;
50
47
  }
51
- switch (n.audienceScope) {
48
+
49
+ let show = false;
50
+ for (const a of n.audiences) {
51
+ switch (a.targetScope) {
52
52
  case Scope.Organisation :
53
- case Scope.UserOrganisation: return organisationId && n.organisationId && n.organisationId === organisationId;
54
- case Scope.User : return userId && n.audienceId === userId;
53
+ case Scope.UserOrganisation: show = show || (organisationId && n.organisationId && n.organisationId === organisationId) as boolean;
54
+ case Scope.User : show = show || (userId && a.targetId === userId) as boolean;
55
55
  case Scope.Application :
56
- case Scope.Public : return application;
57
-
56
+ case Scope.Public : show = show || application as boolean;
57
+ }
58
58
  }
59
59
  return false;
60
60
  });
@@ -78,10 +78,8 @@ export interface NotificationInfosDTO {
78
78
  title: string;
79
79
  body: string;
80
80
  pageUrl: string;
81
- audienceId: string;
82
- audienceScope: number;
81
+ audiences: NotificationAudience[];
83
82
  organisationId?: string;
84
- entityId?: string;
85
83
  type: number;
86
84
  criticity: number;
87
85
  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.156",
4
+ "version": "1.0.157-notif-update",
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": "d67f90e266b8ae583f46c82aec2dbd381c5d3629"
15
+ "gitHead": "dafacb8fd32b23a20ce074b361391db5b1739185"
16
16
  }