@lenne.tech/nest-server 10.0.2 → 10.0.4
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 +9 -0
- package/dist/config.env.js +47 -17
- package/dist/config.env.js.map +1 -1
- package/dist/core/common/args/filter.args.js +3 -3
- package/dist/core/common/args/filter.args.js.map +1 -1
- package/dist/core/common/args/pagination.args.js +6 -6
- package/dist/core/common/args/pagination.args.js.map +1 -1
- package/dist/core/common/decorators/restricted.decorator.js +15 -17
- package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
- package/dist/core/common/filters/http-exception-log.filter.js +1 -3
- package/dist/core/common/filters/http-exception-log.filter.js.map +1 -1
- package/dist/core/common/helpers/db.helper.js +14 -14
- package/dist/core/common/helpers/db.helper.js.map +1 -1
- package/dist/core/common/helpers/file.helper.js +2 -2
- package/dist/core/common/helpers/file.helper.js.map +1 -1
- package/dist/core/common/helpers/filter.helper.d.ts +2 -2
- package/dist/core/common/helpers/filter.helper.js +1 -1
- package/dist/core/common/helpers/filter.helper.js.map +1 -1
- package/dist/core/common/helpers/graphql.helper.js +1 -1
- package/dist/core/common/helpers/graphql.helper.js.map +1 -1
- package/dist/core/common/helpers/input.helper.js +31 -38
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/common/helpers/model.helper.js +7 -7
- package/dist/core/common/helpers/model.helper.js.map +1 -1
- package/dist/core/common/helpers/service.helper.js +2 -2
- package/dist/core/common/helpers/service.helper.js.map +1 -1
- package/dist/core/common/inputs/combined-filter.input.js +3 -3
- package/dist/core/common/inputs/combined-filter.input.js.map +1 -1
- package/dist/core/common/inputs/core-input.input.js +1 -1
- package/dist/core/common/inputs/core-input.input.js.map +1 -1
- package/dist/core/common/inputs/filter.input.js +3 -3
- package/dist/core/common/inputs/filter.input.js.map +1 -1
- package/dist/core/common/inputs/single-filter.input.js +4 -4
- package/dist/core/common/inputs/single-filter.input.js.map +1 -1
- package/dist/core/common/inputs/sort.input.js +1 -1
- package/dist/core/common/inputs/sort.input.js.map +1 -1
- package/dist/core/common/interceptors/check-security.interceptor.d.ts +1 -1
- package/dist/core/common/interceptors/check-security.interceptor.js +2 -2
- package/dist/core/common/interceptors/check-security.interceptor.js.map +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +28 -0
- package/dist/core/common/models/core-model.model.js.map +1 -1
- package/dist/core/common/models/core-persistence.model.js +3 -3
- package/dist/core/common/models/core-persistence.model.js.map +1 -1
- package/dist/core/common/pipes/map-and-validate.pipe.d.ts +1 -1
- package/dist/core/common/pipes/map-and-validate.pipe.js +1 -1
- package/dist/core/common/pipes/map-and-validate.pipe.js.map +1 -1
- package/dist/core/common/scalars/any.scalar.js +2 -2
- package/dist/core/common/scalars/any.scalar.js.map +1 -1
- package/dist/core/common/scalars/date-timestamp.scalar.js +1 -1
- package/dist/core/common/scalars/date-timestamp.scalar.js.map +1 -1
- package/dist/core/common/scalars/date.scalar.js +1 -1
- package/dist/core/common/scalars/date.scalar.js.map +1 -1
- package/dist/core/common/scalars/json.scalar.js +2 -2
- package/dist/core/common/scalars/json.scalar.js.map +1 -1
- package/dist/core/common/services/config.service.js +7 -7
- package/dist/core/common/services/config.service.js.map +1 -1
- package/dist/core/common/services/core-cron-jobs.service.js +5 -5
- package/dist/core/common/services/core-cron-jobs.service.js.map +1 -1
- package/dist/core/common/services/crud.service.js +1 -1
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/core/common/services/mailjet.service.js +5 -5
- package/dist/core/common/services/mailjet.service.js.map +1 -1
- package/dist/core/common/services/model-doc.service.d.ts +16 -0
- package/dist/core/common/services/model-doc.service.js +107 -0
- package/dist/core/common/services/model-doc.service.js.map +1 -0
- package/dist/core/common/services/module.service.js.map +1 -1
- package/dist/core/common/services/template.service.js +3 -3
- package/dist/core/common/services/template.service.js.map +1 -1
- package/dist/core/common/types/core-model-constructor.type.d.ts +2 -2
- package/dist/core/modules/auth/core-auth.module.js +3 -3
- package/dist/core/modules/auth/core-auth.module.js.map +1 -1
- package/dist/core/modules/auth/core-auth.resolver.js +5 -5
- package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
- package/dist/core/modules/auth/guards/auth.guard.js +4 -4
- package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
- package/dist/core/modules/auth/guards/roles.guard.js +1 -1
- package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
- package/dist/core/modules/auth/services/core-auth.service.js +5 -5
- package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
- package/dist/core/modules/auth/strategies/jwt.strategy.js.map +1 -1
- package/dist/core/modules/auth/tokens.decorator.js +2 -2
- package/dist/core/modules/auth/tokens.decorator.js.map +1 -1
- package/dist/core/modules/file/core-file-info.model.js +2 -2
- package/dist/core/modules/file/core-file-info.model.js.map +1 -1
- package/dist/core/modules/file/core-file.controller.d.ts +1 -2
- package/dist/core/modules/file/core-file.controller.js +3 -6
- package/dist/core/modules/file/core-file.controller.js.map +1 -1
- package/dist/core/modules/file/core-file.service.js +1 -1
- package/dist/core/modules/file/core-file.service.js.map +1 -1
- package/dist/core/modules/file/interfaces/file-upload.interface.d.ts +1 -1
- package/dist/core/modules/health-check/core-health-check-result.model.d.ts +8 -0
- package/dist/core/modules/health-check/core-health-check-result.model.js +53 -0
- package/dist/core/modules/health-check/core-health-check-result.model.js.map +1 -0
- package/dist/core/modules/health-check/core-health-check.controller.d.ts +6 -0
- package/dist/core/modules/health-check/core-health-check.controller.js +33 -0
- package/dist/core/modules/health-check/core-health-check.controller.js.map +1 -0
- package/dist/core/modules/health-check/core-health-check.module.d.ts +2 -0
- package/dist/core/modules/health-check/core-health-check.module.js +24 -0
- package/dist/core/modules/health-check/core-health-check.module.js.map +1 -0
- package/dist/core/modules/health-check/core-health-check.resolver.d.ts +6 -0
- package/dist/core/modules/health-check/core-health-check.resolver.js +38 -0
- package/dist/core/modules/health-check/core-health-check.resolver.js.map +1 -0
- package/dist/core/modules/health-check/core-health-check.service.d.ts +11 -0
- package/dist/core/modules/health-check/core-health-check.service.js +52 -0
- package/dist/core/modules/health-check/core-health-check.service.js.map +1 -0
- package/dist/core/modules/user/core-user.model.js +5 -5
- package/dist/core/modules/user/core-user.model.js.map +1 -1
- package/dist/core/modules/user/core-user.service.js +2 -2
- package/dist/core/modules/user/core-user.service.js.map +1 -1
- package/dist/core/modules/user/inputs/core-user.input.js +1 -1
- package/dist/core/modules/user/inputs/core-user.input.js.map +1 -1
- package/dist/core.module.js +14 -5
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/server/modules/auth/auth.service.js +1 -1
- package/dist/server/modules/auth/auth.service.js.map +1 -1
- package/dist/server/modules/file/file.controller.js +1 -1
- package/dist/server/modules/file/file.controller.js.map +1 -1
- package/dist/server/modules/file/file.resolver.js +2 -2
- package/dist/server/modules/file/file.resolver.js.map +1 -1
- package/dist/server/modules/file/file.service.js +1 -1
- package/dist/server/modules/file/file.service.js.map +1 -1
- package/dist/server/modules/file/multer-config.service.js +1 -1
- package/dist/server/modules/file/multer-config.service.js.map +1 -1
- package/dist/server/modules/user/avatar.controller.js +1 -1
- package/dist/server/modules/user/avatar.controller.js.map +1 -1
- package/dist/server/modules/user/user.resolver.js +1 -1
- package/dist/server/modules/user/user.resolver.js.map +1 -1
- package/dist/server/modules/user/user.service.js +3 -3
- package/dist/server/modules/user/user.service.js.map +1 -1
- package/dist/templates/index.ejs +2 -0
- package/dist/templates/password-reset.ejs +3 -0
- package/dist/templates/welcome.ejs +3 -0
- package/dist/test/test.helper.d.ts +1 -1
- package/dist/test/test.helper.js +7 -7
- package/dist/test/test.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +32 -26
- package/src/config.env.ts +50 -20
- package/src/core/common/args/filter.args.ts +4 -4
- package/src/core/common/args/pagination.args.ts +7 -7
- package/src/core/common/decorators/graphql-service-options.decorator.ts +2 -2
- package/src/core/common/decorators/graphql-user.decorator.ts +1 -1
- package/src/core/common/decorators/rest-user.decorator.ts +1 -1
- package/src/core/common/decorators/restricted.decorator.ts +18 -18
- package/src/core/common/filters/http-exception-log.filter.ts +4 -4
- package/src/core/common/helpers/db.helper.ts +35 -40
- package/src/core/common/helpers/decorator.helper.ts +1 -1
- package/src/core/common/helpers/file.helper.ts +2 -2
- package/src/core/common/helpers/filter.helper.ts +7 -8
- package/src/core/common/helpers/graphql.helper.ts +6 -6
- package/src/core/common/helpers/input.helper.ts +54 -61
- package/src/core/common/helpers/model.helper.ts +33 -41
- package/src/core/common/helpers/service.helper.ts +8 -8
- package/src/core/common/inputs/combined-filter.input.ts +4 -4
- package/src/core/common/inputs/core-input.input.ts +2 -2
- package/src/core/common/inputs/filter.input.ts +4 -4
- package/src/core/common/inputs/single-filter.input.ts +4 -4
- package/src/core/common/inputs/sort.input.ts +1 -1
- package/src/core/common/interceptors/check-response.interceptor.ts +1 -1
- package/src/core/common/interceptors/check-security.interceptor.ts +5 -5
- package/src/core/common/interfaces/server-options.interface.ts +109 -0
- package/src/core/common/models/core-model.model.ts +6 -4
- package/src/core/common/models/core-persistence.model.ts +3 -3
- package/src/core/common/pipes/map-and-validate.pipe.ts +2 -2
- package/src/core/common/scalars/any.scalar.ts +2 -2
- package/src/core/common/scalars/date-timestamp.scalar.ts +1 -2
- package/src/core/common/scalars/date.scalar.ts +1 -2
- package/src/core/common/scalars/json.scalar.ts +4 -4
- package/src/core/common/services/config.service.ts +16 -16
- package/src/core/common/services/core-cron-jobs.service.ts +7 -7
- package/src/core/common/services/crud.service.ts +22 -22
- package/src/core/common/services/email.service.ts +1 -1
- package/src/core/common/services/mailjet.service.ts +8 -8
- package/src/core/common/services/model-doc.service.ts +140 -0
- package/src/core/common/services/module.service.ts +5 -6
- package/src/core/common/services/template.service.ts +4 -4
- package/src/core/common/types/core-model-constructor.type.ts +2 -2
- package/src/core/modules/auth/core-auth.controller.ts +2 -2
- package/src/core/modules/auth/core-auth.module.ts +4 -4
- package/src/core/modules/auth/core-auth.resolver.ts +9 -9
- package/src/core/modules/auth/guards/auth.guard.ts +8 -7
- package/src/core/modules/auth/guards/roles.guard.ts +1 -1
- package/src/core/modules/auth/services/core-auth.service.ts +9 -9
- package/src/core/modules/auth/strategies/jwt-refresh.strategy.ts +1 -1
- package/src/core/modules/auth/strategies/jwt.strategy.ts +1 -1
- package/src/core/modules/auth/tokens.decorator.ts +6 -7
- package/src/core/modules/file/core-file-info.model.ts +2 -2
- package/src/core/modules/file/core-file.controller.ts +2 -4
- package/src/core/modules/file/core-file.service.ts +6 -5
- package/src/core/modules/file/interfaces/file-upload.interface.ts +1 -1
- package/src/core/modules/health-check/core-health-check-result.model.ts +46 -0
- package/src/core/modules/health-check/core-health-check.controller.ts +24 -0
- package/src/core/modules/health-check/core-health-check.module.ts +17 -0
- package/src/core/modules/health-check/core-health-check.resolver.ts +32 -0
- package/src/core/modules/health-check/core-health-check.service.ts +62 -0
- package/src/core/modules/user/core-user.model.ts +6 -6
- package/src/core/modules/user/core-user.service.ts +10 -9
- package/src/core/modules/user/inputs/core-user.input.ts +1 -2
- package/src/core.module.ts +23 -12
- package/src/index.ts +11 -0
- package/src/main.ts +2 -2
- package/src/server/modules/auth/auth.controller.ts +1 -1
- package/src/server/modules/auth/auth.resolver.ts +3 -3
- package/src/server/modules/auth/auth.service.ts +2 -2
- package/src/server/modules/file/file.controller.ts +1 -2
- package/src/server/modules/file/file.module.ts +1 -1
- package/src/server/modules/file/file.resolver.ts +4 -3
- package/src/server/modules/file/file.service.ts +1 -1
- package/src/server/modules/file/multer-config.service.ts +1 -1
- package/src/server/modules/user/avatar.controller.ts +3 -3
- package/src/server/modules/user/user.model.ts +1 -1
- package/src/server/modules/user/user.resolver.ts +4 -4
- package/src/server/modules/user/user.service.ts +4 -4
- package/src/test/test.helper.ts +11 -11
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { CustomScalar, Scalar } from '@nestjs/graphql';
|
|
2
|
-
import { Kind } from 'graphql';
|
|
3
2
|
import { checkAndGetDate, getDateFromGraphQL } from '../helpers/input.helper';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Date-Timestamp-Scalar to convert timestamp to date and vice versa
|
|
7
6
|
*/
|
|
8
|
-
@Scalar('Date',
|
|
7
|
+
@Scalar('Date', type => Date)
|
|
9
8
|
export class DateTimestampScalar implements CustomScalar<number, Date> {
|
|
10
9
|
description = 'Date (by Timestamp) custom scalar type';
|
|
11
10
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { CustomScalar, Scalar } from '@nestjs/graphql';
|
|
2
|
-
import { Kind } from 'graphql';
|
|
3
2
|
import { checkAndGetDate, getDateFromGraphQL } from '../helpers/input.helper';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Date scalar to convert string into date
|
|
7
6
|
*/
|
|
8
|
-
@Scalar('Date',
|
|
7
|
+
@Scalar('Date', type => Date)
|
|
9
8
|
export class DateScalar implements CustomScalar<string, Date> {
|
|
10
9
|
description = 'Date custom scalar type';
|
|
11
10
|
|
|
@@ -4,13 +4,13 @@ import { Kind, ValueNode } from 'graphql';
|
|
|
4
4
|
/**
|
|
5
5
|
* JSON scalar (is equivalent to the Any scalar)
|
|
6
6
|
*/
|
|
7
|
-
@Scalar('JSON',
|
|
7
|
+
@Scalar('JSON', type => JSON)
|
|
8
8
|
export class JSON implements CustomScalar<string, any> {
|
|
9
9
|
/**
|
|
10
10
|
* Description of the scalar
|
|
11
11
|
*/
|
|
12
|
-
description
|
|
13
|
-
'JSON scalar type. Information on the exact schema of the JSON object is contained in the description of the field.';
|
|
12
|
+
description
|
|
13
|
+
= 'JSON scalar type. Information on the exact schema of the JSON object is contained in the description of the field.';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Parse value from the client input variables
|
|
@@ -46,7 +46,7 @@ export class JSON implements CustomScalar<string, any> {
|
|
|
46
46
|
return value;
|
|
47
47
|
}
|
|
48
48
|
case Kind.LIST:
|
|
49
|
-
return ast.values.map(
|
|
49
|
+
return ast.values.map(n => this.parseLiteral(n, variables));
|
|
50
50
|
case Kind.NULL:
|
|
51
51
|
return null;
|
|
52
52
|
case Kind.VARIABLE: {
|
|
@@ -37,14 +37,14 @@ export class ConfigService {
|
|
|
37
37
|
/**
|
|
38
38
|
* BehaviorSubject for config
|
|
39
39
|
*/
|
|
40
|
-
protected static _configSubject$: BehaviorSubject<{ [key: string]: any } & Partial<IServerOptions>>
|
|
41
|
-
new BehaviorSubject(undefined);
|
|
40
|
+
protected static _configSubject$: BehaviorSubject<{ [key: string]: any } & Partial<IServerOptions>>
|
|
41
|
+
= new BehaviorSubject(undefined);
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* BehaviorSubject for frozen config
|
|
45
45
|
*/
|
|
46
|
-
protected static _frozenConfigSubject$: BehaviorSubject<{ [key: string]: any } & Partial<IServerOptions>>
|
|
47
|
-
new BehaviorSubject(undefined);
|
|
46
|
+
protected static _frozenConfigSubject$: BehaviorSubject<{ [key: string]: any } & Partial<IServerOptions>>
|
|
47
|
+
= new BehaviorSubject(undefined);
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Singleton instance of ConfigService
|
|
@@ -60,7 +60,7 @@ export class ConfigService {
|
|
|
60
60
|
*/
|
|
61
61
|
constructor(
|
|
62
62
|
configObject?: { [key: string]: any } & Partial<IServerOptions>,
|
|
63
|
-
options?: { reInit?: boolean; warn?: boolean }
|
|
63
|
+
options?: { reInit?: boolean; warn?: boolean },
|
|
64
64
|
) {
|
|
65
65
|
const config = {
|
|
66
66
|
reInit: false,
|
|
@@ -180,8 +180,8 @@ export class ConfigService {
|
|
|
180
180
|
*/
|
|
181
181
|
static get observable() {
|
|
182
182
|
return ConfigService._configSubject$.asObservable().pipe(
|
|
183
|
-
filter(
|
|
184
|
-
map(
|
|
183
|
+
filter(config => !config),
|
|
184
|
+
map(config => clone(config, { circles: false })),
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
187
|
|
|
@@ -196,7 +196,7 @@ export class ConfigService {
|
|
|
196
196
|
* Get observable for faster but read-only deep-frozen configuration
|
|
197
197
|
*/
|
|
198
198
|
static get observableFastButReadOnly() {
|
|
199
|
-
return ConfigService._frozenConfigSubject$.asObservable().pipe(filter(
|
|
199
|
+
return ConfigService._frozenConfigSubject$.asObservable().pipe(filter(config => !config));
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
@@ -243,7 +243,7 @@ export class ConfigService {
|
|
|
243
243
|
*/
|
|
244
244
|
static mergeConfig(
|
|
245
245
|
configData: { [key: string]: any } & Partial<IServerOptions>,
|
|
246
|
-
options?: { init?: boolean; warn?: boolean }
|
|
246
|
+
options?: { init?: boolean; warn?: boolean },
|
|
247
247
|
) {
|
|
248
248
|
const config = {
|
|
249
249
|
init: true,
|
|
@@ -266,7 +266,7 @@ export class ConfigService {
|
|
|
266
266
|
|
|
267
267
|
// Warn if requested
|
|
268
268
|
if (config.warn) {
|
|
269
|
-
console.warn(
|
|
269
|
+
console.warn(`ConfigService ${activity}`, JSON.stringify(merged, null, 2));
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
// Return configuration
|
|
@@ -305,7 +305,7 @@ export class ConfigService {
|
|
|
305
305
|
|
|
306
306
|
// Warn if requested
|
|
307
307
|
if (config.warn) {
|
|
308
|
-
console.warn(
|
|
308
|
+
console.warn(`ConfigService ${key}:`, JSON.stringify(current[key], null, 2));
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
// Return configuration
|
|
@@ -317,7 +317,7 @@ export class ConfigService {
|
|
|
317
317
|
*/
|
|
318
318
|
setConfig(
|
|
319
319
|
configData: { [key: string]: any } & Partial<IServerOptions>,
|
|
320
|
-
options?: { reInit?: boolean; warn?: boolean }
|
|
320
|
+
options?: { reInit?: boolean; warn?: boolean },
|
|
321
321
|
) {
|
|
322
322
|
return ConfigService.setConfig(configData, options);
|
|
323
323
|
}
|
|
@@ -327,7 +327,7 @@ export class ConfigService {
|
|
|
327
327
|
*/
|
|
328
328
|
static setConfig(
|
|
329
329
|
configObject: { [key: string]: any } & Partial<IServerOptions>,
|
|
330
|
-
options?: { init?: boolean; reInit?: boolean; warn?: boolean }
|
|
330
|
+
options?: { init?: boolean; reInit?: boolean; warn?: boolean },
|
|
331
331
|
) {
|
|
332
332
|
const config = {
|
|
333
333
|
init: true,
|
|
@@ -342,8 +342,8 @@ export class ConfigService {
|
|
|
342
342
|
// Check for unintentional overwriting
|
|
343
343
|
if (!firstInitialization && !config.reInit) {
|
|
344
344
|
throw new Error(
|
|
345
|
-
'Unintentional overwriting of the configuration. '
|
|
346
|
-
'If overwriting is desired, please set `reInit` in setConfig of ConfigService to `true`.'
|
|
345
|
+
'Unintentional overwriting of the configuration. '
|
|
346
|
+
+ 'If overwriting is desired, please set `reInit` in setConfig of ConfigService to `true`.',
|
|
347
347
|
);
|
|
348
348
|
}
|
|
349
349
|
|
|
@@ -392,7 +392,7 @@ export class ConfigService {
|
|
|
392
392
|
current[key] = value;
|
|
393
393
|
ConfigService._configSubject$.next(current);
|
|
394
394
|
if (config.warn) {
|
|
395
|
-
console.warn(
|
|
395
|
+
console.warn(`ConfigService ${key}:`, JSON.stringify(value, null, 2));
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
// Return config
|
|
@@ -31,7 +31,7 @@ export abstract class CoreCronJobs implements OnApplicationBootstrap {
|
|
|
31
31
|
protected constructor(
|
|
32
32
|
protected schedulerRegistry: SchedulerRegistry,
|
|
33
33
|
protected cronJobs: Record<string, CronExpression | string | Date | Falsy | CronJobConfig>,
|
|
34
|
-
options?: { log?: boolean }
|
|
34
|
+
options?: { log?: boolean },
|
|
35
35
|
) {
|
|
36
36
|
this.config = {
|
|
37
37
|
log: true,
|
|
@@ -91,7 +91,7 @@ export abstract class CoreCronJobs implements OnApplicationBootstrap {
|
|
|
91
91
|
// check if cron job exists
|
|
92
92
|
if (!this[name]) {
|
|
93
93
|
if (this.config.log) {
|
|
94
|
-
console.info(
|
|
94
|
+
console.info(`Missing cron job function ${name}`);
|
|
95
95
|
}
|
|
96
96
|
continue;
|
|
97
97
|
}
|
|
@@ -105,8 +105,8 @@ export abstract class CoreCronJobs implements OnApplicationBootstrap {
|
|
|
105
105
|
|
|
106
106
|
// Check if parallel execution is allowed and if so how many can run in parallel
|
|
107
107
|
if (
|
|
108
|
-
dates?.length
|
|
109
|
-
(!config.runParallel || (typeof config.runParallel === 'number' && dates.length >= config.runParallel))
|
|
108
|
+
dates?.length
|
|
109
|
+
&& (!config.runParallel || (typeof config.runParallel === 'number' && dates.length >= config.runParallel))
|
|
110
110
|
) {
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
@@ -123,7 +123,7 @@ export abstract class CoreCronJobs implements OnApplicationBootstrap {
|
|
|
123
123
|
await this[name]();
|
|
124
124
|
} catch (e) {
|
|
125
125
|
// Remove job from running list
|
|
126
|
-
this.runningJobs[name] = this.runningJobs[name].filter(
|
|
126
|
+
this.runningJobs[name] = this.runningJobs[name].filter(item => item !== date);
|
|
127
127
|
if (config.throwException) {
|
|
128
128
|
throw e;
|
|
129
129
|
} else {
|
|
@@ -132,7 +132,7 @@ export abstract class CoreCronJobs implements OnApplicationBootstrap {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
// Remove job from running list
|
|
135
|
-
this.runningJobs[name] = this.runningJobs[name].filter(
|
|
135
|
+
this.runningJobs[name] = this.runningJobs[name].filter(item => item !== date);
|
|
136
136
|
},
|
|
137
137
|
null,
|
|
138
138
|
true,
|
|
@@ -140,7 +140,7 @@ export abstract class CoreCronJobs implements OnApplicationBootstrap {
|
|
|
140
140
|
config.context,
|
|
141
141
|
config.runOnInit,
|
|
142
142
|
config.utcOffset,
|
|
143
|
-
config.unrefTimeout
|
|
143
|
+
config.unrefTimeout,
|
|
144
144
|
);
|
|
145
145
|
this.schedulerRegistry.addCronJob(name, job);
|
|
146
146
|
if (this.config.log && this.schedulerRegistry.getCronJob(name)) {
|
|
@@ -13,7 +13,7 @@ import { ModuleService } from './module.service';
|
|
|
13
13
|
export abstract class CrudService<
|
|
14
14
|
Model extends CoreModel = any,
|
|
15
15
|
CreateInput = any,
|
|
16
|
-
UpdateInput = any
|
|
16
|
+
UpdateInput = any,
|
|
17
17
|
> extends ModuleService<Model> {
|
|
18
18
|
/**
|
|
19
19
|
* Create item
|
|
@@ -25,7 +25,7 @@ export abstract class CrudService<
|
|
|
25
25
|
const currentUserId = serviceOptions?.currentUser?.id;
|
|
26
26
|
return new this.mainDbModel({ ...data.input, createdBy: currentUserId, updatedBy: currentUserId }).save();
|
|
27
27
|
},
|
|
28
|
-
{ input, serviceOptions }
|
|
28
|
+
{ input, serviceOptions },
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -87,7 +87,7 @@ export abstract class CrudService<
|
|
|
87
87
|
*/
|
|
88
88
|
async find(
|
|
89
89
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
90
|
-
serviceOptions?: ServiceOptions
|
|
90
|
+
serviceOptions?: ServiceOptions,
|
|
91
91
|
): Promise<Model[]> {
|
|
92
92
|
// If filter is not instance of FilterArgs a simple form with filterQuery and queryOptions is set
|
|
93
93
|
// and should not be processed as FilterArgs
|
|
@@ -118,7 +118,7 @@ export abstract class CrudService<
|
|
|
118
118
|
}
|
|
119
119
|
return find.exec();
|
|
120
120
|
},
|
|
121
|
-
{ input: filter, serviceOptions }
|
|
121
|
+
{ input: filter, serviceOptions },
|
|
122
122
|
);
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -128,7 +128,7 @@ export abstract class CrudService<
|
|
|
128
128
|
*/
|
|
129
129
|
async findForce(
|
|
130
130
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
131
|
-
serviceOptions: ServiceOptions = {}
|
|
131
|
+
serviceOptions: ServiceOptions = {},
|
|
132
132
|
): Promise<Model[]> {
|
|
133
133
|
serviceOptions = serviceOptions || {};
|
|
134
134
|
serviceOptions.force = true;
|
|
@@ -141,7 +141,7 @@ export abstract class CrudService<
|
|
|
141
141
|
*/
|
|
142
142
|
async findRaw(
|
|
143
143
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
144
|
-
serviceOptions: ServiceOptions = {}
|
|
144
|
+
serviceOptions: ServiceOptions = {},
|
|
145
145
|
): Promise<Model[]> {
|
|
146
146
|
serviceOptions = serviceOptions || {};
|
|
147
147
|
serviceOptions.prepareInput = null;
|
|
@@ -154,7 +154,7 @@ export abstract class CrudService<
|
|
|
154
154
|
*/
|
|
155
155
|
async findAndCount(
|
|
156
156
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
157
|
-
serviceOptions?: ServiceOptions
|
|
157
|
+
serviceOptions?: ServiceOptions,
|
|
158
158
|
): Promise<{ items: Model[]; totalCount: number }> {
|
|
159
159
|
// If filter is not instance of FilterArgs a simple form with filterQuery and queryOptions is set
|
|
160
160
|
// and should not be processed as FilterArgs
|
|
@@ -217,13 +217,13 @@ export abstract class CrudService<
|
|
|
217
217
|
|
|
218
218
|
// Find and process db items
|
|
219
219
|
const collation = serviceOptions?.collation || ConfigService.get('mongoose.collation');
|
|
220
|
-
const dbResult
|
|
221
|
-
(await this.mainDbModel.aggregate(aggregation, collation ? { collation } : {}).exec())[0] || {};
|
|
220
|
+
const dbResult
|
|
221
|
+
= (await this.mainDbModel.aggregate(aggregation, collation ? { collation } : {}).exec())[0] || {};
|
|
222
222
|
dbResult.totalCount = dbResult.totalCount?.[0]?.total || 0;
|
|
223
|
-
dbResult.items = dbResult.items?.map(
|
|
223
|
+
dbResult.items = dbResult.items?.map(item => this.mainDbModel.hydrate(item)) || [];
|
|
224
224
|
return dbResult;
|
|
225
225
|
},
|
|
226
|
-
{ input: filter, outputPath: 'items', serviceOptions }
|
|
226
|
+
{ input: filter, outputPath: 'items', serviceOptions },
|
|
227
227
|
);
|
|
228
228
|
}
|
|
229
229
|
|
|
@@ -233,7 +233,7 @@ export abstract class CrudService<
|
|
|
233
233
|
*/
|
|
234
234
|
async findAndCountForce(
|
|
235
235
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
236
|
-
serviceOptions: ServiceOptions = {}
|
|
236
|
+
serviceOptions: ServiceOptions = {},
|
|
237
237
|
): Promise<{ items: Model[]; totalCount: number }> {
|
|
238
238
|
serviceOptions = serviceOptions || {};
|
|
239
239
|
serviceOptions.force = true;
|
|
@@ -246,7 +246,7 @@ export abstract class CrudService<
|
|
|
246
246
|
*/
|
|
247
247
|
async findAndCountRaw(
|
|
248
248
|
filter?: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
249
|
-
serviceOptions: ServiceOptions = {}
|
|
249
|
+
serviceOptions: ServiceOptions = {},
|
|
250
250
|
): Promise<{ items: Model[]; totalCount: number }> {
|
|
251
251
|
serviceOptions = serviceOptions || {};
|
|
252
252
|
serviceOptions.prepareInput = null;
|
|
@@ -260,7 +260,7 @@ export abstract class CrudService<
|
|
|
260
260
|
async findAndUpdate(
|
|
261
261
|
filter: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
262
262
|
update: PlainObject<UpdateInput>,
|
|
263
|
-
serviceOptions?: ServiceOptions
|
|
263
|
+
serviceOptions?: ServiceOptions,
|
|
264
264
|
): Promise<Model[]> {
|
|
265
265
|
const dbItems: Model[] = await this.find(filter, serviceOptions);
|
|
266
266
|
if (!dbItems?.length) {
|
|
@@ -276,7 +276,7 @@ export abstract class CrudService<
|
|
|
276
276
|
} catch (e) {
|
|
277
277
|
reject(e);
|
|
278
278
|
}
|
|
279
|
-
})
|
|
279
|
+
}),
|
|
280
280
|
);
|
|
281
281
|
}
|
|
282
282
|
return await Promise.all(promises);
|
|
@@ -289,7 +289,7 @@ export abstract class CrudService<
|
|
|
289
289
|
async findAndUpdateForce(
|
|
290
290
|
filter: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
291
291
|
update: PlainObject<UpdateInput>,
|
|
292
|
-
serviceOptions: ServiceOptions = {}
|
|
292
|
+
serviceOptions: ServiceOptions = {},
|
|
293
293
|
): Promise<Model[]> {
|
|
294
294
|
serviceOptions = serviceOptions || {};
|
|
295
295
|
serviceOptions.force = true;
|
|
@@ -303,7 +303,7 @@ export abstract class CrudService<
|
|
|
303
303
|
async findAndUpdateRaw(
|
|
304
304
|
filter: FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number },
|
|
305
305
|
update: PlainObject<UpdateInput>,
|
|
306
|
-
serviceOptions: ServiceOptions = {}
|
|
306
|
+
serviceOptions: ServiceOptions = {},
|
|
307
307
|
): Promise<Model[]> {
|
|
308
308
|
serviceOptions = serviceOptions || {};
|
|
309
309
|
serviceOptions.prepareInput = null;
|
|
@@ -329,7 +329,7 @@ export abstract class CrudService<
|
|
|
329
329
|
*/
|
|
330
330
|
async read(
|
|
331
331
|
input: string | FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions },
|
|
332
|
-
serviceOptions?: ServiceOptions
|
|
332
|
+
serviceOptions?: ServiceOptions,
|
|
333
333
|
): Promise<Model | Model[]> {
|
|
334
334
|
if (typeof input === 'string') {
|
|
335
335
|
return this.get(input, serviceOptions);
|
|
@@ -359,7 +359,7 @@ export abstract class CrudService<
|
|
|
359
359
|
*/
|
|
360
360
|
async readForce(
|
|
361
361
|
input: string | FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions },
|
|
362
|
-
serviceOptions?: ServiceOptions
|
|
362
|
+
serviceOptions?: ServiceOptions,
|
|
363
363
|
): Promise<Model | Model[]> {
|
|
364
364
|
if (typeof input === 'string') {
|
|
365
365
|
return this.getForce(input, serviceOptions);
|
|
@@ -389,7 +389,7 @@ export abstract class CrudService<
|
|
|
389
389
|
*/
|
|
390
390
|
async readRaw(
|
|
391
391
|
input: string | FilterArgs | { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions },
|
|
392
|
-
serviceOptions?: ServiceOptions
|
|
392
|
+
serviceOptions?: ServiceOptions,
|
|
393
393
|
): Promise<Model | Model[]> {
|
|
394
394
|
if (typeof input === 'string') {
|
|
395
395
|
return this.getRaw(input, serviceOptions);
|
|
@@ -412,7 +412,7 @@ export abstract class CrudService<
|
|
|
412
412
|
const merged = mergePlain(dbObject, data.input, { updatedBy: currentUserId });
|
|
413
413
|
return await this.mainDbModel.findByIdAndUpdate(id, merged, { returnDocument: 'after' }).exec();
|
|
414
414
|
},
|
|
415
|
-
{ dbObject, input, serviceOptions }
|
|
415
|
+
{ dbObject, input, serviceOptions },
|
|
416
416
|
);
|
|
417
417
|
}
|
|
418
418
|
|
|
@@ -450,7 +450,7 @@ export abstract class CrudService<
|
|
|
450
450
|
await this.mainDbModel.findByIdAndDelete(id).exec();
|
|
451
451
|
return dbObject;
|
|
452
452
|
},
|
|
453
|
-
{ dbObject, serviceOptions }
|
|
453
|
+
{ dbObject, serviceOptions },
|
|
454
454
|
);
|
|
455
455
|
}
|
|
456
456
|
|
|
@@ -30,7 +30,7 @@ export class EmailService {
|
|
|
30
30
|
templateData?: { [key: string]: any };
|
|
31
31
|
text?: string;
|
|
32
32
|
textTemplate?: string;
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
34
|
): Promise<any> {
|
|
35
35
|
// Process config
|
|
36
36
|
const { attachments, htmlTemplate, senderName, senderEmail, templateData, textTemplate } = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpException, Injectable } from '@nestjs/common';
|
|
2
|
-
import { ConfigService } from './config.service';
|
|
3
2
|
import Mailjet from 'node-mailjet';
|
|
3
|
+
import { ConfigService } from './config.service';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Mailjet service
|
|
@@ -30,7 +30,7 @@ export class MailjetService {
|
|
|
30
30
|
}[];
|
|
31
31
|
templateData?: { [key: string]: any };
|
|
32
32
|
sandbox?: boolean;
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
34
|
) {
|
|
35
35
|
// Process config
|
|
36
36
|
const { senderName, senderEmail, templateData, attachments, sandbox } = {
|
|
@@ -81,24 +81,24 @@ export class MailjetService {
|
|
|
81
81
|
});
|
|
82
82
|
} catch (e) {
|
|
83
83
|
if (
|
|
84
|
-
this.configService.getFastButReadOnly('email.mailjet.api_key_public')
|
|
85
|
-
this.configService.getFastButReadOnly('email.mailjet.api_key_private')
|
|
84
|
+
this.configService.getFastButReadOnly('email.mailjet.api_key_public')
|
|
85
|
+
&& this.configService.getFastButReadOnly('email.mailjet.api_key_private')
|
|
86
86
|
) {
|
|
87
87
|
throw new HttpException('Cannot connect to mailjet.', 502);
|
|
88
88
|
}
|
|
89
89
|
console.debug(
|
|
90
90
|
JSON.stringify(
|
|
91
91
|
{
|
|
92
|
-
info: 'Mailjet credentials are missing',
|
|
92
|
+
'info': 'Mailjet credentials are missing',
|
|
93
93
|
'email.mailjet.api_key_public':
|
|
94
94
|
this.configService.getFastButReadOnly('email.mailjet.api_key_public') || 'missing',
|
|
95
95
|
'email.mailjet.api_key_private':
|
|
96
96
|
this.configService.getFastButReadOnly('email.mailjet.api_key_private') || 'missing',
|
|
97
|
-
templateData: templateData,
|
|
97
|
+
'templateData': templateData,
|
|
98
98
|
},
|
|
99
99
|
null,
|
|
100
|
-
2
|
|
101
|
-
)
|
|
100
|
+
2,
|
|
101
|
+
),
|
|
102
102
|
);
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import fs = require('fs');
|
|
2
|
+
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
|
|
3
|
+
import { InjectConnection } from '@nestjs/mongoose';
|
|
4
|
+
import { Connection } from 'mongoose';
|
|
5
|
+
import YumlDiagram = require('yuml-diagram');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Schema config for yUml creation
|
|
9
|
+
*/
|
|
10
|
+
export interface ModelDocSchemaConfig {
|
|
11
|
+
isArray: boolean;
|
|
12
|
+
name: string;
|
|
13
|
+
ref: string;
|
|
14
|
+
type: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Model documentation as yUML-SVG
|
|
19
|
+
*/
|
|
20
|
+
@Injectable()
|
|
21
|
+
export class ModelDocService implements OnApplicationBootstrap {
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
@InjectConnection() private readonly connection: Connection,
|
|
25
|
+
) {
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Lifecycle hook that is called right after the application has started.
|
|
30
|
+
*/
|
|
31
|
+
async onApplicationBootstrap() {
|
|
32
|
+
const schemaJson = this.getSchemaJson();
|
|
33
|
+
const yUml = this.jsonToYuml(schemaJson);
|
|
34
|
+
this.yUmlToSvg(yUml);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Analyse the mongoose database models and create JSON
|
|
39
|
+
* @protected
|
|
40
|
+
*/
|
|
41
|
+
protected getSchemaJson(): Record<string, Record<string, ModelDocSchemaConfig>> {
|
|
42
|
+
|
|
43
|
+
// Prepare results
|
|
44
|
+
const results: Record<string, Record<string, ModelDocSchemaConfig>> = {};
|
|
45
|
+
|
|
46
|
+
// Process models
|
|
47
|
+
const models = this.connection.modelNames();
|
|
48
|
+
for (const modelName of models) {
|
|
49
|
+
results[modelName] = {};
|
|
50
|
+
|
|
51
|
+
// Process schema
|
|
52
|
+
const schema = this.connection.model(modelName).schema;
|
|
53
|
+
Object.keys(schema.paths).forEach((key) => {
|
|
54
|
+
const obj: any = schema.obj[key] || {};
|
|
55
|
+
const path = schema.paths[key];
|
|
56
|
+
|
|
57
|
+
results[modelName][key] = {
|
|
58
|
+
isArray: path.instance === 'Array',
|
|
59
|
+
name: path.path,
|
|
60
|
+
ref: Array.isArray(obj) ? undefined : obj.ref,
|
|
61
|
+
type: path.instance === 'Array'
|
|
62
|
+
? Array.isArray(obj)
|
|
63
|
+
? obj[0]() === '' ? 'String' : obj[0]()
|
|
64
|
+
: typeof obj.type === 'function' ? obj.type.name : obj.type
|
|
65
|
+
: path.instance,
|
|
66
|
+
};
|
|
67
|
+
if (results[modelName][key].type === 'Mixed') {
|
|
68
|
+
results[modelName][key].type = 'JSON';
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Return results
|
|
74
|
+
return results;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Convert JSON to yUML
|
|
79
|
+
* @param json
|
|
80
|
+
* @protected
|
|
81
|
+
*/
|
|
82
|
+
protected jsonToYuml(json: Record<string, Record<string, ModelDocSchemaConfig>>) {
|
|
83
|
+
// Convert JSON to yUML
|
|
84
|
+
let yumlText = '// {type:class}';
|
|
85
|
+
for (const [modelName, properties] of Object.entries(json)) {
|
|
86
|
+
yumlText += `\n[${modelName} | `;
|
|
87
|
+
const refs = [];
|
|
88
|
+
let subYumlText = '';
|
|
89
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
90
|
+
let type = value.type;
|
|
91
|
+
if (value.isArray) {
|
|
92
|
+
type = `Array<${type}>`;
|
|
93
|
+
}
|
|
94
|
+
if (value.ref) {
|
|
95
|
+
refs.push(`[${modelName}]-${key}>[${value.ref}]`);
|
|
96
|
+
}
|
|
97
|
+
if (key.startsWith('__')) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (key === '_id') {
|
|
101
|
+
subYumlText = `id: ObjectId; ${subYumlText}`;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
subYumlText += `${key}: ${type}; `;
|
|
105
|
+
}
|
|
106
|
+
yumlText += `${subYumlText}]\n`;
|
|
107
|
+
for (const ref of refs) {
|
|
108
|
+
yumlText += `${ref}\n`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return yumlText;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Convert yUML to SVG
|
|
116
|
+
* @param yUmlText
|
|
117
|
+
* @protected
|
|
118
|
+
*/
|
|
119
|
+
protected yUmlToSvg(yUmlText: String) {
|
|
120
|
+
|
|
121
|
+
// Create diagrams
|
|
122
|
+
// see https://github.com/jaime-olivares/yuml-diagram
|
|
123
|
+
// and https://yuml.me/diagram/scruffy/class/samples
|
|
124
|
+
const yuml = new YumlDiagram();
|
|
125
|
+
const svgLightBg = yuml.processYumlDocument(yUmlText, false);
|
|
126
|
+
const svgDarkBg = yuml.processYumlDocument(yUmlText, true);
|
|
127
|
+
|
|
128
|
+
// Save diagrams
|
|
129
|
+
fs.writeFile('model-doc-light.svg', svgLightBg, (err) => {
|
|
130
|
+
if (err) {
|
|
131
|
+
console.error(err);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
fs.writeFile('model-doc-dark.svg', svgDarkBg, (err) => {
|
|
135
|
+
if (err) {
|
|
136
|
+
console.error(err);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -53,7 +53,7 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
53
53
|
processType?: ProcessType;
|
|
54
54
|
roles?: string | string[];
|
|
55
55
|
throwError?: boolean;
|
|
56
|
-
}
|
|
56
|
+
},
|
|
57
57
|
): Promise<any> {
|
|
58
58
|
const config = {
|
|
59
59
|
...options,
|
|
@@ -77,7 +77,7 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
77
77
|
outputPath?: string | string[];
|
|
78
78
|
input?: any;
|
|
79
79
|
serviceOptions?: ServiceOptions;
|
|
80
|
-
}
|
|
80
|
+
},
|
|
81
81
|
) {
|
|
82
82
|
// Configuration with default values
|
|
83
83
|
const config: {
|
|
@@ -151,10 +151,9 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
151
151
|
opts.metatype = config.inputType;
|
|
152
152
|
}
|
|
153
153
|
config.input = await this.checkRights(config.input, config.currentUser as any, opts);
|
|
154
|
-
}
|
|
155
154
|
|
|
156
|
-
|
|
157
|
-
else if (!config.input && config.checkRights && this.checkRights) {
|
|
155
|
+
// Check roles before processing the service function if they were not already checked during the input check
|
|
156
|
+
} else if (!config.input && config.checkRights && this.checkRights) {
|
|
158
157
|
await this.checkRights(undefined, config.currentUser as any, config);
|
|
159
158
|
}
|
|
160
159
|
|
|
@@ -240,7 +239,7 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
240
239
|
model?: new (...args: any[]) => T;
|
|
241
240
|
dbModel?: Model<T & Document>;
|
|
242
241
|
ignoreSelections?: boolean;
|
|
243
|
-
} = {}
|
|
242
|
+
} = {},
|
|
244
243
|
) {
|
|
245
244
|
const config = {
|
|
246
245
|
model: this.mainModelConstructor,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import fs = require('fs');
|
|
2
|
+
import { join } from 'path';
|
|
1
3
|
import { Injectable } from '@nestjs/common';
|
|
2
4
|
import ejs = require('ejs');
|
|
3
5
|
import { TemplateFunction } from 'ejs';
|
|
4
|
-
import fs = require('fs');
|
|
5
|
-
import { join } from 'path';
|
|
6
6
|
import { ConfigService } from './config.service';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -44,7 +44,7 @@ export class TemplateService {
|
|
|
44
44
|
|
|
45
45
|
// Get template file
|
|
46
46
|
fs.readFile(
|
|
47
|
-
join(this.configService.getFastButReadOnly('templates.path'), filePath)
|
|
47
|
+
`${join(this.configService.getFastButReadOnly('templates.path'), filePath)}.ejs`,
|
|
48
48
|
{ encoding: 'utf8' },
|
|
49
49
|
(err, data) => {
|
|
50
50
|
if (err) {
|
|
@@ -54,7 +54,7 @@ export class TemplateService {
|
|
|
54
54
|
this.templates[filePath] = ejs.compile(data);
|
|
55
55
|
resolve(this.templates[filePath]);
|
|
56
56
|
}
|
|
57
|
-
}
|
|
57
|
+
},
|
|
58
58
|
);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CoreModel } from '../models/core-model.model';
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export interface CoreModelConstructor<T extends CoreModel> {
|
|
4
4
|
new (): T;
|
|
5
5
|
init(this: new (...args: any[]) => T, ...args: any[]): T;
|
|
6
6
|
map(
|
|
@@ -27,4 +27,4 @@ export type CoreModelConstructor<T extends CoreModel> = {
|
|
|
27
27
|
mapId?: boolean;
|
|
28
28
|
}
|
|
29
29
|
): T;
|
|
30
|
-
}
|
|
30
|
+
}
|