@flusys/nestjs-event-manager 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 +1328 -0
- package/adapters/event-manager.adapter.d.ts +12 -0
- package/adapters/index.d.ts +1 -0
- package/cjs/adapters/event-manager.adapter.js +71 -0
- package/cjs/adapters/index.js +18 -0
- package/cjs/config/event-manager.constants.js +13 -0
- package/cjs/config/index.js +18 -0
- package/cjs/controllers/event-participant.controller.js +271 -0
- package/cjs/controllers/event.controller.js +229 -0
- package/cjs/controllers/index.js +19 -0
- package/cjs/docs/event-manager-swagger.config.js +135 -0
- package/cjs/docs/index.js +24 -0
- package/cjs/dtos/calendar-query.dto.js +186 -0
- package/cjs/dtos/event-participant.dto.js +226 -0
- package/cjs/dtos/event.dto.js +291 -0
- package/cjs/dtos/index.js +20 -0
- package/cjs/entities/event-participant.entity.js +96 -0
- package/cjs/entities/event-with-company.entity.js +56 -0
- package/cjs/entities/event.entity.js +143 -0
- package/cjs/entities/index.js +55 -0
- package/cjs/index.js +27 -0
- package/cjs/interfaces/event-manager-module.interface.js +4 -0
- package/cjs/interfaces/event.interface.js +4 -0
- package/cjs/interfaces/index.js +19 -0
- package/cjs/modules/event-manager.module.js +133 -0
- package/cjs/modules/index.js +18 -0
- package/cjs/services/event-manager-config.service.js +76 -0
- package/cjs/services/event-manager-datasource.provider.js +181 -0
- package/cjs/services/event-manager-helper.service.js +253 -0
- package/cjs/services/event-participant.service.js +164 -0
- package/cjs/services/event.service.js +421 -0
- package/cjs/services/index.js +22 -0
- package/config/event-manager.constants.d.ts +1 -0
- package/config/index.d.ts +1 -0
- package/controllers/event-participant.controller.d.ts +31 -0
- package/controllers/event.controller.d.ts +24 -0
- package/controllers/index.d.ts +2 -0
- package/docs/event-manager-swagger.config.d.ts +3 -0
- package/docs/index.d.ts +2 -0
- package/dtos/calendar-query.dto.d.ts +23 -0
- package/dtos/event-participant.dto.d.ts +31 -0
- package/dtos/event.dto.d.ts +37 -0
- package/dtos/index.d.ts +3 -0
- package/entities/event-participant.entity.d.ts +8 -0
- package/entities/event-with-company.entity.d.ts +4 -0
- package/entities/event.entity.d.ts +14 -0
- package/entities/index.d.ts +11 -0
- package/fesm/adapters/event-manager.adapter.js +61 -0
- package/fesm/adapters/index.js +1 -0
- package/fesm/config/event-manager.constants.js +3 -0
- package/fesm/config/index.js +1 -0
- package/fesm/controllers/event-participant.controller.js +261 -0
- package/fesm/controllers/event.controller.js +219 -0
- package/fesm/controllers/index.js +2 -0
- package/fesm/docs/event-manager-swagger.config.js +128 -0
- package/fesm/docs/index.js +4 -0
- package/fesm/dtos/calendar-query.dto.js +168 -0
- package/fesm/dtos/event-participant.dto.js +199 -0
- package/fesm/dtos/event.dto.js +270 -0
- package/fesm/dtos/index.js +3 -0
- package/fesm/entities/event-participant.entity.js +86 -0
- package/fesm/entities/event-with-company.entity.js +46 -0
- package/fesm/entities/event.entity.js +133 -0
- package/fesm/entities/index.js +24 -0
- package/fesm/index.js +10 -0
- package/fesm/interfaces/event-manager-module.interface.js +3 -0
- package/fesm/interfaces/event.interface.js +1 -0
- package/fesm/interfaces/index.js +2 -0
- package/fesm/modules/event-manager.module.js +123 -0
- package/fesm/modules/index.js +1 -0
- package/fesm/services/event-manager-config.service.js +66 -0
- package/fesm/services/event-manager-datasource.provider.js +130 -0
- package/fesm/services/event-manager-helper.service.js +243 -0
- package/fesm/services/event-participant.service.js +154 -0
- package/fesm/services/event.service.js +411 -0
- package/fesm/services/index.js +5 -0
- package/index.d.ts +9 -0
- package/interfaces/event-manager-module.interface.d.ts +20 -0
- package/interfaces/event.interface.d.ts +28 -0
- package/interfaces/index.d.ts +2 -0
- package/modules/event-manager.module.d.ts +8 -0
- package/modules/index.d.ts +1 -0
- package/package.json +89 -0
- package/services/event-manager-config.service.d.ts +13 -0
- package/services/event-manager-datasource.provider.d.ts +23 -0
- package/services/event-manager-helper.service.d.ts +27 -0
- package/services/event-participant.service.d.ts +27 -0
- package/services/event.service.d.ts +49 -0
- package/services/index.d.ts +5 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./event.interface"), exports);
|
|
6
|
+
_export_star(require("./event-manager-module.interface"), exports);
|
|
7
|
+
function _export_star(from, to) {
|
|
8
|
+
Object.keys(from).forEach(function(k) {
|
|
9
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
+
Object.defineProperty(to, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return from[k];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return from;
|
|
19
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "EventManagerModule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return EventManagerModule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _modules = require("@flusys/nestjs-shared/modules");
|
|
12
|
+
const _interfaces = require("@flusys/nestjs-shared/interfaces");
|
|
13
|
+
const _common = require("@nestjs/common");
|
|
14
|
+
const _eventmanagerconstants = require("../config/event-manager.constants");
|
|
15
|
+
const _controllers = require("../controllers");
|
|
16
|
+
const _adapters = require("../adapters");
|
|
17
|
+
const _services = require("../services");
|
|
18
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
}
|
|
24
|
+
const CONTROLLERS = [
|
|
25
|
+
_controllers.EventController,
|
|
26
|
+
_controllers.EventParticipantController
|
|
27
|
+
];
|
|
28
|
+
const EXPORTED_SERVICES = [
|
|
29
|
+
_services.EventManagerConfigService,
|
|
30
|
+
_services.EventManagerDataSourceProvider,
|
|
31
|
+
_services.EventManagerHelperService,
|
|
32
|
+
_services.EventService,
|
|
33
|
+
_services.EventParticipantService
|
|
34
|
+
];
|
|
35
|
+
const ADAPTER_PROVIDER = {
|
|
36
|
+
provide: _interfaces.EVENT_MANAGER_ADAPTER,
|
|
37
|
+
useClass: _adapters.EventManagerAdapter
|
|
38
|
+
};
|
|
39
|
+
let EventManagerModule = class EventManagerModule {
|
|
40
|
+
static forRoot(options) {
|
|
41
|
+
return {
|
|
42
|
+
module: EventManagerModule,
|
|
43
|
+
global: options.global ?? false,
|
|
44
|
+
imports: [
|
|
45
|
+
_modules.CacheModule,
|
|
46
|
+
_modules.UtilsModule
|
|
47
|
+
],
|
|
48
|
+
controllers: options.includeController !== false ? CONTROLLERS : [],
|
|
49
|
+
providers: [
|
|
50
|
+
...this.buildProviders(options),
|
|
51
|
+
_adapters.EventManagerAdapter,
|
|
52
|
+
ADAPTER_PROVIDER
|
|
53
|
+
],
|
|
54
|
+
exports: [
|
|
55
|
+
...EXPORTED_SERVICES,
|
|
56
|
+
_interfaces.EVENT_MANAGER_ADAPTER
|
|
57
|
+
]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
static forRootAsync(options) {
|
|
61
|
+
return {
|
|
62
|
+
module: EventManagerModule,
|
|
63
|
+
global: options.global ?? false,
|
|
64
|
+
imports: [
|
|
65
|
+
...options.imports || [],
|
|
66
|
+
_modules.CacheModule,
|
|
67
|
+
_modules.UtilsModule
|
|
68
|
+
],
|
|
69
|
+
controllers: options.includeController !== false ? CONTROLLERS : [],
|
|
70
|
+
providers: [
|
|
71
|
+
...this.createAsyncProviders(options),
|
|
72
|
+
...this.buildProviders(),
|
|
73
|
+
_adapters.EventManagerAdapter,
|
|
74
|
+
ADAPTER_PROVIDER
|
|
75
|
+
],
|
|
76
|
+
exports: [
|
|
77
|
+
...EXPORTED_SERVICES,
|
|
78
|
+
_interfaces.EVENT_MANAGER_ADAPTER
|
|
79
|
+
]
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// Private Helpers
|
|
83
|
+
static buildProviders(options) {
|
|
84
|
+
const providers = [
|
|
85
|
+
...EXPORTED_SERVICES
|
|
86
|
+
];
|
|
87
|
+
if (options) {
|
|
88
|
+
providers.unshift({
|
|
89
|
+
provide: _eventmanagerconstants.EVENT_MANAGER_MODULE_OPTIONS,
|
|
90
|
+
useValue: options
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return providers;
|
|
94
|
+
}
|
|
95
|
+
static createAsyncProviders(options) {
|
|
96
|
+
if (options.useFactory) {
|
|
97
|
+
return [
|
|
98
|
+
{
|
|
99
|
+
provide: _eventmanagerconstants.EVENT_MANAGER_MODULE_OPTIONS,
|
|
100
|
+
useFactory: async (...args)=>({
|
|
101
|
+
...options,
|
|
102
|
+
config: await options.useFactory(...args)
|
|
103
|
+
}),
|
|
104
|
+
inject: options.inject || []
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
const factoryClass = options.useClass || options.useExisting;
|
|
109
|
+
if (!factoryClass) return [];
|
|
110
|
+
const providers = [
|
|
111
|
+
{
|
|
112
|
+
provide: _eventmanagerconstants.EVENT_MANAGER_MODULE_OPTIONS,
|
|
113
|
+
useFactory: async (factory)=>({
|
|
114
|
+
...options,
|
|
115
|
+
config: await factory.createEventManagerOptions()
|
|
116
|
+
}),
|
|
117
|
+
inject: [
|
|
118
|
+
factoryClass
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
];
|
|
122
|
+
if (options.useClass) {
|
|
123
|
+
providers.push({
|
|
124
|
+
provide: options.useClass,
|
|
125
|
+
useClass: options.useClass
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return providers;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
EventManagerModule = _ts_decorate([
|
|
132
|
+
(0, _common.Module)({})
|
|
133
|
+
], EventManagerModule);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./event-manager.module"), 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
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "EventManagerConfigService", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return EventManagerConfigService;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _common = require("@nestjs/common");
|
|
12
|
+
const _interfaces = require("../interfaces");
|
|
13
|
+
const _eventmanagerconstants = require("../config/event-manager.constants");
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
28
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
29
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
30
|
+
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;
|
|
31
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
32
|
+
}
|
|
33
|
+
function _ts_metadata(k, v) {
|
|
34
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
35
|
+
}
|
|
36
|
+
function _ts_param(paramIndex, decorator) {
|
|
37
|
+
return function(target, key) {
|
|
38
|
+
decorator(target, key, paramIndex);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const DEFAULT_COLOR = '#3B82F6';
|
|
42
|
+
const DEFAULT_MAX_RECURRENCE_OCCURRENCES = 365;
|
|
43
|
+
let EventManagerConfigService = class EventManagerConfigService {
|
|
44
|
+
// IModuleConfigService Implementation
|
|
45
|
+
isCompanyFeatureEnabled() {
|
|
46
|
+
return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
47
|
+
}
|
|
48
|
+
getDatabaseMode() {
|
|
49
|
+
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
50
|
+
}
|
|
51
|
+
isMultiTenant() {
|
|
52
|
+
return this.getDatabaseMode() === 'multi-tenant';
|
|
53
|
+
}
|
|
54
|
+
// Config Getters
|
|
55
|
+
getDefaultColor() {
|
|
56
|
+
return this.options.config?.defaultColor ?? DEFAULT_COLOR;
|
|
57
|
+
}
|
|
58
|
+
getMaxRecurrenceOccurrences() {
|
|
59
|
+
return this.options.config?.maxRecurrenceOccurrences ?? DEFAULT_MAX_RECURRENCE_OCCURRENCES;
|
|
60
|
+
}
|
|
61
|
+
getOptions() {
|
|
62
|
+
return this.options;
|
|
63
|
+
}
|
|
64
|
+
constructor(options){
|
|
65
|
+
_define_property(this, "options", void 0);
|
|
66
|
+
this.options = options;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
EventManagerConfigService = _ts_decorate([
|
|
70
|
+
(0, _common.Injectable)(),
|
|
71
|
+
_ts_param(0, (0, _common.Inject)(_eventmanagerconstants.EVENT_MANAGER_MODULE_OPTIONS)),
|
|
72
|
+
_ts_metadata("design:type", Function),
|
|
73
|
+
_ts_metadata("design:paramtypes", [
|
|
74
|
+
typeof _interfaces.EventManagerModuleOptions === "undefined" ? Object : _interfaces.EventManagerModuleOptions
|
|
75
|
+
])
|
|
76
|
+
], EventManagerConfigService);
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "EventManagerDataSourceProvider", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return EventManagerDataSourceProvider;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _modules = require("@flusys/nestjs-shared/modules");
|
|
12
|
+
const _common = require("@nestjs/common");
|
|
13
|
+
const _core = require("@nestjs/core");
|
|
14
|
+
const _express = require("express");
|
|
15
|
+
const _eventmanagerconfigservice = require("./event-manager-config.service");
|
|
16
|
+
function _define_property(obj, key, value) {
|
|
17
|
+
if (key in obj) {
|
|
18
|
+
Object.defineProperty(obj, key, {
|
|
19
|
+
value: value,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
obj[key] = value;
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
30
|
+
if (typeof WeakMap !== "function") return null;
|
|
31
|
+
var cacheBabelInterop = new WeakMap();
|
|
32
|
+
var cacheNodeInterop = new WeakMap();
|
|
33
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
34
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
35
|
+
})(nodeInterop);
|
|
36
|
+
}
|
|
37
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
38
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
42
|
+
return {
|
|
43
|
+
default: obj
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
47
|
+
if (cache && cache.has(obj)) {
|
|
48
|
+
return cache.get(obj);
|
|
49
|
+
}
|
|
50
|
+
var newObj = {
|
|
51
|
+
__proto__: null
|
|
52
|
+
};
|
|
53
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
54
|
+
for(var key in obj){
|
|
55
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
56
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
57
|
+
if (desc && (desc.get || desc.set)) {
|
|
58
|
+
Object.defineProperty(newObj, key, desc);
|
|
59
|
+
} else {
|
|
60
|
+
newObj[key] = obj[key];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
newObj.default = obj;
|
|
65
|
+
if (cache) {
|
|
66
|
+
cache.set(obj, newObj);
|
|
67
|
+
}
|
|
68
|
+
return newObj;
|
|
69
|
+
}
|
|
70
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
71
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
72
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
73
|
+
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;
|
|
74
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
75
|
+
}
|
|
76
|
+
function _ts_metadata(k, v) {
|
|
77
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
78
|
+
}
|
|
79
|
+
function _ts_param(paramIndex, decorator) {
|
|
80
|
+
return function(target, key) {
|
|
81
|
+
decorator(target, key, paramIndex);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
let EventManagerDataSourceProvider = class EventManagerDataSourceProvider extends _modules.MultiTenantDataSourceService {
|
|
85
|
+
// Factory Methods
|
|
86
|
+
static buildParentOptions(options) {
|
|
87
|
+
return {
|
|
88
|
+
bootstrapAppConfig: options.bootstrapAppConfig,
|
|
89
|
+
defaultDatabaseConfig: options.config?.defaultDatabaseConfig,
|
|
90
|
+
tenantDefaultDatabaseConfig: options.config?.tenantDefaultDatabaseConfig,
|
|
91
|
+
tenants: options.config?.tenants
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// Feature Flags
|
|
95
|
+
getEnableCompanyFeatureForTenant(tenant) {
|
|
96
|
+
return tenant?.enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
|
|
97
|
+
}
|
|
98
|
+
// Entity Management
|
|
99
|
+
async getEventManagerEntities(enableCompanyFeature) {
|
|
100
|
+
const enable = enableCompanyFeature ?? this.configService.isCompanyFeatureEnabled();
|
|
101
|
+
const entities = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("../entities")));
|
|
102
|
+
// EventParticipant doesn't need company variant - company context comes from Event
|
|
103
|
+
return enable ? [
|
|
104
|
+
entities.EventWithCompany,
|
|
105
|
+
entities.EventParticipant
|
|
106
|
+
] : [
|
|
107
|
+
entities.Event,
|
|
108
|
+
entities.EventParticipant
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
// Overrides
|
|
112
|
+
async createDataSourceFromConfig(config) {
|
|
113
|
+
const currentTenant = this.getCurrentTenant();
|
|
114
|
+
const enableCompanyFeature = this.getEnableCompanyFeatureForTenant(currentTenant ?? undefined);
|
|
115
|
+
const entities = await this.getEventManagerEntities(enableCompanyFeature);
|
|
116
|
+
return super.createDataSourceFromConfig(config, entities);
|
|
117
|
+
}
|
|
118
|
+
async getSingleDataSource() {
|
|
119
|
+
if (EventManagerDataSourceProvider.singleDataSource?.isInitialized) {
|
|
120
|
+
return EventManagerDataSourceProvider.singleDataSource;
|
|
121
|
+
}
|
|
122
|
+
if (EventManagerDataSourceProvider.singleConnectionLock) {
|
|
123
|
+
return EventManagerDataSourceProvider.singleConnectionLock;
|
|
124
|
+
}
|
|
125
|
+
const config = this.getDefaultDatabaseConfig();
|
|
126
|
+
if (!config) {
|
|
127
|
+
throw new _common.InternalServerErrorException('No database config available. Provide defaultDatabaseConfig or tenantDefaultDatabaseConfig.');
|
|
128
|
+
}
|
|
129
|
+
const connectionPromise = this.createDataSourceFromConfig(config);
|
|
130
|
+
EventManagerDataSourceProvider.singleConnectionLock = connectionPromise;
|
|
131
|
+
try {
|
|
132
|
+
const dataSource = await connectionPromise;
|
|
133
|
+
EventManagerDataSourceProvider.singleDataSource = dataSource;
|
|
134
|
+
return dataSource;
|
|
135
|
+
} finally{
|
|
136
|
+
EventManagerDataSourceProvider.singleConnectionLock = null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async getOrCreateTenantConnection(tenant) {
|
|
140
|
+
const existing = EventManagerDataSourceProvider.tenantConnections.get(tenant.id);
|
|
141
|
+
if (existing?.isInitialized) {
|
|
142
|
+
return existing;
|
|
143
|
+
}
|
|
144
|
+
const pendingConnection = EventManagerDataSourceProvider.connectionLocks.get(tenant.id);
|
|
145
|
+
if (pendingConnection) {
|
|
146
|
+
return pendingConnection;
|
|
147
|
+
}
|
|
148
|
+
const config = this.buildTenantDatabaseConfig(tenant);
|
|
149
|
+
const connectionPromise = this.createDataSourceFromConfig(config);
|
|
150
|
+
EventManagerDataSourceProvider.connectionLocks.set(tenant.id, connectionPromise);
|
|
151
|
+
try {
|
|
152
|
+
const dataSource = await connectionPromise;
|
|
153
|
+
EventManagerDataSourceProvider.tenantConnections.set(tenant.id, dataSource);
|
|
154
|
+
return dataSource;
|
|
155
|
+
} finally{
|
|
156
|
+
EventManagerDataSourceProvider.connectionLocks.delete(tenant.id);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
constructor(configService, request){
|
|
160
|
+
super(EventManagerDataSourceProvider.buildParentOptions(configService.getOptions()), request), _define_property(this, "configService", void 0), _define_property(this, "logger", void 0), this.configService = configService, this.logger = new _common.Logger(EventManagerDataSourceProvider.name);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
_define_property(EventManagerDataSourceProvider, "tenantConnections", new Map());
|
|
164
|
+
_define_property(EventManagerDataSourceProvider, "singleDataSource", null);
|
|
165
|
+
_define_property(EventManagerDataSourceProvider, "tenantsRegistry", new Map());
|
|
166
|
+
_define_property(EventManagerDataSourceProvider, "initialized", false);
|
|
167
|
+
_define_property(EventManagerDataSourceProvider, "connectionLocks", new Map());
|
|
168
|
+
_define_property(EventManagerDataSourceProvider, "singleConnectionLock", null);
|
|
169
|
+
EventManagerDataSourceProvider = _ts_decorate([
|
|
170
|
+
(0, _common.Injectable)({
|
|
171
|
+
scope: _common.Scope.REQUEST
|
|
172
|
+
}),
|
|
173
|
+
_ts_param(0, (0, _common.Inject)(_eventmanagerconfigservice.EventManagerConfigService)),
|
|
174
|
+
_ts_param(1, (0, _common.Optional)()),
|
|
175
|
+
_ts_param(1, (0, _common.Inject)(_core.REQUEST)),
|
|
176
|
+
_ts_metadata("design:type", Function),
|
|
177
|
+
_ts_metadata("design:paramtypes", [
|
|
178
|
+
typeof _eventmanagerconfigservice.EventManagerConfigService === "undefined" ? Object : _eventmanagerconfigservice.EventManagerConfigService,
|
|
179
|
+
typeof _express.Request === "undefined" ? Object : _express.Request
|
|
180
|
+
])
|
|
181
|
+
], EventManagerDataSourceProvider);
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "EventManagerHelperService", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return EventManagerHelperService;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _common = require("@nestjs/common");
|
|
12
|
+
const _typeorm = require("typeorm");
|
|
13
|
+
const _classes = require("@flusys/nestjs-shared/classes");
|
|
14
|
+
const _modules = require("@flusys/nestjs-shared/modules");
|
|
15
|
+
const _nestjsshared = require("@flusys/nestjs-shared");
|
|
16
|
+
const _eventmanagerconfigservice = require("./event-manager-config.service");
|
|
17
|
+
const _eventmanagerdatasourceprovider = require("./event-manager-datasource.provider");
|
|
18
|
+
const _entities = require("../entities");
|
|
19
|
+
function _define_property(obj, key, value) {
|
|
20
|
+
if (key in obj) {
|
|
21
|
+
Object.defineProperty(obj, key, {
|
|
22
|
+
value: value,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
obj[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
33
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
34
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
35
|
+
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;
|
|
36
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
37
|
+
}
|
|
38
|
+
function _ts_metadata(k, v) {
|
|
39
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
40
|
+
}
|
|
41
|
+
function _ts_param(paramIndex, decorator) {
|
|
42
|
+
return function(target, key) {
|
|
43
|
+
decorator(target, key, paramIndex);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
let EventManagerHelperService = class EventManagerHelperService {
|
|
47
|
+
async getDataSource() {
|
|
48
|
+
if (!this.dataSource) {
|
|
49
|
+
this.dataSource = await this.dataSourceProvider.getDataSource();
|
|
50
|
+
}
|
|
51
|
+
return this.dataSource;
|
|
52
|
+
}
|
|
53
|
+
async getEventRepository() {
|
|
54
|
+
const ds = await this.getDataSource();
|
|
55
|
+
const EntityClass = this.configService.isCompanyFeatureEnabled() ? _entities.EventWithCompany : _entities.Event;
|
|
56
|
+
return ds.getRepository(EntityClass);
|
|
57
|
+
}
|
|
58
|
+
async getParticipantRepository() {
|
|
59
|
+
const ds = await this.getDataSource();
|
|
60
|
+
return ds.getRepository(_entities.EventParticipant);
|
|
61
|
+
}
|
|
62
|
+
async createEvent(options) {
|
|
63
|
+
const repo = await this.getEventRepository();
|
|
64
|
+
const entity = {
|
|
65
|
+
title: options.title,
|
|
66
|
+
description: options.description ?? null,
|
|
67
|
+
meetingLink: options.meetingLink ?? null,
|
|
68
|
+
startDateTime: options.startDateTime,
|
|
69
|
+
endDateTime: options.endDateTime,
|
|
70
|
+
isAllDay: options.isAllDay ?? false,
|
|
71
|
+
recurrenceType: options.recurrenceType ?? _nestjsshared.RecurrenceType.NONE,
|
|
72
|
+
recurrenceEndDate: options.recurrenceEndDate ?? null,
|
|
73
|
+
color: options.color ?? this.configService.getDefaultColor(),
|
|
74
|
+
isActive: true,
|
|
75
|
+
metadata: options.metadata ?? null
|
|
76
|
+
};
|
|
77
|
+
if (this.configService.isCompanyFeatureEnabled() && options.companyId) {
|
|
78
|
+
entity.companyId = options.companyId;
|
|
79
|
+
}
|
|
80
|
+
const saved = await repo.save(entity);
|
|
81
|
+
await this.addEventParticipants(saved.id, options.participantIds ?? [], options.organizerId);
|
|
82
|
+
await this.clearCache();
|
|
83
|
+
this.logger.debug(`Event created: ${saved.id} - ${options.title}`);
|
|
84
|
+
return this.toEventResult(saved);
|
|
85
|
+
}
|
|
86
|
+
async addParticipants(eventId, userIds, _companyId) {
|
|
87
|
+
const eventRepo = await this.getEventRepository();
|
|
88
|
+
const participantRepo = await this.getParticipantRepository();
|
|
89
|
+
const event = await eventRepo.findOne({
|
|
90
|
+
where: {
|
|
91
|
+
id: eventId,
|
|
92
|
+
deletedAt: (0, _typeorm.IsNull)()
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (!event) {
|
|
96
|
+
throw new _common.NotFoundException('Event not found');
|
|
97
|
+
}
|
|
98
|
+
const existingParticipants = await participantRepo.find({
|
|
99
|
+
where: {
|
|
100
|
+
eventId,
|
|
101
|
+
userId: (0, _typeorm.In)(userIds),
|
|
102
|
+
deletedAt: (0, _typeorm.IsNull)()
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const existingUserIds = new Set(existingParticipants.map((p)=>p.userId));
|
|
106
|
+
const newParticipants = userIds.filter((userId)=>!existingUserIds.has(userId)).map((userId)=>({
|
|
107
|
+
eventId,
|
|
108
|
+
userId,
|
|
109
|
+
status: _nestjsshared.ParticipantStatus.PENDING,
|
|
110
|
+
isOrganizer: false
|
|
111
|
+
}));
|
|
112
|
+
if (newParticipants.length > 0) {
|
|
113
|
+
await participantRepo.save(newParticipants);
|
|
114
|
+
this.logger.debug(`Added ${newParticipants.length} participants to event ${eventId}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async removeParticipant(eventId, userId) {
|
|
118
|
+
const participantRepo = await this.getParticipantRepository();
|
|
119
|
+
const participant = await participantRepo.findOne({
|
|
120
|
+
where: {
|
|
121
|
+
eventId,
|
|
122
|
+
userId,
|
|
123
|
+
deletedAt: (0, _typeorm.IsNull)()
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
if (participant) {
|
|
127
|
+
await participantRepo.softRemove(participant);
|
|
128
|
+
this.logger.debug(`Removed participant ${userId} from event ${eventId}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async updateParticipantStatus(participantId, status) {
|
|
132
|
+
const participantRepo = await this.getParticipantRepository();
|
|
133
|
+
const participant = await participantRepo.findOne({
|
|
134
|
+
where: {
|
|
135
|
+
id: participantId,
|
|
136
|
+
deletedAt: (0, _typeorm.IsNull)()
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
if (!participant) {
|
|
140
|
+
throw new _common.NotFoundException('Event participant not found');
|
|
141
|
+
}
|
|
142
|
+
participant.status = status;
|
|
143
|
+
await participantRepo.save(participant);
|
|
144
|
+
this.logger.debug(`Updated participant ${participantId} status to ${status}`);
|
|
145
|
+
}
|
|
146
|
+
async getEventsForUser(userId, startDate, endDate, companyId) {
|
|
147
|
+
const eventRepo = await this.getEventRepository();
|
|
148
|
+
const participantRepo = await this.getParticipantRepository();
|
|
149
|
+
const participantEvents = await participantRepo.createQueryBuilder('ep').select('ep.eventId').where('ep.userId = :userId', {
|
|
150
|
+
userId
|
|
151
|
+
}).andWhere('ep.deletedAt IS NULL').getRawMany();
|
|
152
|
+
const eventIds = participantEvents.map((p)=>p.ep_event_id);
|
|
153
|
+
if (eventIds.length === 0) {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
const query = eventRepo.createQueryBuilder('event').where('event.id IN (:...eventIds)', {
|
|
157
|
+
eventIds
|
|
158
|
+
}).andWhere('event.deletedAt IS NULL').andWhere('event.isActive = :isActive', {
|
|
159
|
+
isActive: true
|
|
160
|
+
}).andWhere('event.startDateTime <= :endDate', {
|
|
161
|
+
endDate
|
|
162
|
+
}).andWhere('event.endDateTime >= :startDate', {
|
|
163
|
+
startDate
|
|
164
|
+
});
|
|
165
|
+
if (this.configService.isCompanyFeatureEnabled() && companyId) {
|
|
166
|
+
query.andWhere('event.companyId = :companyId', {
|
|
167
|
+
companyId
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
const events = await query.getMany();
|
|
171
|
+
return events.map((e)=>this.toEventResult(e));
|
|
172
|
+
}
|
|
173
|
+
async getEventById(eventId) {
|
|
174
|
+
const repo = await this.getEventRepository();
|
|
175
|
+
const event = await repo.findOne({
|
|
176
|
+
where: {
|
|
177
|
+
id: eventId,
|
|
178
|
+
deletedAt: (0, _typeorm.IsNull)()
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
return event ? this.toEventResult(event) : null;
|
|
182
|
+
}
|
|
183
|
+
async addEventParticipants(eventId, participantIds, organizerId) {
|
|
184
|
+
if (!organizerId && participantIds.length === 0) return;
|
|
185
|
+
const participantRepo = await this.getParticipantRepository();
|
|
186
|
+
const allUserIds = new Set([
|
|
187
|
+
...organizerId ? [
|
|
188
|
+
organizerId
|
|
189
|
+
] : [],
|
|
190
|
+
...participantIds
|
|
191
|
+
]);
|
|
192
|
+
const participants = Array.from(allUserIds).map((userId)=>({
|
|
193
|
+
eventId,
|
|
194
|
+
userId,
|
|
195
|
+
status: _nestjsshared.ParticipantStatus.PENDING,
|
|
196
|
+
isOrganizer: userId === organizerId
|
|
197
|
+
}));
|
|
198
|
+
await participantRepo.save(participants);
|
|
199
|
+
}
|
|
200
|
+
toEventResult(event) {
|
|
201
|
+
const eventExt = event;
|
|
202
|
+
return {
|
|
203
|
+
id: event.id,
|
|
204
|
+
title: event.title,
|
|
205
|
+
description: event.description,
|
|
206
|
+
meetingLink: event.meetingLink,
|
|
207
|
+
startDateTime: event.startDateTime,
|
|
208
|
+
endDateTime: event.endDateTime,
|
|
209
|
+
isAllDay: event.isAllDay,
|
|
210
|
+
recurrenceType: event.recurrenceType,
|
|
211
|
+
recurrenceEndDate: event.recurrenceEndDate,
|
|
212
|
+
color: event.color,
|
|
213
|
+
isActive: event.isActive,
|
|
214
|
+
metadata: event.metadata,
|
|
215
|
+
companyId: eventExt.companyId ?? null,
|
|
216
|
+
createdAt: event.createdAt,
|
|
217
|
+
updatedAt: event.updatedAt
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
async clearCache() {
|
|
221
|
+
await this.utilsService.clearCache(this.eventEntityName, this.cacheManager);
|
|
222
|
+
}
|
|
223
|
+
constructor(cacheManager, utilsService, configService, dataSourceProvider){
|
|
224
|
+
_define_property(this, "cacheManager", void 0);
|
|
225
|
+
_define_property(this, "utilsService", void 0);
|
|
226
|
+
_define_property(this, "configService", void 0);
|
|
227
|
+
_define_property(this, "dataSourceProvider", void 0);
|
|
228
|
+
_define_property(this, "logger", void 0);
|
|
229
|
+
_define_property(this, "eventEntityName", void 0);
|
|
230
|
+
_define_property(this, "dataSource", void 0);
|
|
231
|
+
this.cacheManager = cacheManager;
|
|
232
|
+
this.utilsService = utilsService;
|
|
233
|
+
this.configService = configService;
|
|
234
|
+
this.dataSourceProvider = dataSourceProvider;
|
|
235
|
+
this.logger = new _common.Logger(EventManagerHelperService.name);
|
|
236
|
+
this.eventEntityName = 'event';
|
|
237
|
+
this.dataSource = null;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
EventManagerHelperService = _ts_decorate([
|
|
241
|
+
(0, _common.Injectable)(),
|
|
242
|
+
_ts_param(0, (0, _common.Inject)('CACHE_INSTANCE')),
|
|
243
|
+
_ts_param(1, (0, _common.Inject)(_modules.UtilsService)),
|
|
244
|
+
_ts_param(2, (0, _common.Inject)(_eventmanagerconfigservice.EventManagerConfigService)),
|
|
245
|
+
_ts_param(3, (0, _common.Inject)(_eventmanagerdatasourceprovider.EventManagerDataSourceProvider)),
|
|
246
|
+
_ts_metadata("design:type", Function),
|
|
247
|
+
_ts_metadata("design:paramtypes", [
|
|
248
|
+
typeof _classes.HybridCache === "undefined" ? Object : _classes.HybridCache,
|
|
249
|
+
typeof _modules.UtilsService === "undefined" ? Object : _modules.UtilsService,
|
|
250
|
+
typeof _eventmanagerconfigservice.EventManagerConfigService === "undefined" ? Object : _eventmanagerconfigservice.EventManagerConfigService,
|
|
251
|
+
typeof _eventmanagerdatasourceprovider.EventManagerDataSourceProvider === "undefined" ? Object : _eventmanagerdatasourceprovider.EventManagerDataSourceProvider
|
|
252
|
+
])
|
|
253
|
+
], EventManagerHelperService);
|