@lenne.tech/nest-server 3.1.3 → 3.2.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.
- package/dist/core/common/decorators/restricted.decorator.js +2 -0
- package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
- package/dist/core/common/helpers/model.helper.js +1 -0
- package/dist/core/common/helpers/model.helper.js.map +1 -1
- package/dist/core/common/helpers/service.helper.js +1 -1
- package/dist/core/common/helpers/service.helper.js.map +1 -1
- package/dist/core/common/pipes/map.pipe.d.ts +4 -0
- package/dist/core/common/pipes/map.pipe.js +25 -0
- package/dist/core/common/pipes/map.pipe.js.map +1 -0
- package/dist/core/modules/user/core-user.service.js +1 -1
- package/dist/core/modules/user/core-user.service.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.d.ts +2 -1
- package/dist/core/modules/user/inputs/core-user.input.js +12 -2
- package/dist/core/modules/user/inputs/core-user.input.js.map +1 -1
- package/dist/main.js +2 -0
- package/dist/main.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/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/common/decorators/restricted.decorator.ts +2 -0
- package/src/core/common/helpers/model.helper.ts +3 -0
- package/src/core/common/helpers/service.helper.ts +1 -1
- package/src/core/common/pipes/map.pipe.ts +16 -0
- package/src/core/modules/user/core-user.service.ts +1 -1
- package/src/core/modules/user/inputs/core-user-create.input.ts +1 -1
- package/src/core/modules/user/inputs/core-user.input.ts +9 -8
- package/src/main.ts +4 -0
- package/src/server/modules/user/user.resolver.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
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",
|
|
@@ -77,6 +77,9 @@ export class ModelHelper {
|
|
|
77
77
|
// Merge target with prepared source
|
|
78
78
|
Object.assign(target, preparedSource);
|
|
79
79
|
|
|
80
|
+
// Remove all props with undefined
|
|
81
|
+
Object.keys(target).forEach((key) => target[key] === undefined && delete target[key]);
|
|
82
|
+
|
|
80
83
|
// Return target
|
|
81
84
|
return target;
|
|
82
85
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
@Injectable()
|
|
4
|
+
export class MapPipe implements PipeTransform {
|
|
5
|
+
transform(value: any, metadata: ArgumentMetadata) {
|
|
6
|
+
let result = value;
|
|
7
|
+
|
|
8
|
+
// Check map function is available
|
|
9
|
+
if ((metadata.metatype as any)?.map) {
|
|
10
|
+
// Map object to correct type
|
|
11
|
+
result = (metadata.metatype as any).map(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -2,53 +2,54 @@ import { IsEmail, IsOptional } from 'class-validator';
|
|
|
2
2
|
import { Field, InputType } from '@nestjs/graphql';
|
|
3
3
|
import { Restricted } from '../../../common/decorators/restricted.decorator';
|
|
4
4
|
import { RoleEnum } from '../../../common/enums/role.enum';
|
|
5
|
+
import { CoreModel } from '../../../common/models/core-model.model';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* User input to update a user
|
|
8
9
|
*/
|
|
9
10
|
@InputType({ description: 'User input', isAbstract: true })
|
|
10
|
-
export abstract class CoreUserInput {
|
|
11
|
+
export abstract class CoreUserInput extends CoreModel {
|
|
11
12
|
/**
|
|
12
13
|
* Email of the user
|
|
13
14
|
*/
|
|
14
15
|
@Field({ description: 'Email of the user', nullable: true })
|
|
15
16
|
@IsOptional()
|
|
16
17
|
@IsEmail()
|
|
17
|
-
email?: string;
|
|
18
|
+
email?: string = undefined;
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* First name of the user
|
|
21
22
|
*/
|
|
22
23
|
@Field({ description: 'First name of the user', nullable: true })
|
|
23
24
|
@IsOptional()
|
|
24
|
-
firstName?: string;
|
|
25
|
+
firstName?: string = undefined;
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Last name of the user
|
|
28
29
|
*/
|
|
29
30
|
@Field({ description: 'Last name of the user', nullable: true })
|
|
30
31
|
@IsOptional()
|
|
31
|
-
lastName?: string;
|
|
32
|
+
lastName?: string = undefined;
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Roles of the user
|
|
35
36
|
*/
|
|
36
|
-
@Restricted(RoleEnum.ADMIN
|
|
37
|
+
@Restricted(RoleEnum.ADMIN)
|
|
37
38
|
@Field((type) => [String], { description: 'Roles of the user', nullable: true })
|
|
38
39
|
@IsOptional()
|
|
39
|
-
roles?: string[];
|
|
40
|
+
roles?: string[] = [];
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* Username / alias of the user
|
|
43
44
|
*/
|
|
44
45
|
@Field({ description: 'Username / alias of the user', nullable: true })
|
|
45
46
|
@IsOptional()
|
|
46
|
-
username?: string;
|
|
47
|
+
username?: string = undefined;
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
* Password of the user
|
|
50
51
|
*/
|
|
51
52
|
@Field({ description: 'Password of the user', nullable: true })
|
|
52
53
|
@IsOptional()
|
|
53
|
-
password?: string;
|
|
54
|
+
password?: string = undefined;
|
|
54
55
|
}
|
package/src/main.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { NestFactory } from '@nestjs/core';
|
|
|
2
2
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
3
3
|
import envConfig from './config.env';
|
|
4
4
|
import { ServerModule } from './server/server.module';
|
|
5
|
+
import { MapPipe } from './core/common/pipes/map.pipe';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Preparations for server start
|
|
@@ -13,6 +14,9 @@ async function bootstrap() {
|
|
|
13
14
|
ServerModule
|
|
14
15
|
);
|
|
15
16
|
|
|
17
|
+
// Add map pipe for mapping inputs to class
|
|
18
|
+
server.useGlobalPipes(new MapPipe());
|
|
19
|
+
|
|
16
20
|
// Asset directory
|
|
17
21
|
server.useStaticAssets(envConfig.staticAssets.path, envConfig.staticAssets.options);
|
|
18
22
|
|
|
@@ -88,7 +88,7 @@ export class UserResolver {
|
|
|
88
88
|
@Roles(RoleEnum.ADMIN, RoleEnum.OWNER)
|
|
89
89
|
@Mutation((returns) => User, { description: 'Update existing user' })
|
|
90
90
|
async updateUser(
|
|
91
|
-
@Args('input') input: UserInput,
|
|
91
|
+
@Args('input', { type: () => UserInput }) input: UserInput,
|
|
92
92
|
@Args('id') id: string,
|
|
93
93
|
@GraphQLUser() user: User,
|
|
94
94
|
@Info() info: GraphQLResolveInfo
|