@tmlmobilidade/interfaces 20251002.1112.25-staging.0 → 20251002.1508.28

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.
@@ -44,6 +44,7 @@ declare class UsersClass extends MongoCollectionClass<User, CreateUserDto, Updat
44
44
  phone?: string | null | undefined | undefined;
45
45
  email: string;
46
46
  permissions: import("@tmlmobilidade/types").Permission<unknown>[];
47
+ active_notifications: string[];
47
48
  avatar?: string | null | undefined | undefined;
48
49
  bio?: string | null | undefined | undefined;
49
50
  email_verified?: import("@tmlmobilidade/types").UnixTimestamp | null | undefined;
@@ -53,6 +54,7 @@ declare class UsersClass extends MongoCollectionClass<User, CreateUserDto, Updat
53
54
  preferences?: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null | undefined;
54
55
  role_ids: string[];
55
56
  session_ids: string[];
57
+ subscribed_topics: string[];
56
58
  theme_id?: string | null | undefined | undefined;
57
59
  verification_token_ids: string[];
58
60
  _id: string;
@@ -75,6 +77,7 @@ declare class UsersClass extends MongoCollectionClass<User, CreateUserDto, Updat
75
77
  phone?: string | null | undefined | undefined;
76
78
  email: string;
77
79
  permissions: import("@tmlmobilidade/types").Permission<unknown>[];
80
+ active_notifications: string[];
78
81
  avatar?: string | null | undefined | undefined;
79
82
  bio?: string | null | undefined | undefined;
80
83
  email_verified?: import("@tmlmobilidade/types").UnixTimestamp | null | undefined;
@@ -84,6 +87,7 @@ declare class UsersClass extends MongoCollectionClass<User, CreateUserDto, Updat
84
87
  preferences?: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null | undefined;
85
88
  role_ids: string[];
86
89
  session_ids: string[];
90
+ subscribed_topics: string[];
87
91
  theme_id?: string | null | undefined | undefined;
88
92
  verification_token_ids: string[];
89
93
  _id: string;
@@ -20,12 +20,20 @@ class NotificationsClass extends MongoCollectionClass {
20
20
  return NotificationsClass._instance;
21
21
  }
22
22
  async sendNotification(notification) {
23
- const usersWithTopic = await users.findMany({ 'permissions.action': notification.topic });
23
+ const usersWithTopic = await users.findMany({ subscribed_topics: { $in: [notification.topic] } });
24
24
  if (usersWithTopic.length === 0)
25
25
  return;
26
26
  for (const user of usersWithTopic.filter(u => u._id !== notification.created_by)) {
27
27
  const newNotification = { ...notification, user_id: user._id };
28
- await notifications.insertOne(newNotification);
28
+ try {
29
+ const response = await notifications.insertOne(newNotification);
30
+ users.updateById(user._id, {
31
+ active_notifications: [...(user.active_notifications || []), response._id],
32
+ });
33
+ }
34
+ catch (err) {
35
+ console.error('Failed to update user notifications:', err);
36
+ }
29
37
  }
30
38
  }
31
39
  getCollectionIndexes() {
@@ -29,7 +29,7 @@ class AuthProvider {
29
29
  // Get the user and their roles
30
30
  const userData = await this.getUser(sessionToken);
31
31
  const rolesData = await roles.findMany({ _id: { $in: userData.role_ids } });
32
- const allPermissions = [...rolesData.flatMap(role => role.permissions), ...userData.permissions];
32
+ const allPermissions = [...rolesData.flatMap(role => role.permissions), ...userData.permissions, ...userData.subscribed_topics];
33
33
  const permissionsMap = new Map();
34
34
  for (const permission of allPermissions) {
35
35
  const key = `${permission.scope}:${permission.action}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/interfaces",
3
- "version": "20251002.1112.25-staging.0",
3
+ "version": "20251002.1508.28",
4
4
  "author": "João de Vasconcelos & Jusi Monteiro",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "homepage": "https://github.com/tmlmobilidade/services#readme",