@dative-gpi/foundation-core-services 0.0.215 → 0.0.217

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.
@@ -25,6 +25,7 @@ export * from "./useGroups";
25
25
  export * from "./useLocations";
26
26
  export * from "./useManufacturers";
27
27
  export * from "./useModels";
28
+ export * from "./useNotifications";
28
29
  export * from "./useOrganisations";
29
30
  export * from "./useOrganisationTypes";
30
31
  export * from "./usePermissionCategories";
@@ -1,5 +1,4 @@
1
- import type { AlertDetailsDTO, AlertFilters, AlertInfosDTO } from "@dative-gpi/foundation-core-domain/models";
2
- import { AlertDetails, AlertInfos } from "@dative-gpi/foundation-core-domain/models";
1
+ import { AlertDetails, type AlertDetailsDTO, type AlertFilters, AlertInfos, type AlertInfosDTO } from "@dative-gpi/foundation-core-domain/models";
3
2
  import { HubFactory } from "@dative-gpi/foundation-shared-services/tools/hubFactory";
4
3
  import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
5
4
 
@@ -7,52 +6,52 @@ import { ALERTS_HUB_URL, ALERTS_URL, ALERT_URL } from "../../config/urls";
7
6
  import { HUBS } from "../../config/literals";
8
7
 
9
8
  const AlertServiceFactory = new ServiceFactory<AlertDetailsDTO, AlertDetails>("alert", AlertDetails).create(factory => factory.build(
10
- factory.addGet(ALERT_URL),
11
- factory.addGetMany<AlertInfosDTO, AlertInfos, AlertFilters>(ALERTS_URL, AlertInfos),
12
- factory.addRemove(ALERT_URL),
13
- factory.addNotify(notifyService => ({
14
- notifyCreate: (alert: AlertDetails) => notifyService.notify("add", alert),
15
- notifyUpdate: (alert: AlertDetails) => notifyService.notify("update", alert),
16
- notifyRemove: (alertId: string) => notifyService.notify("delete", alertId),
17
- ...ServiceFactory.addCustom("acknowledge", (axios, alertId: string) => axios.patch(ALERT_URL(alertId)), (dto: AlertDetailsDTO) => {
18
- const result = new AlertDetails(dto);
19
- notifyService.notify("update", result);
20
- return result;
21
- })
22
- }))
9
+ factory.addGet(ALERT_URL),
10
+ factory.addGetMany<AlertInfosDTO, AlertInfos, AlertFilters>(ALERTS_URL, AlertInfos),
11
+ factory.addRemove(ALERT_URL),
12
+ factory.addNotify(notifyService => ({
13
+ notifyCreate: (alert: AlertDetails) => notifyService.notify("add", alert),
14
+ notifyUpdate: (alert: AlertDetails) => notifyService.notify("update", alert),
15
+ notifyRemove: (alertId: string) => notifyService.notify("delete", alertId),
16
+ ...ServiceFactory.addCustom("acknowledge", (axios, alertId: string) => axios.patch(ALERT_URL(alertId)), (dto: AlertDetailsDTO) => {
17
+ const result = new AlertDetails(dto);
18
+ notifyService.notify("update", result);
19
+ return result;
20
+ })
21
+ }))
23
22
  ));
24
23
 
