@messenger-box/platform-server 10.0.3-alpha.7 → 10.0.3-alpha.72

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.
Files changed (149) hide show
  1. package/lib/containers/containers.js +4 -1
  2. package/lib/containers/containers.js.map +1 -1
  3. package/lib/containers/context-services-from-container.d.ts +1 -1
  4. package/lib/containers/context-services-from-container.js +1 -1
  5. package/lib/containers/context-services-from-container.js.map +1 -1
  6. package/lib/graphql/resolvers/channel-member.d.ts +3 -2
  7. package/lib/graphql/resolvers/channel-member.js +30 -5
  8. package/lib/graphql/resolvers/channel-member.js.map +1 -1
  9. package/lib/graphql/resolvers/channel.d.ts +3 -2
  10. package/lib/graphql/resolvers/channel.js +279 -53
  11. package/lib/graphql/resolvers/channel.js.map +1 -1
  12. package/lib/graphql/resolvers/extended-token-account.d.ts +3 -2
  13. package/lib/graphql/resolvers/extended-token-account.js +90 -23
  14. package/lib/graphql/resolvers/extended-token-account.js.map +1 -1
  15. package/lib/graphql/resolvers/index.d.ts +1 -1
  16. package/lib/graphql/resolvers/post-thread.d.ts +1 -1
  17. package/lib/graphql/resolvers/post-thread.js +294 -132
  18. package/lib/graphql/resolvers/post-thread.js.map +1 -1
  19. package/lib/graphql/resolvers/post.d.ts +2 -3
  20. package/lib/graphql/resolvers/post.js +696 -234
  21. package/lib/graphql/resolvers/post.js.map +1 -1
  22. package/lib/graphql/resolvers/reaction.d.ts +3 -2
  23. package/lib/graphql/resolvers/reaction.js +96 -14
  24. package/lib/graphql/resolvers/reaction.js.map +1 -1
  25. package/lib/graphql/schema/channel-member.graphql +110 -21
  26. package/lib/graphql/schema/channel-member.graphql.js +1 -1
  27. package/lib/graphql/schema/channel.graphql +337 -38
  28. package/lib/graphql/schema/channel.graphql.js +1 -1
  29. package/lib/graphql/schema/post-thread.graphql +167 -21
  30. package/lib/graphql/schema/post-thread.graphql.js +1 -1
  31. package/lib/graphql/schema/post.graphql +284 -40
  32. package/lib/graphql/schema/post.graphql.js +1 -1
  33. package/lib/graphql/schema/reaction.graphql +71 -13
  34. package/lib/graphql/schema/reaction.graphql.js +1 -1
  35. package/lib/graphql/schema/services.graphql +2 -0
  36. package/lib/graphql/schema/users.graphql +76 -13
  37. package/lib/graphql/schema/users.graphql.js +1 -1
  38. package/lib/index.js +1 -1
  39. package/lib/index.js.map +1 -1
  40. package/lib/interfaces/index.d.ts +0 -1
  41. package/lib/interfaces/services.d.ts +1 -1
  42. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.d.ts +17 -0
  43. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.js +44 -0
  44. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.js.map +1 -0
  45. package/lib/migrations/dbMigrations/index.d.ts +1 -0
  46. package/lib/migrations/index.d.ts +1 -0
  47. package/lib/migrations/mail-template-migration.js +1 -1
  48. package/lib/migrations/message-notification-template-migration.d.ts +1 -1
  49. package/lib/migrations/message-notification-template-migration.js +1 -1
  50. package/lib/plugins/channel-moleculer-service.d.ts +21 -1
  51. package/lib/plugins/channel-moleculer-service.js +417 -115
  52. package/lib/plugins/channel-moleculer-service.js.map +1 -1
  53. package/lib/plugins/extended-token-account-moleculer-service.d.ts +25 -1
  54. package/lib/plugins/extended-token-account-moleculer-service.js +348 -22
  55. package/lib/plugins/extended-token-account-moleculer-service.js.map +1 -1
  56. package/lib/plugins/messenger-notification-moleculer-service.d.ts +27 -3
  57. package/lib/plugins/messenger-notification-moleculer-service.js +404 -58
  58. package/lib/plugins/messenger-notification-moleculer-service.js.map +1 -1
  59. package/lib/plugins/post-moleculer-service.d.ts +85 -21
  60. package/lib/plugins/post-moleculer-service.js +986 -256
  61. package/lib/plugins/post-moleculer-service.js.map +1 -1
  62. package/lib/plugins/post-thread-moleculer-service.d.ts +33 -1
  63. package/lib/plugins/post-thread-moleculer-service.js +326 -8
  64. package/lib/plugins/post-thread-moleculer-service.js.map +1 -1
  65. package/lib/plugins/reaction-moleculer-service.js +1 -1
  66. package/lib/plugins/reaction-moleculer-service.js.map +1 -1
  67. package/lib/preferences/settings/post-settings.d.ts +2 -0
  68. package/lib/preferences/settings/post-settings.js +47 -9
  69. package/lib/preferences/settings/post-settings.js.map +1 -1
  70. package/lib/services/channel-service.d.ts +179 -33
  71. package/lib/services/channel-service.js +821 -274
  72. package/lib/services/channel-service.js.map +1 -1
  73. package/lib/services/extended-token-account-service.d.ts +130 -14
  74. package/lib/services/extended-token-account-service.js +462 -52
  75. package/lib/services/extended-token-account-service.js.map +1 -1
  76. package/lib/services/index.d.ts +1 -0
  77. package/lib/services/messenger-notification-service.d.ts +106 -13
  78. package/lib/services/messenger-notification-service.js +824 -442
  79. package/lib/services/messenger-notification-service.js.map +1 -1
  80. package/lib/services/post-service.d.ts +182 -16
  81. package/lib/services/post-service.js +731 -115
  82. package/lib/services/post-service.js.map +1 -1
  83. package/lib/services/post-thread-service.d.ts +114 -5
  84. package/lib/services/post-thread-service.js +400 -13
  85. package/lib/services/post-thread-service.js.map +1 -1
  86. package/lib/services/proxy-services/channel-microservice.d.ts +5 -3
  87. package/lib/services/proxy-services/channel-microservice.js +19 -10
  88. package/lib/services/proxy-services/channel-microservice.js.map +1 -1
  89. package/lib/services/proxy-services/messenger-notification-microservice.d.ts +128 -8
  90. package/lib/services/proxy-services/messenger-notification-microservice.js +324 -29
  91. package/lib/services/proxy-services/messenger-notification-microservice.js.map +1 -1
  92. package/lib/services/proxy-services/post-microservice.d.ts +186 -12
  93. package/lib/services/proxy-services/post-microservice.js +543 -54
  94. package/lib/services/proxy-services/post-microservice.js.map +1 -1
  95. package/lib/services/proxy-services/post-thread-microservice.d.ts +134 -3
  96. package/lib/services/proxy-services/post-thread-microservice.js +388 -6
  97. package/lib/services/proxy-services/post-thread-microservice.js.map +1 -1
  98. package/lib/services/proxy-services/reaction-microservice.d.ts +161 -3
  99. package/lib/services/proxy-services/reaction-microservice.js +474 -2
  100. package/lib/services/proxy-services/reaction-microservice.js.map +1 -1
  101. package/lib/services/reaction-service.d.ts +124 -4
  102. package/lib/services/reaction-service.js +415 -3
  103. package/lib/services/reaction-service.js.map +1 -1
  104. package/lib/services/redis-cache-manager.d.ts +18 -0
  105. package/lib/services/redis-cache-manager.js +83 -0
  106. package/lib/services/redis-cache-manager.js.map +1 -0
  107. package/lib/store/models/account-token-store.d.ts +1 -1
  108. package/lib/store/models/account-token-store.js.map +1 -1
  109. package/lib/store/models/channel.d.ts +2 -3
  110. package/lib/store/models/channel.js +181 -72
  111. package/lib/store/models/channel.js.map +1 -1
  112. package/lib/store/models/post-thread.d.ts +3 -3
  113. package/lib/store/models/post-thread.js +96 -14
  114. package/lib/store/models/post-thread.js.map +1 -1
  115. package/lib/store/models/post.d.ts +2 -3
  116. package/lib/store/models/post.js +143 -23
  117. package/lib/store/models/post.js.map +1 -1
  118. package/lib/store/models/reaction.d.ts +2 -3
  119. package/lib/store/models/reaction.js +67 -8
  120. package/lib/store/models/reaction.js.map +1 -1
  121. package/lib/store/repositories/__tests__/__fixtures__/team-repository.d.ts +3 -3
  122. package/lib/store/repositories/channel-repository.d.ts +6 -6
  123. package/lib/store/repositories/channel-repository.js +5 -2
  124. package/lib/store/repositories/channel-repository.js.map +1 -1
  125. package/lib/store/repositories/post-repository.d.ts +6 -6
  126. package/lib/store/repositories/post-repository.js +5 -2
  127. package/lib/store/repositories/post-repository.js.map +1 -1
  128. package/lib/store/repositories/post-thread-repository.d.ts +6 -6
  129. package/lib/store/repositories/post-thread-repository.js +5 -2
  130. package/lib/store/repositories/post-thread-repository.js.map +1 -1
  131. package/lib/store/repositories/reaction-repository.d.ts +6 -6
  132. package/lib/store/repositories/reaction-repository.js +5 -2
  133. package/lib/store/repositories/reaction-repository.js.map +1 -1
  134. package/lib/templates/constants/SERVER_TYPES.ts.template +0 -3
  135. package/lib/templates/repositories/ChannelRepository.ts.template +3 -3
  136. package/lib/templates/repositories/PostRepository.ts.template +3 -3
  137. package/lib/templates/repositories/PostThreadRepository.ts.template +3 -3
  138. package/lib/templates/repositories/ReactionRepository.ts.template +3 -4
  139. package/lib/templates/services/ChannelService.ts.template +280 -39
  140. package/lib/templates/services/ExtendedTokenAccountService.ts.template +104 -9
  141. package/lib/templates/services/MessengerNotificationService.ts.template +94 -19
  142. package/lib/templates/services/PostService.ts.template +184 -20
  143. package/lib/templates/services/PostThreadService.ts.template +151 -6
  144. package/lib/templates/services/ReactionService.ts.template +129 -3
  145. package/lib/templates/services/RedisCacheManager.ts.template +22 -0
  146. package/package.json +6 -5
  147. package/lib/interfaces/context.d.ts +0 -14
  148. package/lib/store/models/common-options.js +0 -20
  149. package/lib/store/models/common-options.js.map +0 -1
