@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/cjs/adapters/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./notification.adapter"), exports);
|
|
6
|
-
function _export_star(from, to) {
|
|
7
|
-
Object.keys(from).forEach(function(k) {
|
|
8
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
-
Object.defineProperty(to, k, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function() {
|
|
12
|
-
return from[k];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
return from;
|
|
18
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "NotificationAdapter", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return NotificationAdapter;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _common = require("@nestjs/common");
|
|
12
|
-
const _notificationhelperservice = require("../services/notification-helper.service");
|
|
13
|
-
function _define_property(obj, key, value) {
|
|
14
|
-
if (key in obj) {
|
|
15
|
-
Object.defineProperty(obj, key, {
|
|
16
|
-
value: value,
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true
|
|
20
|
-
});
|
|
21
|
-
} else {
|
|
22
|
-
obj[key] = value;
|
|
23
|
-
}
|
|
24
|
-
return obj;
|
|
25
|
-
}
|
|
26
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
27
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
29
|
-
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;
|
|
30
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
31
|
-
}
|
|
32
|
-
function _ts_metadata(k, v) {
|
|
33
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
34
|
-
}
|
|
35
|
-
function _ts_param(paramIndex, decorator) {
|
|
36
|
-
return function(target, key) {
|
|
37
|
-
decorator(target, key, paramIndex);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
let NotificationAdapter = class NotificationAdapter {
|
|
41
|
-
async send(options) {
|
|
42
|
-
await this.notificationHelper.send(options);
|
|
43
|
-
}
|
|
44
|
-
async sendToMany(options) {
|
|
45
|
-
await this.notificationHelper.sendToMany(options);
|
|
46
|
-
}
|
|
47
|
-
isUserOnline(userId) {
|
|
48
|
-
return this.notificationHelper.isUserOnline(userId);
|
|
49
|
-
}
|
|
50
|
-
constructor(notificationHelper){
|
|
51
|
-
_define_property(this, "notificationHelper", void 0);
|
|
52
|
-
this.notificationHelper = notificationHelper;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
NotificationAdapter = _ts_decorate([
|
|
56
|
-
(0, _common.Injectable)(),
|
|
57
|
-
_ts_param(0, (0, _common.Inject)(_notificationhelperservice.NotificationHelperService)),
|
|
58
|
-
_ts_metadata("design:type", Function),
|
|
59
|
-
_ts_metadata("design:paramtypes", [
|
|
60
|
-
typeof _notificationhelperservice.NotificationHelperService === "undefined" ? Object : _notificationhelperservice.NotificationHelperService
|
|
61
|
-
])
|
|
62
|
-
], NotificationAdapter);
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _notificationadapter = require("./notification.adapter");
|
|
6
|
-
describe('NotificationAdapter', ()=>{
|
|
7
|
-
let adapter;
|
|
8
|
-
let mockHelper;
|
|
9
|
-
beforeEach(()=>{
|
|
10
|
-
mockHelper = {
|
|
11
|
-
send: jest.fn(),
|
|
12
|
-
sendToMany: jest.fn(),
|
|
13
|
-
isUserOnline: jest.fn()
|
|
14
|
-
};
|
|
15
|
-
adapter = new _notificationadapter.NotificationAdapter(mockHelper);
|
|
16
|
-
});
|
|
17
|
-
describe('send', ()=>{
|
|
18
|
-
it('delegates to NotificationHelperService.send with the same options', async ()=>{
|
|
19
|
-
const options = {
|
|
20
|
-
userId: 'user-uuid-1',
|
|
21
|
-
title: 'Hello',
|
|
22
|
-
message: 'World'
|
|
23
|
-
};
|
|
24
|
-
mockHelper.send.mockResolvedValue(undefined);
|
|
25
|
-
await adapter.send(options);
|
|
26
|
-
expect(mockHelper.send).toHaveBeenCalledWith(options);
|
|
27
|
-
expect(mockHelper.send).toHaveBeenCalledTimes(1);
|
|
28
|
-
});
|
|
29
|
-
it('propagates errors thrown by the helper service', async ()=>{
|
|
30
|
-
const options = {
|
|
31
|
-
userId: 'user-uuid-1',
|
|
32
|
-
title: 'Hello'
|
|
33
|
-
};
|
|
34
|
-
mockHelper.send.mockRejectedValue(new Error('boom'));
|
|
35
|
-
await expect(adapter.send(options)).rejects.toThrow('boom');
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe('sendToMany', ()=>{
|
|
39
|
-
it('delegates to NotificationHelperService.sendToMany with the same options', async ()=>{
|
|
40
|
-
const options = {
|
|
41
|
-
userIds: [
|
|
42
|
-
'user-uuid-1',
|
|
43
|
-
'user-uuid-2'
|
|
44
|
-
],
|
|
45
|
-
title: 'Broadcast'
|
|
46
|
-
};
|
|
47
|
-
mockHelper.sendToMany.mockResolvedValue(undefined);
|
|
48
|
-
await adapter.sendToMany(options);
|
|
49
|
-
expect(mockHelper.sendToMany).toHaveBeenCalledWith(options);
|
|
50
|
-
expect(mockHelper.sendToMany).toHaveBeenCalledTimes(1);
|
|
51
|
-
});
|
|
52
|
-
it('handles an empty userIds array without throwing', async ()=>{
|
|
53
|
-
const options = {
|
|
54
|
-
userIds: [],
|
|
55
|
-
title: 'Nobody'
|
|
56
|
-
};
|
|
57
|
-
mockHelper.sendToMany.mockResolvedValue(undefined);
|
|
58
|
-
await expect(adapter.sendToMany(options)).resolves.toBeUndefined();
|
|
59
|
-
expect(mockHelper.sendToMany).toHaveBeenCalledWith(options);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe('isUserOnline', ()=>{
|
|
63
|
-
it('returns true when the helper reports the user online', ()=>{
|
|
64
|
-
mockHelper.isUserOnline.mockReturnValue(true);
|
|
65
|
-
expect(adapter.isUserOnline('user-uuid-1')).toBe(true);
|
|
66
|
-
expect(mockHelper.isUserOnline).toHaveBeenCalledWith('user-uuid-1');
|
|
67
|
-
});
|
|
68
|
-
it('returns false when the helper reports the user offline', ()=>{
|
|
69
|
-
mockHelper.isUserOnline.mockReturnValue(false);
|
|
70
|
-
expect(adapter.isUserOnline('user-uuid-2')).toBe(false);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Domain event actions published by the notification module, alongside the CRUD
|
|
3
|
-
* lifecycle actions every ApiService emits.
|
|
4
|
-
*/ "use strict";
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
function _export(target, all) {
|
|
9
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
_export(exports, {
|
|
15
|
-
get NOTIFICATION_EVENT_ACTIONS () {
|
|
16
|
-
return NOTIFICATION_EVENT_ACTIONS;
|
|
17
|
-
},
|
|
18
|
-
get NOTIFICATION_EVENT_ENTITIES () {
|
|
19
|
-
return NOTIFICATION_EVENT_ENTITIES;
|
|
20
|
-
},
|
|
21
|
-
get NOTIFICATION_EVENT_MODULE () {
|
|
22
|
-
return NOTIFICATION_EVENT_MODULE;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const NOTIFICATION_EVENT_ACTIONS = {
|
|
26
|
-
SENT: 'sent',
|
|
27
|
-
READ: 'read',
|
|
28
|
-
ALL_READ: 'all-read'
|
|
29
|
-
};
|
|
30
|
-
const NOTIFICATION_EVENT_ENTITIES = {
|
|
31
|
-
NOTIFICATION: 'notification'
|
|
32
|
-
};
|
|
33
|
-
const NOTIFICATION_EVENT_MODULE = 'notification';
|
package/cjs/config/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./event-actions"), exports);
|
|
6
|
-
_export_star(require("./message-keys"), exports);
|
|
7
|
-
_export_star(require("./notification.constants"), exports);
|
|
8
|
-
function _export_star(from, to) {
|
|
9
|
-
Object.keys(from).forEach(function(k) {
|
|
10
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
11
|
-
Object.defineProperty(to, k, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function() {
|
|
14
|
-
return from[k];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return from;
|
|
20
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// ==================== NOTIFICATION MODULE MESSAGE KEYS ====================
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "NOTIFICATION_MESSAGES", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function() {
|
|
9
|
-
return NOTIFICATION_MESSAGES;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
const NOTIFICATION_MESSAGES = {
|
|
13
|
-
NOT_FOUND: 'notification.not.found',
|
|
14
|
-
MARK_READ_SUCCESS: 'notification.mark.read.success',
|
|
15
|
-
MARK_ALL_READ_SUCCESS: 'notification.mark.all.read.success',
|
|
16
|
-
UNREAD_COUNT_SUCCESS: 'notification.unread.count.success',
|
|
17
|
-
SEND_SUCCESS: 'notification.send.success',
|
|
18
|
-
BROADCAST_SUCCESS: 'notification.broadcast.success'
|
|
19
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "NOTIFICATION_MODULE_OPTIONS", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return NOTIFICATION_MODULE_OPTIONS;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const NOTIFICATION_MODULE_OPTIONS = 'NOTIFICATION_MODULE_OPTIONS';
|
package/cjs/controllers/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./notification.controller"), exports);
|
|
6
|
-
function _export_star(from, to) {
|
|
7
|
-
Object.keys(from).forEach(function(k) {
|
|
8
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
-
Object.defineProperty(to, k, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function() {
|
|
12
|
-
return from[k];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
return from;
|
|
18
|
-
}
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "NotificationController", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return NotificationController;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _classes = require("@flusys/nestjs-shared/classes");
|
|
12
|
-
const _decorators = require("@flusys/nestjs-shared/decorators");
|
|
13
|
-
const _dtos = require("@flusys/nestjs-shared/dtos");
|
|
14
|
-
const _guards = require("@flusys/nestjs-shared/guards");
|
|
15
|
-
const _interfaces = require("@flusys/nestjs-shared/interfaces");
|
|
16
|
-
const _common = require("@nestjs/common");
|
|
17
|
-
const _swagger = require("@nestjs/swagger");
|
|
18
|
-
const _classtransformer = require("class-transformer");
|
|
19
|
-
const _config = require("../config");
|
|
20
|
-
const _dtos1 = require("../dtos");
|
|
21
|
-
const _notificationhelperservice = require("../services/notification-helper.service");
|
|
22
|
-
const _notificationservice = require("../services/notification.service");
|
|
23
|
-
function _define_property(obj, key, value) {
|
|
24
|
-
if (key in obj) {
|
|
25
|
-
Object.defineProperty(obj, key, {
|
|
26
|
-
value: value,
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
obj[key] = value;
|
|
33
|
-
}
|
|
34
|
-
return obj;
|
|
35
|
-
}
|
|
36
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
37
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
38
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
39
|
-
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;
|
|
40
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
41
|
-
}
|
|
42
|
-
function _ts_metadata(k, v) {
|
|
43
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
44
|
-
}
|
|
45
|
-
function _ts_param(paramIndex, decorator) {
|
|
46
|
-
return function(target, key) {
|
|
47
|
-
decorator(target, key, paramIndex);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
let NotificationController = class NotificationController extends (0, _classes.createApiController)(_dtos1.CreateNotificationDto, _dtos1.UpdateNotificationDto, _dtos1.NotificationResponseDto, {
|
|
51
|
-
entityName: 'notification',
|
|
52
|
-
security: {
|
|
53
|
-
insert: {
|
|
54
|
-
level: 'permission',
|
|
55
|
-
permissions: [
|
|
56
|
-
_classes.NOTIFICATION_PERMISSIONS.CREATE
|
|
57
|
-
]
|
|
58
|
-
},
|
|
59
|
-
insertMany: {
|
|
60
|
-
level: 'permission',
|
|
61
|
-
permissions: [
|
|
62
|
-
_classes.NOTIFICATION_PERMISSIONS.CREATE
|
|
63
|
-
]
|
|
64
|
-
},
|
|
65
|
-
getById: {
|
|
66
|
-
level: 'permission',
|
|
67
|
-
permissions: [
|
|
68
|
-
_classes.NOTIFICATION_PERMISSIONS.READ
|
|
69
|
-
]
|
|
70
|
-
},
|
|
71
|
-
getAll: {
|
|
72
|
-
level: 'jwt'
|
|
73
|
-
},
|
|
74
|
-
update: {
|
|
75
|
-
level: 'permission',
|
|
76
|
-
permissions: [
|
|
77
|
-
_classes.NOTIFICATION_PERMISSIONS.UPDATE
|
|
78
|
-
]
|
|
79
|
-
},
|
|
80
|
-
updateMany: {
|
|
81
|
-
level: 'permission',
|
|
82
|
-
permissions: [
|
|
83
|
-
_classes.NOTIFICATION_PERMISSIONS.UPDATE
|
|
84
|
-
]
|
|
85
|
-
},
|
|
86
|
-
delete: {
|
|
87
|
-
level: 'permission',
|
|
88
|
-
permissions: [
|
|
89
|
-
_classes.NOTIFICATION_PERMISSIONS.DELETE
|
|
90
|
-
]
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}) {
|
|
94
|
-
async markAsRead(dto, user) {
|
|
95
|
-
const notification = await this.service.markAsRead(dto.id, user);
|
|
96
|
-
const plainOptions = {
|
|
97
|
-
excludeExtraneousValues: true
|
|
98
|
-
};
|
|
99
|
-
return {
|
|
100
|
-
success: true,
|
|
101
|
-
message: 'Notification marked as read',
|
|
102
|
-
messageKey: _config.NOTIFICATION_MESSAGES.MARK_READ_SUCCESS,
|
|
103
|
-
data: (0, _classtransformer.plainToInstance)(_dtos1.NotificationResponseDto, notification, plainOptions)
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
async markAllAsRead(user) {
|
|
107
|
-
const count = await this.service.markAllAsRead(user);
|
|
108
|
-
return {
|
|
109
|
-
success: true,
|
|
110
|
-
message: `${count} notifications marked as read`,
|
|
111
|
-
messageKey: _config.NOTIFICATION_MESSAGES.MARK_ALL_READ_SUCCESS,
|
|
112
|
-
messageVariables: {
|
|
113
|
-
count
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
async getUnreadCount(user) {
|
|
118
|
-
const count = await this.service.getUnreadCount(user);
|
|
119
|
-
return {
|
|
120
|
-
success: true,
|
|
121
|
-
message: 'Unread count retrieved',
|
|
122
|
-
messageKey: _config.NOTIFICATION_MESSAGES.UNREAD_COUNT_SUCCESS,
|
|
123
|
-
data: {
|
|
124
|
-
count
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
async sendNotification(dto) {
|
|
129
|
-
const notification = await this.notificationHelper.send({
|
|
130
|
-
userId: dto.userId,
|
|
131
|
-
title: dto.title,
|
|
132
|
-
message: dto.message,
|
|
133
|
-
type: dto.type,
|
|
134
|
-
data: dto.data,
|
|
135
|
-
companyId: dto.companyId
|
|
136
|
-
});
|
|
137
|
-
const plainOptions = {
|
|
138
|
-
excludeExtraneousValues: true
|
|
139
|
-
};
|
|
140
|
-
return {
|
|
141
|
-
success: true,
|
|
142
|
-
message: 'Notification sent successfully',
|
|
143
|
-
messageKey: _config.NOTIFICATION_MESSAGES.SEND_SUCCESS,
|
|
144
|
-
data: (0, _classtransformer.plainToInstance)(_dtos1.NotificationResponseDto, notification, plainOptions)
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
async sendBulkNotification(dto) {
|
|
148
|
-
const notifications = await this.notificationHelper.sendToMany({
|
|
149
|
-
userIds: dto.userIds,
|
|
150
|
-
title: dto.title,
|
|
151
|
-
message: dto.message,
|
|
152
|
-
type: dto.type,
|
|
153
|
-
data: dto.data,
|
|
154
|
-
companyId: dto.companyId
|
|
155
|
-
});
|
|
156
|
-
const plainOptions = {
|
|
157
|
-
excludeExtraneousValues: true
|
|
158
|
-
};
|
|
159
|
-
return {
|
|
160
|
-
success: true,
|
|
161
|
-
message: `${notifications.length} notifications sent successfully`,
|
|
162
|
-
messageKey: _config.NOTIFICATION_MESSAGES.BROADCAST_SUCCESS,
|
|
163
|
-
messageVariables: {
|
|
164
|
-
count: notifications.length
|
|
165
|
-
},
|
|
166
|
-
data: notifications.map((n)=>(0, _classtransformer.plainToInstance)(_dtos1.NotificationResponseDto, n, plainOptions)),
|
|
167
|
-
meta: {
|
|
168
|
-
count: notifications.length,
|
|
169
|
-
total: dto.userIds.length
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
constructor(service, notificationHelper){
|
|
174
|
-
super(service), _define_property(this, "service", void 0), _define_property(this, "notificationHelper", void 0), this.service = service, this.notificationHelper = notificationHelper;
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
_ts_decorate([
|
|
178
|
-
(0, _common.Post)('mark-read'),
|
|
179
|
-
(0, _common.HttpCode)(_common.HttpStatus.OK),
|
|
180
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
181
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
182
|
-
(0, _swagger.ApiOperation)({
|
|
183
|
-
summary: 'Mark a notification as read'
|
|
184
|
-
}),
|
|
185
|
-
(0, _swagger.ApiBody)({
|
|
186
|
-
type: _dtos1.MarkReadDto
|
|
187
|
-
}),
|
|
188
|
-
(0, _swagger.ApiResponse)({
|
|
189
|
-
status: 200,
|
|
190
|
-
description: 'Notification marked as read',
|
|
191
|
-
type: _dtos.SingleResponseDto
|
|
192
|
-
}),
|
|
193
|
-
_ts_param(0, (0, _common.Body)()),
|
|
194
|
-
_ts_param(1, (0, _decorators.CurrentUser)()),
|
|
195
|
-
_ts_metadata("design:type", Function),
|
|
196
|
-
_ts_metadata("design:paramtypes", [
|
|
197
|
-
typeof _dtos1.MarkReadDto === "undefined" ? Object : _dtos1.MarkReadDto,
|
|
198
|
-
typeof _interfaces.ILoggedUserInfo === "undefined" ? Object : _interfaces.ILoggedUserInfo
|
|
199
|
-
]),
|
|
200
|
-
_ts_metadata("design:returntype", Promise)
|
|
201
|
-
], NotificationController.prototype, "markAsRead", null);
|
|
202
|
-
_ts_decorate([
|
|
203
|
-
(0, _common.Post)('mark-all-read'),
|
|
204
|
-
(0, _common.HttpCode)(_common.HttpStatus.OK),
|
|
205
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
206
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
207
|
-
(0, _swagger.ApiOperation)({
|
|
208
|
-
summary: 'Mark all notifications as read'
|
|
209
|
-
}),
|
|
210
|
-
(0, _swagger.ApiResponse)({
|
|
211
|
-
status: 200,
|
|
212
|
-
description: 'All notifications marked as read',
|
|
213
|
-
type: _dtos.MessageResponseDto
|
|
214
|
-
}),
|
|
215
|
-
_ts_param(0, (0, _decorators.CurrentUser)()),
|
|
216
|
-
_ts_metadata("design:type", Function),
|
|
217
|
-
_ts_metadata("design:paramtypes", [
|
|
218
|
-
typeof _interfaces.ILoggedUserInfo === "undefined" ? Object : _interfaces.ILoggedUserInfo
|
|
219
|
-
]),
|
|
220
|
-
_ts_metadata("design:returntype", Promise)
|
|
221
|
-
], NotificationController.prototype, "markAllAsRead", null);
|
|
222
|
-
_ts_decorate([
|
|
223
|
-
(0, _common.Post)('unread-count'),
|
|
224
|
-
(0, _common.HttpCode)(_common.HttpStatus.OK),
|
|
225
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
226
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
227
|
-
(0, _swagger.ApiOperation)({
|
|
228
|
-
summary: 'Get unread notification count'
|
|
229
|
-
}),
|
|
230
|
-
(0, _swagger.ApiResponse)({
|
|
231
|
-
status: 200,
|
|
232
|
-
description: 'Unread count retrieved',
|
|
233
|
-
type: _dtos.SingleResponseDto
|
|
234
|
-
}),
|
|
235
|
-
_ts_param(0, (0, _decorators.CurrentUser)()),
|
|
236
|
-
_ts_metadata("design:type", Function),
|
|
237
|
-
_ts_metadata("design:paramtypes", [
|
|
238
|
-
typeof _interfaces.ILoggedUserInfo === "undefined" ? Object : _interfaces.ILoggedUserInfo
|
|
239
|
-
]),
|
|
240
|
-
_ts_metadata("design:returntype", Promise)
|
|
241
|
-
], NotificationController.prototype, "getUnreadCount", null);
|
|
242
|
-
_ts_decorate([
|
|
243
|
-
(0, _common.Post)('send'),
|
|
244
|
-
(0, _common.HttpCode)(_common.HttpStatus.OK),
|
|
245
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard, _guards.PermissionGuard),
|
|
246
|
-
(0, _decorators.RequirePermission)(_classes.NOTIFICATION_PERMISSIONS.CREATE),
|
|
247
|
-
(0, _swagger.ApiOperation)({
|
|
248
|
-
summary: 'Send a notification to a user'
|
|
249
|
-
}),
|
|
250
|
-
(0, _swagger.ApiBody)({
|
|
251
|
-
type: _dtos1.SendNotificationDto
|
|
252
|
-
}),
|
|
253
|
-
(0, _swagger.ApiResponse)({
|
|
254
|
-
status: 200,
|
|
255
|
-
description: 'Notification sent successfully',
|
|
256
|
-
type: _dtos.SingleResponseDto
|
|
257
|
-
}),
|
|
258
|
-
_ts_param(0, (0, _common.Body)()),
|
|
259
|
-
_ts_metadata("design:type", Function),
|
|
260
|
-
_ts_metadata("design:paramtypes", [
|
|
261
|
-
typeof _dtos1.SendNotificationDto === "undefined" ? Object : _dtos1.SendNotificationDto
|
|
262
|
-
]),
|
|
263
|
-
_ts_metadata("design:returntype", Promise)
|
|
264
|
-
], NotificationController.prototype, "sendNotification", null);
|
|
265
|
-
_ts_decorate([
|
|
266
|
-
(0, _common.Post)('send-bulk'),
|
|
267
|
-
(0, _common.HttpCode)(_common.HttpStatus.OK),
|
|
268
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard, _guards.PermissionGuard),
|
|
269
|
-
(0, _decorators.RequirePermission)(_classes.NOTIFICATION_PERMISSIONS.CREATE),
|
|
270
|
-
(0, _swagger.ApiOperation)({
|
|
271
|
-
summary: 'Send a notification to multiple users'
|
|
272
|
-
}),
|
|
273
|
-
(0, _swagger.ApiBody)({
|
|
274
|
-
type: _dtos1.SendBulkNotificationDto
|
|
275
|
-
}),
|
|
276
|
-
(0, _swagger.ApiResponse)({
|
|
277
|
-
status: 200,
|
|
278
|
-
description: 'Notifications sent successfully',
|
|
279
|
-
type: _dtos.BulkResponseDto
|
|
280
|
-
}),
|
|
281
|
-
_ts_param(0, (0, _common.Body)()),
|
|
282
|
-
_ts_metadata("design:type", Function),
|
|
283
|
-
_ts_metadata("design:paramtypes", [
|
|
284
|
-
typeof _dtos1.SendBulkNotificationDto === "undefined" ? Object : _dtos1.SendBulkNotificationDto
|
|
285
|
-
]),
|
|
286
|
-
_ts_metadata("design:returntype", Promise)
|
|
287
|
-
], NotificationController.prototype, "sendBulkNotification", null);
|
|
288
|
-
NotificationController = _ts_decorate([
|
|
289
|
-
(0, _swagger.ApiTags)('Notifications'),
|
|
290
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
291
|
-
(0, _common.Controller)('notification'),
|
|
292
|
-
_ts_param(0, (0, _common.Inject)(_notificationservice.NotificationService)),
|
|
293
|
-
_ts_param(1, (0, _common.Inject)(_notificationhelperservice.NotificationHelperService)),
|
|
294
|
-
_ts_metadata("design:type", Function),
|
|
295
|
-
_ts_metadata("design:paramtypes", [
|
|
296
|
-
typeof _notificationservice.NotificationService === "undefined" ? Object : _notificationservice.NotificationService,
|
|
297
|
-
typeof _notificationhelperservice.NotificationHelperService === "undefined" ? Object : _notificationhelperservice.NotificationHelperService
|
|
298
|
-
])
|
|
299
|
-
], NotificationController);
|