25
24
  const useAlertsHub = HubFactory.create(ALERTS_HUB_URL,
26
- (connection, { isWatched, hasWatchers }) => {
27
- connection.on(HUBS.CREATE_ALERT, (alertId: string) => hasWatchers()
28
- ? AlertServiceFactory.get(alertId).then(AlertServiceFactory.notifyCreate)
29
- : null);
30
- connection.on(HUBS.UPDATE_ALERT, (alertId: string) => isWatched(alertId) || hasWatchers()
31
- ? AlertServiceFactory.get(alertId).then(AlertServiceFactory.notifyUpdate)
32
- : null);
33
- connection.on(HUBS.REMOVE_ALERT, (alertId: string) => hasWatchers()
34
- ? AlertServiceFactory.notifyRemove(alertId)
35
- : null);
36
- },
37
- async (connection) => {
38
- await connection.invoke(HUBS.SUBSCRIBE);
39
- }
25
+ (connection, { isWatched, hasWatchers }) => {
26
+ connection.on(HUBS.CREATE_ALERT, (alertId: string) => hasWatchers()
27
+ ? AlertServiceFactory.get(alertId).then(AlertServiceFactory.notifyCreate)
28
+ : null);
29
+ connection.on(HUBS.UPDATE_ALERT, (alertId: string) => isWatched(alertId) || hasWatchers()
30
+ ? AlertServiceFactory.get(alertId).then(AlertServiceFactory.notifyUpdate)
31
+ : null);
32
+ connection.on(HUBS.REMOVE_ALERT, (alertId: string) => hasWatchers()
33
+ ? AlertServiceFactory.notifyRemove(alertId)
34
+ : null);
35
+ },
36
+ async (connection) => {
37
+ await connection.invoke(HUBS.SUBSCRIBE);
38
+ }
40
39
  );
41
40
 
42
41
  const useWatchAlerts = HubFactory.createWatcher(useAlertsHub);
43
42
 
44
43
  export const useAlert = ComposableFactory.get(AlertServiceFactory, () => {
45
- const { watchOne } = useWatchAlerts();
46
- return (alert) => {
47
- watchOne(alert.value.id);
48
- }
44
+ const { watchOne } = useWatchAlerts();
45
+ return (alert) => {
46
+ watchOne(alert.value.id);
47
+ }
49
48
  });
50
49
 
51
50
  export const useAlerts = ComposableFactory.getMany(AlertServiceFactory, () => {
52
- const { watchMany } = useWatchAlerts();
53
- return () => {
54
- watchMany();
55
- }
51
+ const { watchMany } = useWatchAlerts();
52
+ return () => {
53
+ watchMany();
54
+ }
56
55
  });
57
56
 
58
57
  export const useRemoveAlert = ComposableFactory.remove(AlertServiceFactory);
@@ -1,5 +1,4 @@
1
- import type { ModelDetailsDTO, ModelFilters, ModelInfosDTO } from "@dative-gpi/foundation-core-domain/models";
2
- import { ModelDetails, ModelInfos } from "@dative-gpi/foundation-core-domain/models";
1
+ import { ModelDetails, type ModelDetailsDTO, type ModelFilters, ModelInfos, type ModelInfosDTO } from "@dative-gpi/foundation-core-domain/models";
3
2
  import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
4
3
 
5
4
  import { MODELS_URL, MODEL_URL } from "../../config/urls";
