@lenne.tech/nest-server 9.0.14 → 9.0.17
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/helpers/input.helper.d.ts +1 -0
- package/dist/core/common/helpers/input.helper.js +20 -1
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/modules/user/core-user.model.d.ts +1 -0
- package/dist/core/modules/user/core-user.model.js +6 -0
- package/dist/core/modules/user/core-user.model.js.map +1 -1
- package/dist/core/modules/user/core-user.service.d.ts +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/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +11 -4
- package/src/core/common/helpers/input.helper.ts +32 -0
- package/src/core/modules/user/core-user.model.ts +7 -0
- package/src/core/modules/user/core-user.service.ts +6 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.17",
|
|
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",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "rimraf dist && tsc -p tsconfig.build.json",
|
|
18
18
|
"build:pack": "npm pack && echo 'use file:/ROOT_PATH_TO_TGZ_FILE to integrate the package'",
|
|
19
|
+
"build:dev": "npm run build && yalc push --private",
|
|
19
20
|
"docs": "npm run docs:ci && open ./public/index.html",
|
|
20
21
|
"docs:bootstrap": "node extras/update-spectaql-version.mjs && npx -y spectaql ./spectaql.yml",
|
|
21
22
|
"docs:ci": "ts-node ./scripts/init-server.ts && npm run docs:bootstrap",
|
|
@@ -45,7 +46,8 @@
|
|
|
45
46
|
"prepack": "npm run prestart:prod",
|
|
46
47
|
"prepare": "husky install",
|
|
47
48
|
"prepublishOnly": "npm run format && npm run lint && npm run test:ci",
|
|
48
|
-
"preversion": "npm run lint"
|
|
49
|
+
"preversion": "npm run lint",
|
|
50
|
+
"watch": "npm-watch"
|
|
49
51
|
},
|
|
50
52
|
"repository": {
|
|
51
53
|
"type": "git",
|
|
@@ -119,6 +121,7 @@
|
|
|
119
121
|
"grunt-sync": "0.8.2",
|
|
120
122
|
"husky": "8.0.1",
|
|
121
123
|
"jest": "29.2.1",
|
|
124
|
+
"npm-watch": "0.11.0",
|
|
122
125
|
"pm2": "5.2.2",
|
|
123
126
|
"prettier": "2.7.1",
|
|
124
127
|
"pretty-quick": "3.1.3",
|
|
@@ -127,7 +130,8 @@
|
|
|
127
130
|
"ts-morph": "16.0.0",
|
|
128
131
|
"ts-node": "10.9.1",
|
|
129
132
|
"tsconfig-paths": "4.1.0",
|
|
130
|
-
"typescript": "4.8.4"
|
|
133
|
+
"typescript": "4.8.4",
|
|
134
|
+
"yalc": "^1.0.0-pre.53"
|
|
131
135
|
},
|
|
132
136
|
"jest": {
|
|
133
137
|
"collectCoverage": true,
|
|
@@ -149,5 +153,8 @@
|
|
|
149
153
|
"files": [
|
|
150
154
|
"dist/**/*",
|
|
151
155
|
"src/**/*"
|
|
152
|
-
]
|
|
156
|
+
],
|
|
157
|
+
"watch": {
|
|
158
|
+
"build:dev": "src"
|
|
159
|
+
}
|
|
153
160
|
}
|
|
@@ -626,3 +626,35 @@ export function instanceofArray(arr: any[], strict = false): string {
|
|
|
626
626
|
}
|
|
627
627
|
return constructor;
|
|
628
628
|
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Process data via function deep
|
|
632
|
+
* @param data
|
|
633
|
+
* @param func
|
|
634
|
+
* @param processedObjects
|
|
635
|
+
*/
|
|
636
|
+
export function processDeep(data: any, func: (data: any) => any, processedObjects = new WeakMap()): any {
|
|
637
|
+
// Prevent circular processing
|
|
638
|
+
if (typeof data === 'object') {
|
|
639
|
+
if (processedObjects.get(data)) {
|
|
640
|
+
return data;
|
|
641
|
+
}
|
|
642
|
+
processedObjects.set(data, true);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// Process array
|
|
646
|
+
if (Array.isArray(data)) {
|
|
647
|
+
return data.map((item) => processDeep(item, func));
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// Process object
|
|
651
|
+
if (typeof data === 'object') {
|
|
652
|
+
for (const [key, value] of Object.entries(data)) {
|
|
653
|
+
data[key] = processDeep(value, func, processedObjects);
|
|
654
|
+
}
|
|
655
|
+
return data;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// Process others
|
|
659
|
+
return func(data);
|
|
660
|
+
}
|
|
@@ -84,6 +84,13 @@ export abstract class CoreUserModel extends CorePersistenceModel {
|
|
|
84
84
|
@Prop({ type: Boolean })
|
|
85
85
|
verified: boolean = undefined;
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Verification date
|
|
89
|
+
*/
|
|
90
|
+
@Field({ description: 'Verified date', nullable: true })
|
|
91
|
+
@Prop()
|
|
92
|
+
verifiedAt: Date = undefined;
|
|
93
|
+
|
|
87
94
|
// ===================================================================================================================
|
|
88
95
|
// Methods
|
|
89
96
|
// ===================================================================================================================
|
|
@@ -98,22 +98,25 @@ export abstract class CoreUserService<
|
|
|
98
98
|
/**
|
|
99
99
|
* Verify user with token
|
|
100
100
|
*/
|
|
101
|
-
async verify(token: string, serviceOptions?: ServiceOptions): Promise<TUser> {
|
|
101
|
+
async verify(token: string, serviceOptions?: ServiceOptions): Promise<TUser | string> {
|
|
102
102
|
// Get user
|
|
103
103
|
const dbObject = await this.mainDbModel.findOne({ verificationToken: token }).exec();
|
|
104
104
|
if (!dbObject) {
|
|
105
105
|
throw new NotFoundException(`No user found with verify token: ${token}`);
|
|
106
106
|
}
|
|
107
|
+
|
|
107
108
|
if (!dbObject.verificationToken) {
|
|
108
109
|
throw new Error('User has no token');
|
|
109
110
|
}
|
|
111
|
+
|
|
110
112
|
if (dbObject.verified) {
|
|
111
|
-
|
|
113
|
+
return 'User already verified';
|
|
112
114
|
}
|
|
115
|
+
|
|
113
116
|
return this.process(
|
|
114
117
|
async () => {
|
|
115
118
|
// Update and return user
|
|
116
|
-
return await assignPlain(dbObject, { verified: true,
|
|
119
|
+
return await assignPlain(dbObject, { verified: true, verifiedAt: new Date() }).save();
|
|
117
120
|
},
|
|
118
121
|
{ dbObject, serviceOptions }
|
|
119
122
|
);
|