@lenne.tech/nest-server 10.3.1 → 10.3.2
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/dist/core/common/inputs/combined-filter.input.js +5 -0
- package/dist/core/common/inputs/combined-filter.input.js.map +1 -1
- package/dist/core/common/inputs/filter.input.js +5 -0
- package/dist/core/common/inputs/filter.input.js.map +1 -1
- package/dist/core/common/inputs/single-filter.input.js +10 -0
- package/dist/core/common/inputs/single-filter.input.js.map +1 -1
- package/dist/core/common/inputs/sort.input.js +5 -0
- package/dist/core/common/inputs/sort.input.js.map +1 -1
- package/dist/core/common/models/core-persistence.model.js +1 -0
- package/dist/core/common/models/core-persistence.model.js.map +1 -1
- package/dist/core/modules/auth/core-auth.controller.js +7 -0
- package/dist/core/modules/auth/core-auth.controller.js.map +1 -1
- package/dist/core/modules/auth/core-auth.model.js +6 -0
- package/dist/core/modules/auth/core-auth.model.js.map +1 -1
- package/dist/core/modules/auth/core-auth.resolver.js +7 -0
- package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
- package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js +7 -0
- package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js.map +1 -1
- package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js +3 -0
- package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js.map +1 -1
- package/dist/core/modules/file/core-file-info.model.js +14 -0
- package/dist/core/modules/file/core-file-info.model.js.map +1 -1
- package/dist/core/modules/file/core-file.controller.js +4 -0
- package/dist/core/modules/file/core-file.controller.js.map +1 -1
- package/dist/core/modules/file/core-file.resolver.js +7 -0
- package/dist/core/modules/file/core-file.resolver.js.map +1 -1
- package/dist/core/modules/health-check/core-health-check-result.model.js +7 -0
- package/dist/core/modules/health-check/core-health-check-result.model.js.map +1 -1
- package/dist/core/modules/health-check/core-health-check.controller.js +4 -0
- package/dist/core/modules/health-check/core-health-check.controller.js.map +1 -1
- package/dist/core/modules/user/core-user.model.js +15 -0
- package/dist/core/modules/user/core-user.model.js.map +1 -1
- package/dist/core/modules/user/inputs/core-user-create.input.js +4 -0
- package/dist/core/modules/user/inputs/core-user-create.input.js.map +1 -1
- package/dist/core/modules/user/inputs/core-user.input.js +6 -0
- package/dist/core/modules/user/inputs/core-user.input.js.map +1 -1
- package/dist/server/common/models/persistence.model.js +5 -0
- package/dist/server/common/models/persistence.model.js.map +1 -1
- package/dist/server/modules/auth/auth.controller.js +3 -0
- package/dist/server/modules/auth/auth.controller.js.map +1 -1
- package/dist/server/modules/auth/auth.model.js +4 -0
- package/dist/server/modules/auth/auth.model.js.map +1 -1
- package/dist/server/modules/auth/auth.resolver.js +5 -0
- package/dist/server/modules/auth/auth.resolver.js.map +1 -1
- package/dist/server/modules/auth/inputs/auth-sign-in.input.js +3 -0
- package/dist/server/modules/auth/inputs/auth-sign-in.input.js.map +1 -1
- package/dist/server/modules/auth/inputs/auth-sign-up.input.js +5 -0
- package/dist/server/modules/auth/inputs/auth-sign-up.input.js.map +1 -1
- package/dist/server/modules/file/file-info.model.js +3 -0
- package/dist/server/modules/file/file-info.model.js.map +1 -1
- package/dist/server/modules/file/file.controller.js +4 -0
- package/dist/server/modules/file/file.controller.js.map +1 -1
- package/dist/server/modules/user/avatar.controller.js +1 -0
- package/dist/server/modules/user/avatar.controller.js.map +1 -1
- package/dist/server/modules/user/inputs/user-create.input.js +3 -0
- package/dist/server/modules/user/inputs/user-create.input.js.map +1 -1
- package/dist/server/modules/user/inputs/user.input.js +3 -0
- package/dist/server/modules/user/inputs/user.input.js.map +1 -1
- package/dist/server/modules/user/outputs/find-and-count-users-result.output.js +5 -0
- package/dist/server/modules/user/outputs/find-and-count-users-result.output.js.map +1 -1
- package/dist/server/modules/user/user.model.d.ts +1 -0
- package/dist/server/modules/user/user.model.js +14 -0
- package/dist/server/modules/user/user.model.js.map +1 -1
- package/dist/server/server.controller.js +2 -0
- package/dist/server/server.controller.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/common/inputs/combined-filter.input.ts +5 -0
- package/src/core/common/inputs/filter.input.ts +5 -0
- package/src/core/common/inputs/single-filter.input.ts +10 -0
- package/src/core/common/inputs/sort.input.ts +5 -0
- package/src/core/common/models/core-persistence.model.ts +1 -0
- package/src/core/modules/auth/core-auth.controller.ts +7 -0
- package/src/core/modules/auth/core-auth.model.ts +6 -0
- package/src/core/modules/auth/core-auth.resolver.ts +7 -0
- package/src/core/modules/auth/inputs/core-auth-sign-in.input.ts +7 -0
- package/src/core/modules/auth/inputs/core-auth-sign-up.input.ts +3 -0
- package/src/core/modules/file/core-file-info.model.ts +10 -0
- package/src/core/modules/file/core-file.controller.ts +4 -0
- package/src/core/modules/file/core-file.resolver.ts +7 -0
- package/src/core/modules/health-check/core-health-check-result.model.ts +7 -0
- package/src/core/modules/health-check/core-health-check.controller.ts +4 -0
- package/src/core/modules/user/core-user.model.ts +15 -0
- package/src/core/modules/user/inputs/core-user-create.input.ts +4 -0
- package/src/core/modules/user/inputs/core-user.input.ts +6 -0
- package/src/server/common/models/persistence.model.ts +5 -0
- package/src/server/modules/auth/auth.controller.ts +3 -0
- package/src/server/modules/auth/auth.model.ts +4 -0
- package/src/server/modules/auth/auth.resolver.ts +5 -0
- package/src/server/modules/auth/inputs/auth-sign-in.input.ts +3 -0
- package/src/server/modules/auth/inputs/auth-sign-up.input.ts +5 -0
- package/src/server/modules/file/file-info.model.ts +3 -0
- package/src/server/modules/file/file.controller.ts +4 -0
- package/src/server/modules/user/avatar.controller.ts +1 -0
- package/src/server/modules/user/inputs/user-create.input.ts +3 -0
- package/src/server/modules/user/inputs/user.input.ts +3 -0
- package/src/server/modules/user/outputs/find-and-count-users-result.output.ts +5 -0
- package/src/server/modules/user/user.model.ts +15 -0
- package/src/server/server.controller.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "10.3.
|
|
3
|
+
"version": "10.3.2",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Field, InputType } from '@nestjs/graphql';
|
|
2
2
|
|
|
3
|
+
import { Restricted } from '../decorators/restricted.decorator';
|
|
3
4
|
import { LogicalOperatorEnum } from '../enums/logical-operator.enum';
|
|
5
|
+
import { RoleEnum } from '../enums/role.enum';
|
|
4
6
|
import { maps } from '../helpers/model.helper';
|
|
5
7
|
import { CoreInput } from './core-input.input';
|
|
6
8
|
import { FilterInput } from './filter.input';
|
|
7
9
|
|
|
10
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
8
11
|
@InputType({
|
|
9
12
|
description: 'Combination of multiple filters via logical operator',
|
|
10
13
|
})
|
|
@@ -12,6 +15,7 @@ export class CombinedFilterInput extends CoreInput {
|
|
|
12
15
|
/**
|
|
13
16
|
* Logical Operator to combine filters
|
|
14
17
|
*/
|
|
18
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
15
19
|
@Field(type => LogicalOperatorEnum, {
|
|
16
20
|
description: 'Logical Operator to combine filters',
|
|
17
21
|
})
|
|
@@ -20,6 +24,7 @@ export class CombinedFilterInput extends CoreInput {
|
|
|
20
24
|
/**
|
|
21
25
|
* Filters to combine via logical operator
|
|
22
26
|
*/
|
|
27
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
23
28
|
@Field(type => [FilterInput], {
|
|
24
29
|
description: 'Filters to combine via logical operator',
|
|
25
30
|
})
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Field, InputType } from '@nestjs/graphql';
|
|
2
2
|
|
|
3
|
+
import { Restricted } from '../decorators/restricted.decorator';
|
|
4
|
+
import { RoleEnum } from '../enums/role.enum';
|
|
3
5
|
import { CombinedFilterInput } from './combined-filter.input';
|
|
4
6
|
import { CoreInput } from './core-input.input';
|
|
5
7
|
import { SingleFilterInput } from './single-filter.input';
|
|
@@ -7,6 +9,7 @@ import { SingleFilterInput } from './single-filter.input';
|
|
|
7
9
|
/**
|
|
8
10
|
* Input for filtering. The `singleFilter` will be ignored if the `combinedFilter` is set.
|
|
9
11
|
*/
|
|
12
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
10
13
|
@InputType({
|
|
11
14
|
description: 'Input for filtering. The `singleFilter` will be ignored if the `combinedFilter` is set.',
|
|
12
15
|
})
|
|
@@ -14,6 +17,7 @@ export class FilterInput extends CoreInput {
|
|
|
14
17
|
/**
|
|
15
18
|
* Combination of multiple filters via logical operator
|
|
16
19
|
*/
|
|
20
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
17
21
|
@Field(type => CombinedFilterInput, {
|
|
18
22
|
description: 'Combination of multiple filters via logical operator',
|
|
19
23
|
nullable: true,
|
|
@@ -23,6 +27,7 @@ export class FilterInput extends CoreInput {
|
|
|
23
27
|
/**
|
|
24
28
|
* Filter for a single property
|
|
25
29
|
*/
|
|
30
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
26
31
|
@Field(type => SingleFilterInput, {
|
|
27
32
|
description: 'Filter for a single property',
|
|
28
33
|
nullable: true,
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { Field, InputType } from '@nestjs/graphql';
|
|
2
2
|
|
|
3
|
+
import { Restricted } from '../decorators/restricted.decorator';
|
|
3
4
|
import { ComparisonOperatorEnum } from '../enums/comparison-operator.enum';
|
|
5
|
+
import { RoleEnum } from '../enums/role.enum';
|
|
4
6
|
import { JSON } from '../scalars/json.scalar';
|
|
5
7
|
import { CoreInput } from './core-input.input';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Input for a configuration of a filter
|
|
9
11
|
*/
|
|
12
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
10
13
|
@InputType({ description: 'Input for a configuration of a filter' })
|
|
11
14
|
export class SingleFilterInput extends CoreInput {
|
|
12
15
|
/**
|
|
13
16
|
* Convert value to ObjectId
|
|
14
17
|
*/
|
|
18
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
15
19
|
@Field({
|
|
16
20
|
description: 'Convert value to ObjectId',
|
|
17
21
|
nullable: true,
|
|
@@ -21,12 +25,14 @@ export class SingleFilterInput extends CoreInput {
|
|
|
21
25
|
/**
|
|
22
26
|
* Name of the property to be used for the filter
|
|
23
27
|
*/
|
|
28
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
24
29
|
@Field({ description: 'Name of the property to be used for the filter' })
|
|
25
30
|
field: string = undefined;
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
33
|
* Process value as reference
|
|
29
34
|
*/
|
|
35
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
30
36
|
@Field({
|
|
31
37
|
description: 'Process value as reference',
|
|
32
38
|
nullable: true,
|
|
@@ -36,6 +42,7 @@ export class SingleFilterInput extends CoreInput {
|
|
|
36
42
|
/**
|
|
37
43
|
* [Negate operator](https://docs.mongodb.com/manual/reference/operator/query/not/)
|
|
38
44
|
*/
|
|
45
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
39
46
|
@Field({
|
|
40
47
|
description: '[Negate operator](https://docs.mongodb.com/manual/reference/operator/query/not/)',
|
|
41
48
|
nullable: true,
|
|
@@ -45,6 +52,7 @@ export class SingleFilterInput extends CoreInput {
|
|
|
45
52
|
/**
|
|
46
53
|
* [Comparison operator](https://docs.mongodb.com/manual/reference/operator/query-comparison/)
|
|
47
54
|
*/
|
|
55
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
48
56
|
@Field(type => ComparisonOperatorEnum, {
|
|
49
57
|
description: '[Comparison operator](https://docs.mongodb.com/manual/reference/operator/query-comparison/)',
|
|
50
58
|
})
|
|
@@ -54,6 +62,7 @@ export class SingleFilterInput extends CoreInput {
|
|
|
54
62
|
* [Options](https://docs.mongodb.com/manual/reference/operator/query/regex/#op._S_options) for
|
|
55
63
|
* [REGEX](https://docs.mongodb.com/manual/reference/operator/query/regex/) operator
|
|
56
64
|
*/
|
|
65
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
57
66
|
@Field({
|
|
58
67
|
description:
|
|
59
68
|
'[Options](https://docs.mongodb.com/manual/reference/operator/query/regex/#op._S_options) for '
|
|
@@ -62,6 +71,7 @@ export class SingleFilterInput extends CoreInput {
|
|
|
62
71
|
})
|
|
63
72
|
options?: string = undefined;
|
|
64
73
|
|
|
74
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
65
75
|
@Field(type => JSON, { description: 'Value of the property' })
|
|
66
76
|
value: any = undefined;
|
|
67
77
|
}
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { Field, InputType } from '@nestjs/graphql';
|
|
2
2
|
|
|
3
|
+
import { Restricted } from '../decorators/restricted.decorator';
|
|
4
|
+
import { RoleEnum } from '../enums/role.enum';
|
|
3
5
|
import { SortOrderEnum } from '../enums/sort-order.emum';
|
|
4
6
|
import { CoreInput } from './core-input.input';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Sorting the returned elements
|
|
8
10
|
*/
|
|
11
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
9
12
|
@InputType({ description: 'Sorting the returned elements' })
|
|
10
13
|
export class SortInput extends CoreInput {
|
|
11
14
|
/**
|
|
12
15
|
* Field that is to be used for sorting
|
|
13
16
|
*/
|
|
17
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
14
18
|
@Field({ description: 'Field that is to be used for sorting' })
|
|
15
19
|
field: string = undefined;
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
22
|
* SortInput order of the field
|
|
19
23
|
*/
|
|
24
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
20
25
|
@Field(type => SortOrderEnum, { description: 'SortInput order of the field' })
|
|
21
26
|
order: SortOrderEnum = undefined;
|
|
22
27
|
}
|
|
@@ -18,6 +18,7 @@ import { CoreModel } from './core-model.model';
|
|
|
18
18
|
* with undefined if possible. If necessary and useful, the init method can then be used deliberately:
|
|
19
19
|
* const corePersistenceModel = item ? CorePersistenceModel.map(item).init() : CorePersistenceModel.init();
|
|
20
20
|
*/
|
|
21
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
21
22
|
@ObjectType({
|
|
22
23
|
description: 'Persistence model which will be saved in DB',
|
|
23
24
|
isAbstract: true,
|
|
@@ -3,6 +3,8 @@ import { Args } from '@nestjs/graphql';
|
|
|
3
3
|
import { Response as ResponseType } from 'express';
|
|
4
4
|
|
|
5
5
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
6
|
+
import { Roles } from '../../common/decorators/roles.decorator';
|
|
7
|
+
import { RoleEnum } from '../../common/enums/role.enum';
|
|
6
8
|
import { ConfigService } from '../../common/services/config.service';
|
|
7
9
|
import { AuthGuardStrategy } from './auth-guard-strategy.enum';
|
|
8
10
|
import { CoreAuthModel } from './core-auth.model';
|
|
@@ -13,6 +15,7 @@ import { ICoreAuthUser } from './interfaces/core-auth-user.interface';
|
|
|
13
15
|
import { CoreAuthService } from './services/core-auth.service';
|
|
14
16
|
import { Tokens } from './tokens.decorator';
|
|
15
17
|
|
|
18
|
+
@Roles(RoleEnum.ADMIN)
|
|
16
19
|
@Controller('auth')
|
|
17
20
|
export class CoreAuthController {
|
|
18
21
|
/**
|
|
@@ -26,6 +29,7 @@ export class CoreAuthController {
|
|
|
26
29
|
/**
|
|
27
30
|
* Logout user (from specific device)
|
|
28
31
|
*/
|
|
32
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
29
33
|
@UseGuards(AuthGuard(AuthGuardStrategy.JWT))
|
|
30
34
|
@Get()
|
|
31
35
|
async logout(
|
|
@@ -41,6 +45,7 @@ export class CoreAuthController {
|
|
|
41
45
|
/**
|
|
42
46
|
* Refresh token (for specific device)
|
|
43
47
|
*/
|
|
48
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
44
49
|
@UseGuards(AuthGuard(AuthGuardStrategy.JWT_REFRESH))
|
|
45
50
|
@Get()
|
|
46
51
|
async refreshToken(
|
|
@@ -55,6 +60,7 @@ export class CoreAuthController {
|
|
|
55
60
|
/**
|
|
56
61
|
* Sign in user via email and password (on specific device)
|
|
57
62
|
*/
|
|
63
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
58
64
|
@Post()
|
|
59
65
|
async signIn(@Res() res: ResponseType, @Body('input') input: CoreAuthSignInInput): Promise<CoreAuthModel> {
|
|
60
66
|
const result = await this.authService.signIn(input);
|
|
@@ -64,6 +70,7 @@ export class CoreAuthController {
|
|
|
64
70
|
/**
|
|
65
71
|
* Register a new user account (on specific device)
|
|
66
72
|
*/
|
|
73
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
67
74
|
@Post()
|
|
68
75
|
async signUp(@Res() res: ResponseType, @Args('input') input: CoreAuthSignUpInput): Promise<CoreAuthModel> {
|
|
69
76
|
const result = await this.authService.signUp(input);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Field, ObjectType } from '@nestjs/graphql';
|
|
2
2
|
|
|
3
|
+
import { Restricted } from '../../common/decorators/restricted.decorator';
|
|
4
|
+
import { RoleEnum } from '../../common/enums/role.enum';
|
|
3
5
|
import { CoreModel } from '../../common/models/core-model.model';
|
|
4
6
|
import { CoreUserModel } from '../user/core-user.model';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* CoreAuth model for the response after the sign in
|
|
8
10
|
*/
|
|
11
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
9
12
|
@ObjectType({ description: 'CoreAuth', isAbstract: true })
|
|
10
13
|
export class CoreAuthModel extends CoreModel {
|
|
11
14
|
// ===================================================================================================================
|
|
@@ -15,18 +18,21 @@ export class CoreAuthModel extends CoreModel {
|
|
|
15
18
|
/**
|
|
16
19
|
* JavaScript Web Token (JWT)
|
|
17
20
|
*/
|
|
21
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
18
22
|
@Field({ description: 'JavaScript Web Token (JWT)', nullable: true })
|
|
19
23
|
token?: string = undefined;
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Refresh token
|
|
23
27
|
*/
|
|
28
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
24
29
|
@Field({ description: 'Refresh token', nullable: true })
|
|
25
30
|
refreshToken?: string = undefined;
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
33
|
* Current user
|
|
29
34
|
*/
|
|
35
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
30
36
|
@Field({ description: 'Current user' })
|
|
31
37
|
user: CoreUserModel = undefined;
|
|
32
38
|
|
|
@@ -4,6 +4,8 @@ import { Response as ResponseType } from 'express';
|
|
|
4
4
|
|
|
5
5
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
6
6
|
import { GraphQLServiceOptions } from '../../common/decorators/graphql-service-options.decorator';
|
|
7
|
+
import { Roles } from '../../common/decorators/roles.decorator';
|
|
8
|
+
import { RoleEnum } from '../../common/enums/role.enum';
|
|
7
9
|
import { ServiceOptions } from '../../common/interfaces/service-options.interface';
|
|
8
10
|
import { ConfigService } from '../../common/services/config.service';
|
|
9
11
|
import { AuthGuardStrategy } from './auth-guard-strategy.enum';
|
|
@@ -18,6 +20,7 @@ import { Tokens } from './tokens.decorator';
|
|
|
18
20
|
/**
|
|
19
21
|
* Authentication resolver for the sign in
|
|
20
22
|
*/
|
|
23
|
+
@Roles(RoleEnum.ADMIN)
|
|
21
24
|
@Resolver(of => CoreAuthModel, { isAbstract: true })
|
|
22
25
|
export class CoreAuthResolver {
|
|
23
26
|
/**
|
|
@@ -35,6 +38,7 @@ export class CoreAuthResolver {
|
|
|
35
38
|
/**
|
|
36
39
|
* Logout user (from specific device)
|
|
37
40
|
*/
|
|
41
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
38
42
|
@UseGuards(AuthGuard(AuthGuardStrategy.JWT))
|
|
39
43
|
@Mutation(returns => Boolean, { description: 'Logout user (from specific device)' })
|
|
40
44
|
async logout(
|
|
@@ -50,6 +54,7 @@ export class CoreAuthResolver {
|
|
|
50
54
|
/**
|
|
51
55
|
* Refresh token (for specific device)
|
|
52
56
|
*/
|
|
57
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
53
58
|
@UseGuards(AuthGuard(AuthGuardStrategy.JWT_REFRESH))
|
|
54
59
|
@Mutation(returns => CoreAuthModel, { description: 'Refresh tokens (for specific device)' })
|
|
55
60
|
async refreshToken(
|
|
@@ -64,6 +69,7 @@ export class CoreAuthResolver {
|
|
|
64
69
|
/**
|
|
65
70
|
* Sign in user via email and password (on specific device)
|
|
66
71
|
*/
|
|
72
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
67
73
|
@Mutation(returns => CoreAuthModel, {
|
|
68
74
|
description: 'Sign in user via email and password and get JWT tokens (for specific device)',
|
|
69
75
|
})
|
|
@@ -79,6 +85,7 @@ export class CoreAuthResolver {
|
|
|
79
85
|
/**
|
|
80
86
|
* Register a new user account (on specific device)
|
|
81
87
|
*/
|
|
88
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
82
89
|
@Mutation(returns => CoreAuthModel, { description: 'Register a new user account (on specific device)' })
|
|
83
90
|
async signUp(
|
|
84
91
|
@GraphQLServiceOptions({ gqlPath: 'signUp.user' }) serviceOptions: ServiceOptions,
|
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
import { Field, InputType } from '@nestjs/graphql';
|
|
2
2
|
|
|
3
|
+
import { Restricted } from '../../../common/decorators/restricted.decorator';
|
|
4
|
+
import { RoleEnum } from '../../../common/enums/role.enum';
|
|
3
5
|
import { CoreInput } from '../../../common/inputs/core-input.input';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* SignIn input
|
|
7
9
|
*/
|
|
10
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
8
11
|
@InputType({ description: 'Sign-in input' })
|
|
9
12
|
export class CoreAuthSignInInput extends CoreInput {
|
|
10
13
|
// ===================================================================================================================
|
|
11
14
|
// Properties
|
|
12
15
|
// ===================================================================================================================
|
|
13
16
|
|
|
17
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
14
18
|
@Field({ description: 'Device ID (is created automatically if it is not set)', nullable: true })
|
|
15
19
|
deviceId?: string = undefined;
|
|
16
20
|
|
|
21
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
17
22
|
@Field({ description: 'Device description', nullable: true })
|
|
18
23
|
deviceDescription?: string = undefined;
|
|
19
24
|
|
|
25
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
20
26
|
@Field({ description: 'Email', nullable: false })
|
|
21
27
|
email: string = undefined;
|
|
22
28
|
|
|
29
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
23
30
|
@Field({ description: 'Password', nullable: false })
|
|
24
31
|
password: string = undefined;
|
|
25
32
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { InputType } from '@nestjs/graphql';
|
|
2
2
|
|
|
3
|
+
import { Restricted } from '../../../common/decorators/restricted.decorator';
|
|
4
|
+
import { RoleEnum } from '../../../common/enums/role.enum';
|
|
3
5
|
import { CoreAuthSignInInput } from './core-auth-sign-in.input';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* SignUp input
|
|
7
9
|
*/
|
|
10
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
8
11
|
@InputType({ description: 'Sign-up input' })
|
|
9
12
|
export class CoreAuthSignUpInput extends CoreAuthSignInInput {}
|
|
@@ -2,17 +2,21 @@ import { Field, ObjectType } from '@nestjs/graphql';
|
|
|
2
2
|
import { Prop } from '@nestjs/mongoose';
|
|
3
3
|
import { Types } from 'mongoose';
|
|
4
4
|
|
|
5
|
+
import { Restricted } from '../../common/decorators/restricted.decorator';
|
|
6
|
+
import { RoleEnum } from '../../common/enums/role.enum';
|
|
5
7
|
import { CoreModel } from '../../common/models/core-model.model';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* File info
|
|
9
11
|
*/
|
|
12
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
10
13
|
@ObjectType({ description: 'Information about file' })
|
|
11
14
|
export class CoreFileInfo extends CoreModel {
|
|
12
15
|
// ===========================================================================
|
|
13
16
|
// Getter
|
|
14
17
|
// ===========================================================================
|
|
15
18
|
|
|
19
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
16
20
|
get _id() {
|
|
17
21
|
return new Types.ObjectId(this.id);
|
|
18
22
|
}
|
|
@@ -21,9 +25,11 @@ export class CoreFileInfo extends CoreModel {
|
|
|
21
25
|
// Properties
|
|
22
26
|
// ===========================================================================
|
|
23
27
|
|
|
28
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
24
29
|
@Field(() => String, { description: 'ID of the file' })
|
|
25
30
|
id: string = undefined;
|
|
26
31
|
|
|
32
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
27
33
|
@Field(() => Number, {
|
|
28
34
|
description:
|
|
29
35
|
'The size of each chunk in bytes. GridFS divides the document into chunks of size chunkSize, '
|
|
@@ -33,18 +39,22 @@ export class CoreFileInfo extends CoreModel {
|
|
|
33
39
|
@Prop({ required: false, type: Number })
|
|
34
40
|
chunkSize: number = undefined;
|
|
35
41
|
|
|
42
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
36
43
|
@Field(() => String, { description: 'Content type', nullable: true })
|
|
37
44
|
@Prop({ required: false, type: String })
|
|
38
45
|
contentType?: string = undefined;
|
|
39
46
|
|
|
47
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
40
48
|
@Field(() => String, { description: 'Name of the file', nullable: true })
|
|
41
49
|
@Prop({ required: false, type: String })
|
|
42
50
|
filename?: string = undefined;
|
|
43
51
|
|
|
52
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
44
53
|
@Field(() => Number, { description: 'The size of the document in bytes', nullable: true })
|
|
45
54
|
@Prop({ required: false, type: Number })
|
|
46
55
|
length: number = undefined;
|
|
47
56
|
|
|
57
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
48
58
|
@Field(() => Date, { description: 'The date the file was first stored', nullable: true })
|
|
49
59
|
@Prop({ required: false, type: Date })
|
|
50
60
|
uploadDate: Date = undefined;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { BadRequestException, Controller, Get, NotFoundException, Param, Res } from '@nestjs/common';
|
|
2
2
|
|
|
3
|
+
import { Roles } from '../../common/decorators/roles.decorator';
|
|
4
|
+
import { RoleEnum } from '../../common/enums/role.enum';
|
|
3
5
|
import { CoreFileService } from './core-file.service';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* File controller
|
|
7
9
|
*/
|
|
10
|
+
@Roles(RoleEnum.ADMIN)
|
|
8
11
|
@Controller('files')
|
|
9
12
|
export abstract class CoreFileController {
|
|
10
13
|
/**
|
|
@@ -15,6 +18,7 @@ export abstract class CoreFileController {
|
|
|
15
18
|
/**
|
|
16
19
|
* Download file
|
|
17
20
|
*/
|
|
21
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
18
22
|
@Get(':filename')
|
|
19
23
|
async getFile(@Param('filename') filename: string, @Res() res) {
|
|
20
24
|
if (!filename) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
|
2
2
|
import * as GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
|
|
3
3
|
|
|
4
|
+
import { Roles } from '../../common/decorators/roles.decorator';
|
|
5
|
+
import { RoleEnum } from '../../common/enums/role.enum';
|
|
4
6
|
import { CoreFileService } from './core-file.service';
|
|
5
7
|
import { CoreFileInfo } from './core-file-info.model';
|
|
6
8
|
import { FileUpload } from './interfaces/file-upload.interface';
|
|
@@ -8,6 +10,7 @@ import { FileUpload } from './interfaces/file-upload.interface';
|
|
|
8
10
|
/**
|
|
9
11
|
* File resolver
|
|
10
12
|
*/
|
|
13
|
+
@Roles(RoleEnum.ADMIN)
|
|
11
14
|
@Resolver()
|
|
12
15
|
export class CoreFileResolver {
|
|
13
16
|
/**
|
|
@@ -22,6 +25,7 @@ export class CoreFileResolver {
|
|
|
22
25
|
/**
|
|
23
26
|
* Get file info
|
|
24
27
|
*/
|
|
28
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
25
29
|
@Query(() => CoreFileInfo, { nullable: true })
|
|
26
30
|
async getFileInfo(@Args({ name: 'filename', type: () => String }) filename: string): Promise<any> {
|
|
27
31
|
return await this.fileService.getFileInfoByName(filename);
|
|
@@ -34,6 +38,7 @@ export class CoreFileResolver {
|
|
|
34
38
|
/**
|
|
35
39
|
* Delete file
|
|
36
40
|
*/
|
|
41
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
37
42
|
@Mutation(() => CoreFileInfo)
|
|
38
43
|
async deleteFile(@Args({ name: 'filename', type: () => String }) filename: string): Promise<any> {
|
|
39
44
|
return await this.fileService.deleteFileByName(filename);
|
|
@@ -42,6 +47,7 @@ export class CoreFileResolver {
|
|
|
42
47
|
/**
|
|
43
48
|
* Upload file
|
|
44
49
|
*/
|
|
50
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
45
51
|
@Mutation(() => CoreFileInfo)
|
|
46
52
|
async uploadFile(@Args({ name: 'file', type: () => GraphQLUpload }) file: FileUpload): Promise<any> {
|
|
47
53
|
return await this.fileService.createFile(file);
|
|
@@ -50,6 +56,7 @@ export class CoreFileResolver {
|
|
|
50
56
|
/**
|
|
51
57
|
* Upload files
|
|
52
58
|
*/
|
|
59
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
53
60
|
@Mutation(() => [CoreFileInfo])
|
|
54
61
|
async uploadFiles(@Args({ name: 'files', type: () => [GraphQLUpload] }) files: FileUpload[]): Promise<any> {
|
|
55
62
|
return await this.fileService.createFiles(files);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Field, ObjectType } from '@nestjs/graphql';
|
|
2
2
|
|
|
3
|
+
import { Restricted } from '../../common/decorators/restricted.decorator';
|
|
4
|
+
import { RoleEnum } from '../../common/enums/role.enum';
|
|
3
5
|
import { CoreModel } from '../../common/models/core-model.model';
|
|
4
6
|
import { JSON } from '../../common/scalars/json.scalar';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* User model
|
|
8
10
|
*/
|
|
11
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
9
12
|
@ObjectType({ description: 'Health check result' })
|
|
10
13
|
export abstract class CoreHealthCheckResult extends CoreModel {
|
|
11
14
|
// ===================================================================================================================
|
|
@@ -15,12 +18,14 @@ export abstract class CoreHealthCheckResult extends CoreModel {
|
|
|
15
18
|
/**
|
|
16
19
|
* The overall status of the Health Check
|
|
17
20
|
*/
|
|
21
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
18
22
|
@Field({ description: 'The overall status of the Health Check', nullable: false })
|
|
19
23
|
status: 'error' | 'ok' | 'shutting_down' = undefined;
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* The info object contains information of each health indicator which is of status “up”
|
|
23
27
|
*/
|
|
28
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
24
29
|
@Field(type => JSON, {
|
|
25
30
|
description: 'The info object contains information of each health indicator which is of status “up”',
|
|
26
31
|
nullable: true,
|
|
@@ -30,6 +35,7 @@ export abstract class CoreHealthCheckResult extends CoreModel {
|
|
|
30
35
|
/**
|
|
31
36
|
* The error object contains information of each health indicator which is of status “down”
|
|
32
37
|
*/
|
|
38
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
33
39
|
@Field(type => JSON, {
|
|
34
40
|
description: 'The error object contains information of each health indicator which is of status “down”',
|
|
35
41
|
nullable: true,
|
|
@@ -39,6 +45,7 @@ export abstract class CoreHealthCheckResult extends CoreModel {
|
|
|
39
45
|
/**
|
|
40
46
|
* The details object contains information of every health indicator
|
|
41
47
|
*/
|
|
48
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
42
49
|
@Field(type => JSON, {
|
|
43
50
|
description: 'The details object contains information of every health indicator',
|
|
44
51
|
nullable: false,
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Controller, Get } from '@nestjs/common';
|
|
2
2
|
|
|
3
|
+
import { Roles } from '../../common/decorators/roles.decorator';
|
|
4
|
+
import { RoleEnum } from '../../common/enums/role.enum';
|
|
3
5
|
import { CoreHealthCheckService } from './core-health-check.service';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* The HealthController class checks the health of various components including the database, memory, and disk.
|
|
7
9
|
* Inspired by https://mobileappcircular.com/marketplace-backend-creating-a-health-check-endpoint-in-nestjs-app-using-terminus-25727e96c7d2
|
|
8
10
|
*/
|
|
11
|
+
@Roles(RoleEnum.ADMIN)
|
|
9
12
|
@Controller()
|
|
10
13
|
export class CoreHealthCheckController {
|
|
11
14
|
constructor(protected readonly healthCheckService: CoreHealthCheckService) {}
|
|
@@ -18,6 +21,7 @@ export class CoreHealthCheckController {
|
|
|
18
21
|
* storage. The `healthCheck()` method will return a Promise that resolves with an array of objects
|
|
19
22
|
* representing the results of each check
|
|
20
23
|
*/
|
|
24
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
21
25
|
@Get('health-check')
|
|
22
26
|
async healthCheck() {
|
|
23
27
|
return this.healthCheckService.healthCheck();
|
|
@@ -3,6 +3,8 @@ import { Schema as MongooseSchema, Prop, raw } from '@nestjs/mongoose';
|
|
|
3
3
|
import { IsEmail, IsOptional } from 'class-validator';
|
|
4
4
|
import { Document } from 'mongoose';
|
|
5
5
|
|
|
6
|
+
import { Restricted } from '../../common/decorators/restricted.decorator';
|
|
7
|
+
import { RoleEnum } from '../../common/enums/role.enum';
|
|
6
8
|
import { CorePersistenceModel } from '../../common/models/core-persistence.model';
|
|
7
9
|
import { CoreTokenData } from '../auth/interfaces/core-token-data.interface';
|
|
8
10
|
|
|
@@ -11,6 +13,7 @@ export type CoreUserModelDocument = CoreUserModel & Document;
|
|
|
11
13
|
/**
|
|
12
14
|
* User model
|
|
13
15
|
*/
|
|
16
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
14
17
|
@ObjectType({ description: 'User', isAbstract: true })
|
|
15
18
|
@MongooseSchema({ timestamps: true })
|
|
16
19
|
export abstract class CoreUserModel extends CorePersistenceModel {
|
|
@@ -21,6 +24,7 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
21
24
|
/**
|
|
22
25
|
* E-Mail address of the user
|
|
23
26
|
*/
|
|
27
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
24
28
|
@Field({ description: 'Email of the user', nullable: true })
|
|
25
29
|
@IsEmail()
|
|
26
30
|
@Prop({ lowercase: true, trim: true, unique: true })
|
|
@@ -29,6 +33,7 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
29
33
|
/**
|
|
30
34
|
* First name of the user
|
|
31
35
|
*/
|
|
36
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
32
37
|
@Field({ description: 'First name of the user', nullable: true })
|
|
33
38
|
@IsOptional()
|
|
34
39
|
@Prop()
|
|
@@ -37,6 +42,7 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
37
42
|
/**
|
|
38
43
|
* Last name of the user
|
|
39
44
|
*/
|
|
45
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
40
46
|
@Field({ description: 'Last name of the user', nullable: true })
|
|
41
47
|
@IsOptional()
|
|
42
48
|
@Prop()
|
|
@@ -45,12 +51,14 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
45
51
|
/**
|
|
46
52
|
* Password of the user
|
|
47
53
|
*/
|
|
54
|
+
@Restricted(RoleEnum.S_NO_ONE)
|
|
48
55
|
@Prop()
|
|
49
56
|
password: string = undefined;
|
|
50
57
|
|
|
51
58
|
/**
|
|
52
59
|
* Roles of the user
|
|
53
60
|
*/
|
|
61
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
54
62
|
@Field(type => [String], { description: 'Roles of the user', nullable: true })
|
|
55
63
|
@IsOptional()
|
|
56
64
|
@Prop([String])
|
|
@@ -59,6 +67,7 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
59
67
|
/**
|
|
60
68
|
* Username of the user
|
|
61
69
|
*/
|
|
70
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
62
71
|
@Field({ description: 'Username of the user', nullable: true })
|
|
63
72
|
@IsOptional()
|
|
64
73
|
@Prop()
|
|
@@ -67,6 +76,7 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
67
76
|
/**
|
|
68
77
|
* Password reset token of the user
|
|
69
78
|
*/
|
|
79
|
+
@Restricted(RoleEnum.S_NO_ONE)
|
|
70
80
|
@IsOptional()
|
|
71
81
|
@Prop()
|
|
72
82
|
passwordResetToken: string = undefined;
|
|
@@ -76,6 +86,7 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
76
86
|
* key: Token
|
|
77
87
|
* value: TokenData
|
|
78
88
|
*/
|
|
89
|
+
@Restricted(RoleEnum.S_NO_ONE)
|
|
79
90
|
@IsOptional()
|
|
80
91
|
@Prop(raw({}))
|
|
81
92
|
refreshTokens: Record<string, CoreTokenData> = undefined;
|
|
@@ -84,6 +95,7 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
84
95
|
* Temporary token for parallel requests during the token refresh process
|
|
85
96
|
* See sameTokenIdPeriod in configuration
|
|
86
97
|
*/
|
|
98
|
+
@Restricted(RoleEnum.S_NO_ONE)
|
|
87
99
|
@IsOptional()
|
|
88
100
|
@Prop(raw({}))
|
|
89
101
|
tempTokens: Record<string, { createdAt: number; deviceId: string; tokenId: string }> = undefined;
|
|
@@ -91,6 +103,7 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
91
103
|
/**
|
|
92
104
|
* Verification token of the user
|
|
93
105
|
*/
|
|
106
|
+
@Restricted(RoleEnum.S_NO_ONE)
|
|
94
107
|
@IsOptional()
|
|
95
108
|
@Prop()
|
|
96
109
|
verificationToken: string = undefined;
|
|
@@ -98,6 +111,7 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
98
111
|
/**
|
|
99
112
|
* Verification of the user
|
|
100
113
|
*/
|
|
114
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
101
115
|
@Field(type => Boolean, { description: 'Verification state of the user', nullable: true })
|
|
102
116
|
@Prop({ type: Boolean })
|
|
103
117
|
verified: boolean = undefined;
|
|
@@ -105,6 +119,7 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
105
119
|
/**
|
|
106
120
|
* Verification date
|
|
107
121
|
*/
|
|
122
|
+
@Restricted(RoleEnum.S_EVERYONE)
|
|
108
123
|
@Field({ description: 'Verified date', nullable: true })
|
|
109
124
|
@Prop()
|
|
110
125
|
verifiedAt: Date = undefined;
|