@flusys/nestjs-notification 7.1.0 → 8.0.0
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.
- package/adapters/index.d.ts +1 -1
- package/adapters/notification.adapter.d.ts +2 -2
- package/config/index.d.ts +3 -3
- package/controllers/index.d.ts +1 -1
- package/controllers/notification.controller.d.ts +4 -4
- package/docs/index.d.ts +1 -1
- package/docs/notification-swagger.config.d.ts +2 -2
- package/dtos/index.d.ts +1 -1
- package/entities/index.d.ts +5 -5
- package/entities/notification-with-company.entity.d.ts +1 -1
- package/fesm/244.js +816 -0
- package/fesm/446.js +939 -0
- package/fesm/adapters/index.js +79 -1
- package/fesm/config/index.js +84 -3
- package/fesm/controllers/index.js +13 -1
- package/fesm/docs/index.js +112 -1
- package/fesm/dtos/index.js +311 -1
- package/fesm/entities/index.js +211 -8
- package/fesm/gateways/index.js +286 -1
- package/fesm/index.js +467 -10
- package/fesm/interfaces/index.js +16 -2
- package/fesm/modules/index.js +269 -1
- package/fesm/runtime.js +85 -0
- package/fesm/services/index.js +357 -4
- package/gateways/index.d.ts +1 -1
- package/gateways/notification.gateway.d.ts +2 -2
- package/index.d.ts +10 -10
- package/interfaces/index.d.ts +2 -2
- package/interfaces/notification-module.interface.d.ts +3 -3
- package/interfaces/notification.interface.d.ts +1 -1
- package/modules/index.d.ts +1 -1
- package/modules/notification.module.d.ts +2 -2
- package/package.json +33 -44
- package/services/index.d.ts +4 -4
- package/services/notification-config.service.d.ts +3 -3
- package/services/notification-datasource.provider.d.ts +3 -3
- package/services/notification-helper.service.d.ts +5 -5
- package/services/notification.service.d.ts +8 -8
- package/cjs/adapters/index.js +0 -18
- package/cjs/adapters/notification.adapter.js +0 -62
- package/cjs/adapters/notification.adapter.spec.js +0 -73
- package/cjs/config/event-actions.js +0 -33
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -19
- package/cjs/config/notification.constants.js +0 -11
- package/cjs/controllers/index.js +0 -18
- package/cjs/controllers/notification.controller.js +0 -299
- package/cjs/controllers/notification.controller.spec.js +0 -214
- package/cjs/docs/index.js +0 -18
- package/cjs/docs/notification-swagger.config.js +0 -97
- package/cjs/docs/notification-swagger.config.spec.js +0 -68
- package/cjs/dtos/index.js +0 -18
- package/cjs/dtos/notification.dto.js +0 -295
- package/cjs/entities/index.js +0 -48
- package/cjs/entities/index.spec.js +0 -13
- package/cjs/entities/notification-with-company.entity.js +0 -57
- package/cjs/entities/notification.entity.js +0 -112
- package/cjs/gateways/index.js +0 -18
- package/cjs/gateways/notification.gateway.js +0 -172
- package/cjs/gateways/notification.gateway.spec.js +0 -359
- package/cjs/index.js +0 -28
- package/cjs/interfaces/index.js +0 -19
- package/cjs/interfaces/notification-module.interface.js +0 -4
- package/cjs/interfaces/notification.interface.js +0 -4
- package/cjs/modules/index.js +0 -18
- package/cjs/modules/notification.module.js +0 -139
- package/cjs/modules/notification.module.spec.js +0 -152
- package/cjs/services/index.js +0 -21
- package/cjs/services/notification-config.service.js +0 -69
- package/cjs/services/notification-config.service.spec.js +0 -113
- package/cjs/services/notification-datasource.provider.js +0 -133
- package/cjs/services/notification-datasource.provider.spec.js +0 -136
- package/cjs/services/notification-helper.service.js +0 -197
- package/cjs/services/notification-helper.service.spec.js +0 -392
- package/cjs/services/notification.service.js +0 -281
- package/cjs/services/notification.service.spec.js +0 -560
- package/fesm/adapters/notification.adapter.js +0 -52
- package/fesm/adapters/notification.adapter.spec.js +0 -69
- package/fesm/config/event-actions.js +0 -12
- package/fesm/config/message-keys.js +0 -9
- package/fesm/config/notification.constants.js +0 -1
- package/fesm/controllers/notification.controller.js +0 -289
- package/fesm/controllers/notification.controller.spec.js +0 -210
- package/fesm/docs/notification-swagger.config.js +0 -87
- package/fesm/docs/notification-swagger.config.spec.js +0 -64
- package/fesm/dtos/notification.dto.js +0 -262
- package/fesm/entities/index.spec.js +0 -9
- package/fesm/entities/notification-with-company.entity.js +0 -47
- package/fesm/entities/notification.entity.js +0 -102
- package/fesm/gateways/notification.gateway.js +0 -162
- package/fesm/gateways/notification.gateway.spec.js +0 -355
- package/fesm/interfaces/notification-module.interface.js +0 -1
- package/fesm/interfaces/notification.interface.js +0 -1
- package/fesm/modules/notification.module.js +0 -129
- package/fesm/modules/notification.module.spec.js +0 -148
- package/fesm/services/notification-config.service.js +0 -59
- package/fesm/services/notification-config.service.spec.js +0 -109
- package/fesm/services/notification-datasource.provider.js +0 -82
- package/fesm/services/notification-datasource.provider.spec.js +0 -132
- package/fesm/services/notification-helper.service.js +0 -187
- package/fesm/services/notification-helper.service.spec.js +0 -388
- package/fesm/services/notification.service.js +0 -271
- package/fesm/services/notification.service.spec.js +0 -556
package/fesm/446.js
ADDED
|
@@ -0,0 +1,939 @@
|
|
|
1
|
+
import { IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, IsUUID, MaxLength } from "class-validator";
|
|
2
|
+
import { applyCompanyFilter } from "@flusys/nestjs-shared/utils";
|
|
3
|
+
import * as __rspack_external__nestjs_swagger_7cd450b5 from "@nestjs/swagger";
|
|
4
|
+
import * as __rspack_external_class_transformer_c5a479fb from "class-transformer";
|
|
5
|
+
import * as __rspack_external__flusys_nestjs_shared_decorators_c129b601 from "@flusys/nestjs-shared/decorators";
|
|
6
|
+
import * as __rspack_external__flusys_nestjs_shared_dtos_c4585026 from "@flusys/nestjs-shared/dtos";
|
|
7
|
+
import * as __rspack_external__flusys_nestjs_shared_guards_3f79ddd1 from "@flusys/nestjs-shared/guards";
|
|
8
|
+
export const __rspack_esm_id = 446;
|
|
9
|
+
export const __rspack_esm_ids = [446];
|
|
10
|
+
export const __webpack_modules__ = {
|
|
11
|
+
158(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
12
|
+
// ==================== NOTIFICATION MODULE MESSAGE KEYS ====================
|
|
13
|
+
const NOTIFICATION_MESSAGES = {
|
|
14
|
+
NOT_FOUND: 'notification.not.found',
|
|
15
|
+
MARK_READ_SUCCESS: 'notification.mark.read.success',
|
|
16
|
+
MARK_ALL_READ_SUCCESS: 'notification.mark.all.read.success',
|
|
17
|
+
UNREAD_COUNT_SUCCESS: 'notification.unread.count.success',
|
|
18
|
+
SEND_SUCCESS: 'notification.send.success',
|
|
19
|
+
BROADCAST_SUCCESS: 'notification.broadcast.success'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
23
|
+
}, {
|
|
24
|
+
x: NOTIFICATION_MESSAGES
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
},
|
|
29
|
+
101(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
30
|
+
|
|
31
|
+
// EXPORTS
|
|
32
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
33
|
+
e: () => (/* reexport */ NotificationController)
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/classes"
|
|
37
|
+
var classes_ = __webpack_require__(937);
|
|
38
|
+
;// CONCATENATED MODULE: external "@flusys/nestjs-shared/decorators"
|
|
39
|
+
|
|
40
|
+
;// CONCATENATED MODULE: external "@flusys/nestjs-shared/dtos"
|
|
41
|
+
|
|
42
|
+
;// CONCATENATED MODULE: external "@flusys/nestjs-shared/guards"
|
|
43
|
+
|
|
44
|
+
// EXTERNAL MODULE: external "@nestjs/common"
|
|
45
|
+
var common_ = __webpack_require__(157);
|
|
46
|
+
// EXTERNAL MODULE: external "@nestjs/swagger"
|
|
47
|
+
var swagger_ = __webpack_require__(176);
|
|
48
|
+
// EXTERNAL MODULE: external "class-transformer"
|
|
49
|
+
var external_class_transformer_ = __webpack_require__(812);
|
|
50
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/config/message-keys.ts
|
|
51
|
+
var message_keys = __webpack_require__(158);
|
|
52
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/dtos/index.ts + 2 modules
|
|
53
|
+
var dtos = __webpack_require__(733);
|
|
54
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/services/notification-helper.service.ts
|
|
55
|
+
var notification_helper_service = __webpack_require__(487);
|
|
56
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/services/notification.service.ts + 1 modules
|
|
57
|
+
var notification_service = __webpack_require__(305);
|
|
58
|
+
;// CONCATENATED MODULE: ./projects/nestjs-notification/src/controllers/notification.controller.ts
|
|
59
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
60
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
61
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
62
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
63
|
+
} else {
|
|
64
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
65
|
+
if (d = decorators[i]) {
|
|
66
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
71
|
+
}
|
|
72
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
73
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
74
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function _ts_param(paramIndex, decorator) {
|
|
78
|
+
return function(target, key) {
|
|
79
|
+
decorator(target, key, paramIndex);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class NotificationController extends (0,classes_.createApiController)(dtos/* .CreateNotificationDto */.X0, dtos/* .UpdateNotificationDto */.Oc, dtos/* .NotificationResponseDto */.eB, {
|
|
94
|
+
entityName: 'notification',
|
|
95
|
+
security: {
|
|
96
|
+
insert: {
|
|
97
|
+
level: 'permission',
|
|
98
|
+
permissions: [
|
|
99
|
+
classes_.NOTIFICATION_PERMISSIONS.CREATE
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
insertMany: {
|
|
103
|
+
level: 'permission',
|
|
104
|
+
permissions: [
|
|
105
|
+
classes_.NOTIFICATION_PERMISSIONS.CREATE
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
getById: {
|
|
109
|
+
level: 'permission',
|
|
110
|
+
permissions: [
|
|
111
|
+
classes_.NOTIFICATION_PERMISSIONS.READ
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
getAll: {
|
|
115
|
+
level: 'jwt'
|
|
116
|
+
},
|
|
117
|
+
update: {
|
|
118
|
+
level: 'permission',
|
|
119
|
+
permissions: [
|
|
120
|
+
classes_.NOTIFICATION_PERMISSIONS.UPDATE
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
updateMany: {
|
|
124
|
+
level: 'permission',
|
|
125
|
+
permissions: [
|
|
126
|
+
classes_.NOTIFICATION_PERMISSIONS.UPDATE
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
delete: {
|
|
130
|
+
level: 'permission',
|
|
131
|
+
permissions: [
|
|
132
|
+
classes_.NOTIFICATION_PERMISSIONS.DELETE
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}) {
|
|
137
|
+
service;
|
|
138
|
+
notificationHelper;
|
|
139
|
+
constructor(service, notificationHelper){
|
|
140
|
+
super(service), this.service = service, this.notificationHelper = notificationHelper;
|
|
141
|
+
}
|
|
142
|
+
async markAsRead(dto, user) {
|
|
143
|
+
const notification = await this.service.markAsRead(dto.id, user);
|
|
144
|
+
const plainOptions = {
|
|
145
|
+
excludeExtraneousValues: true
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
success: true,
|
|
149
|
+
message: 'Notification marked as read',
|
|
150
|
+
messageKey: message_keys/* .NOTIFICATION_MESSAGES.MARK_READ_SUCCESS */.x.MARK_READ_SUCCESS,
|
|
151
|
+
data: (0,external_class_transformer_.plainToInstance)(dtos/* .NotificationResponseDto */.eB, notification, plainOptions)
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
async markAllAsRead(user) {
|
|
155
|
+
const count = await this.service.markAllAsRead(user);
|
|
156
|
+
return {
|
|
157
|
+
success: true,
|
|
158
|
+
message: `${count} notifications marked as read`,
|
|
159
|
+
messageKey: message_keys/* .NOTIFICATION_MESSAGES.MARK_ALL_READ_SUCCESS */.x.MARK_ALL_READ_SUCCESS,
|
|
160
|
+
messageVariables: {
|
|
161
|
+
count
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
async getUnreadCount(user) {
|
|
166
|
+
const count = await this.service.getUnreadCount(user);
|
|
167
|
+
return {
|
|
168
|
+
success: true,
|
|
169
|
+
message: 'Unread count retrieved',
|
|
170
|
+
messageKey: message_keys/* .NOTIFICATION_MESSAGES.UNREAD_COUNT_SUCCESS */.x.UNREAD_COUNT_SUCCESS,
|
|
171
|
+
data: {
|
|
172
|
+
count
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async sendNotification(dto) {
|
|
177
|
+
const notification = await this.notificationHelper.send({
|
|
178
|
+
userId: dto.userId,
|
|
179
|
+
title: dto.title,
|
|
180
|
+
message: dto.message,
|
|
181
|
+
type: dto.type,
|
|
182
|
+
data: dto.data,
|
|
183
|
+
companyId: dto.companyId
|
|
184
|
+
});
|
|
185
|
+
const plainOptions = {
|
|
186
|
+
excludeExtraneousValues: true
|
|
187
|
+
};
|
|
188
|
+
return {
|
|
189
|
+
success: true,
|
|
190
|
+
message: 'Notification sent successfully',
|
|
191
|
+
messageKey: message_keys/* .NOTIFICATION_MESSAGES.SEND_SUCCESS */.x.SEND_SUCCESS,
|
|
192
|
+
data: (0,external_class_transformer_.plainToInstance)(dtos/* .NotificationResponseDto */.eB, notification, plainOptions)
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
async sendBulkNotification(dto) {
|
|
196
|
+
const notifications = await this.notificationHelper.sendToMany({
|
|
197
|
+
userIds: dto.userIds,
|
|
198
|
+
title: dto.title,
|
|
199
|
+
message: dto.message,
|
|
200
|
+
type: dto.type,
|
|
201
|
+
data: dto.data,
|
|
202
|
+
companyId: dto.companyId
|
|
203
|
+
});
|
|
204
|
+
const plainOptions = {
|
|
205
|
+
excludeExtraneousValues: true
|
|
206
|
+
};
|
|
207
|
+
return {
|
|
208
|
+
success: true,
|
|
209
|
+
message: `${notifications.length} notifications sent successfully`,
|
|
210
|
+
messageKey: message_keys/* .NOTIFICATION_MESSAGES.BROADCAST_SUCCESS */.x.BROADCAST_SUCCESS,
|
|
211
|
+
messageVariables: {
|
|
212
|
+
count: notifications.length
|
|
213
|
+
},
|
|
214
|
+
data: notifications.map((n)=>(0,external_class_transformer_.plainToInstance)(dtos/* .NotificationResponseDto */.eB, n, plainOptions)),
|
|
215
|
+
meta: {
|
|
216
|
+
count: notifications.length,
|
|
217
|
+
total: dto.userIds.length
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
_ts_decorate([
|
|
223
|
+
(0,common_.Post)('mark-read'),
|
|
224
|
+
(0,common_.HttpCode)(common_.HttpStatus.OK),
|
|
225
|
+
(0,common_.UseGuards)(__rspack_external__flusys_nestjs_shared_guards_3f79ddd1.JwtAuthGuard),
|
|
226
|
+
(0,swagger_.ApiBearerAuth)(),
|
|
227
|
+
(0,swagger_.ApiOperation)({
|
|
228
|
+
summary: 'Mark a notification as read'
|
|
229
|
+
}),
|
|
230
|
+
(0,swagger_.ApiBody)({
|
|
231
|
+
type: dtos/* .MarkReadDto */.xo
|
|
232
|
+
}),
|
|
233
|
+
(0,swagger_.ApiResponse)({
|
|
234
|
+
status: 200,
|
|
235
|
+
description: 'Notification marked as read',
|
|
236
|
+
type: __rspack_external__flusys_nestjs_shared_dtos_c4585026.SingleResponseDto
|
|
237
|
+
}),
|
|
238
|
+
_ts_param(0, (0,common_.Body)()),
|
|
239
|
+
_ts_param(1, (0,__rspack_external__flusys_nestjs_shared_decorators_c129b601.CurrentUser)()),
|
|
240
|
+
_ts_metadata("design:type", Function),
|
|
241
|
+
_ts_metadata("design:paramtypes", [
|
|
242
|
+
typeof dtos/* .MarkReadDto */.xo === "undefined" ? Object : dtos/* .MarkReadDto */.xo,
|
|
243
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
244
|
+
]),
|
|
245
|
+
_ts_metadata("design:returntype", Promise)
|
|
246
|
+
], NotificationController.prototype, "markAsRead", null);
|
|
247
|
+
_ts_decorate([
|
|
248
|
+
(0,common_.Post)('mark-all-read'),
|
|
249
|
+
(0,common_.HttpCode)(common_.HttpStatus.OK),
|
|
250
|
+
(0,common_.UseGuards)(__rspack_external__flusys_nestjs_shared_guards_3f79ddd1.JwtAuthGuard),
|
|
251
|
+
(0,swagger_.ApiBearerAuth)(),
|
|
252
|
+
(0,swagger_.ApiOperation)({
|
|
253
|
+
summary: 'Mark all notifications as read'
|
|
254
|
+
}),
|
|
255
|
+
(0,swagger_.ApiResponse)({
|
|
256
|
+
status: 200,
|
|
257
|
+
description: 'All notifications marked as read',
|
|
258
|
+
type: __rspack_external__flusys_nestjs_shared_dtos_c4585026.MessageResponseDto
|
|
259
|
+
}),
|
|
260
|
+
_ts_param(0, (0,__rspack_external__flusys_nestjs_shared_decorators_c129b601.CurrentUser)()),
|
|
261
|
+
_ts_metadata("design:type", Function),
|
|
262
|
+
_ts_metadata("design:paramtypes", [
|
|
263
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
264
|
+
]),
|
|
265
|
+
_ts_metadata("design:returntype", Promise)
|
|
266
|
+
], NotificationController.prototype, "markAllAsRead", null);
|
|
267
|
+
_ts_decorate([
|
|
268
|
+
(0,common_.Post)('unread-count'),
|
|
269
|
+
(0,common_.HttpCode)(common_.HttpStatus.OK),
|
|
270
|
+
(0,common_.UseGuards)(__rspack_external__flusys_nestjs_shared_guards_3f79ddd1.JwtAuthGuard),
|
|
271
|
+
(0,swagger_.ApiBearerAuth)(),
|
|
272
|
+
(0,swagger_.ApiOperation)({
|
|
273
|
+
summary: 'Get unread notification count'
|
|
274
|
+
}),
|
|
275
|
+
(0,swagger_.ApiResponse)({
|
|
276
|
+
status: 200,
|
|
277
|
+
description: 'Unread count retrieved',
|
|
278
|
+
type: __rspack_external__flusys_nestjs_shared_dtos_c4585026.SingleResponseDto
|
|
279
|
+
}),
|
|
280
|
+
_ts_param(0, (0,__rspack_external__flusys_nestjs_shared_decorators_c129b601.CurrentUser)()),
|
|
281
|
+
_ts_metadata("design:type", Function),
|
|
282
|
+
_ts_metadata("design:paramtypes", [
|
|
283
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
284
|
+
]),
|
|
285
|
+
_ts_metadata("design:returntype", Promise)
|
|
286
|
+
], NotificationController.prototype, "getUnreadCount", null);
|
|
287
|
+
_ts_decorate([
|
|
288
|
+
(0,common_.Post)('send'),
|
|
289
|
+
(0,common_.HttpCode)(common_.HttpStatus.OK),
|
|
290
|
+
(0,common_.UseGuards)(__rspack_external__flusys_nestjs_shared_guards_3f79ddd1.JwtAuthGuard, __rspack_external__flusys_nestjs_shared_guards_3f79ddd1.PermissionGuard),
|
|
291
|
+
(0,__rspack_external__flusys_nestjs_shared_decorators_c129b601.RequirePermission)(classes_.NOTIFICATION_PERMISSIONS.CREATE),
|
|
292
|
+
(0,swagger_.ApiOperation)({
|
|
293
|
+
summary: 'Send a notification to a user'
|
|
294
|
+
}),
|
|
295
|
+
(0,swagger_.ApiBody)({
|
|
296
|
+
type: dtos/* .SendNotificationDto */.Zs
|
|
297
|
+
}),
|
|
298
|
+
(0,swagger_.ApiResponse)({
|
|
299
|
+
status: 200,
|
|
300
|
+
description: 'Notification sent successfully',
|
|
301
|
+
type: __rspack_external__flusys_nestjs_shared_dtos_c4585026.SingleResponseDto
|
|
302
|
+
}),
|
|
303
|
+
_ts_param(0, (0,common_.Body)()),
|
|
304
|
+
_ts_metadata("design:type", Function),
|
|
305
|
+
_ts_metadata("design:paramtypes", [
|
|
306
|
+
typeof dtos/* .SendNotificationDto */.Zs === "undefined" ? Object : dtos/* .SendNotificationDto */.Zs
|
|
307
|
+
]),
|
|
308
|
+
_ts_metadata("design:returntype", Promise)
|
|
309
|
+
], NotificationController.prototype, "sendNotification", null);
|
|
310
|
+
_ts_decorate([
|
|
311
|
+
(0,common_.Post)('send-bulk'),
|
|
312
|
+
(0,common_.HttpCode)(common_.HttpStatus.OK),
|
|
313
|
+
(0,common_.UseGuards)(__rspack_external__flusys_nestjs_shared_guards_3f79ddd1.JwtAuthGuard, __rspack_external__flusys_nestjs_shared_guards_3f79ddd1.PermissionGuard),
|
|
314
|
+
(0,__rspack_external__flusys_nestjs_shared_decorators_c129b601.RequirePermission)(classes_.NOTIFICATION_PERMISSIONS.CREATE),
|
|
315
|
+
(0,swagger_.ApiOperation)({
|
|
316
|
+
summary: 'Send a notification to multiple users'
|
|
317
|
+
}),
|
|
318
|
+
(0,swagger_.ApiBody)({
|
|
319
|
+
type: dtos/* .SendBulkNotificationDto */.HD
|
|
320
|
+
}),
|
|
321
|
+
(0,swagger_.ApiResponse)({
|
|
322
|
+
status: 200,
|
|
323
|
+
description: 'Notifications sent successfully',
|
|
324
|
+
type: __rspack_external__flusys_nestjs_shared_dtos_c4585026.BulkResponseDto
|
|
325
|
+
}),
|
|
326
|
+
_ts_param(0, (0,common_.Body)()),
|
|
327
|
+
_ts_metadata("design:type", Function),
|
|
328
|
+
_ts_metadata("design:paramtypes", [
|
|
329
|
+
typeof dtos/* .SendBulkNotificationDto */.HD === "undefined" ? Object : dtos/* .SendBulkNotificationDto */.HD
|
|
330
|
+
]),
|
|
331
|
+
_ts_metadata("design:returntype", Promise)
|
|
332
|
+
], NotificationController.prototype, "sendBulkNotification", null);
|
|
333
|
+
NotificationController = _ts_decorate([
|
|
334
|
+
(0,swagger_.ApiTags)('Notifications'),
|
|
335
|
+
(0,swagger_.ApiBearerAuth)(),
|
|
336
|
+
(0,common_.Controller)('notification'),
|
|
337
|
+
_ts_param(0, (0,common_.Inject)(notification_service/* .NotificationService */.J)),
|
|
338
|
+
_ts_param(1, (0,common_.Inject)(notification_helper_service/* .NotificationHelperService */.T)),
|
|
339
|
+
_ts_metadata("design:type", Function),
|
|
340
|
+
_ts_metadata("design:paramtypes", [
|
|
341
|
+
typeof notification_service/* .NotificationService */.J === "undefined" ? Object : notification_service/* .NotificationService */.J,
|
|
342
|
+
typeof notification_helper_service/* .NotificationHelperService */.T === "undefined" ? Object : notification_helper_service/* .NotificationHelperService */.T
|
|
343
|
+
])
|
|
344
|
+
], NotificationController);
|
|
345
|
+
|
|
346
|
+
;// CONCATENATED MODULE: ./projects/nestjs-notification/src/controllers/index.ts
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
},
|
|
351
|
+
733(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
352
|
+
|
|
353
|
+
// EXPORTS
|
|
354
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
355
|
+
X0: () => (/* reexport */ CreateNotificationDto),
|
|
356
|
+
xo: () => (/* reexport */ MarkReadDto),
|
|
357
|
+
eB: () => (/* reexport */ NotificationResponseDto),
|
|
358
|
+
HD: () => (/* reexport */ SendBulkNotificationDto),
|
|
359
|
+
Zs: () => (/* reexport */ SendNotificationDto),
|
|
360
|
+
vi: () => (/* reexport */ UnreadCountResponseDto),
|
|
361
|
+
Oc: () => (/* reexport */ UpdateNotificationDto)
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/enums"
|
|
365
|
+
var enums_ = __webpack_require__(471);
|
|
366
|
+
// EXTERNAL MODULE: external "@nestjs/swagger"
|
|
367
|
+
var swagger_ = __webpack_require__(176);
|
|
368
|
+
// EXTERNAL MODULE: external "class-transformer"
|
|
369
|
+
var external_class_transformer_ = __webpack_require__(812);
|
|
370
|
+
;// CONCATENATED MODULE: external "class-validator"
|
|
371
|
+
|
|
372
|
+
;// CONCATENATED MODULE: ./projects/nestjs-notification/src/dtos/notification.dto.ts
|
|
373
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
374
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
375
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
376
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
377
|
+
} else {
|
|
378
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
379
|
+
if (d = decorators[i]) {
|
|
380
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
385
|
+
}
|
|
386
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
387
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
388
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
let NotificationContentDto = class NotificationContentDto {
|
|
396
|
+
title;
|
|
397
|
+
message;
|
|
398
|
+
type;
|
|
399
|
+
data;
|
|
400
|
+
companyId;
|
|
401
|
+
};
|
|
402
|
+
_ts_decorate([
|
|
403
|
+
(0,swagger_.ApiProperty)({
|
|
404
|
+
maxLength: 255
|
|
405
|
+
}),
|
|
406
|
+
IsNotEmpty(),
|
|
407
|
+
IsString(),
|
|
408
|
+
MaxLength(255),
|
|
409
|
+
_ts_metadata("design:type", String)
|
|
410
|
+
], NotificationContentDto.prototype, "title", void 0);
|
|
411
|
+
_ts_decorate([
|
|
412
|
+
(0,swagger_.ApiPropertyOptional)(),
|
|
413
|
+
IsOptional(),
|
|
414
|
+
IsString(),
|
|
415
|
+
_ts_metadata("design:type", String)
|
|
416
|
+
], NotificationContentDto.prototype, "message", void 0);
|
|
417
|
+
_ts_decorate([
|
|
418
|
+
(0,swagger_.ApiPropertyOptional)({
|
|
419
|
+
enum: enums_.NotificationType,
|
|
420
|
+
default: enums_.NotificationType.INFO
|
|
421
|
+
}),
|
|
422
|
+
IsOptional(),
|
|
423
|
+
IsEnum(enums_.NotificationType),
|
|
424
|
+
_ts_metadata("design:type", typeof enums_.NotificationType === "undefined" ? Object : enums_.NotificationType)
|
|
425
|
+
], NotificationContentDto.prototype, "type", void 0);
|
|
426
|
+
_ts_decorate([
|
|
427
|
+
(0,swagger_.ApiPropertyOptional)(),
|
|
428
|
+
IsOptional(),
|
|
429
|
+
IsObject(),
|
|
430
|
+
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
431
|
+
], NotificationContentDto.prototype, "data", void 0);
|
|
432
|
+
_ts_decorate([
|
|
433
|
+
(0,swagger_.ApiPropertyOptional)(),
|
|
434
|
+
IsOptional(),
|
|
435
|
+
IsUUID(),
|
|
436
|
+
_ts_metadata("design:type", String)
|
|
437
|
+
], NotificationContentDto.prototype, "companyId", void 0);
|
|
438
|
+
let UserIdDto = class UserIdDto {
|
|
439
|
+
userId;
|
|
440
|
+
};
|
|
441
|
+
_ts_decorate([
|
|
442
|
+
(0,swagger_.ApiProperty)(),
|
|
443
|
+
IsNotEmpty(),
|
|
444
|
+
IsUUID(),
|
|
445
|
+
_ts_metadata("design:type", String)
|
|
446
|
+
], UserIdDto.prototype, "userId", void 0);
|
|
447
|
+
let UserIdsDto = class UserIdsDto {
|
|
448
|
+
userIds;
|
|
449
|
+
};
|
|
450
|
+
_ts_decorate([
|
|
451
|
+
(0,swagger_.ApiProperty)({
|
|
452
|
+
type: [
|
|
453
|
+
String
|
|
454
|
+
]
|
|
455
|
+
}),
|
|
456
|
+
IsNotEmpty(),
|
|
457
|
+
IsUUID('4', {
|
|
458
|
+
each: true
|
|
459
|
+
}),
|
|
460
|
+
_ts_metadata("design:type", Array)
|
|
461
|
+
], UserIdsDto.prototype, "userIds", void 0);
|
|
462
|
+
class CreateNotificationDto extends (0,swagger_.IntersectionType)(UserIdDto, NotificationContentDto) {
|
|
463
|
+
}
|
|
464
|
+
class UpdateNotificationDto extends (0,swagger_.PartialType)((0,swagger_.OmitType)(CreateNotificationDto, [
|
|
465
|
+
'userId'
|
|
466
|
+
])) {
|
|
467
|
+
id;
|
|
468
|
+
}
|
|
469
|
+
_ts_decorate([
|
|
470
|
+
(0,swagger_.ApiProperty)(),
|
|
471
|
+
IsUUID(),
|
|
472
|
+
IsNotEmpty(),
|
|
473
|
+
_ts_metadata("design:type", String)
|
|
474
|
+
], UpdateNotificationDto.prototype, "id", void 0);
|
|
475
|
+
class MarkReadDto {
|
|
476
|
+
id;
|
|
477
|
+
}
|
|
478
|
+
_ts_decorate([
|
|
479
|
+
(0,swagger_.ApiProperty)(),
|
|
480
|
+
IsUUID(),
|
|
481
|
+
IsNotEmpty(),
|
|
482
|
+
_ts_metadata("design:type", String)
|
|
483
|
+
], MarkReadDto.prototype, "id", void 0);
|
|
484
|
+
class NotificationResponseDto {
|
|
485
|
+
id;
|
|
486
|
+
userId;
|
|
487
|
+
type;
|
|
488
|
+
title;
|
|
489
|
+
message;
|
|
490
|
+
data;
|
|
491
|
+
isRead;
|
|
492
|
+
readAt;
|
|
493
|
+
companyId;
|
|
494
|
+
createdAt;
|
|
495
|
+
updatedAt;
|
|
496
|
+
}
|
|
497
|
+
_ts_decorate([
|
|
498
|
+
(0,external_class_transformer_.Expose)(),
|
|
499
|
+
(0,swagger_.ApiProperty)({
|
|
500
|
+
description: 'Unique identifier of the notification',
|
|
501
|
+
example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c'
|
|
502
|
+
}),
|
|
503
|
+
_ts_metadata("design:type", String)
|
|
504
|
+
], NotificationResponseDto.prototype, "id", void 0);
|
|
505
|
+
_ts_decorate([
|
|
506
|
+
(0,external_class_transformer_.Expose)(),
|
|
507
|
+
(0,swagger_.ApiProperty)({
|
|
508
|
+
description: 'ID of the user this notification belongs to',
|
|
509
|
+
example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c'
|
|
510
|
+
}),
|
|
511
|
+
_ts_metadata("design:type", String)
|
|
512
|
+
], NotificationResponseDto.prototype, "userId", void 0);
|
|
513
|
+
_ts_decorate([
|
|
514
|
+
(0,external_class_transformer_.Expose)(),
|
|
515
|
+
(0,swagger_.ApiProperty)({
|
|
516
|
+
description: 'Category of the notification',
|
|
517
|
+
enum: enums_.NotificationType,
|
|
518
|
+
example: enums_.NotificationType.SUCCESS
|
|
519
|
+
}),
|
|
520
|
+
_ts_metadata("design:type", typeof enums_.NotificationType === "undefined" ? Object : enums_.NotificationType)
|
|
521
|
+
], NotificationResponseDto.prototype, "type", void 0);
|
|
522
|
+
_ts_decorate([
|
|
523
|
+
(0,external_class_transformer_.Expose)(),
|
|
524
|
+
(0,swagger_.ApiProperty)({
|
|
525
|
+
description: 'Short title of the notification',
|
|
526
|
+
example: 'Your export is ready'
|
|
527
|
+
}),
|
|
528
|
+
_ts_metadata("design:type", String)
|
|
529
|
+
], NotificationResponseDto.prototype, "title", void 0);
|
|
530
|
+
_ts_decorate([
|
|
531
|
+
(0,external_class_transformer_.Expose)(),
|
|
532
|
+
(0,swagger_.ApiPropertyOptional)({
|
|
533
|
+
description: 'Optional longer body text for the notification',
|
|
534
|
+
example: 'Your CSV export has finished processing and is ready to download.',
|
|
535
|
+
nullable: true
|
|
536
|
+
}),
|
|
537
|
+
_ts_metadata("design:type", Object)
|
|
538
|
+
], NotificationResponseDto.prototype, "message", void 0);
|
|
539
|
+
_ts_decorate([
|
|
540
|
+
(0,external_class_transformer_.Expose)(),
|
|
541
|
+
(0,swagger_.ApiPropertyOptional)({
|
|
542
|
+
description: 'Arbitrary JSON payload attached to the notification',
|
|
543
|
+
type: 'object',
|
|
544
|
+
additionalProperties: true,
|
|
545
|
+
nullable: true,
|
|
546
|
+
example: {
|
|
547
|
+
exportId: 'abc123',
|
|
548
|
+
fileUrl: 'https://cdn.example.com/export.csv'
|
|
549
|
+
}
|
|
550
|
+
}),
|
|
551
|
+
_ts_metadata("design:type", Object)
|
|
552
|
+
], NotificationResponseDto.prototype, "data", void 0);
|
|
553
|
+
_ts_decorate([
|
|
554
|
+
(0,external_class_transformer_.Expose)(),
|
|
555
|
+
(0,swagger_.ApiProperty)({
|
|
556
|
+
description: 'Whether the user has read this notification',
|
|
557
|
+
example: false
|
|
558
|
+
}),
|
|
559
|
+
_ts_metadata("design:type", Boolean)
|
|
560
|
+
], NotificationResponseDto.prototype, "isRead", void 0);
|
|
561
|
+
_ts_decorate([
|
|
562
|
+
(0,external_class_transformer_.Expose)(),
|
|
563
|
+
(0,swagger_.ApiPropertyOptional)({
|
|
564
|
+
description: 'Timestamp when the notification was marked as read; null if unread',
|
|
565
|
+
type: 'string',
|
|
566
|
+
format: 'date-time',
|
|
567
|
+
nullable: true,
|
|
568
|
+
example: '2024-03-15T10:30:00.000Z'
|
|
569
|
+
}),
|
|
570
|
+
_ts_metadata("design:type", Object)
|
|
571
|
+
], NotificationResponseDto.prototype, "readAt", void 0);
|
|
572
|
+
_ts_decorate([
|
|
573
|
+
(0,external_class_transformer_.Expose)(),
|
|
574
|
+
(0,swagger_.ApiPropertyOptional)({
|
|
575
|
+
description: 'Company scope for the notification; null for personal notifications',
|
|
576
|
+
example: '018e1b2c-3d4e-5f6a-7b8c-9d0e1f2a3b4c',
|
|
577
|
+
nullable: true
|
|
578
|
+
}),
|
|
579
|
+
_ts_metadata("design:type", Object)
|
|
580
|
+
], NotificationResponseDto.prototype, "companyId", void 0);
|
|
581
|
+
_ts_decorate([
|
|
582
|
+
(0,external_class_transformer_.Expose)(),
|
|
583
|
+
(0,swagger_.ApiProperty)({
|
|
584
|
+
description: 'Timestamp when the notification was created',
|
|
585
|
+
type: 'string',
|
|
586
|
+
format: 'date-time',
|
|
587
|
+
example: '2024-03-15T10:00:00.000Z'
|
|
588
|
+
}),
|
|
589
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
590
|
+
], NotificationResponseDto.prototype, "createdAt", void 0);
|
|
591
|
+
_ts_decorate([
|
|
592
|
+
(0,external_class_transformer_.Expose)(),
|
|
593
|
+
(0,swagger_.ApiProperty)({
|
|
594
|
+
description: 'Timestamp when the notification was last updated',
|
|
595
|
+
type: 'string',
|
|
596
|
+
format: 'date-time',
|
|
597
|
+
example: '2024-03-15T10:30:00.000Z'
|
|
598
|
+
}),
|
|
599
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
600
|
+
], NotificationResponseDto.prototype, "updatedAt", void 0);
|
|
601
|
+
class UnreadCountResponseDto {
|
|
602
|
+
count;
|
|
603
|
+
}
|
|
604
|
+
_ts_decorate([
|
|
605
|
+
(0,external_class_transformer_.Expose)(),
|
|
606
|
+
(0,swagger_.ApiProperty)({
|
|
607
|
+
description: 'Total number of unread notifications for the user',
|
|
608
|
+
example: 5,
|
|
609
|
+
minimum: 0
|
|
610
|
+
}),
|
|
611
|
+
_ts_metadata("design:type", Number)
|
|
612
|
+
], UnreadCountResponseDto.prototype, "count", void 0);
|
|
613
|
+
class SendNotificationDto extends (0,swagger_.IntersectionType)(UserIdDto, NotificationContentDto) {
|
|
614
|
+
}
|
|
615
|
+
class SendBulkNotificationDto extends (0,swagger_.IntersectionType)(UserIdsDto, NotificationContentDto) {
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
;// CONCATENATED MODULE: ./projects/nestjs-notification/src/dtos/index.ts
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
},
|
|
623
|
+
305(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
624
|
+
|
|
625
|
+
// EXPORTS
|
|
626
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
627
|
+
J: () => (/* binding */ NotificationService)
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared"
|
|
631
|
+
var nestjs_shared_ = __webpack_require__(422);
|
|
632
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/classes"
|
|
633
|
+
var classes_ = __webpack_require__(937);
|
|
634
|
+
// EXTERNAL MODULE: external "@flusys/nestjs-shared/modules"
|
|
635
|
+
var modules_ = __webpack_require__(236);
|
|
636
|
+
;// CONCATENATED MODULE: external "@flusys/nestjs-shared/utils"
|
|
637
|
+
|
|
638
|
+
// EXTERNAL MODULE: external "@nestjs/common"
|
|
639
|
+
var common_ = __webpack_require__(157);
|
|
640
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/config/event-actions.ts
|
|
641
|
+
var event_actions = __webpack_require__(360);
|
|
642
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/config/message-keys.ts
|
|
643
|
+
var message_keys = __webpack_require__(158);
|
|
644
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/entities/index.ts + 4 modules
|
|
645
|
+
var src_entities = __webpack_require__(240);
|
|
646
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/gateways/index.ts + 4 modules
|
|
647
|
+
var gateways = __webpack_require__(31);
|
|
648
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/services/notification-config.service.ts
|
|
649
|
+
var notification_config_service = __webpack_require__(53);
|
|
650
|
+
// EXTERNAL MODULE: ./projects/nestjs-notification/src/services/notification-datasource.provider.ts + 1 modules
|
|
651
|
+
var notification_datasource_provider = __webpack_require__(335);
|
|
652
|
+
;// CONCATENATED MODULE: ./projects/nestjs-notification/src/services/notification.service.ts
|
|
653
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
654
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
655
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
656
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
657
|
+
} else {
|
|
658
|
+
for(var i = decorators.length - 1; i >= 0; i--){
|
|
659
|
+
if (d = decorators[i]) {
|
|
660
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
665
|
+
}
|
|
666
|
+
function _ts_metadata(metadataKey, metadataValue) {
|
|
667
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
668
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
function _ts_param(paramIndex, decorator) {
|
|
672
|
+
return function(target, key) {
|
|
673
|
+
decorator(target, key, paramIndex);
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
class NotificationService extends classes_.ApiService {
|
|
687
|
+
cacheManager;
|
|
688
|
+
utilsService;
|
|
689
|
+
notificationConfig;
|
|
690
|
+
gateway;
|
|
691
|
+
constructor(cacheManager, utilsService, notificationConfig, dataSourceProvider, gateway){
|
|
692
|
+
super(event_actions/* .NOTIFICATION_EVENT_ENTITIES.NOTIFICATION */.BA.NOTIFICATION, cacheManager, utilsService, NotificationService.name, false, event_actions/* .NOTIFICATION_EVENT_MODULE */.Wx, dataSourceProvider, notificationConfig.isCompanyFeatureEnabled() ? src_entities.NotificationWithCompany : src_entities.Notification), this.cacheManager = cacheManager, this.utilsService = utilsService, this.notificationConfig = notificationConfig, this.gateway = gateway;
|
|
693
|
+
}
|
|
694
|
+
async convertSingleDtoToEntity(dto, user) {
|
|
695
|
+
let entity = {};
|
|
696
|
+
if ('id' in dto && dto.id) {
|
|
697
|
+
const existing = await this.repository.findOne({
|
|
698
|
+
where: {
|
|
699
|
+
id: dto.id
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
if (!existing) {
|
|
703
|
+
throw new common_.NotFoundException({
|
|
704
|
+
message: 'Notification not found',
|
|
705
|
+
messageKey: message_keys/* .NOTIFICATION_MESSAGES.NOT_FOUND */.x.NOT_FOUND
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
entity = existing;
|
|
709
|
+
}
|
|
710
|
+
const merged = {
|
|
711
|
+
...entity,
|
|
712
|
+
userId: user?.id ?? entity.userId,
|
|
713
|
+
type: dto.type ?? entity.type ?? 'info',
|
|
714
|
+
title: dto.title ?? entity.title,
|
|
715
|
+
message: dto.message ?? entity.message,
|
|
716
|
+
data: dto.data ?? entity.data,
|
|
717
|
+
isRead: entity.isRead ?? false,
|
|
718
|
+
readAt: entity.readAt
|
|
719
|
+
};
|
|
720
|
+
if (this.notificationConfig.isCompanyFeatureEnabled()) {
|
|
721
|
+
merged.companyId = dto.companyId ?? user?.companyId ?? entity.companyId ?? null;
|
|
722
|
+
}
|
|
723
|
+
return merged;
|
|
724
|
+
}
|
|
725
|
+
async getSelectQuery(query, _user, select) {
|
|
726
|
+
const fields = select && select.length ? select : [];
|
|
727
|
+
const always = [
|
|
728
|
+
'createdAt',
|
|
729
|
+
'updatedAt'
|
|
730
|
+
];
|
|
731
|
+
const merged = [
|
|
732
|
+
...new Set([
|
|
733
|
+
...fields,
|
|
734
|
+
...always
|
|
735
|
+
])
|
|
736
|
+
];
|
|
737
|
+
query.addSelect(merged.map((f)=>`${this.entityName}.${f}`));
|
|
738
|
+
return {
|
|
739
|
+
query,
|
|
740
|
+
isRaw: false
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
async getFilterQuery(query, filter, _user) {
|
|
744
|
+
for (const [key, value] of Object.entries(filter)){
|
|
745
|
+
if (key === 'isRead' && typeof value === 'boolean') {
|
|
746
|
+
query.andWhere(`${this.entityName}.isRead = :isRead`, {
|
|
747
|
+
isRead: value
|
|
748
|
+
});
|
|
749
|
+
} else if (key === 'type' && value) {
|
|
750
|
+
query.andWhere(`${this.entityName}.type = :type`, {
|
|
751
|
+
type: value
|
|
752
|
+
});
|
|
753
|
+
} else if (key === 'userId' && value) {
|
|
754
|
+
query.andWhere(`${this.entityName}.userId = :userId`, {
|
|
755
|
+
userId: value
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return {
|
|
760
|
+
query,
|
|
761
|
+
isRaw: false
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
async getExtraManipulateQuery(query, filterDto, user) {
|
|
765
|
+
const result = await super.getExtraManipulateQuery(query, filterDto, user);
|
|
766
|
+
if (user?.id) {
|
|
767
|
+
query.andWhere(`${this.entityName}.userId = :currentUserId`, {
|
|
768
|
+
currentUserId: user.id
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
applyCompanyFilter(query, {
|
|
772
|
+
isCompanyFeatureEnabled: this.notificationConfig.isCompanyFeatureEnabled(),
|
|
773
|
+
entityAlias: this.entityName
|
|
774
|
+
}, user);
|
|
775
|
+
const filterSort = filterDto?.sort;
|
|
776
|
+
if (!filterSort || Object.keys(filterSort).length === 0) {
|
|
777
|
+
query.orderBy(`${this.entityName}.createdAt`, 'DESC');
|
|
778
|
+
}
|
|
779
|
+
return result;
|
|
780
|
+
}
|
|
781
|
+
async afterInsertOperation(entities, _dto, _user, _qr) {
|
|
782
|
+
for (const entity of entities){
|
|
783
|
+
const ext = entity;
|
|
784
|
+
this.emitToUser(entity.userId, ext.companyId, 'notification:new', this.toPayload(entity));
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
async markAsRead(id, user) {
|
|
788
|
+
await this.ensureDataSourceRepository();
|
|
789
|
+
const notification = await this.repository.findOne({
|
|
790
|
+
where: {
|
|
791
|
+
id,
|
|
792
|
+
userId: user.id
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
if (!notification) {
|
|
796
|
+
throw new common_.NotFoundException({
|
|
797
|
+
message: 'Notification not found',
|
|
798
|
+
messageKey: message_keys/* .NOTIFICATION_MESSAGES.NOT_FOUND */.x.NOT_FOUND
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
notification.isRead = true;
|
|
802
|
+
notification.readAt = new Date();
|
|
803
|
+
await this.repository.save(notification);
|
|
804
|
+
await Promise.all([
|
|
805
|
+
this.clearCacheForAll(),
|
|
806
|
+
this.clearCacheForId([
|
|
807
|
+
notification
|
|
808
|
+
])
|
|
809
|
+
]);
|
|
810
|
+
// Emit to user's sockets in the same company context
|
|
811
|
+
const ext = notification;
|
|
812
|
+
this.emitToUser(user.id, ext.companyId ?? user.companyId, 'notification:read', {
|
|
813
|
+
id
|
|
814
|
+
});
|
|
815
|
+
await this.publishDomainAction(event_actions/* .NOTIFICATION_EVENT_ACTIONS.READ */.R.READ, {
|
|
816
|
+
ids: [
|
|
817
|
+
notification.id
|
|
818
|
+
],
|
|
819
|
+
user
|
|
820
|
+
});
|
|
821
|
+
return notification;
|
|
822
|
+
}
|
|
823
|
+
async markAllAsRead(user) {
|
|
824
|
+
await this.ensureDataSourceRepository();
|
|
825
|
+
const where = {
|
|
826
|
+
userId: user.id,
|
|
827
|
+
isRead: false
|
|
828
|
+
};
|
|
829
|
+
if (this.notificationConfig.isCompanyFeatureEnabled() && user.companyId) {
|
|
830
|
+
where.companyId = user.companyId;
|
|
831
|
+
}
|
|
832
|
+
const result = await this.repository.update(where, {
|
|
833
|
+
isRead: true,
|
|
834
|
+
readAt: new Date()
|
|
835
|
+
});
|
|
836
|
+
await this.clearCacheForAll();
|
|
837
|
+
// Emit to user's sockets in the current company context
|
|
838
|
+
this.emitToUser(user.id, user.companyId, 'notification:read-all', {});
|
|
839
|
+
await this.publishDomainAction(event_actions/* .NOTIFICATION_EVENT_ACTIONS.ALL_READ */.R.ALL_READ, {
|
|
840
|
+
metadata: {
|
|
841
|
+
count: result.affected ?? 0
|
|
842
|
+
},
|
|
843
|
+
user
|
|
844
|
+
});
|
|
845
|
+
return result.affected ?? 0;
|
|
846
|
+
}
|
|
847
|
+
async getUnreadCount(user) {
|
|
848
|
+
await this.ensureDataSourceRepository();
|
|
849
|
+
const where = {
|
|
850
|
+
userId: user.id,
|
|
851
|
+
isRead: false
|
|
852
|
+
};
|
|
853
|
+
if (this.notificationConfig.isCompanyFeatureEnabled() && user.companyId) {
|
|
854
|
+
where.companyId = user.companyId;
|
|
855
|
+
}
|
|
856
|
+
return this.repository.count({
|
|
857
|
+
where
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
toPayload(entity) {
|
|
861
|
+
return {
|
|
862
|
+
id: entity.id,
|
|
863
|
+
type: entity.type,
|
|
864
|
+
title: entity.title,
|
|
865
|
+
message: entity.message,
|
|
866
|
+
data: entity.data,
|
|
867
|
+
createdAt: entity.createdAt
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
emitToUser(userId, companyId, event, payload) {
|
|
871
|
+
if (!this.gateway) {
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
if (this.notificationConfig.isCompanyFeatureEnabled() && companyId) {
|
|
875
|
+
this.gateway.emitToUserInCompany(userId, companyId, event, payload);
|
|
876
|
+
} else {
|
|
877
|
+
this.gateway.emitToUser(userId, event, payload);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
_ts_decorate([
|
|
882
|
+
(0,nestjs_shared_.LogAction)({
|
|
883
|
+
action: 'notification.markAsRead',
|
|
884
|
+
module: 'notification'
|
|
885
|
+
}),
|
|
886
|
+
_ts_metadata("design:type", Function),
|
|
887
|
+
_ts_metadata("design:paramtypes", [
|
|
888
|
+
String,
|
|
889
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
890
|
+
]),
|
|
891
|
+
_ts_metadata("design:returntype", Promise)
|
|
892
|
+
], NotificationService.prototype, "markAsRead", null);
|
|
893
|
+
_ts_decorate([
|
|
894
|
+
(0,nestjs_shared_.LogAction)({
|
|
895
|
+
action: 'notification.markAllAsRead',
|
|
896
|
+
module: 'notification'
|
|
897
|
+
}),
|
|
898
|
+
_ts_metadata("design:type", Function),
|
|
899
|
+
_ts_metadata("design:paramtypes", [
|
|
900
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
901
|
+
]),
|
|
902
|
+
_ts_metadata("design:returntype", Promise)
|
|
903
|
+
], NotificationService.prototype, "markAllAsRead", null);
|
|
904
|
+
NotificationService = _ts_decorate([
|
|
905
|
+
(0,common_.Injectable)({
|
|
906
|
+
scope: common_.Scope.REQUEST
|
|
907
|
+
}),
|
|
908
|
+
_ts_param(0, (0,common_.Inject)('CACHE_INSTANCE')),
|
|
909
|
+
_ts_param(1, (0,common_.Inject)(modules_.UtilsService)),
|
|
910
|
+
_ts_param(2, (0,common_.Inject)(notification_config_service/* .NotificationConfigService */.v)),
|
|
911
|
+
_ts_param(3, (0,common_.Inject)(notification_datasource_provider/* .NotificationDataSourceProvider */.M)),
|
|
912
|
+
_ts_param(4, (0,common_.Optional)()),
|
|
913
|
+
_ts_param(4, (0,common_.Inject)(gateways/* .NotificationGateway */.g)),
|
|
914
|
+
_ts_metadata("design:type", Function),
|
|
915
|
+
_ts_metadata("design:paramtypes", [
|
|
916
|
+
typeof classes_.HybridCache === "undefined" ? Object : classes_.HybridCache,
|
|
917
|
+
typeof modules_.UtilsService === "undefined" ? Object : modules_.UtilsService,
|
|
918
|
+
typeof notification_config_service/* .NotificationConfigService */.v === "undefined" ? Object : notification_config_service/* .NotificationConfigService */.v,
|
|
919
|
+
typeof notification_datasource_provider/* .NotificationDataSourceProvider */.M === "undefined" ? Object : notification_datasource_provider/* .NotificationDataSourceProvider */.M,
|
|
920
|
+
typeof gateways/* .NotificationGateway */.g === "undefined" ? Object : gateways/* .NotificationGateway */.g
|
|
921
|
+
])
|
|
922
|
+
], NotificationService);
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
},
|
|
926
|
+
176(module) {
|
|
927
|
+
|
|
928
|
+
module.exports = __rspack_external__nestjs_swagger_7cd450b5;
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
},
|
|
932
|
+
812(module) {
|
|
933
|
+
|
|
934
|
+
module.exports = __rspack_external_class_transformer_c5a479fb;
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
},
|
|
938
|
+
|
|
939
|
+
};
|