@flusys/nestjs-notification 3.0.1
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/README.md +998 -0
- package/adapters/index.d.ts +1 -0
- package/adapters/notification.adapter.d.ts +10 -0
- package/cjs/adapters/index.js +18 -0
- package/cjs/adapters/notification.adapter.js +79 -0
- package/cjs/config/index.js +18 -0
- package/cjs/config/notification.constants.js +11 -0
- package/cjs/controllers/index.js +18 -0
- package/cjs/controllers/notification.controller.js +278 -0
- package/cjs/docs/index.js +18 -0
- package/cjs/docs/notification-swagger.config.js +61 -0
- package/cjs/dtos/index.js +18 -0
- package/cjs/dtos/notification.dto.js +244 -0
- package/cjs/entities/index.js +48 -0
- package/cjs/entities/notification-with-company.entity.js +57 -0
- package/cjs/entities/notification.entity.js +111 -0
- package/cjs/gateways/index.js +18 -0
- package/cjs/gateways/notification.gateway.js +226 -0
- package/cjs/index.js +28 -0
- package/cjs/interfaces/index.js +19 -0
- package/cjs/interfaces/notification-module.interface.js +4 -0
- package/cjs/interfaces/notification.interface.js +4 -0
- package/cjs/modules/index.js +18 -0
- package/cjs/modules/notification.module.js +139 -0
- package/cjs/services/index.js +21 -0
- package/cjs/services/notification-config.service.js +72 -0
- package/cjs/services/notification-datasource.provider.js +174 -0
- package/cjs/services/notification-helper.service.js +186 -0
- package/cjs/services/notification.service.js +220 -0
- package/config/index.d.ts +1 -0
- package/config/notification.constants.d.ts +1 -0
- package/controllers/index.d.ts +1 -0
- package/controllers/notification.controller.d.ts +26 -0
- package/docs/index.d.ts +1 -0
- package/docs/notification-swagger.config.d.ts +2 -0
- package/dtos/index.d.ts +1 -0
- package/dtos/notification.dto.d.ts +47 -0
- package/entities/index.d.ts +8 -0
- package/entities/notification-with-company.entity.d.ts +4 -0
- package/entities/notification.entity.d.ts +10 -0
- package/fesm/adapters/index.js +1 -0
- package/fesm/adapters/notification.adapter.js +69 -0
- package/fesm/config/index.js +1 -0
- package/fesm/config/notification.constants.js +1 -0
- package/fesm/controllers/index.js +1 -0
- package/fesm/controllers/notification.controller.js +268 -0
- package/fesm/docs/index.js +1 -0
- package/fesm/docs/notification-swagger.config.js +51 -0
- package/fesm/dtos/index.js +1 -0
- package/fesm/dtos/notification.dto.js +211 -0
- package/fesm/entities/index.js +14 -0
- package/fesm/entities/notification-with-company.entity.js +47 -0
- package/fesm/entities/notification.entity.js +101 -0
- package/fesm/gateways/index.js +1 -0
- package/fesm/gateways/notification.gateway.js +175 -0
- package/fesm/index.js +20 -0
- package/fesm/interfaces/index.js +2 -0
- package/fesm/interfaces/notification-module.interface.js +1 -0
- package/fesm/interfaces/notification.interface.js +1 -0
- package/fesm/modules/index.js +1 -0
- package/fesm/modules/notification.module.js +129 -0
- package/fesm/services/index.js +4 -0
- package/fesm/services/notification-config.service.js +62 -0
- package/fesm/services/notification-datasource.provider.js +123 -0
- package/fesm/services/notification-helper.service.js +176 -0
- package/fesm/services/notification.service.js +210 -0
- package/gateways/index.d.ts +1 -0
- package/gateways/notification.gateway.d.ts +21 -0
- package/index.d.ts +10 -0
- package/interfaces/index.d.ts +2 -0
- package/interfaces/notification-module.interface.d.ts +20 -0
- package/interfaces/notification.interface.d.ts +19 -0
- package/modules/index.d.ts +1 -0
- package/modules/notification.module.d.ts +8 -0
- package/package.json +98 -0
- package/services/index.d.ts +4 -0
- package/services/notification-config.service.d.ts +13 -0
- package/services/notification-datasource.provider.d.ts +23 -0
- package/services/notification-helper.service.d.ts +44 -0
- package/services/notification.service.d.ts +35 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './notification.entity';
|
|
2
|
+
export * from './notification-with-company.entity';
|
|
3
|
+
import { Notification } from './notification.entity';
|
|
4
|
+
import { NotificationWithCompany } from './notification-with-company.entity';
|
|
5
|
+
export declare const NotificationCoreEntities: (typeof Notification)[];
|
|
6
|
+
export declare const NotificationCompanyEntities: (typeof NotificationWithCompany)[];
|
|
7
|
+
export declare function getNotificationEntitiesByConfig(enableCompanyFeature: boolean): any[];
|
|
8
|
+
export { Notification as NotificationBase } from './notification.entity';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Identity } from '@flusys/nestjs-shared/entities';
|
|
2
|
+
export declare class Notification extends Identity {
|
|
3
|
+
userId: string;
|
|
4
|
+
type: string;
|
|
5
|
+
title: string;
|
|
6
|
+
message: string | null;
|
|
7
|
+
data: Record<string, unknown> | null;
|
|
8
|
+
isRead: boolean;
|
|
9
|
+
readAt: Date | null;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './notification.adapter';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
+
}
|
|
20
|
+
function _ts_metadata(k, v) {
|
|
21
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
+
}
|
|
23
|
+
function _ts_param(paramIndex, decorator) {
|
|
24
|
+
return function(target, key) {
|
|
25
|
+
decorator(target, key, paramIndex);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
import { Injectable, Inject } from '@nestjs/common';
|
|
29
|
+
import { NotificationHelperService } from '../services/notification-helper.service';
|
|
30
|
+
export class NotificationAdapter {
|
|
31
|
+
async send(options) {
|
|
32
|
+
await this.notificationHelper.send({
|
|
33
|
+
userId: options.userId,
|
|
34
|
+
title: options.title,
|
|
35
|
+
message: options.message,
|
|
36
|
+
type: options.type,
|
|
37
|
+
data: options.data,
|
|
38
|
+
companyId: options.companyId
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async sendToMany(options) {
|
|
42
|
+
await this.notificationHelper.sendToMany({
|
|
43
|
+
userIds: options.userIds,
|
|
44
|
+
title: options.title,
|
|
45
|
+
message: options.message,
|
|
46
|
+
type: options.type,
|
|
47
|
+
data: options.data,
|
|
48
|
+
companyId: options.companyId
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async broadcastToCompany(companyId, title, message, type, data) {
|
|
52
|
+
await this.notificationHelper.sendToCompany(companyId, title, message, type, data);
|
|
53
|
+
}
|
|
54
|
+
isUserOnline(userId) {
|
|
55
|
+
return this.notificationHelper.isUserOnline(userId);
|
|
56
|
+
}
|
|
57
|
+
constructor(notificationHelper){
|
|
58
|
+
_define_property(this, "notificationHelper", void 0);
|
|
59
|
+
this.notificationHelper = notificationHelper;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
NotificationAdapter = _ts_decorate([
|
|
63
|
+
Injectable(),
|
|
64
|
+
_ts_param(0, Inject(NotificationHelperService)),
|
|
65
|
+
_ts_metadata("design:type", Function),
|
|
66
|
+
_ts_metadata("design:paramtypes", [
|
|
67
|
+
typeof NotificationHelperService === "undefined" ? Object : NotificationHelperService
|
|
68
|
+
])
|
|
69
|
+
], NotificationAdapter);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './notification.constants';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const NOTIFICATION_MODULE_OPTIONS = 'NOTIFICATION_MODULE_OPTIONS';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './notification.controller';
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
+
}
|
|
20
|
+
function _ts_metadata(k, v) {
|
|
21
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
+
}
|
|
23
|
+
function _ts_param(paramIndex, decorator) {
|
|
24
|
+
return function(target, key) {
|
|
25
|
+
decorator(target, key, paramIndex);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
import { createApiController } from '@flusys/nestjs-shared/classes';
|
|
29
|
+
import { NOTIFICATION_PERMISSIONS } from '@flusys/nestjs-shared/constants';
|
|
30
|
+
import { CurrentUser, RequirePermission } from '@flusys/nestjs-shared/decorators';
|
|
31
|
+
import { BulkResponseDto, MessageResponseDto, SingleResponseDto } from '@flusys/nestjs-shared/dtos';
|
|
32
|
+
import { JwtAuthGuard, PermissionGuard } from '@flusys/nestjs-shared/guards';
|
|
33
|
+
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
34
|
+
import { Body, Controller, HttpCode, HttpStatus, Inject, Post, UseGuards } from '@nestjs/common';
|
|
35
|
+
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
36
|
+
import { plainToInstance } from 'class-transformer';
|
|
37
|
+
import { CreateNotificationDto, MarkReadDto, NotificationResponseDto, SendBulkNotificationDto, SendNotificationDto, UpdateNotificationDto } from '../dtos';
|
|
38
|
+
import { NotificationHelperService } from '../services/notification-helper.service';
|
|
39
|
+
import { NotificationService } from '../services/notification.service';
|
|
40
|
+
export class NotificationController extends createApiController(CreateNotificationDto, UpdateNotificationDto, NotificationResponseDto, {
|
|
41
|
+
security: {
|
|
42
|
+
insert: {
|
|
43
|
+
level: 'permission',
|
|
44
|
+
permissions: [
|
|
45
|
+
NOTIFICATION_PERMISSIONS.CREATE
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
insertMany: {
|
|
49
|
+
level: 'permission',
|
|
50
|
+
permissions: [
|
|
51
|
+
NOTIFICATION_PERMISSIONS.CREATE
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
getById: {
|
|
55
|
+
level: 'permission',
|
|
56
|
+
permissions: [
|
|
57
|
+
NOTIFICATION_PERMISSIONS.READ
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
getAll: {
|
|
61
|
+
level: 'jwt'
|
|
62
|
+
},
|
|
63
|
+
update: {
|
|
64
|
+
level: 'permission',
|
|
65
|
+
permissions: [
|
|
66
|
+
NOTIFICATION_PERMISSIONS.UPDATE
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
updateMany: {
|
|
70
|
+
level: 'permission',
|
|
71
|
+
permissions: [
|
|
72
|
+
NOTIFICATION_PERMISSIONS.UPDATE
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
delete: {
|
|
76
|
+
level: 'permission',
|
|
77
|
+
permissions: [
|
|
78
|
+
NOTIFICATION_PERMISSIONS.DELETE
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}) {
|
|
83
|
+
async markAsRead(dto, user) {
|
|
84
|
+
const notification = await this.service.markAsRead(dto.id, user);
|
|
85
|
+
return {
|
|
86
|
+
success: true,
|
|
87
|
+
message: 'Notification marked as read',
|
|
88
|
+
data: plainToInstance(NotificationResponseDto, notification)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async markAllAsRead(user) {
|
|
92
|
+
const count = await this.service.markAllAsRead(user);
|
|
93
|
+
return {
|
|
94
|
+
success: true,
|
|
95
|
+
message: `${count} notifications marked as read`
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async getUnreadCount(user) {
|
|
99
|
+
const count = await this.service.getUnreadCount(user);
|
|
100
|
+
return {
|
|
101
|
+
success: true,
|
|
102
|
+
message: 'Unread count retrieved',
|
|
103
|
+
data: {
|
|
104
|
+
count
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async sendNotification(dto) {
|
|
109
|
+
const notification = await this.notificationHelper.send({
|
|
110
|
+
userId: dto.userId,
|
|
111
|
+
title: dto.title,
|
|
112
|
+
message: dto.message,
|
|
113
|
+
type: dto.type,
|
|
114
|
+
data: dto.data,
|
|
115
|
+
companyId: dto.companyId
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
success: true,
|
|
119
|
+
message: 'Notification sent successfully',
|
|
120
|
+
data: plainToInstance(NotificationResponseDto, notification)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async sendBulkNotification(dto) {
|
|
124
|
+
const notifications = await this.notificationHelper.sendToMany({
|
|
125
|
+
userIds: dto.userIds,
|
|
126
|
+
title: dto.title,
|
|
127
|
+
message: dto.message,
|
|
128
|
+
type: dto.type,
|
|
129
|
+
data: dto.data,
|
|
130
|
+
companyId: dto.companyId
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
success: true,
|
|
134
|
+
message: `${notifications.length} notifications sent successfully`,
|
|
135
|
+
data: notifications.map((n)=>plainToInstance(NotificationResponseDto, n)),
|
|
136
|
+
meta: {
|
|
137
|
+
count: notifications.length,
|
|
138
|
+
total: dto.userIds.length
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
constructor(service, notificationHelper){
|
|
143
|
+
super(service), _define_property(this, "service", void 0), _define_property(this, "notificationHelper", void 0), this.service = service, this.notificationHelper = notificationHelper;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
_ts_decorate([
|
|
147
|
+
Post('mark-read'),
|
|
148
|
+
HttpCode(HttpStatus.OK),
|
|
149
|
+
UseGuards(JwtAuthGuard),
|
|
150
|
+
ApiBearerAuth(),
|
|
151
|
+
ApiOperation({
|
|
152
|
+
summary: 'Mark a notification as read'
|
|
153
|
+
}),
|
|
154
|
+
ApiBody({
|
|
155
|
+
type: MarkReadDto
|
|
156
|
+
}),
|
|
157
|
+
ApiResponse({
|
|
158
|
+
status: 200,
|
|
159
|
+
description: 'Notification marked as read',
|
|
160
|
+
type: SingleResponseDto
|
|
161
|
+
}),
|
|
162
|
+
_ts_param(0, Body()),
|
|
163
|
+
_ts_param(1, CurrentUser()),
|
|
164
|
+
_ts_metadata("design:type", Function),
|
|
165
|
+
_ts_metadata("design:paramtypes", [
|
|
166
|
+
typeof MarkReadDto === "undefined" ? Object : MarkReadDto,
|
|
167
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
168
|
+
]),
|
|
169
|
+
_ts_metadata("design:returntype", Promise)
|
|
170
|
+
], NotificationController.prototype, "markAsRead", null);
|
|
171
|
+
_ts_decorate([
|
|
172
|
+
Post('mark-all-read'),
|
|
173
|
+
HttpCode(HttpStatus.OK),
|
|
174
|
+
UseGuards(JwtAuthGuard),
|
|
175
|
+
ApiBearerAuth(),
|
|
176
|
+
ApiOperation({
|
|
177
|
+
summary: 'Mark all notifications as read'
|
|
178
|
+
}),
|
|
179
|
+
ApiResponse({
|
|
180
|
+
status: 200,
|
|
181
|
+
description: 'All notifications marked as read',
|
|
182
|
+
type: MessageResponseDto
|
|
183
|
+
}),
|
|
184
|
+
_ts_param(0, CurrentUser()),
|
|
185
|
+
_ts_metadata("design:type", Function),
|
|
186
|
+
_ts_metadata("design:paramtypes", [
|
|
187
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
188
|
+
]),
|
|
189
|
+
_ts_metadata("design:returntype", Promise)
|
|
190
|
+
], NotificationController.prototype, "markAllAsRead", null);
|
|
191
|
+
_ts_decorate([
|
|
192
|
+
Post('unread-count'),
|
|
193
|
+
HttpCode(HttpStatus.OK),
|
|
194
|
+
UseGuards(JwtAuthGuard),
|
|
195
|
+
ApiBearerAuth(),
|
|
196
|
+
ApiOperation({
|
|
197
|
+
summary: 'Get unread notification count'
|
|
198
|
+
}),
|
|
199
|
+
ApiResponse({
|
|
200
|
+
status: 200,
|
|
201
|
+
description: 'Unread count retrieved',
|
|
202
|
+
type: SingleResponseDto
|
|
203
|
+
}),
|
|
204
|
+
_ts_param(0, CurrentUser()),
|
|
205
|
+
_ts_metadata("design:type", Function),
|
|
206
|
+
_ts_metadata("design:paramtypes", [
|
|
207
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
208
|
+
]),
|
|
209
|
+
_ts_metadata("design:returntype", Promise)
|
|
210
|
+
], NotificationController.prototype, "getUnreadCount", null);
|
|
211
|
+
_ts_decorate([
|
|
212
|
+
Post('send'),
|
|
213
|
+
HttpCode(HttpStatus.OK),
|
|
214
|
+
UseGuards(JwtAuthGuard, PermissionGuard),
|
|
215
|
+
RequirePermission(NOTIFICATION_PERMISSIONS.CREATE),
|
|
216
|
+
ApiOperation({
|
|
217
|
+
summary: 'Send a notification to a user'
|
|
218
|
+
}),
|
|
219
|
+
ApiBody({
|
|
220
|
+
type: SendNotificationDto
|
|
221
|
+
}),
|
|
222
|
+
ApiResponse({
|
|
223
|
+
status: 200,
|
|
224
|
+
description: 'Notification sent successfully',
|
|
225
|
+
type: SingleResponseDto
|
|
226
|
+
}),
|
|
227
|
+
_ts_param(0, Body()),
|
|
228
|
+
_ts_metadata("design:type", Function),
|
|
229
|
+
_ts_metadata("design:paramtypes", [
|
|
230
|
+
typeof SendNotificationDto === "undefined" ? Object : SendNotificationDto
|
|
231
|
+
]),
|
|
232
|
+
_ts_metadata("design:returntype", Promise)
|
|
233
|
+
], NotificationController.prototype, "sendNotification", null);
|
|
234
|
+
_ts_decorate([
|
|
235
|
+
Post('send-bulk'),
|
|
236
|
+
HttpCode(HttpStatus.OK),
|
|
237
|
+
UseGuards(JwtAuthGuard, PermissionGuard),
|
|
238
|
+
RequirePermission(NOTIFICATION_PERMISSIONS.CREATE),
|
|
239
|
+
ApiOperation({
|
|
240
|
+
summary: 'Send a notification to multiple users'
|
|
241
|
+
}),
|
|
242
|
+
ApiBody({
|
|
243
|
+
type: SendBulkNotificationDto
|
|
244
|
+
}),
|
|
245
|
+
ApiResponse({
|
|
246
|
+
status: 200,
|
|
247
|
+
description: 'Notifications sent successfully',
|
|
248
|
+
type: BulkResponseDto
|
|
249
|
+
}),
|
|
250
|
+
_ts_param(0, Body()),
|
|
251
|
+
_ts_metadata("design:type", Function),
|
|
252
|
+
_ts_metadata("design:paramtypes", [
|
|
253
|
+
typeof SendBulkNotificationDto === "undefined" ? Object : SendBulkNotificationDto
|
|
254
|
+
]),
|
|
255
|
+
_ts_metadata("design:returntype", Promise)
|
|
256
|
+
], NotificationController.prototype, "sendBulkNotification", null);
|
|
257
|
+
NotificationController = _ts_decorate([
|
|
258
|
+
ApiTags('Notifications'),
|
|
259
|
+
ApiBearerAuth(),
|
|
260
|
+
Controller('notification'),
|
|
261
|
+
_ts_param(0, Inject(NotificationService)),
|
|
262
|
+
_ts_param(1, Inject(NotificationHelperService)),
|
|
263
|
+
_ts_metadata("design:type", Function),
|
|
264
|
+
_ts_metadata("design:paramtypes", [
|
|
265
|
+
typeof NotificationService === "undefined" ? Object : NotificationService,
|
|
266
|
+
typeof NotificationHelperService === "undefined" ? Object : NotificationHelperService
|
|
267
|
+
])
|
|
268
|
+
], NotificationController);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './notification-swagger.config';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export function notificationSwaggerConfig() {
|
|
2
|
+
return {
|
|
3
|
+
title: 'Notification API',
|
|
4
|
+
description: `
|
|
5
|
+
## Notification API
|
|
6
|
+
|
|
7
|
+
Real-time notification system with WebSocket support.
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
- Push notifications to users
|
|
11
|
+
- Mark notifications as read
|
|
12
|
+
- Unread count tracking
|
|
13
|
+
- Real-time delivery via WebSocket
|
|
14
|
+
- Bulk notification sending
|
|
15
|
+
|
|
16
|
+
### Endpoints
|
|
17
|
+
|
|
18
|
+
#### User Notifications
|
|
19
|
+
- \`POST /notification/get-all\` - Get user's notifications (paginated, sorted by newest)
|
|
20
|
+
- \`POST /notification/get/:id\` - Get single notification
|
|
21
|
+
- \`POST /notification/mark-read\` - Mark notification as read
|
|
22
|
+
- \`POST /notification/mark-all-read\` - Mark all notifications as read
|
|
23
|
+
- \`POST /notification/unread-count\` - Get unread notification count
|
|
24
|
+
|
|
25
|
+
#### Admin/System
|
|
26
|
+
- \`POST /notification/send\` - Send notification to a user
|
|
27
|
+
- \`POST /notification/send-bulk\` - Send notification to multiple users
|
|
28
|
+
|
|
29
|
+
### WebSocket Events
|
|
30
|
+
|
|
31
|
+
Connect to WebSocket with JWT authentication:
|
|
32
|
+
\`\`\`
|
|
33
|
+
ws://localhost:2002/notification?token=<jwt>
|
|
34
|
+
\`\`\`
|
|
35
|
+
|
|
36
|
+
**Events:**
|
|
37
|
+
- \`notification:new\` - New notification received
|
|
38
|
+
- \`notification:read\` - Notification marked as read
|
|
39
|
+
- \`notification:read-all\` - All notifications marked as read
|
|
40
|
+
|
|
41
|
+
### Notification Types
|
|
42
|
+
- \`info\` - General information
|
|
43
|
+
- \`success\` - Success message
|
|
44
|
+
- \`warning\` - Warning message
|
|
45
|
+
- \`error\` - Error message
|
|
46
|
+
`,
|
|
47
|
+
version: '1.0',
|
|
48
|
+
path: 'api/docs/notification',
|
|
49
|
+
bearerAuth: true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './notification.dto';
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
+
}
|
|
20
|
+
function _ts_metadata(k, v) {
|
|
21
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
+
}
|
|
23
|
+
import { ApiProperty, ApiPropertyOptional, IntersectionType, OmitType, PartialType } from '@nestjs/swagger';
|
|
24
|
+
import { Expose } from 'class-transformer';
|
|
25
|
+
import { IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, IsUUID, MaxLength } from 'class-validator';
|
|
26
|
+
import { NotificationType } from '@flusys/nestjs-shared/enums';
|
|
27
|
+
let NotificationContentDto = class NotificationContentDto {
|
|
28
|
+
constructor(){
|
|
29
|
+
_define_property(this, "title", void 0);
|
|
30
|
+
_define_property(this, "message", void 0);
|
|
31
|
+
_define_property(this, "type", void 0);
|
|
32
|
+
_define_property(this, "data", void 0);
|
|
33
|
+
_define_property(this, "companyId", void 0);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
_ts_decorate([
|
|
37
|
+
ApiProperty({
|
|
38
|
+
maxLength: 255
|
|
39
|
+
}),
|
|
40
|
+
IsNotEmpty(),
|
|
41
|
+
IsString(),
|
|
42
|
+
MaxLength(255),
|
|
43
|
+
_ts_metadata("design:type", String)
|
|
44
|
+
], NotificationContentDto.prototype, "title", void 0);
|
|
45
|
+
_ts_decorate([
|
|
46
|
+
ApiPropertyOptional(),
|
|
47
|
+
IsOptional(),
|
|
48
|
+
IsString(),
|
|
49
|
+
_ts_metadata("design:type", String)
|
|
50
|
+
], NotificationContentDto.prototype, "message", void 0);
|
|
51
|
+
_ts_decorate([
|
|
52
|
+
ApiPropertyOptional({
|
|
53
|
+
enum: NotificationType,
|
|
54
|
+
default: NotificationType.INFO
|
|
55
|
+
}),
|
|
56
|
+
IsOptional(),
|
|
57
|
+
IsEnum(NotificationType),
|
|
58
|
+
_ts_metadata("design:type", typeof NotificationType === "undefined" ? Object : NotificationType)
|
|
59
|
+
], NotificationContentDto.prototype, "type", void 0);
|
|
60
|
+
_ts_decorate([
|
|
61
|
+
ApiPropertyOptional(),
|
|
62
|
+
IsOptional(),
|
|
63
|
+
IsObject(),
|
|
64
|
+
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
65
|
+
], NotificationContentDto.prototype, "data", void 0);
|
|
66
|
+
_ts_decorate([
|
|
67
|
+
ApiPropertyOptional(),
|
|
68
|
+
IsOptional(),
|
|
69
|
+
IsUUID(),
|
|
70
|
+
_ts_metadata("design:type", String)
|
|
71
|
+
], NotificationContentDto.prototype, "companyId", void 0);
|
|
72
|
+
let UserIdDto = class UserIdDto {
|
|
73
|
+
constructor(){
|
|
74
|
+
_define_property(this, "userId", void 0);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
_ts_decorate([
|
|
78
|
+
ApiProperty(),
|
|
79
|
+
IsNotEmpty(),
|
|
80
|
+
IsUUID(),
|
|
81
|
+
_ts_metadata("design:type", String)
|
|
82
|
+
], UserIdDto.prototype, "userId", void 0);
|
|
83
|
+
let UserIdsDto = class UserIdsDto {
|
|
84
|
+
constructor(){
|
|
85
|
+
_define_property(this, "userIds", void 0);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
_ts_decorate([
|
|
89
|
+
ApiProperty({
|
|
90
|
+
type: [
|
|
91
|
+
String
|
|
92
|
+
]
|
|
93
|
+
}),
|
|
94
|
+
IsNotEmpty(),
|
|
95
|
+
IsUUID('4', {
|
|
96
|
+
each: true
|
|
97
|
+
}),
|
|
98
|
+
_ts_metadata("design:type", Array)
|
|
99
|
+
], UserIdsDto.prototype, "userIds", void 0);
|
|
100
|
+
export class CreateNotificationDto extends IntersectionType(UserIdDto, NotificationContentDto) {
|
|
101
|
+
}
|
|
102
|
+
export class UpdateNotificationDto extends PartialType(OmitType(CreateNotificationDto, [
|
|
103
|
+
'userId'
|
|
104
|
+
])) {
|
|
105
|
+
constructor(...args){
|
|
106
|
+
super(...args), _define_property(this, "id", void 0);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
_ts_decorate([
|
|
110
|
+
ApiProperty(),
|
|
111
|
+
IsUUID(),
|
|
112
|
+
IsNotEmpty(),
|
|
113
|
+
_ts_metadata("design:type", String)
|
|
114
|
+
], UpdateNotificationDto.prototype, "id", void 0);
|
|
115
|
+
export class MarkReadDto {
|
|
116
|
+
constructor(){
|
|
117
|
+
_define_property(this, "id", void 0);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
_ts_decorate([
|
|
121
|
+
ApiProperty(),
|
|
122
|
+
IsUUID(),
|
|
123
|
+
IsNotEmpty(),
|
|
124
|
+
_ts_metadata("design:type", String)
|
|
125
|
+
], MarkReadDto.prototype, "id", void 0);
|
|
126
|
+
export class NotificationResponseDto {
|
|
127
|
+
constructor(){
|
|
128
|
+
_define_property(this, "id", void 0);
|
|
129
|
+
_define_property(this, "userId", void 0);
|
|
130
|
+
_define_property(this, "type", void 0);
|
|
131
|
+
_define_property(this, "title", void 0);
|
|
132
|
+
_define_property(this, "message", void 0);
|
|
133
|
+
_define_property(this, "data", void 0);
|
|
134
|
+
_define_property(this, "isRead", void 0);
|
|
135
|
+
_define_property(this, "readAt", void 0);
|
|
136
|
+
_define_property(this, "companyId", void 0);
|
|
137
|
+
_define_property(this, "createdAt", void 0);
|
|
138
|
+
_define_property(this, "updatedAt", void 0);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
_ts_decorate([
|
|
142
|
+
Expose(),
|
|
143
|
+
ApiProperty(),
|
|
144
|
+
_ts_metadata("design:type", String)
|
|
145
|
+
], NotificationResponseDto.prototype, "id", void 0);
|
|
146
|
+
_ts_decorate([
|
|
147
|
+
Expose(),
|
|
148
|
+
ApiProperty(),
|
|
149
|
+
_ts_metadata("design:type", String)
|
|
150
|
+
], NotificationResponseDto.prototype, "userId", void 0);
|
|
151
|
+
_ts_decorate([
|
|
152
|
+
Expose(),
|
|
153
|
+
ApiProperty({
|
|
154
|
+
enum: NotificationType
|
|
155
|
+
}),
|
|
156
|
+
_ts_metadata("design:type", String)
|
|
157
|
+
], NotificationResponseDto.prototype, "type", void 0);
|
|
158
|
+
_ts_decorate([
|
|
159
|
+
Expose(),
|
|
160
|
+
ApiProperty(),
|
|
161
|
+
_ts_metadata("design:type", String)
|
|
162
|
+
], NotificationResponseDto.prototype, "title", void 0);
|
|
163
|
+
_ts_decorate([
|
|
164
|
+
Expose(),
|
|
165
|
+
ApiPropertyOptional(),
|
|
166
|
+
_ts_metadata("design:type", Object)
|
|
167
|
+
], NotificationResponseDto.prototype, "message", void 0);
|
|
168
|
+
_ts_decorate([
|
|
169
|
+
Expose(),
|
|
170
|
+
ApiPropertyOptional(),
|
|
171
|
+
_ts_metadata("design:type", Object)
|
|
172
|
+
], NotificationResponseDto.prototype, "data", void 0);
|
|
173
|
+
_ts_decorate([
|
|
174
|
+
Expose(),
|
|
175
|
+
ApiProperty(),
|
|
176
|
+
_ts_metadata("design:type", Boolean)
|
|
177
|
+
], NotificationResponseDto.prototype, "isRead", void 0);
|
|
178
|
+
_ts_decorate([
|
|
179
|
+
Expose(),
|
|
180
|
+
ApiPropertyOptional(),
|
|
181
|
+
_ts_metadata("design:type", Object)
|
|
182
|
+
], NotificationResponseDto.prototype, "readAt", void 0);
|
|
183
|
+
_ts_decorate([
|
|
184
|
+
Expose(),
|
|
185
|
+
ApiPropertyOptional(),
|
|
186
|
+
_ts_metadata("design:type", Object)
|
|
187
|
+
], NotificationResponseDto.prototype, "companyId", void 0);
|
|
188
|
+
_ts_decorate([
|
|
189
|
+
Expose(),
|
|
190
|
+
ApiProperty(),
|
|
191
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
192
|
+
], NotificationResponseDto.prototype, "createdAt", void 0);
|
|
193
|
+
_ts_decorate([
|
|
194
|
+
Expose(),
|
|
195
|
+
ApiProperty(),
|
|
196
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
197
|
+
], NotificationResponseDto.prototype, "updatedAt", void 0);
|
|
198
|
+
export class UnreadCountResponseDto {
|
|
199
|
+
constructor(){
|
|
200
|
+
_define_property(this, "count", void 0);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
_ts_decorate([
|
|
204
|
+
Expose(),
|
|
205
|
+
ApiProperty(),
|
|
206
|
+
_ts_metadata("design:type", Number)
|
|
207
|
+
], UnreadCountResponseDto.prototype, "count", void 0);
|
|
208
|
+
export class SendNotificationDto extends IntersectionType(UserIdDto, NotificationContentDto) {
|
|
209
|
+
}
|
|
210
|
+
export class SendBulkNotificationDto extends IntersectionType(UserIdsDto, NotificationContentDto) {
|
|
211
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './notification.entity';
|
|
2
|
+
export * from './notification-with-company.entity';
|
|
3
|
+
import { Notification } from './notification.entity';
|
|
4
|
+
import { NotificationWithCompany } from './notification-with-company.entity';
|
|
5
|
+
export const NotificationCoreEntities = [
|
|
6
|
+
Notification
|
|
7
|
+
];
|
|
8
|
+
export const NotificationCompanyEntities = [
|
|
9
|
+
NotificationWithCompany
|
|
10
|
+
];
|
|
11
|
+
export function getNotificationEntitiesByConfig(enableCompanyFeature) {
|
|
12
|
+
return enableCompanyFeature ? NotificationCompanyEntities : NotificationCoreEntities;
|
|
13
|
+
}
|
|
14
|
+
export { Notification as NotificationBase } from './notification.entity';
|