@flusys/nestjs-notification 7.0.0-beta.1 → 7.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.
@@ -139,7 +139,7 @@ let NotificationHelperService = class NotificationHelperService {
139
139
  };
140
140
  }
141
141
  async clearCache() {
142
- await this.utilsService.clearCache('notification', this.cacheManager);
142
+ await this.utilsService.clearCache(_config.NOTIFICATION_EVENT_ENTITIES.NOTIFICATION, this.cacheManager);
143
143
  }
144
144
  constructor(cacheManager, utilsService, configService, dataSourceProvider, gateway){
145
145
  _define_property(this, "cacheManager", void 0);
@@ -47,9 +47,6 @@ function _ts_param(paramIndex, decorator) {
47
47
  };
48
48
  }
49
49
  let NotificationService = class NotificationService extends _classes.ApiService {
50
- resolveEntity() {
51
- return this.notificationConfig.isCompanyFeatureEnabled() ? _entities.NotificationWithCompany : _entities.Notification;
52
- }
53
50
  async convertSingleDtoToEntity(dto, user) {
54
51
  let entity = {};
55
52
  if ('id' in dto && dto.id) {
@@ -237,7 +234,7 @@ let NotificationService = class NotificationService extends _classes.ApiService
237
234
  }
238
235
  }
239
236
  constructor(cacheManager, utilsService, notificationConfig, dataSourceProvider, gateway){
240
- super('notification', cacheManager, utilsService, NotificationService.name, false, 'notification', undefined, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "notificationConfig", void 0), _define_property(this, "gateway", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.notificationConfig = notificationConfig, this.gateway = gateway;
237
+ super(_config.NOTIFICATION_EVENT_ENTITIES.NOTIFICATION, cacheManager, utilsService, NotificationService.name, false, _config.NOTIFICATION_EVENT_MODULE, dataSourceProvider, notificationConfig.isCompanyFeatureEnabled() ? _entities.NotificationWithCompany : _entities.Notification), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "notificationConfig", void 0), _define_property(this, "gateway", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.notificationConfig = notificationConfig, this.gateway = gateway;
241
238
  }
242
239
  };
243
240
  _ts_decorate([
@@ -43,11 +43,11 @@ describe('NotificationService', ()=>{
43
43
  let mockRepo;
44
44
  let mockConfig;
45
45
  let mockGateway;
46
- async function buildService(withGateway = true) {
46
+ async function buildService(withGateway = true, companyFeatureEnabled = false) {
47
47
  mockRepo = (0, _repositorymock.createMockRepository)();
48
48
  const mockDataSourceProvider = (0, _repositorymock.createMockDataSourceProvider)(mockRepo);
49
49
  mockConfig = {
50
- isCompanyFeatureEnabled: jest.fn().mockReturnValue(false)
50
+ isCompanyFeatureEnabled: jest.fn().mockReturnValue(companyFeatureEnabled)
51
51
  };
52
52
  mockGateway = {
53
53
  emitToUser: jest.fn(),
@@ -90,13 +90,14 @@ describe('NotificationService', ()=>{
90
90
  beforeEach(async ()=>{
91
91
  service = await buildService();
92
92
  });
93
- describe('resolveEntity', ()=>{
94
- it('returns Notification when the company feature is disabled', ()=>{
95
- expect(service.resolveEntity()).toBe(_entities.Notification);
96
- });
97
- it('returns NotificationWithCompany when the company feature is enabled', ()=>{
98
- mockConfig.isCompanyFeatureEnabled.mockReturnValue(true);
99
- expect(service.resolveEntity()).toBe(_entities.NotificationWithCompany);
93
+ describe('entity selection', ()=>{
94
+ it('uses Notification when the company feature is disabled', async ()=>{
95
+ const built = await buildService(true, false);
96
+ expect(built['_entity']).toBe(_entities.Notification);
97
+ });
98
+ it('uses NotificationWithCompany when the company feature is enabled', async ()=>{
99
+ const built = await buildService(true, true);
100
+ expect(built['_entity']).toBe(_entities.NotificationWithCompany);
100
101
  });
101
102
  });
102
103
  describe('convertSingleDtoToEntity', ()=>{
@@ -129,7 +129,7 @@ export class NotificationHelperService {
129
129
  };
130
130
  }
131
131
  async clearCache() {
132
- await this.utilsService.clearCache('notification', this.cacheManager);
132
+ await this.utilsService.clearCache(NOTIFICATION_EVENT_ENTITIES.NOTIFICATION, this.cacheManager);
133
133
  }
134
134
  constructor(cacheManager, utilsService, configService, dataSourceProvider, gateway){
135
135
  _define_property(this, "cacheManager", void 0);
@@ -31,15 +31,12 @@ import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
31
31
  import { UtilsService } from '@flusys/nestjs-shared/modules';
32
32
  import { applyCompanyFilter } from '@flusys/nestjs-shared/utils';
33
33
  import { Inject, Injectable, NotFoundException, Optional, Scope } from '@nestjs/common';
34
- import { NOTIFICATION_EVENT_ACTIONS, NOTIFICATION_MESSAGES } from '../config';
34
+ import { NOTIFICATION_EVENT_ACTIONS, NOTIFICATION_EVENT_ENTITIES, NOTIFICATION_EVENT_MODULE, NOTIFICATION_MESSAGES } from '../config';
35
35
  import { Notification, NotificationWithCompany } from '../entities';
36
36
  import { NotificationGateway } from '../gateways';
37
37
  import { NotificationConfigService } from './notification-config.service';
38
38
  import { NotificationDataSourceProvider } from './notification-datasource.provider';
39
39
  export class NotificationService extends ApiService {
40
- resolveEntity() {
41
- return this.notificationConfig.isCompanyFeatureEnabled() ? NotificationWithCompany : Notification;
42
- }
43
40
  async convertSingleDtoToEntity(dto, user) {
44
41
  let entity = {};
45
42
  if ('id' in dto && dto.id) {
@@ -227,7 +224,7 @@ export class NotificationService extends ApiService {
227
224
  }
228
225
  }
229
226
  constructor(cacheManager, utilsService, notificationConfig, dataSourceProvider, gateway){
230
- super('notification', cacheManager, utilsService, NotificationService.name, false, 'notification', undefined, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "notificationConfig", void 0), _define_property(this, "gateway", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.notificationConfig = notificationConfig, this.gateway = gateway;
227
+ super(NOTIFICATION_EVENT_ENTITIES.NOTIFICATION, cacheManager, utilsService, NotificationService.name, false, NOTIFICATION_EVENT_MODULE, dataSourceProvider, notificationConfig.isCompanyFeatureEnabled() ? NotificationWithCompany : Notification), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "notificationConfig", void 0), _define_property(this, "gateway", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.notificationConfig = notificationConfig, this.gateway = gateway;
231
228
  }
232
229
  }
233
230
  _ts_decorate([
@@ -39,11 +39,11 @@ describe('NotificationService', ()=>{
39
39
  let mockRepo;
40
40
  let mockConfig;
41
41
  let mockGateway;
42
- async function buildService(withGateway = true) {
42
+ async function buildService(withGateway = true, companyFeatureEnabled = false) {
43
43
  mockRepo = createMockRepository();
44
44
  const mockDataSourceProvider = createMockDataSourceProvider(mockRepo);
45
45
  mockConfig = {
46
- isCompanyFeatureEnabled: jest.fn().mockReturnValue(false)
46
+ isCompanyFeatureEnabled: jest.fn().mockReturnValue(companyFeatureEnabled)
47
47
  };
48
48
  mockGateway = {
49
49
  emitToUser: jest.fn(),
@@ -86,13 +86,14 @@ describe('NotificationService', ()=>{
86
86
  beforeEach(async ()=>{
87
87
  service = await buildService();
88
88
  });
89
- describe('resolveEntity', ()=>{
90
- it('returns Notification when the company feature is disabled', ()=>{
91
- expect(service.resolveEntity()).toBe(Notification);
92
- });
93
- it('returns NotificationWithCompany when the company feature is enabled', ()=>{
94
- mockConfig.isCompanyFeatureEnabled.mockReturnValue(true);
95
- expect(service.resolveEntity()).toBe(NotificationWithCompany);
89
+ describe('entity selection', ()=>{
90
+ it('uses Notification when the company feature is disabled', async ()=>{
91
+ const built = await buildService(true, false);
92
+ expect(built['_entity']).toBe(Notification);
93
+ });
94
+ it('uses NotificationWithCompany when the company feature is enabled', async ()=>{
95
+ const built = await buildService(true, true);
96
+ expect(built['_entity']).toBe(NotificationWithCompany);
96
97
  });
97
98
  });
98
99
  describe('convertSingleDtoToEntity', ()=>{
@@ -1,4 +1,4 @@
1
- import { IBootstrapAppConfig, IDataSourceServiceOptions, IDynamicModuleConfig, IModuleOptionsFactory } from '@flusys/nestjs-core';
1
+ import { IBootstrapAppConfig, IDataSourceServiceOptions, IDynamicModuleConfig } from '@flusys/nestjs-core';
2
2
  import { IModuleEventsConfig } from '@flusys/nestjs-shared/interfaces';
3
3
  import { ModuleMetadata, Type } from '@nestjs/common';
4
4
  export interface INotificationModuleConfig extends IDataSourceServiceOptions {
@@ -9,7 +9,7 @@ export interface NotificationModuleOptions extends IDynamicModuleConfig {
9
9
  bootstrapAppConfig?: IBootstrapAppConfig;
10
10
  config?: INotificationModuleConfig;
11
11
  }
12
- export interface NotificationOptionsFactory extends IModuleOptionsFactory<INotificationModuleConfig> {
12
+ export interface NotificationOptionsFactory {
13
13
  createNotificationOptions(): Promise<INotificationModuleConfig> | INotificationModuleConfig;
14
14
  }
15
15
  export interface NotificationModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'>, IDynamicModuleConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flusys/nestjs-notification",
3
- "version": "7.0.0-beta.1",
3
+ "version": "7.0.1",
4
4
  "description": "Notification module with real-time Socket.IO support",
5
5
  "main": "cjs/index.js",
6
6
  "module": "fesm/index.js",
@@ -93,7 +93,7 @@
93
93
  "express": "^5.0.0"
94
94
  },
95
95
  "dependencies": {
96
- "@flusys/nestjs-core": "7.0.0-beta.1",
97
- "@flusys/nestjs-shared": "7.0.0-beta.1"
96
+ "@flusys/nestjs-core": "7.0.1",
97
+ "@flusys/nestjs-shared": "7.0.1"
98
98
  }
99
99
  }
@@ -1,7 +1,7 @@
1
1
  import { ApiService, HybridCache } from '@flusys/nestjs-shared/classes';
2
2
  import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
3
3
  import { UtilsService } from '@flusys/nestjs-shared/modules';
4
- import { EntityTarget, QueryRunner, SelectQueryBuilder } from 'typeorm';
4
+ import { QueryRunner, SelectQueryBuilder } from 'typeorm';
5
5
  import { CreateNotificationDto, UpdateNotificationDto } from '../dtos';
6
6
  import { NotificationBase } from '../entities';
7
7
  import { NotificationGateway } from '../gateways';
@@ -14,7 +14,6 @@ export declare class NotificationService extends ApiService<CreateNotificationDt
14
14
  private readonly notificationConfig;
15
15
  private readonly gateway?;
16
16
  constructor(cacheManager: HybridCache, utilsService: UtilsService, notificationConfig: NotificationConfigService, dataSourceProvider: NotificationDataSourceProvider, gateway?: NotificationGateway | undefined);
17
- protected resolveEntity(): EntityTarget<NotificationBase>;
18
17
  convertSingleDtoToEntity(dto: CreateNotificationDto | UpdateNotificationDto, user: ILoggedUserInfo | null): Promise<NotificationBase>;
19
18
  protected getSelectQuery(query: SelectQueryBuilder<NotificationBase>, _user: ILoggedUserInfo | null, select?: string[]): Promise<{
20
19
  query: SelectQueryBuilder<NotificationBase>;