@@ -1,4 +1,6 @@
1
- import {generateUri}from'@adminide-stack/core';import {RoomType,PostTypeEnum,SortEnum,ClientCacheTypeNames}from'common';import {get}from'lodash-es';import {GraphQLError}from'graphql';// export const postResolvers = ({ pubsub }): IResolvers<IContext> => ({
1
+ import {RoomType,PostTypeEnum,SortEnum,ConfigCollectionName,Scheme,ClientCacheTypeNames}from'common/server';import {get}from'lodash-es';import {GraphQLError}from'graphql';import {generateResourceUri,DEFAULT_TENANT_ID,buildNodeContext}from'@adminide-stack/core/lib/index.js';// import { IContext } from '../../interfaces';
2
+ // export const postResolvers = ({ pubsub }): IResolvers<IContext> => ({
3
+ // export const postResolvers: (options: IResolverOptions) => IResolvers<IContext> = (options) => ({
2
4
  const postResolvers = options => ({
3
5
  // Temporary fix, until we have extension support in base module
4
6
  FileInfo: {
@@ -7,125 +9,292 @@ const postResolvers = options => ({
7
9
  }, args, {
8
10
  fileInfoService
9
11
  }) => {
10
- const basePath = fileInfoService.awsS3Service.basePath || 'aws';
11
- if (!url.includes(basePath)) {
12
- return url;
12
+ options.logger.trace('(FileInfo.url) url [%s]', url);
13
+ try {
14
+ if (!url) {
15
+ options.logger.warn('Missing URL in FileInfo');
16
+ return null;
17
+ }
18
+ const basePath = fileInfoService.awsS3Service.basePath || 'aws';
19
+ if (!url.includes(basePath)) {
20
+ return url;
21
+ }
22
+ return fileInfoService.getResizedImage(url, {
23
+ width: undefined,
24
+ height: undefined
25
+ });
26
+ } catch (error) {
27
+ options.logger.error('Error getting FileInfo URL: %o', error);
28
+ return url; // Fallback to original URL
13
29
  }
14
- return fileInfoService.getResizedImage(url, {
15
- width: undefined,
16
- height: undefined
17
- });
18
30
  },
19
31
  extension(src) {
20
- return src.mimeType.split('/')[1];
32
+ options.logger.trace('(FileInfo.extension) mimeType [%s]', src?.mimeType);
33
+ try {
34
+ if (!src?.mimeType || typeof src.mimeType !== 'string') {
35
+ options.logger.warn('Missing or invalid mimeType in FileInfo');
36
+ return null;
37
+ }
38
+ const parts = src.mimeType.split('/');
39
+ return parts.length > 1 ? parts[1] : null;
40
+ } catch (error) {
41
+ options.logger.error('Error getting FileInfo extension: %o', error);
42
+ return null;
43
+ }
21
44
  }
22
45
  },
23
46
  Post: {
24
47
  editedBy(src, args, {
25
- accountService
48
+ accountService,
49
+ accountUserDataLoader
26
50
  }) {
27
- return src?.editedBy ? accountService.findAccountById(src.editedBy.toString()) : null;
51
+ options.logger.trace('(Post.editedBy) editedBy [%s]', src?.editedBy);
52
+ try {
53
+ if (!src?.editedBy) {
54
+ return null;
55
+ }
56
+ return accountUserDataLoader.load(src.editedBy.toString());
57
+ } catch (error) {
58
+ options.logger.error('Error getting Post editedBy: %o', error);
59
+ return null;
60
+ }
28
61
  },
29
62
  deletedBy(src, args, {
30
- accountService
63
+ accountService,
64
+ accountUserDataLoader
31
65
  }) {
32
- return src?.deletedBy ? accountService.findAccountById(src?.deletedBy.toString()) : null;
66
+ options.logger.trace('(Post.deletedBy) deletedBy [%s]', src?.deletedBy);
67
+ try {
68
+ if (!src?.deletedBy) {
69
+ return null;
70
+ }
71
+ return accountUserDataLoader.load(src.deletedBy.toString());
72
+ } catch (error) {
73
+ options.logger.error('Error getting Post deletedBy: %o', error);
74
+ return null;
75
+ }
33
76
  },
34
77
  author(src, args, {
35
78
  accountService
36
79
  }) {
37
- const author = src.author?.toString();
38
- if (author) {
39
- return accountService.findAccountById(author);
80
+ options.logger.trace('(Post.author) author [%s], editedBy [%s]', src?.author, src?.editedBy);
81
+ try {
82
+ const author = src?.author?.toString();
83
+ if (author) {
84
+ return accountService.findAccountById(author);
85
+ }
86
+ // Fallback to editedBy if author is not available
87
+ if (src?.editedBy) {
88
+ return accountService.findAccountById(src.editedBy.toString());
89
+ }
90
+ return null;
91
+ } catch (error) {
92
+ options.logger.error('Error getting Post author: %o', error);
93
+ return null;
40
94
  }
41
- return src?.editedBy ? accountService.findAccountById(src.editedBy.toString()) : null;
42
95
  },
43
96
  channel(src, args, {
44
97
  channelService
45
98
  }) {
46
- return channelService.get(src.channel.toString());
99
+ options.logger.trace('(Post.channel) channel [%s]', src?.channel);
100
+ try {
101
+ if (!src?.channel) {
102
+ options.logger.warn('Missing channel in Post');
103
+ return null;
104
+ }
105
+ return channelService.get(src.channel.toString());
106
+ } catch (error) {
107
+ options.logger.error('Error getting Post channel: %o', error);
108
+ return null;
109
+ }
47
110
  },
48
111
  props(src, _, {
49
112
  userContext
50
113
  }) {
51
- return src?.props?.[`[${userContext.accountId}]`];
114
+ options.logger.trace('(Post.props) accountId [%s]', userContext?.accountId);
115
+ try {
116
+ if (!userContext?.accountId || !src?.props) {
117
+ return null;
118
+ }
119
+ return src.props[`[${userContext.accountId}]`] || null;
120
+ } catch (error) {
121
+ options.logger.error('Error getting Post props: %o', error);
122
+ return null;
123
+ }
52
124
  },
53
125
  isRead(src, _, {
54
126
  userContext
55
127
  }) {
56
- return get(src?.props?.[`[${userContext.accountId}]`], `messenger.posts.isRead`);
128
+ options.logger.trace('(Post.isRead) accountId [%s]', userContext?.accountId);
129
+ try {
130
+ if (!userContext?.accountId || !src?.props) {
131
+ return false;
132
+ }
133
+ return get(src.props[`[${userContext.accountId}]`], 'messenger.posts.isRead', false);
134
+ } catch (error) {
135
+ options.logger.error('Error getting Post isRead: %o', error);
136
+ return false;
137
+ }
57
138
  },
58
139
  isDelivered(src, _, {
59
140
  userContext
60
141
  }) {
61
- return get(src?.props?.[`[${userContext.accountId}]`], `messenger.posts.isDelivered`);
142
+ options.logger.trace('(Post.isDelivered) accountId [%s]', userContext?.accountId);
143
+ try {
144
+ if (!userContext?.accountId || !src?.props) {
145
+ return false;
146
+ }
147
+ return get(src.props[`[${userContext.accountId}]`], 'messenger.posts.isDelivered', false);
148
+ } catch (error) {
149
+ options.logger.error('Error getting Post isDelivered: %o', error);
150
+ return false;
151
+ }
62
152
  },
63
- propsConfiguration(src, args, {
64
- configurationService
153
+ async propsConfiguration(src, args, {
154
+ configurationService,
155
+ userContext
65
156
  }) {
66
- const resource = generateUri('messenger', {
67
- _id: src.id
68
- }, 'props');
69
- let data = '{}';
157
+ options.logger.trace('(Post.propsConfiguration) postId [%s], orgName [%s]', src?.id);
70
158
  try {
71
- data = JSON.stringify(src.props);
72
- } catch (err) {
73
- console.log('---Errr---', err);
159
+ // if (!src?.id || !userContext?.orgName) {
160
+ if (!src?.id) {
161
+ options.logger.warn('Missing required data for propsConfiguration');
162
+ throw new Error('Missing post ID or organization name');
163
+ }
164
+ // const { orgName } = userContext;
165
+ // options.logger.debug('Processing propsConfiguration for orgName: %s', orgName);
166
+ const resource = generateResourceUri(ConfigCollectionName.Post, {
167
+ _id: src.id
168
+ }, 'props', DEFAULT_TENANT_ID, {
169
+ scheme: Scheme.CDECODE_RESOURCE
170
+ });
171
+ let data = '{}';
172
+ try {
173
+ data = JSON.stringify(src.props || {});
174
+ } catch (err) {
175
+ options.logger.warn('Error serializing props data: %o', err);
176
+ data = '{}';
177
+ }
178
+ const nodeContext = buildNodeContext(userContext);
179
+ const machineModel = await configurationService.parser(resource.toString(), data, nodeContext, null, false);
180
+ if (machineModel instanceof Error) {
181
+ options.logger.error('Error parsing configuration: %o', machineModel);
182
+ throw machineModel;
183
+ }
184
+ return {
185
+ resource,
186
+ contents: machineModel.contents,
187
+ overrides: machineModel.overrides,
188
+ keys: machineModel.keys,
189
+ __typename: ClientCacheTypeNames.MachineConfiguration
190
+ };
191
+ } catch (error) {
192
+ options.logger.error('Error getting Post propsConfiguration: %o', error);
193
+ throw error;
74
194
  }
75
- const machineModel = configurationService.parser(resource.toString(), data);
76
- return {
77
- resource,
78
- contents: machineModel.contents,
79
- overrides: machineModel.overrides,
80
- keys: machineModel.keys,
81
- __typename: ClientCacheTypeNames.MachineConfiguration
82
- };
83
195
  },
84
196
  async files(src, args, {
85
197
  fileInfoService
86
198
  }) {
87
- const {
88
- data,
89
- totalCount
90
- } = await fileInfoService.getAllWithCount({
91
- ...args,
92
- criteria: {
93
- ...args.criteria,
94
- refType: 'Post',
95
- ref: src.id
96
- }
97
- });
98
- return {
99
- data: data.map(({
199
+ options.logger.trace('(Post.files) postId [%s], args [%j]', src?.id, args);
200
+ try {
201
+ if (!src?.id) {
202
+ options.logger.warn('Missing post ID for files');
203
+ return {
204
+ data: [],
205
+ totalCount: 0
206
+ };
207
+ }
208
+ if (!fileInfoService) {
209
+ options.logger.warn('FileInfoService not available');
210
+ return {
211
+ data: [],
212
+ totalCount: 0
213
+ };
214
+ }
215
+ const {
216
+ data,
217
+ totalCount
218
+ } = await fileInfoService.getAllWithCount({
219
+ ...args,
220
+ criteria: {
221
+ ...args.criteria,
222
+ refType: 'Post',
223
+ ref: src.id
224
+ }
225
+ });
226
+ const processedData = data.map(({
100
227
  url,
101
228
  ...rest
102
229
  }) => ({
103
230
  ...rest,
104
231
  url: fileInfoService.getThumbnailImage(url)
105
- })),
106
- totalCount
107
- };
232
+ }));
233
+ options.logger.debug('Retrieved %d files for post %s', processedData.length, src.id);
234
+ return {
235
+ data: processedData,
236
+ totalCount
237
+ };
238
+ } catch (error) {
239
+ options.logger.error('Error getting Post files: %o', error);
240
+ return {
241
+ data: [],
242
+ totalCount: 0
243
+ };
244
+ }
108
245
  },
109
246
  async replies(src, args, {
110
247
  postService
111
248
  }) {
112
- const {
113
- data,
114
- totalCount
115
- } = (await postService?.getAllWithCount({
116
- criteria: {
117
- channel: src.channel.toString(),
118
- parentId: src?.id.toString()
119
- },
120
- sort: {
121
- key: 'createdAt',
122
- value: SortEnum.Desc
249
+ options.logger.trace('(Post.replies) postId [%s], channelId [%s]', src?.id, src?.channel);
250
+ try {
251
+ if (!src?.id || !src?.channel) {
252
+ options.logger.warn('Missing post ID or channel for replies');
253
+ return {
254
+ data: [],
255
+ totalCount: 0
256
+ };
257
+ }
258
+ if (!postService) {
259
+ options.logger.warn('PostService not available');
260
+ return {
261
+ data: [],
262
+ totalCount: 0
263
+ };
123
264
  }
124
- })) ?? [];
125
- return {
126
- totalCount,
127
- data
128
- };
265
+ const {
266
+ data,
267
+ totalCount
268
+ } = (await postService?.getAllWithCount({
269
+ criteria: {
270
+ channel: src.channel.toString(),
271
+ parentId: src.id.toString()
272
+ },
273
+ sort: {
274
+ key: 'createdAt',
275
+ value: SortEnum.Desc
276
+ }
277
+ })) ?? {
278
+ data: [],
279
+ totalCount: 0
280
+ };
281
+ options.logger.debug('Retrieved %d replies for post %s', totalCount, src.id);
282
+ // Set default type to Simple if not specified
283
+ const processedData = data.map(post => ({
284
+ ...post,
285
+ type: (post.type === 'message' ? PostTypeEnum.Message : post.type) || PostTypeEnum.Simple
286
+ }));
287
+ return {
288
+ totalCount,
289
+ data: processedData
290
+ };
291
+ } catch (error) {
292
+ options.logger.error('Error getting Post replies: %o', error);
293
+ return {
294
+ data: [],
295
+ totalCount: 0
296
+ };
297
+ }
129
298
  }
130
299
  },
131
300
  Query: {
@@ -139,26 +308,50 @@ const postResolvers = options => ({
139
308
  postService,
140
309
  userContext
141
310
  }) {
142
- const sortBy = sort || {
143
- key: 'createdAt',
144
- value: SortEnum.Desc
145
- };
146
- const {
147
- data,
148
- totalCount
149
- } = await postService.getAllWithCount({
150
- criteria: {
151
- channel: channelId,
152
- parentId
153
- },
154
- limit,
155
- skip,
156
- sort: sortBy
157
- });
158
- return {
159
- totalCount,
160
- data
161
- };
311
+ options.logger.trace('(Query.messages) channelId [%s], parentId [%s], limit [%d], skip [%d]', channelId, parentId, limit, skip);
312
+ try {
313
+ if (!channelId) {
314
+ options.logger.warn('Missing channelId in messages query');
315
+ throw new Error('Channel ID is required');
316
+ }
317
+ if (!userContext?.accountId) {
318
+ options.logger.warn('Missing user context in messages query');
319
+ throw new Error('User authentication required');
320
+ }
321
+ if (!postService) {
322
+ options.logger.warn('PostService not available');
323
+ throw new Error('Post service unavailable');
324
+ }
325
+ const sortBy = sort || {
326
+ key: 'createdAt',
327
+ value: SortEnum.Desc
328
+ };
329
+ const {
330
+ data,
331
+ totalCount
332
+ } = await postService.getAllWithCount({
333
+ criteria: {
334
+ channel: channelId,
335
+ parentId
336
+ },
337
+ limit,
338
+ skip,
339
+ sort: sortBy
340
+ });
341
+ options.logger.debug('Retrieved %d messages for channel %s', totalCount, channelId);
342
+ // Set default type to Simple if not specified
343
+ const processedData = data.map(post => ({
344
+ ...post,
345
+ type: (post.type === 'message' ? PostTypeEnum.Message : post.type) || PostTypeEnum.Simple
346
+ }));
347
+ return {
348
+ totalCount,
349
+ data: processedData
350
+ };
351
+ } catch (error) {
352
+ options.logger.error('Error in messages query: %o', error);
353
+ throw error;
354
+ }
162
355
  },
163
356
  async publicMessages(src, {
164
357
  channelId
@@ -166,23 +359,43 @@ const postResolvers = options => ({
166
359
  postService,
167
360
  userContext
168
361
  }) {
169
- const {
170
- data,
171
- totalCount
172
- } = await postService.getAllWithCount({
173
- criteria: {
174
- channel: channelId,
175
- type: PostTypeEnum.Public
176
- },
177
- sort: {
178
- key: 'createdAt',
179
- value: SortEnum.Desc
362
+ options.logger.trace('(Query.publicMessages) channelId [%s]', channelId);
363
+ try {
364
+ if (!channelId) {
365
+ options.logger.warn('Missing channelId in publicMessages query');
366
+ throw new Error('Channel ID is required');
180
367
  }
181
- });
182
- return {
183
- totalCount,
184
- data
185
- };
368
+ if (!postService) {
369
+ options.logger.warn('PostService not available');
370
+ throw new Error('Post service unavailable');
371
+ }
372
+ const {
373
+ data,
374
+ totalCount
375
+ } = await postService.getAllWithCount({
376
+ criteria: {
377
+ channel: channelId,
378
+ type: PostTypeEnum.Public
379
+ },
380
+ sort: {
381
+ key: 'createdAt',
382
+ value: SortEnum.Desc
383
+ }
384
+ });
385
+ options.logger.debug('Retrieved %d public messages for channel %s', totalCount, channelId);
386
+ // Set default type to Simple if not specified
387
+ const processedData = data.map(post => ({
388
+ ...post,
389
+ type: post.type || PostTypeEnum.Simple
390
+ }));
391
+ return {
392
+ totalCount,
393
+ data: processedData
394
+ };
395
+ } catch (error) {
396
+ options.logger.error('Error in publicMessages query: %o', error);
397
+ throw error;
398
+ }
186
399
  }
187
400
  },
188
401
  Mutation: {
@@ -191,14 +404,29 @@ const postResolvers = options => ({
191
404
  }, {
192
405
  postService
193
406
  }) {
194
- const {
195
- channelId,
196
- messageId: id
197
- } = messageId;
198
- return postService.delete({
199
- channel: channelId,
200
- id
201
- });
407
+ options.logger.trace('(Mutation.deleteMessage) messageId [%j]', messageId);
408
+ try {
409
+ if (!messageId?.channelId || !messageId?.messageId) {
410
+ options.logger.warn('Missing required messageId parameters');
411
+ throw new Error('Channel ID and Message ID are required');
412
+ }
413
+ if (!postService) {
414
+ options.logger.warn('PostService not available');
415
+ throw new Error('Post service unavailable');
416
+ }
417
+ const {
418
+ channelId,
419
+ messageId: id
420
+ } = messageId;
421
+ options.logger.debug('Deleting message %s from channel %s', id, channelId);
422
+ return postService.delete({
423
+ channel: channelId,
424
+ id
425
+ });
426
+ } catch (error) {
427
+ options.logger.error('Error deleting message: %o', error);
428
+ throw error;
429
+ }
202
430
  },
203
431
  editMessage(src, {
204
432
  messageId,
@@ -207,12 +435,35 @@ const postResolvers = options => ({
207
435
  postService,
208
436
  userContext
209
437
  }) {
210
- return postService.update(messageId.messageId, {
211
- message: messageInput.content,
212
- editedBy: userContext.accountId,
213
- channel: messageId.channelId,
214
- files: messageInput.files
215
- });
438
+ options.logger.trace('(Mutation.editMessage) messageId [%j], content length [%d]', messageId, messageInput?.content?.length || 0);
439
+ try {
440
+ if (!messageId?.messageId || !messageId?.channelId) {
441
+ options.logger.warn('Missing required messageId parameters');
442
+ throw new Error('Message ID and Channel ID are required');
443
+ }
444
+ if (!messageInput?.content) {
445
+ options.logger.warn('Missing message content');
446
+ throw new Error('Message content is required');
447
+ }
448
+ if (!userContext?.accountId) {
449
+ options.logger.warn('Missing user context');
450
+ throw new Error('User authentication required');
451
+ }
452
+ if (!postService) {
453
+ options.logger.warn('PostService not available');
454
+ throw new Error('Post service unavailable');
455
+ }
456
+ options.logger.debug('Editing message %s in channel %s', messageId.messageId, messageId.channelId);
457
+ return postService.update(messageId.messageId, {
458
+ message: messageInput.content,
459
+ editedBy: userContext.accountId,
460
+ channel: messageId.channelId,
461
+ files: messageInput.files
462
+ });
463
+ } catch (error) {
464
+ options.logger.error('Error editing message: %o', error);
465
+ throw error;
466
+ }
216
467
  },
217
468
  async sendMessage(src, {
218
469
  channelId,
@@ -222,30 +473,35 @@ const postResolvers = options => ({
222
473
  postService,
223
474
  userContext
224
475
  }) {
225
- const {
226
- content,
227
- files,
228
- createdBy,
229
- notificationParams
230
- } = messageInput;
231
- const {
232
- accountId
233
- } = userContext;
234
- let post;
235
- if (postId) {
236
- post = await postService.create({
237
- _id: postId,
238
- channel: channelId,
239
- message: content,
240
- editedBy: createdBy || accountId,
241
- author: createdBy || accountId,
476
+ options.logger.trace('(Mutation.sendMessage) channelId [%s], postId [%s], content length [%d]', channelId, postId, messageInput?.content?.length || 0);
477
+ try {
478
+ if (!channelId) {
479
+ options.logger.warn('Missing channelId');
480
+ throw new Error('Channel ID is required');
481
+ }
482
+ if (!messageInput?.content) {
483
+ options.logger.warn('Missing message content');
484
+ throw new Error('Message content is required');
485
+ }
486
+ if (!userContext?.accountId) {
487
+ options.logger.warn('Missing user context');
488
+ throw new Error('User authentication required');
489
+ }
490
+ if (!postService) {
491
+ options.logger.warn('PostService not available');
492
+ throw new Error('Post service unavailable');
493
+ }
494
+ const {
495
+ content,
242
496
  files,
243
- props: notificationParams ? {
244
- notificationParams
245
- } : undefined
246
- });
247
- } else {
248
- post = await postService.create({
497
+ createdBy,
498
+ notificationParams,
499
+ type
500
+ } = messageInput;
501
+ const {
502
+ accountId
503
+ } = userContext;
504
+ const postData = {
249
505
  channel: channelId,
250
506
  message: content,
251
507
  editedBy: createdBy || accountId,
@@ -253,18 +509,27 @@ const postResolvers = options => ({
253
509
  files,
254
510
  props: notificationParams ? {
255
511
  notificationParams
256
- } : undefined
257
- });
512
+ } : undefined,
513
+ type: type || PostTypeEnum.Simple
514
+ };
515
+ let post;
516
+ if (postId) {
517
+ options.logger.debug('Creating message with specific ID %s', postId);
518
+ post = await postService.create({
519
+ _id: postId,
520
+ ...postData
521
+ });
522
+ } else {
523
+ options.logger.debug('Creating new message in channel %s', channelId);
524
+ post = await postService.create(postData);
525
+ }
526
+ options.logger.debug('Message created successfully with ID %s', post?.id || post?._id);
527
+ //options.pubsub.publish(`POST_CREATED.${channelId}`, post);
528
+ return post;
529
+ } catch (error) {
530
+ options.logger.error('Error sending message: %o', error);
531
+ throw error;
258
532
  }
259
- // const post = await postService.create({
260
- // channel: channelId as any,
261
- // message: content,
262
- // editedBy: accountId as any,
263
- // author: accountId as any,
264
- // files,
265
- // });
266
- // options.pubsub.publish(`POST_CREATED.${channelId}`, post);
267
- return post;
268
533
  },
269
534
  async sendPublicMessage(src, {
270
535
  channelId,
@@ -275,46 +540,71 @@ const postResolvers = options => ({
275
540
  channelService,
276
541
  userContext
277
542
  }) {
278
- const {
279
- content,
280
- files,
281
- createdBy
282
- } = messageInput;
283
- const {
284
- accountId
285
- } = userContext;
286
- let post = null;
287
- const channelExits = await channelService.get(channelId);
288
- if (!channelExits) {
289
- const channel = await channelService.savePublicChannel({
290
- _id: channelId,
291
- type: RoomType.Public,
292
- title: `public-channel-${channelId}`
293
- });
294
- if (channel) {
295
- post = await postService.createWithoutSubscription({
296
- _id: postId || undefined,
297
- channel: channelId,
298
- message: content,
299
- editedBy: createdBy || accountId,
300
- author: createdBy || accountId,
301
- files,
302
- type: PostTypeEnum.Public
543
+ options.logger.trace('(Mutation.sendPublicMessage) channelId [%s], postId [%s]', channelId, postId);
544
+ try {
545
+ if (!channelId) {
546
+ options.logger.warn('Missing channelId');
547
+ throw new Error('Channel ID is required');
548
+ }
549
+ if (!messageInput?.content) {
550
+ options.logger.warn('Missing message content');
551
+ throw new Error('Message content is required');
552
+ }
553
+ if (!userContext?.accountId) {
554
+ options.logger.warn('Missing user context');
555
+ throw new Error('User authentication required');
556
+ }
557
+ if (!postService || !channelService) {
558
+ options.logger.warn('Required services not available');
559
+ throw new Error('Required services unavailable');
560
+ }
561
+ const {
562
+ content,
563
+ files,
564
+ createdBy
565
+ } = messageInput;
566
+ const {
567
+ accountId
568
+ } = userContext;
569
+ let post = null;
570
+ const channelExists = await channelService.get(channelId);
571
+ if (!channelExists) {
572
+ options.logger.debug('Creating public channel %s', channelId);
573
+ const channel = await channelService.savePublicChannel({
574
+ _id: channelId,
575
+ type: RoomType.Public,
576
+ title: `public-channel-${channelId}`
303
577
  });
578
+ if (!channel) {
579
+ options.logger.error('Failed to create public channel %s', channelId);
580
+ throw new Error('Failed to create public channel');
581
+ }
304
582
  }
305
- } else {
306
- post = await postService.createWithoutSubscription({
307
- _id: postId || undefined,
583
+ const postData = {
308
584
  channel: channelId,
309
585
  message: content,
310
586
  editedBy: createdBy || accountId,
311
587
  author: createdBy || accountId,
312
588
  files,
313
589
  type: PostTypeEnum.Public
314
- });
590
+ };
591
+ if (postId) {
592
+ post = await postService.createWithoutSubscription({
593
+ _id: postId,
594
+ ...postData
595
+ });
596
+ } else {
597
+ post = await postService.createWithoutSubscription(postData);
598
+ }
599
+ if (post) {
600
+ options.logger.debug('Publishing public post created event for channel %s', channelId);
601
+ options.pubsub.publish(`PUBLIC_POST_CREATED.${channelId}`, post);
602
+ }
603
+ return post;
604
+ } catch (error) {
605
+ options.logger.error('Error sending public message: %o', error);
606
+ throw error;
315
607
  }
316
- if (post) options.pubsub.publish(`PUBLIC_POST_CREATED.${channelId}`, post);
317
- return post;
318
608
  },
319
609
  async sendExpoNotificationOnPost(_, {
320
610
  postId,
@@ -324,9 +614,29 @@ const postResolvers = options => ({
324
614
  postService,
325
615
  userContext
326
616
  }) {
327
- const post = await postService.get(postId.toString());
328
- const res = await messengerNotificationService.sendExpoNotificationOnPost(post, notificationData);
329
- return res;
617
+ options.logger.trace('(Mutation.sendExpoNotificationOnPost) postId [%s]', postId);
618
+ try {
619
+ if (!postId) {
620
+ options.logger.warn('Missing postId');
621
+ throw new Error('Post ID is required');
622
+ }
623
+ if (!messengerNotificationService || !postService) {
624
+ options.logger.warn('Required services not available');
625
+ throw new Error('Required services unavailable');
626
+ }
627
+ const post = await postService.get(postId.toString());
628
+ if (!post) {
629
+ options.logger.warn('Post not found: %s', postId);
630
+ throw new Error('Post not found');
631
+ }
632
+ options.logger.debug('Sending expo notification for post %s', postId);
633
+ const result = await messengerNotificationService.sendExpoNotificationOnPost(post, notificationData);
634
+ options.logger.debug('Expo notification sent successfully for post %s', postId);
635
+ return result;
636
+ } catch (error) {
637
+ options.logger.error('Error sending expo notification: %o', error);
638
+ throw error;
639
+ }
330
640
  },
331
641
  createMessageFileUploadLink(_, {
332
642
  postId,
@@ -335,7 +645,25 @@ const postResolvers = options => ({
335
645
  postService,
336
646
  userContext
337
647
  }) {
338
- return postService.createFileUploadLink(postId, filename, userContext.accountId);
648
+ options.logger.trace('(Mutation.createMessageFileUploadLink) postId [%s], filename [%s]', postId, filename);
649
+ try {
650
+ if (!postId || !filename) {
651
+ options.logger.warn('Missing postId or filename');
652
+ throw new Error('Post ID and filename are required');
653
+ }
654
+ if (!userContext?.accountId) {
655
+ options.logger.warn('Missing user context');
656
+ throw new Error('User authentication required');
657
+ }
658
+ if (!postService) {
659
+ options.logger.warn('PostService not available');
660
+ throw new Error('Post service unavailable');
661
+ }
662
+ return postService.createFileUploadLink(postId, filename, userContext.accountId);
663
+ } catch (error) {
664
+ options.logger.error('Error creating file upload link: %o', error);
665
+ throw error;
666
+ }
339
667
  },
340
668
  attachUploadedFileToMessage(_, {
341
669
  postId,
@@ -344,7 +672,25 @@ const postResolvers = options => ({
344
672
  postService,
345
673
  userContext
346
674
  }) {
347
- return postService.attachUploadedFile(postId, file, userContext.accountId);
675
+ options.logger.trace('(Mutation.attachUploadedFileToMessage) postId [%s], filename [%s]', postId, file?.name);
676
+ try {
677
+ if (!postId || !file) {
678
+ options.logger.warn('Missing postId or file');
679
+ throw new Error('Post ID and file are required');
680
+ }
681
+ if (!userContext?.accountId) {
682
+ options.logger.warn('Missing user context');
683
+ throw new Error('User authentication required');
684
+ }
685
+ if (!postService) {
686
+ options.logger.warn('PostService not available');
687
+ throw new Error('Post service unavailable');
688
+ }
689
+ return postService.attachUploadedFile(postId, file, userContext.accountId);
690
+ } catch (error) {
691
+ options.logger.error('Error attaching uploaded file: %o', error);
692
+ throw error;
693
+ }
348
694
  },
349
695
  async createMessageFilesUploadLink(_, {
350
696
  postId,
@@ -353,7 +699,25 @@ const postResolvers = options => ({
353
699
  postService,
354
700
  userContext
355
701
  }) {
356
- return postService.createFilesUploadLink(postId, filenames, userContext.accountId);
702
+ options.logger.trace('(Mutation.createMessageFilesUploadLink) postId [%s], fileCount [%d]', postId, filenames?.length || 0);
703
+ try {
704
+ if (!postId || !filenames || !Array.isArray(filenames) || filenames.length === 0) {
705
+ options.logger.warn('Missing postId or filenames');
706
+ throw new Error('Post ID and filenames array are required');
707
+ }
708
+ if (!userContext?.accountId) {
709
+ options.logger.warn('Missing user context');
710
+ throw new Error('User authentication required');
711
+ }
712
+ if (!postService) {
713
+ options.logger.warn('PostService not available');
714
+ throw new Error('Post service unavailable');
715
+ }
716
+ return postService.createFilesUploadLink(postId, filenames, userContext.accountId);
717
+ } catch (error) {
718
+ options.logger.error('Error creating files upload links: %o', error);
719
+ throw error;
720
+ }
357
721
  },
358
722
  async attachUploadedFilesToMessage(_, {
359
723
  postId,
@@ -362,14 +726,46 @@ const postResolvers = options => ({
362
726
  postService,
363
727
  userContext
364
728
  }) {
365
- return postService.attachUploadedFiles(postId, files, userContext.accountId);
729
+ options.logger.trace('(Mutation.attachUploadedFilesToMessage) postId [%s], fileCount [%d]', postId, files?.length || 0);
730
+ try {
731
+ if (!postId || !files || !Array.isArray(files) || files.length === 0) {
732
+ options.logger.warn('Missing postId or files');
733
+ throw new Error('Post ID and files array are required');
734
+ }
735
+ if (!userContext?.accountId) {
736
+ options.logger.warn('Missing user context');
737
+ throw new Error('User authentication required');
738
+ }
739
+ if (!postService) {
740
+ options.logger.warn('PostService not available');
741
+ throw new Error('Post service unavailable');
742
+ }
743
+ return postService.attachUploadedFiles(postId, files, userContext.accountId);
744
+ } catch (error) {
745
+ options.logger.error('Error attaching uploaded files: %o', error);
746
+ throw error;
747
+ }
366
748
  },
367
749
  deleteMessageFile(_, {
368
750
  url
369
751
  }, {
370
752
  postService
371
753
  }) {
372
- return postService.deleteFile(url);
754
+ options.logger.trace('(Mutation.deleteMessageFile) url [%s]', url);
755
+ try {
756
+ if (!url) {
757
+ options.logger.warn('Missing URL');
758
+ throw new Error('File URL is required');
759
+ }
760
+ if (!postService) {
761
+ options.logger.warn('PostService not available');
762
+ throw new Error('Post service unavailable');
763
+ }
764
+ return postService.deleteFile(url);
765
+ } catch (error) {
766
+ options.logger.error('Error deleting message file: %o', error);
767
+ throw error;
768
+ }
373
769
  },
374
770
  async readMessage(src, {
375
771
  messageId
@@ -378,11 +774,30 @@ const postResolvers = options => ({
378
774
  userContext,
379
775
  channelService
380
776
  }) {
381
- const member = await channelService.isMember(messageId.channelId, userContext.accountId);
382
- if (!member) {
383
- throw new GraphQLError('Message does not belong to user');
777
+ options.logger.trace('(Mutation.readMessage) messageId [%j], accountId [%s]', messageId, userContext?.accountId);
778
+ try {
779
+ if (!messageId?.channelId || !messageId?.messageId) {
780
+ options.logger.warn('Missing messageId parameters');
781
+ throw new GraphQLError('Message ID and Channel ID are required');
782
+ }
783
+ if (!userContext?.accountId) {
784
+ options.logger.warn('Missing user context');
785
+ throw new GraphQLError('User authentication required');
786
+ }
787
+ if (!postService || !channelService) {
788
+ options.logger.warn('Required services not available');
789
+ throw new GraphQLError('Required services unavailable');
790
+ }
791
+ const member = await channelService.isMember(messageId.channelId, userContext.accountId);
792
+ if (!member) {
793
+ options.logger.warn('User %s is not a member of channel %s', userContext.accountId, messageId.channelId);
794
+ throw new GraphQLError('Message does not belong to user');
795
+ }
796
+ return postService.readMessage(messageId, userContext.accountId);
797
+ } catch (error) {
798
+ options.logger.error('Error reading message: %o', error);
799
+ throw error;
384
800
  }
385
- return postService.readMessage(messageId, userContext.accountId);
386
801
  },
387
802
  async deliverMessage(src, {
388
803
  messageId
@@ -391,70 +806,117 @@ const postResolvers = options => ({
391
806
  userContext,
392
807
  channelService
393
808
  }) {
394
- const member = await channelService.isMember(messageId.channelId, userContext.accountId);
395
- if (!member) {
396
- throw new GraphQLError('Message does not belong to user');
809
+ options.logger.trace('(Mutation.deliverMessage) messageId [%j], accountId [%s]', messageId, userContext?.accountId);
810
+ try {
811
+ if (!messageId?.channelId || !messageId?.messageId) {
812
+ options.logger.warn('Missing messageId parameters');
813
+ throw new GraphQLError('Message ID and Channel ID are required');
814
+ }
815
+ if (!userContext?.accountId) {
816
+ options.logger.warn('Missing user context');
817
+ throw new GraphQLError('User authentication required');
818
+ }
819
+ if (!postService || !channelService) {
820
+ options.logger.warn('Required services not available');
821
+ throw new GraphQLError('Required services unavailable');
822
+ }
823
+ const member = await channelService.isMember(messageId.channelId, userContext.accountId);
824
+ if (!member) {
825
+ options.logger.warn('User %s is not a member of channel %s', userContext.accountId, messageId.channelId);
826
+ throw new GraphQLError('Message does not belong to user');
827
+ }
828
+ return postService.deliverMessage(messageId, userContext.accountId);
829
+ } catch (error) {
830
+ options.logger.error('Error delivering message: %o', error);
831
+ throw error;
397
832
  }
398
- return postService.deliverMessage(messageId, userContext.accountId);
399
833
  },
400
- // uploadFile(src, { files, postId }, { fileInfoService, userContext }) {
401
- // const res = [];
402
- // files.map((file) =>
403
- // res.push(
404
- // fileInfoService.create({
405
- // refType: FileRefType.Post as never,
406
- // file,
407
- // createdBy: userContext.accountId,
408
- // ref: postId,
409
- // }),
410
- // ),
411
- // );
412
- // return res;
413
- // },
414
834
  async TestchatMessage(src, {
415
835
  channelId
416
836
  }, context) {
417
- // if (!context.logger) {
418
- // throw new Error('Logger is not defined in context');
419
- // }
420
- options.pubsub.publish(`CHAT_CREATED.${channelId}`, {
421
- chatMessageTest: {
837
+ options.logger.trace('(Mutation.TestchatMessage) channelId [%s]', channelId);
838
+ try {
839
+ if (!channelId) {
840
+ options.logger.warn('Missing channelId');
841
+ throw new Error('Channel ID is required');
842
+ }
843
+ const testData = {
422
844
  channelId,
423
845
  orgName: 'upadhyaytarun'
424
- }
425
- });
426
- return {
427
- channelId,
428
- orgName: 'upadhyaytarun'
429
- };
846
+ };
847
+ options.logger.debug('Publishing test chat message for channel %s', channelId);
848
+ options.pubsub.publish(`CHAT_CREATED.${channelId}`, {
849
+ chatMessageTest: testData
850
+ });
851
+ return testData;
852
+ } catch (error) {
853
+ options.logger.error('Error in TestchatMessage: %o', error);
854
+ throw error;
855
+ }
430
856
  }
431
857
  },
432
858
  Subscription: {
433
859
  chatMessageAdded: {
434
- // More on pubsub below
435
860
  subscribe: (_, {
436
861
  channelId,
437
862
  directTo
438
863
  }) => {
439
- return options.pubsub.asyncIterator([`POST_CREATED.${channelId}`]);
864
+ options.logger.trace('(Subscription.chatMessageAdded) channelId [%s], directTo [%s]', channelId, directTo);
865
+ try {
866
+ if (!channelId) {
867
+ throw new Error('Channel ID is required for subscription');
868
+ }
869
+ return options.pubsub.asyncIterator([`POST_CREATED.${channelId}`]);
870
+ } catch (error) {
871
+ options.logger.error('Error subscribing to chatMessageAdded: %o', error);
872
+ throw error;
873
+ }
440
874
  },
441
- resolve: payload => payload
875
+ resolve: payload => {
876
+ options.logger.trace('(Subscription.chatMessageAdded.resolve) payload received');
877
+ return payload;
878
+ }
442
879
  },
443
880
  chatMessageTest: {
444
- // More on pubsub below
445
881
  subscribe: (_, {
446
882
  channelId,
447
883
  directTo
448
884
  }) => {
449
- return options.pubsub.asyncIterator([`CHAT_CREATED.${channelId}`]);
885
+ options.logger.trace('(Subscription.chatMessageTest) channelId [%s], directTo [%s]', channelId, directTo);
886
+ try {
887
+ if (!channelId) {
888
+ throw new Error('Channel ID is required for subscription');
889
+ }
890
+ return options.pubsub.asyncIterator([`CHAT_CREATED.${channelId}`]);
891
+ } catch (error) {
892
+ options.logger.error('Error subscribing to chatMessageTest: %o', error);
893
+ throw error;
894
+ }
450
895
  },
451
- resolve: payload => payload
896
+ resolve: payload => {
897
+ options.logger.trace('(Subscription.chatMessageTest.resolve) payload received');
898
+ return payload;
899
+ }
452
900
  },
453
901
  publicPostAdded: {
454
902
  subscribe: (_, {
455
903
  channelId
456
- }) => options.pubsub.asyncIterator([`PUBLIC_POST_CREATED.${channelId}`]),
457
- resolve: payload => payload
904
+ }) => {
905
+ options.logger.trace('(Subscription.publicPostAdded) channelId [%s]', channelId);
906
+ try {
907
+ if (!channelId) {
908
+ throw new Error('Channel ID is required for subscription');
909
+ }
910
+ return options.pubsub.asyncIterator([`PUBLIC_POST_CREATED.${channelId}`]);
911
+ } catch (error) {
912
+ options.logger.error('Error subscribing to publicPostAdded: %o', error);
913
+ throw error;
914
+ }
915
+ },
916
+ resolve: payload => {
917
+ options.logger.trace('(Subscription.publicPostAdded.resolve) payload received');
918
+ return payload;
919
+ }
458
920
  }
459
921
  }
460
922
  });export{postResolvers};//# sourceMappingURL=post.js.map