@lenne.tech/nest-server 11.0.1 → 11.1.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.
Files changed (117) hide show
  1. package/dist/core/common/args/filter.args.js +6 -8
  2. package/dist/core/common/args/filter.args.js.map +1 -1
  3. package/dist/core/common/args/pagination.args.js +16 -16
  4. package/dist/core/common/args/pagination.args.js.map +1 -1
  5. package/dist/core/common/decorators/restricted.decorator.js +1 -1
  6. package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
  7. package/dist/core/common/decorators/unified-field.decorator.d.ts +25 -0
  8. package/dist/core/common/decorators/unified-field.decorator.js +144 -0
  9. package/dist/core/common/decorators/unified-field.decorator.js.map +1 -0
  10. package/dist/core/common/helpers/config.helper.js +1 -1
  11. package/dist/core/common/helpers/config.helper.js.map +1 -1
  12. package/dist/core/common/helpers/db.helper.js +1 -1
  13. package/dist/core/common/helpers/db.helper.js.map +1 -1
  14. package/dist/core/common/helpers/graphql.helper.js.map +1 -1
  15. package/dist/core/common/helpers/input.helper.js +2 -2
  16. package/dist/core/common/helpers/input.helper.js.map +1 -1
  17. package/dist/core/common/helpers/service.helper.js +2 -2
  18. package/dist/core/common/helpers/service.helper.js.map +1 -1
  19. package/dist/core/common/inputs/combined-filter.input.js +8 -4
  20. package/dist/core/common/inputs/combined-filter.input.js.map +1 -1
  21. package/dist/core/common/inputs/filter.input.js +10 -7
  22. package/dist/core/common/inputs/filter.input.js.map +1 -1
  23. package/dist/core/common/inputs/single-filter.input.js +26 -18
  24. package/dist/core/common/inputs/single-filter.input.js.map +1 -1
  25. package/dist/core/common/inputs/sort.input.js +10 -4
  26. package/dist/core/common/inputs/sort.input.js.map +1 -1
  27. package/dist/core/common/models/core-persistence.model.js +18 -11
  28. package/dist/core/common/models/core-persistence.model.js.map +1 -1
  29. package/dist/core/common/pipes/map-and-validate.pipe.js +12 -3
  30. package/dist/core/common/pipes/map-and-validate.pipe.js.map +1 -1
  31. package/dist/core/common/services/brevo.service.js +1 -1
  32. package/dist/core/common/services/brevo.service.js.map +1 -1
  33. package/dist/core/common/services/config.service.js +1 -1
  34. package/dist/core/common/services/config.service.js.map +1 -1
  35. package/dist/core/common/services/email.service.js +1 -1
  36. package/dist/core/common/services/email.service.js.map +1 -1
  37. package/dist/core/common/services/model-doc.service.js +1 -1
  38. package/dist/core/common/services/model-doc.service.js.map +1 -1
  39. package/dist/core/common/services/module.service.js +1 -1
  40. package/dist/core/common/services/module.service.js.map +1 -1
  41. package/dist/core/common/services/template.service.js +2 -2
  42. package/dist/core/common/services/template.service.js.map +1 -1
  43. package/dist/core/modules/auth/core-auth.model.js +10 -11
  44. package/dist/core/modules/auth/core-auth.model.js.map +1 -1
  45. package/dist/core/modules/auth/guards/auth.guard.js +1 -1
  46. package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
  47. package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js +25 -21
  48. package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js.map +1 -1
  49. package/dist/core/modules/auth/services/core-auth.service.js +1 -1
  50. package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
  51. package/dist/core/modules/health-check/core-health-check-result.model.js +18 -11
  52. package/dist/core/modules/health-check/core-health-check-result.model.js.map +1 -1
  53. package/dist/core/modules/user/core-user.service.js +2 -2
  54. package/dist/core/modules/user/core-user.service.js.map +1 -1
  55. package/dist/core/modules/user/inputs/core-user-create.input.js +6 -3
  56. package/dist/core/modules/user/inputs/core-user-create.input.js.map +1 -1
  57. package/dist/core/modules/user/inputs/core-user.input.js +32 -18
  58. package/dist/core/modules/user/inputs/core-user.input.js.map +1 -1
  59. package/dist/core.module.js +1 -1
  60. package/dist/core.module.js.map +1 -1
  61. package/dist/index.d.ts +1 -0
  62. package/dist/index.js +1 -0
  63. package/dist/index.js.map +1 -1
  64. package/dist/main.js +2 -2
  65. package/dist/main.js.map +1 -1
  66. package/dist/server/common/models/persistence.model.js +1 -1
  67. package/dist/server/common/models/persistence.model.js.map +1 -1
  68. package/dist/server/modules/auth/inputs/auth-sign-up.input.js +11 -4
  69. package/dist/server/modules/auth/inputs/auth-sign-up.input.js.map +1 -1
  70. package/dist/server/modules/file/file.resolver.js +2 -2
  71. package/dist/server/modules/file/file.resolver.js.map +1 -1
  72. package/dist/server/modules/user/outputs/find-and-count-users-result.output.js +11 -4
  73. package/dist/server/modules/user/outputs/find-and-count-users-result.output.js.map +1 -1
  74. package/dist/server/modules/user/user.service.js +1 -1
  75. package/dist/server/modules/user/user.service.js.map +1 -1
  76. package/dist/test/test.helper.js +1 -1
  77. package/dist/test/test.helper.js.map +1 -1
  78. package/dist/tsconfig.build.tsbuildinfo +1 -1
  79. package/package.json +23 -23
  80. package/src/core/common/args/filter.args.ts +7 -10
  81. package/src/core/common/args/pagination.args.ts +17 -17
  82. package/src/core/common/decorators/restricted.decorator.ts +1 -2
  83. package/src/core/common/decorators/unified-field.decorator.ts +243 -0
  84. package/src/core/common/helpers/config.helper.ts +1 -4
  85. package/src/core/common/helpers/db.helper.ts +1 -2
  86. package/src/core/common/helpers/graphql.helper.ts +0 -1
  87. package/src/core/common/helpers/input.helper.ts +2 -3
  88. package/src/core/common/helpers/service.helper.ts +2 -3
  89. package/src/core/common/inputs/combined-filter.input.ts +9 -5
  90. package/src/core/common/inputs/filter.input.ts +14 -11
  91. package/src/core/common/inputs/single-filter.input.ts +28 -19
  92. package/src/core/common/inputs/sort.input.ts +11 -5
  93. package/src/core/common/models/core-persistence.model.ts +19 -12
  94. package/src/core/common/pipes/map-and-validate.pipe.ts +15 -4
  95. package/src/core/common/services/brevo.service.ts +1 -2
  96. package/src/core/common/services/config.service.ts +1 -2
  97. package/src/core/common/services/email.service.ts +1 -2
  98. package/src/core/common/services/model-doc.service.ts +1 -2
  99. package/src/core/common/services/module.service.ts +1 -2
  100. package/src/core/common/services/template.service.ts +2 -3
  101. package/src/core/modules/auth/core-auth.model.ts +11 -12
  102. package/src/core/modules/auth/guards/auth.guard.ts +1 -2
  103. package/src/core/modules/auth/inputs/core-auth-sign-in.input.ts +27 -23
  104. package/src/core/modules/auth/services/core-auth.service.ts +1 -2
  105. package/src/core/modules/health-check/core-health-check-result.model.ts +19 -12
  106. package/src/core/modules/user/core-user.service.ts +2 -3
  107. package/src/core/modules/user/inputs/core-user-create.input.ts +7 -4
  108. package/src/core/modules/user/inputs/core-user.input.ts +34 -20
  109. package/src/core.module.ts +1 -2
  110. package/src/index.ts +1 -0
  111. package/src/main.ts +2 -3
  112. package/src/server/common/models/persistence.model.ts +1 -2
  113. package/src/server/modules/auth/inputs/auth-sign-up.input.ts +12 -5
  114. package/src/server/modules/file/file.resolver.ts +2 -3
  115. package/src/server/modules/user/outputs/find-and-count-users-result.output.ts +12 -5
  116. package/src/server/modules/user/user.service.ts +1 -2
  117. package/src/test/test.helper.ts +2 -3