@@ -0,0 +1,48 @@
1
+ import { NotificationDetails, type NotificationDetailsDTO, NotificationInfos, type NotificationInfosDTO, type NotificationFilters } from "@dative-gpi/foundation-core-domain/models";
2
+ import { HubFactory } from "@dative-gpi/foundation-shared-services/tools/hubFactory";
3
+ import { ComposableFactory, ServiceFactory } from "@dative-gpi/bones-ui/core";
4
+
5
+ import { NOTIFICATIONS_HUB_URL, NOTIFICATIONS_URL, NOTIFICATION_URL } from "../../config";
6
+ import { HUBS } from "../../config/literals";
7
+
8
+ const NotificationServiceFactory = new ServiceFactory<NotificationDetailsDTO, NotificationDetails>("notifications", NotificationDetails).create(factory => factory.build(
9
+ factory.addGet(NOTIFICATION_URL),
10
+ factory.addGetMany<NotificationInfosDTO, NotificationInfos, NotificationFilters>(NOTIFICATIONS_URL, NotificationInfos),
11
+ factory.addNotify(notifyService => ({
12
+ notifyCreate: (notification: NotificationDetails) => notifyService.notify("add", notification),
13
+ ...ServiceFactory.addCustom("acknowledge", (axios, notificationId: string) => axios.patch(NOTIFICATION_URL(notificationId)), (dto: NotificationDetailsDTO) => {
14
+ const result = new NotificationDetails(dto);
15
+ notifyService.notify("update", result);
16
+ return result;
17
+ })
18
+ }))
19
+ ));
20
+
21
+ const useNotificationsHub = HubFactory.create(NOTIFICATIONS_HUB_URL,
22
+ (connection, { hasWatchers }) => {
23
+ connection.on(HUBS.CREATE_NOTIFICATION, (notificationId: string) => hasWatchers()
24
+ ? NotificationServiceFactory.get(notificationId).then(NotificationServiceFactory.notifyCreate)
25
+ : null);
26
+ },
27
+ async (connection) => {
28
+ await connection.invoke(HUBS.SUBSCRIBE);
29
+ }
30
+ );
31
+
32
+ const useWatchNotifications = HubFactory.createWatcher(useNotificationsHub);
33
+
34
+ export const useNotification = ComposableFactory.get(NotificationServiceFactory, () => {
35
+ const { watchOne } = useWatchNotifications();
36
+ return (notification) => {
37
+ watchOne(notification.value.id);
38
+ }
39
+ });
40
+
41
+ export const useNotifications = ComposableFactory.getMany(NotificationServiceFactory, () => {
42
+ const { watchMany } = useWatchNotifications();
43
+ return () => {
44
+ watchMany();
45
+ }
46
+ });
47
+
48
+ export const useAcknowledgeNotification = ComposableFactory.custom(NotificationServiceFactory.acknowledge);
@@ -11,4 +11,6 @@ export const REMOVE_ALERT = "RemoveAlert";
11
11
 
12
12
  export const CREATE_CONNECTIVITY_ALERT = "CreateConnectivityAlert";
13
13
  export const UPDATE_CONNECTIVITY_ALERT = "UpdateConnectivityAlert";
14
- export const REMOVE_CONNECTIVITY_ALERT = "RemoveConnectivityAlert";
14
+ export const REMOVE_CONNECTIVITY_ALERT = "RemoveConnectivityAlert";
15
+
16
+ export const CREATE_NOTIFICATION = "CreateNotification";
@@ -23,6 +23,7 @@ export * from "./groups";
23
23
  export * from "./locations";
24
24
  export * from "./manufacturers";
25
25
  export * from "./models";
26
+ export * from "./notifications";
26
27
  export * from "./organisations";
27
28
  export * from "./organisationTypes";
28
29
  export * from "./permissionCategories";
@@ -0,0 +1,6 @@
1
+ import { CORE_URL, HUBS_URL } from "./base";
2
+
3
+ export const NOTIFICATIONS_URL = () => `${CORE_URL()}/notifications`;
4
+ export const NOTIFICATION_URL = (notificationId: string) => `${CORE_URL()}/notifications/${notificationId}`;
5
+
6
+ export const NOTIFICATIONS_HUB_URL = () => `${HUBS_URL()}/notifications`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-core-services",
3
3
  "sideEffects": false,
4
- "version": "0.0.215",
4
+ "version": "0.0.217",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,7 +10,7 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@dative-gpi/foundation-core-domain": "0.0.215"
13
+ "@dative-gpi/foundation-core-domain": "0.0.217"
14
14
  },
15
15
  "peerDependencies": {
16
16
  "@dative-gpi/bones-ui": "^0.0.75",
@@ -18,5 +18,5 @@
18
18
  "vue": "^3.4.29",
19
19
  "vue-router": "^4.3.0"
20
20
  },
21
- "gitHead": "0d0aafb99e7a818b3606c3ac8bea917213e389ad"
21
+ "gitHead": "fc671993afed7c9953bf4325f4788592d280cda7"
22
22
  }