@@ -1,6 +1,7 @@
1
- import { Field, InputType } from '@nestjs/graphql';
1
+ import { InputType } from '@nestjs/graphql';
2
2
 
3
3
  import { Restricted } from '../decorators/restricted.decorator';
4
+ import { UnifiedField } from '../decorators/unified-field.decorator';
4
5
  import { ComparisonOperatorEnum } from '../enums/comparison-operator.enum';
5
6
  import { RoleEnum } from '../enums/role.enum';
6
7
  import { JSON } from '../scalars/json.scalar';
@@ -15,63 +16,71 @@ export class SingleFilterInput extends CoreInput {
15
16
  /**
16
17
  * Convert value to ObjectId
17
18
  */
18
- @Field({
19
+
20
+ @UnifiedField({
19
21
  description: 'Convert value to ObjectId',
20
- nullable: true,
22
+ isOptional: true,
23
+ roles: RoleEnum.S_EVERYONE,
21
24
  })
22
- @Restricted(RoleEnum.S_EVERYONE)
23
25
  convertToObjectId?: boolean = undefined;
24
26
 
25
27
  /**
26
28
  * Name of the property to be used for the filter
27
29
  */
28
- @Field({ description: 'Name of the property to be used for the filter' })
29
- @Restricted(RoleEnum.S_EVERYONE)
30
+ @UnifiedField({
31
+ description: 'Name of the property to be used for the filter',
32
+ roles: RoleEnum.S_EVERYONE,
33
+ })
30
34
  field: string = undefined;
31
35
 
32
36
  /**
33
37
  * Process value as reference
34
38
  */
35
- @Field({
39
+ @UnifiedField({
36
40
  description: 'Process value as reference',
37
- nullable: true,
41
+ isOptional: true,
42
+ roles: RoleEnum.S_EVERYONE,
38
43
  })
39
- @Restricted(RoleEnum.S_EVERYONE)
40
44
  isReference?: boolean = undefined;
41
45
 
42
46
  /**
43
47
  * [Negate operator](https://docs.mongodb.com/manual/reference/operator/query/not/)
44
48
  */
45
- @Field({
49
+ @UnifiedField({
46
50
  description: '[Negate operator](https://docs.mongodb.com/manual/reference/operator/query/not/)',
47
- nullable: true,
51
+ isOptional: true,
52
+ roles: RoleEnum.S_EVERYONE,
48
53
  })
49
- @Restricted(RoleEnum.S_EVERYONE)
50
54
  not?: boolean = undefined;
51
55
 
52
56
  /**
53
57
  * [Comparison operator](https://docs.mongodb.com/manual/reference/operator/query-comparison/)
54
58
  */
55
- @Field(() => ComparisonOperatorEnum, {
59
+ @UnifiedField({
56
60
  description: '[Comparison operator](https://docs.mongodb.com/manual/reference/operator/query-comparison/)',
61
+ enum: { enum: ComparisonOperatorEnum },
62
+ roles: RoleEnum.S_EVERYONE,
57
63
  })
58
- @Restricted(RoleEnum.S_EVERYONE)
59
64
  operator: ComparisonOperatorEnum = undefined;
60
65
 
61
66
  /**
62
67
  * [Options](https://docs.mongodb.com/manual/reference/operator/query/regex/#op._S_options) for
63
68
  * [REGEX](https://docs.mongodb.com/manual/reference/operator/query/regex/) operator
64
69
  */
65
- @Field({
70
+ @UnifiedField({
66
71
  description:
67
72
  '[Options](https://docs.mongodb.com/manual/reference/operator/query/regex/#op._S_options) for '
68
73
  + '[REGEX](https://docs.mongodb.com/manual/reference/operator/query/regex/) operator',
69
- nullable: true,
74
+ isOptional: true,
75
+ roles: RoleEnum.S_EVERYONE,
70
76
  })
71
- @Restricted(RoleEnum.S_EVERYONE)
72
77
  options?: string = undefined;
73
78
 
74
- @Field(() => JSON, { description: 'Value of the property' })
75
- @Restricted(RoleEnum.S_EVERYONE)
79
+ @UnifiedField({
80
+ description: 'Value of the property',
81
+ isOptional: true,
82
+ roles: RoleEnum.S_EVERYONE,
83
+ type: () => JSON,
84
+ })
76
85
  value: any = undefined;
77
86
  }
@@ -1,6 +1,7 @@
1
- import { Field, InputType } from '@nestjs/graphql';
1
+ import { InputType } from '@nestjs/graphql';
2
2
 
3
3
  import { Restricted } from '../decorators/restricted.decorator';
4
+ import { UnifiedField } from '../decorators/unified-field.decorator';
4
5
  import { RoleEnum } from '../enums/role.enum';
5
6
  import { SortOrderEnum } from '../enums/sort-order.emum';
6
7
  import { CoreInput } from './core-input.input';
@@ -14,14 +15,19 @@ export class SortInput extends CoreInput {
14
15
  /**
15
16
  * Field that is to be used for sorting
16
17
  */
17
- @Field({ description: 'Field that is to be used for sorting' })
18
- @Restricted(RoleEnum.S_EVERYONE)
18
+ @UnifiedField({
19
+ description: 'Field that is to be used for sorting',
20
+ roles: RoleEnum.S_EVERYONE,
21
+ })
19
22
  field: string = undefined;
20
23
 
21
24
  /**
22
25
  * SortInput order of the field
23
26
  */
24
- @Field(() => SortOrderEnum, { description: 'SortInput order of the field' })
25
- @Restricted(RoleEnum.S_EVERYONE)
27
+ @UnifiedField({
28
+ description: 'SortInput order of the field',
29
+ enum: { enum: SortOrderEnum },
30
+ roles: RoleEnum.S_EVERYONE,
31
+ })
26
32
  order: SortOrderEnum = undefined;
27
33
  }
@@ -1,9 +1,9 @@
1
- import { Field, ID, ObjectType } from '@nestjs/graphql';
1
+ import { ObjectType } from '@nestjs/graphql';
2
2
  import { Prop, Schema } from '@nestjs/mongoose';
3
- import { ApiProperty } from '@nestjs/swagger';
4
3
  import { Types } from 'mongoose';
5
4
 
6
5
  import { Restricted } from '../decorators/restricted.decorator';
6
+ import { UnifiedField } from '../decorators/unified-field.decorator';
7
7
  import { RoleEnum } from '../enums/role.enum';
8
8
  import { getStringIds } from '../helpers/db.helper';
9
9
  import { CoreModel } from './core-model.model';
@@ -43,30 +43,37 @@ export abstract class CorePersistenceModel extends CoreModel {
43
43
  /**
44
44
  * ID of the persistence object as string
45
45
  */
46
- @ApiProperty({ type: String })
47
- @Field(() => ID, {
46
+ @UnifiedField({
48
47
  description: 'ID of the persistence object',
49
- nullable: true,
48
+ isOptional: true,
49
+ roles: RoleEnum.S_EVERYONE,
50
50
  })
51
- @Restricted(RoleEnum.S_EVERYONE)
52
51
  id: string = undefined;
53
52
 
54
53
  /**
55
54
  * Created date, is set automatically by mongoose
56
55
  */
57
- @ApiProperty({ example: 1740037703939, format: 'int64', type: Date })
58
- @Field({ description: 'Created date', nullable: true })
59
56
  @Prop({ onCreate: () => new Date() })
60
- @Restricted(RoleEnum.S_EVERYONE)
57
+ @UnifiedField({
58
+ description: 'Created date',
59
+ isOptional: true,
60
+ roles: RoleEnum.S_EVERYONE,
61
+ swaggerApiOptions: { example: 1740037703939, format: 'int64', type: Date },
62
+ type: Date,
63
+ })
61
64
  createdAt: Date = undefined;
62
65
 
63
66
  /**
64
67
  * Updated date is set automatically by mongoose
65
68
  */
66
- @ApiProperty({ example: 1740037703939, format: 'int64', type: String })
67
- @Field({ description: 'Updated date', nullable: true })
68
69
  @Prop({ onUpdate: () => new Date() })
69
- @Restricted(RoleEnum.S_EVERYONE)
70
+ @UnifiedField({
71
+ description: 'Updated date',
72
+ isOptional: true,
73
+ roles: RoleEnum.S_EVERYONE,
74
+ swaggerApiOptions: { example: 1740037703939, format: 'int64', type: Date },
75
+ type: Date,
76
+ })
70
77
  updatedAt: Date = undefined;
71
78
 
72
79
  // ===========================================================================
@@ -1,6 +1,6 @@
1
1
  import { ArgumentMetadata, BadRequestException, Injectable, PipeTransform } from '@nestjs/common';
2
2
  import { plainToInstance } from 'class-transformer';
3
- import { validate } from 'class-validator';
3
+ import { validate, ValidationError } from 'class-validator';
4
4
 
5
5
  import { isBasicType } from '../helpers/input.helper';
6
6
 
@@ -26,9 +26,20 @@ export class MapAndValidatePipe implements PipeTransform {
26
26
  const errors = await validate(value, { forbidUnknownValues: false });
27
27
  if (errors.length > 0) {
28
28
  const result = {};
29
- errors.forEach((e) => {
30
- result[e.property] = e.constraints;
31
- });
29
+
30
+ const processErrors = (errorList: ValidationError[], parentKey = '') => {
31
+ errorList.forEach((e) => {
32
+ const key = parentKey ? `${parentKey}.${e.property}` : e.property;
33
+
34
+ if (e.children && e.children.length > 0) {
35
+ processErrors(e.children, key);
36
+ } else {
37
+ result[key] = e.constraints;
38
+ }
39
+ });
40
+ };
41
+
42
+ processErrors(errors);
32
43
  throw new BadRequestException(result);
33
44
  }
34
45
 
@@ -1,9 +1,8 @@
1
+ import brevo = require('@getbrevo/brevo');
1
2
  import { Injectable } from '@nestjs/common';
2
3
 
3
4
  import { ConfigService } from './config.service';
4
5
 
5
- import brevo = require('@getbrevo/brevo');
6
-
7
6
  /**
8
7
  * Brevo service to send transactional emails
9
8
  */
@@ -1,4 +1,5 @@
1
1
  import { cloneDeep } from 'lodash';
2
+ import _ = require('lodash');
2
3
  import { BehaviorSubject, firstValueFrom } from 'rxjs';
3
4
  import { filter, map } from 'rxjs/operators';
4
5
 
@@ -6,8 +7,6 @@ import { merge } from '../helpers/config.helper';
6
7
  import { clone, deepFreeze } from '../helpers/input.helper';
7
8
  import { IServerOptions } from '../interfaces/server-options.interface';
8
9
 
9
- import _ = require('lodash');
10
-
11
10
  /**
12
11
  * Config service can be used as provider (after initialization in CoreModule.forRoot)
13
12
  *
@@ -1,12 +1,11 @@
1
1
  import { Injectable } from '@nestjs/common';
2
+ import nodemailer = require('nodemailer');
2
3
  import { Attachment } from 'nodemailer/lib/mailer';
3
4
 
4
5
  import { isNonEmptyString, isTrue, returnFalse } from '../helpers/input.helper';
5
6
  import { ConfigService } from './config.service';
6
7
  import { TemplateService } from './template.service';
7
8
 
8
- import nodemailer = require('nodemailer');
9
-
10
9
  /**
11
10
  * Email service
12
11
  */
@@ -1,8 +1,7 @@
1
1
  import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
2
2
  import { InjectConnection } from '@nestjs/mongoose';
3
- import { Connection } from 'mongoose';
4
-
5
3
  import fs = require('fs');
4
+ import { Connection } from 'mongoose';
6
5
  import YumlDiagram = require('yuml-diagram');
7
6
 
8
7
  /**
@@ -1,3 +1,4 @@
1
+ import _ = require('lodash');
1
2
  import { Document, Model, Types } from 'mongoose';
2
3
 
3
4
  import { ProcessType } from '../enums/process-type.enum';
@@ -9,8 +10,6 @@ import { CoreModel } from '../models/core-model.model';
9
10
  import { FieldSelection } from '../types/field-selection.type';
10
11
  import { ConfigService } from './config.service';
11
12
 
12
- import _ = require('lodash');
13
-
14
13
  /**
15
14
  * Module service class to be extended by concrete module services
16
15
  */
@@ -1,12 +1,11 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { TemplateFunction } from 'ejs';
3
+ import ejs = require('ejs');
4
+ import fs = require('fs');
3
5
  import { join } from 'path';
4
6
 
5
7
  import { ConfigService } from './config.service';
6
8
 
7
- import ejs = require('ejs');
8
- import fs = require('fs');
9
-
10
9
  /**
11
10
  * Template service
12
11
  */
@@ -1,7 +1,7 @@
1
- import { Field, ObjectType } from '@nestjs/graphql';
2
- import { ApiProperty } from '@nestjs/swagger';
1
+ import { ObjectType } from '@nestjs/graphql';
3
2
 
4
3
  import { Restricted } from '../../common/decorators/restricted.decorator';
4
+ import { UnifiedField } from '../../common/decorators/unified-field.decorator';
5
5
  import { RoleEnum } from '../../common/enums/role.enum';
6
6
  import { CoreModel } from '../../common/models/core-model.model';
7
7
  import { CoreUserModel } from '../user/core-user.model';
@@ -19,35 +19,34 @@ export class CoreAuthModel extends CoreModel {
19
19
  /**
20
20
  * JSON Web Token(JWT)
21
21
  */
22
- @ApiProperty({
22
+ @UnifiedField({
23
23
  description: 'JSON Web Token(JWT) used for auth',
24
24
  example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
25
+ isOptional: true,
26
+ roles: RoleEnum.S_EVERYONE,
25
27
  })
26
- @Field({ description: 'JSON Web Token(JWT)', nullable: true })
27
- @Restricted(RoleEnum.S_EVERYONE)
28
28
  token?: string = undefined;
29
29
 
30
30
  /**
31
31
  * Refresh token
32
32
  */
33
- @ApiProperty({
33
+ @UnifiedField({
34
34
  description: 'Refresh JSON Web Token(JWT) used for auth',
35
35
  example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
36
+ isOptional: true,
37
+ roles: RoleEnum.S_EVERYONE,
36
38
  })
37
- @Field({ description: 'Refresh token', nullable: true })
38
- @Restricted(RoleEnum.S_EVERYONE)
39
39
  refreshToken?: string = undefined;
40
40
 
41
41
  /**
42
42
  * Current user
43
43
  */
44
- @ApiProperty({
44
+ @UnifiedField({
45
45
  description: 'User who signed in',
46
- required: true,
46
+ isOptional: false,
47
+ roles: RoleEnum.S_EVERYONE,
47
48
  type: () => CoreUserModel,
48
49
  })
49
- @Field({ description: 'Current user' })
50
- @Restricted(RoleEnum.S_EVERYONE)
51
50
  user: CoreUserModel = undefined;
52
51
 
53
52
  // ===================================================================================================================
@@ -3,14 +3,13 @@ import { GqlExecutionContext } from '@nestjs/graphql';
3
3
  import { AuthModuleOptions, Type } from '@nestjs/passport';
4
4
  import { defaultOptions } from '@nestjs/passport/dist/options';
5
5
  import { memoize } from '@nestjs/passport/dist/utils/memoize.util';
6
+ import passport = require('passport');
6
7
 
7
8
  import { AuthGuardStrategy } from '../auth-guard-strategy.enum';
8
9
  import { ExpiredRefreshTokenException } from '../exceptions/expired-refresh-token.exception';
9
10
  import { ExpiredTokenException } from '../exceptions/expired-token.exception';
10
11
  import { InvalidTokenException } from '../exceptions/invalid-token.exception';
11
12
 
12
- import passport = require('passport');
13
-
14
13
  /**
15
14
  * Missing strategy error
16
15
  */
@@ -1,8 +1,8 @@
1
- import { Field, InputType } from '@nestjs/graphql';
2
- import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
3
- import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
1
+ import { InputType } from '@nestjs/graphql';
2
+ import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
4
3
 
5
4
  import { Restricted } from '../../../common/decorators/restricted.decorator';
5
+ import { UnifiedField } from '../../../common/decorators/unified-field.decorator';
6
6
  import { RoleEnum } from '../../../common/enums/role.enum';
7
7
  import { CoreInput } from '../../../common/inputs/core-input.input';
8
8
 
@@ -16,31 +16,35 @@ export class CoreAuthSignInInput extends CoreInput {
16
16
  // Properties
17
17
  // ===================================================================================================================
18
18
 
19
- @ApiPropertyOptional({ description: 'Device ID (is created automatically if it is not set)' })
20
- @Field({ description: 'Device ID (is created automatically if it is not set)', nullable: true })
21
- @IsOptional()
22
- @IsString()
23
- @Restricted(RoleEnum.S_EVERYONE)
19
+ @UnifiedField({
20
+ description: 'Device ID (is created automatically if it is not set)',
21
+ isOptional: true,
22
+ roles: RoleEnum.S_EVERYONE,
23
+ validator: () => [IsString()],
24
+ })
24
25
  deviceId?: string = undefined;
25
26
 
26
- @ApiPropertyOptional({ description: 'Device description' })
27
- @Field({ description: 'Device description', nullable: true })
28
- @IsOptional()
29
- @IsString()
30
- @Restricted(RoleEnum.S_EVERYONE)
27
+ @UnifiedField({
28
+ description: 'Device description',
29
+ isOptional: true,
30
+ roles: RoleEnum.S_EVERYONE,
31
+ validator: () => [IsString()],
32
+ })
31
33
  deviceDescription?: string = undefined;
32
34
 
33
- @ApiProperty()
34
- @Field({ description: 'Email', nullable: false })
35
- @IsEmail()
36
- @IsNotEmpty()
37
- @Restricted(RoleEnum.S_EVERYONE)
35
+ @UnifiedField({
36
+ description: 'Email',
37
+ isOptional: false,
38
+ roles: RoleEnum.S_EVERYONE,
39
+ validator: () => [IsEmail(), IsString(), IsNotEmpty()],
40
+ })
38
41
  email: string = undefined;
39
42
 
40
- @ApiProperty()
41
- @Field({ description: 'Password', nullable: false })
42
- @IsNotEmpty()
43
- @IsString()
44
- @Restricted(RoleEnum.S_EVERYONE)
43
+ @UnifiedField({
44
+ description: 'Password',
45
+ isOptional: false,
46
+ roles: RoleEnum.S_EVERYONE,
47
+ validator: () => [IsString(), IsNotEmpty()],
48
+ })
45
49
  password: string = undefined;
46
50
  }
@@ -1,5 +1,6 @@
1
1
  import { BadRequestException, Injectable, UnauthorizedException } from '@nestjs/common';
2
2
  import { JwtService } from '@nestjs/jwt';
3
+ import bcrypt = require('bcrypt');
3
4
  import { randomUUID } from 'crypto';
4
5
  import { sha256 } from 'js-sha256';
5
6
 
@@ -14,8 +15,6 @@ import { ICoreAuthUser } from '../interfaces/core-auth-user.interface';
14
15
  import { JwtPayload } from '../interfaces/jwt-payload.interface';
15
16
  import { CoreAuthUserService } from './core-auth-user.service';
16
17
 
17
- import bcrypt = require('bcrypt');
18
-
19
18
  /**
20
19
  * CoreAuthService to handle user authentication
21
20
  */
@@ -1,6 +1,7 @@
1
- import { Field, ObjectType } from '@nestjs/graphql';
1
+ import { ObjectType } from '@nestjs/graphql';
2
2
 
3
3
  import { Restricted } from '../../common/decorators/restricted.decorator';
4
+ import { UnifiedField } from '../../common/decorators/unified-field.decorator';
4
5
  import { RoleEnum } from '../../common/enums/role.enum';
5
6
  import { CoreModel } from '../../common/models/core-model.model';
6
7
  import { JSON } from '../../common/scalars/json.scalar';
@@ -18,37 +19,43 @@ export abstract class CoreHealthCheckResult extends CoreModel {
18
19
  /**
19
20
  * The overall status of the Health Check
20
21
  */
21
- @Field({ description: 'The overall status of the Health Check', nullable: false })
22
- @Restricted(RoleEnum.S_EVERYONE)
22
+ @UnifiedField({
23
+ description: 'The overall status of the Health Check',
24
+ isOptional: false,
25
+ roles: RoleEnum.S_EVERYONE,
26
+ })
23
27
  status: 'error' | 'ok' | 'shutting_down' = undefined;
24
28
 
25
29
  /**
26
30
  * The info object contains information of each health indicator which is of status “up”
27
31
  */
28
- @Field(() => JSON, {
32
+ @UnifiedField({
29
33
  description: 'The info object contains information of each health indicator which is of status “up”',
30
- nullable: true,
34
+ isOptional: true,
35
+ roles: RoleEnum.S_EVERYONE,
36
+ type: () => JSON,
31
37
  })
32
- @Restricted(RoleEnum.S_EVERYONE)
33
38
  info: JSON = undefined;
34
39
 
35
40
  /**
36
41
  * The error object contains information of each health indicator which is of status “down”
37
42
  */
38
- @Field(() => JSON, {
43
+ @UnifiedField({
39
44
  description: 'The error object contains information of each health indicator which is of status “down”',
40
- nullable: true,
45
+ isOptional: true,
46
+ roles: RoleEnum.S_EVERYONE,
47
+ type: () => JSON,
41
48
  })
42
- @Restricted(RoleEnum.S_EVERYONE)
43
49
  error: JSON = undefined;
44
50
 
45
51
  /**
46
52
  * The details object contains information of every health indicator
47
53
  */
48
- @Field(() => JSON, {
54
+ @UnifiedField({
49
55
  description: 'The details object contains information of every health indicator',
50
- nullable: false,
56
+ isOptional: true,
57
+ roles: RoleEnum.S_EVERYONE,
58
+ type: () => JSON,
51
59
  })
52
- @Restricted(RoleEnum.S_EVERYONE)
53
60
  details: JSON = undefined;
54
61
  }
@@ -1,4 +1,6 @@
1
1
  import { BadRequestException, NotFoundException, UnprocessableEntityException } from '@nestjs/common';
2
+ import bcrypt = require('bcrypt');
3
+ import crypto = require('crypto');
2
4
  import { sha256 } from 'js-sha256';
3
5
  import { Document, Model } from 'mongoose';
4
6
 
@@ -12,9 +14,6 @@ import { CoreUserModel } from './core-user.model';
12
14
  import { CoreUserCreateInput } from './inputs/core-user-create.input';
13
15
  import { CoreUserInput } from './inputs/core-user.input';
14
16
 
15
- import bcrypt = require('bcrypt');
16
- import crypto = require('crypto');
17
-
18
17
  /**
19
18
  * User service
20
19
  */
@@ -1,7 +1,8 @@
1
- import { Field, InputType } from '@nestjs/graphql';
1
+ import { InputType } from '@nestjs/graphql';
2
2
  import { IsEmail } from 'class-validator';
3
3
 
4
4
  import { Restricted } from '../../../common/decorators/restricted.decorator';
5
+ import { UnifiedField } from '../../../common/decorators/unified-field.decorator';
5
6
  import { RoleEnum } from '../../../common/enums/role.enum';
6
7
  import { CoreUserInput } from './core-user.input';
7
8
 
@@ -15,8 +16,10 @@ import { CoreUserInput } from './core-user.input';
15
16
  @InputType({ description: 'User input to create a new user', isAbstract: true })
16
17
  @Restricted(RoleEnum.S_EVERYONE)
17
18
  export abstract class CoreUserCreateInput extends CoreUserInput {
18
- @Field({ description: 'Email of the user', nullable: false })
19
- @IsEmail()
20
- @Restricted(RoleEnum.S_EVERYONE)
19
+ @UnifiedField({
20
+ description: 'Email of the user',
21
+ roles: RoleEnum.S_EVERYONE,
22
+ validator: () => [IsEmail()],
23
+ })
21
24
  override email: string = undefined;
22
25
  }
@@ -1,7 +1,8 @@
1
- import { Field, InputType } from '@nestjs/graphql';
2
- import { IsEmail, IsOptional } from 'class-validator';
1
+ import { InputType } from '@nestjs/graphql';
2
+ import { IsEmail } from 'class-validator';
3
3
 
4
4
  import { Restricted } from '../../../common/decorators/restricted.decorator';
5
+ import { UnifiedField } from '../../../common/decorators/unified-field.decorator';
5
6
  import { ProcessType } from '../../../common/enums/process-type.enum';
6
7
  import { RoleEnum } from '../../../common/enums/role.enum';
7
8
  import { CoreInput } from '../../../common/inputs/core-input.input';
@@ -19,49 +20,62 @@ export abstract class CoreUserInput extends CoreInput {
19
20
  /**
20
21
  * Email of the user
21
22
  */
22
- @Field({ description: 'Email of the user', nullable: true })
23
- @IsEmail()
24
- @IsOptional()
25
- @Restricted(RoleEnum.S_EVERYONE)
23
+ @UnifiedField({
24
+ description: 'Email of the user',
25
+ isOptional: true,
26
+ roles: RoleEnum.S_EVERYONE,
27
+ validator: () => [IsEmail()],
28
+ })
26
29
  email?: string = undefined;
27
30
 
28
31
  /**
29
32
  * First name of the user
30
33
  */
31
- @Field({ description: 'First name of the user', nullable: true })
32
- @IsOptional()
33
- @Restricted(RoleEnum.S_EVERYONE)
34
+ @UnifiedField({
35
+ description: 'Last name of the user',
36
+ isOptional: true,
37
+ roles: RoleEnum.S_EVERYONE,
38
+ })
34
39
  firstName?: string = undefined;
35
40
 
36
41
  /**
37
42
  * Last name of the user
38
43
  */
39
- @Field({ description: 'Last name of the user', nullable: true })
40
- @IsOptional()
41
- @Restricted(RoleEnum.S_EVERYONE)
44
+ @UnifiedField({
45
+ description: 'Last name of the user',
46
+ isOptional: true,
47
+ roles: RoleEnum.S_EVERYONE,
48
+ })
42
49
  lastName?: string = undefined;
43
50
 
44
51
  /**
45
52
  * Roles of the user
46
53
  */
47
- @Field(() => [String], { description: 'Roles of the user', nullable: true })
48
- @IsOptional()
49
54
  @Restricted({ processType: ProcessType.INPUT, roles: RoleEnum.ADMIN })
55
+ @UnifiedField({
56
+ array: true,
57
+ isOptional: true,
58
+ type: String,
59
+ })
50
60
  roles?: string[] = undefined;
51
61
 
52
62
  /**
53
63
  * Username / alias of the user
54
64
  */
55
- @Field({ description: 'Username / alias of the user', nullable: true })
56
- @IsOptional()
57
- @Restricted(RoleEnum.S_EVERYONE)
65
+ @UnifiedField({
66
+ description: 'Username / alias of the user',
67
+ isOptional: true,
68
+ roles: RoleEnum.S_EVERYONE,
69
+ })
58
70
  username?: string = undefined;
59
71
 
60
72
  /**
61
73
  * Password of the user
62
74
  */
63
- @Field({ description: 'Password of the user', nullable: true })
64
- @IsOptional()
65
- @Restricted(RoleEnum.S_EVERYONE)
75
+ @UnifiedField({
76
+ description: 'Password of the user',
77
+ isOptional: true,
78
+ roles: RoleEnum.S_EVERYONE,
79
+ })
66
80
  password?: string = undefined;
67
81
  }