@lenne.tech/nest-server 8.6.5 → 8.6.8
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 +4 -4
- package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
- package/dist/core/common/helpers/db.helper.js +3 -2
- package/dist/core/common/helpers/db.helper.js.map +1 -1
- package/dist/core/common/helpers/file.helper.js +4 -7
- package/dist/core/common/helpers/file.helper.js.map +1 -1
- package/dist/core/common/helpers/filter.helper.d.ts +7 -0
- package/dist/core/common/helpers/filter.helper.js +38 -1
- package/dist/core/common/helpers/filter.helper.js.map +1 -1
- package/dist/core/common/helpers/input.helper.d.ts +6 -0
- package/dist/core/common/helpers/input.helper.js +28 -6
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/common/helpers/service.helper.d.ts +2 -0
- package/dist/core/common/helpers/service.helper.js +7 -9
- package/dist/core/common/helpers/service.helper.js.map +1 -1
- package/dist/core/common/interfaces/prepare-input-options.interface.d.ts +1 -0
- package/dist/core/common/interfaces/prepare-output-options.interface.d.ts +1 -0
- package/dist/core/common/interfaces/service-options.interface.d.ts +3 -1
- package/dist/core/common/models/core-model.model.js +4 -1
- package/dist/core/common/models/core-model.model.js.map +1 -1
- package/dist/core/common/services/crud.service.js +9 -4
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/core/common/services/mailjet.service.d.ts +1 -1
- package/dist/core/common/services/mailjet.service.js +2 -2
- package/dist/core/common/services/mailjet.service.js.map +1 -1
- package/dist/core/common/services/module.service.js +14 -2
- package/dist/core/common/services/module.service.js.map +1 -1
- package/dist/core/common/types/field-selection.type.d.ts +1 -1
- package/dist/core/modules/auth/guards/roles.guard.js +2 -1
- package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
- package/dist/core/modules/user/core-user.service.js +9 -13
- package/dist/core/modules/user/core-user.service.js.map +1 -1
- package/dist/core.module.js +2 -2
- package/dist/core.module.js.map +1 -1
- package/dist/server/modules/file/file.resolver.d.ts +1 -1
- package/dist/server/modules/file/file.resolver.js +4 -5
- package/dist/server/modules/file/file.resolver.js.map +1 -1
- package/dist/server/modules/user/user.model.d.ts +14 -1
- package/dist/server/modules/user/user.resolver.js +2 -1
- package/dist/server/modules/user/user.resolver.js.map +1 -1
- package/dist/test/test.helper.js +11 -25
- package/dist/test/test.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +33 -32
- package/src/core/common/decorators/restricted.decorator.ts +1 -2
- package/src/core/common/helpers/db.helper.ts +7 -2
- package/src/core/common/helpers/file.helper.ts +9 -11
- package/src/core/common/helpers/filter.helper.ts +66 -1
- package/src/core/common/helpers/input.helper.ts +61 -2
- package/src/core/common/helpers/service.helper.ts +8 -9
- package/src/core/common/interfaces/prepare-input-options.interface.ts +1 -0
- package/src/core/common/interfaces/prepare-output-options.interface.ts +1 -0
- package/src/core/common/interfaces/service-options.interface.ts +8 -2
- package/src/core/common/models/core-model.model.ts +4 -1
- package/src/core/common/services/crud.service.ts +7 -4
- package/src/core/common/services/mailjet.service.ts +1 -1
- package/src/core/common/services/module.service.ts +17 -1
- package/src/core/common/types/field-selection.type.ts +1 -1
- package/src/core/modules/auth/guards/roles.guard.ts +1 -1
- package/src/core/modules/user/core-user.service.ts +13 -22
- package/src/core.module.ts +1 -1
- package/src/server/modules/file/file.resolver.ts +2 -1
- package/src/server/modules/user/user.resolver.ts +1 -1
- package/src/test/test.helper.ts +27 -34
|
@@ -3,6 +3,7 @@ import * as bcrypt from 'bcrypt';
|
|
|
3
3
|
import * as crypto from 'crypto';
|
|
4
4
|
import { Document, Model } from 'mongoose';
|
|
5
5
|
import { merge } from '../../common/helpers/config.helper';
|
|
6
|
+
import { assignPlain } from '../../common/helpers/input.helper';
|
|
6
7
|
import { ServiceOptions } from '../../common/interfaces/service-options.interface';
|
|
7
8
|
import { CrudService } from '../../common/services/crud.service';
|
|
8
9
|
import { EmailService } from '../../common/services/email.service';
|
|
@@ -39,9 +40,12 @@ export abstract class CoreUserService<
|
|
|
39
40
|
return this.process(
|
|
40
41
|
async (data) => {
|
|
41
42
|
// Create user with verification token
|
|
43
|
+
const currentUserId = serviceOptions?.currentUser?._id;
|
|
42
44
|
const createdUser = new this.mainDbModel({
|
|
43
45
|
...data.input,
|
|
44
46
|
verificationToken: crypto.randomBytes(32).toString('hex'),
|
|
47
|
+
createdBy: currentUserId,
|
|
48
|
+
updatedBy: currentUserId,
|
|
45
49
|
});
|
|
46
50
|
|
|
47
51
|
// Distinguish between different error messages when saving
|
|
@@ -105,21 +109,15 @@ export abstract class CoreUserService<
|
|
|
105
109
|
}
|
|
106
110
|
return this.process(
|
|
107
111
|
async () => {
|
|
108
|
-
// Update user
|
|
109
|
-
await
|
|
110
|
-
verified: true,
|
|
111
|
-
verificationToken: null,
|
|
112
|
-
}).save();
|
|
113
|
-
|
|
114
|
-
// Return prepared user
|
|
115
|
-
return dbObject;
|
|
112
|
+
// Update and return user
|
|
113
|
+
return await assignPlain(dbObject, { verified: true, verificationToken: null }).save();
|
|
116
114
|
},
|
|
117
115
|
{ dbObject, serviceOptions }
|
|
118
116
|
);
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
/**
|
|
122
|
-
* Set
|
|
120
|
+
* Set new password for user with token
|
|
123
121
|
*/
|
|
124
122
|
async resetPassword(token: string, newPassword: string, serviceOptions?: ServiceOptions): Promise<TUser> {
|
|
125
123
|
// Get user
|
|
@@ -130,14 +128,11 @@ export abstract class CoreUserService<
|
|
|
130
128
|
|
|
131
129
|
return this.process(
|
|
132
130
|
async () => {
|
|
133
|
-
// Update user
|
|
134
|
-
await
|
|
131
|
+
// Update and return user
|
|
132
|
+
return await assignPlain(dbObject, {
|
|
135
133
|
password: await bcrypt.hash(newPassword, 10),
|
|
136
134
|
passwordResetToken: null,
|
|
137
135
|
}).save();
|
|
138
|
-
|
|
139
|
-
// Return user
|
|
140
|
-
return dbObject;
|
|
141
136
|
},
|
|
142
137
|
{ dbObject, serviceOptions }
|
|
143
138
|
);
|
|
@@ -154,13 +149,9 @@ export abstract class CoreUserService<
|
|
|
154
149
|
}
|
|
155
150
|
return this.process(
|
|
156
151
|
async () => {
|
|
157
|
-
// Set reset token
|
|
158
|
-
|
|
159
|
-
dbObject.
|
|
160
|
-
await dbObject.save();
|
|
161
|
-
|
|
162
|
-
// Return user
|
|
163
|
-
return dbObject;
|
|
152
|
+
// Set reset token and return
|
|
153
|
+
dbObject.passwordResetToken = crypto.randomBytes(32).toString('hex');
|
|
154
|
+
return await dbObject.save();
|
|
164
155
|
},
|
|
165
156
|
{ dbObject, serviceOptions }
|
|
166
157
|
);
|
|
@@ -182,7 +173,7 @@ export abstract class CoreUserService<
|
|
|
182
173
|
|
|
183
174
|
// Update and return user
|
|
184
175
|
return this.process(
|
|
185
|
-
async (
|
|
176
|
+
async () => {
|
|
186
177
|
return await this.mainDbModel.findByIdAndUpdate(userId, { roles }).exec();
|
|
187
178
|
},
|
|
188
179
|
{ serviceOptions }
|
package/src/core.module.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { APP_PIPE } from '@nestjs/core';
|
|
|
4
4
|
import { GraphQLModule } from '@nestjs/graphql';
|
|
5
5
|
import { MongooseModule } from '@nestjs/mongoose';
|
|
6
6
|
import { Context } from 'apollo-server-core';
|
|
7
|
-
import
|
|
7
|
+
import * as graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js';
|
|
8
8
|
import { merge } from './core/common/helpers/config.helper';
|
|
9
9
|
import { IServerOptions } from './core/common/interfaces/server-options.interface';
|
|
10
10
|
import { MapAndValidatePipe } from './core/common/pipes/map-and-validate.pipe';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Args, Mutation, Resolver } from '@nestjs/graphql';
|
|
2
2
|
import { createWriteStream } from 'fs';
|
|
3
|
-
import
|
|
3
|
+
import * as GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
|
|
4
|
+
import type { FileUpload } from 'graphql-upload/processRequest.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* File resolver
|
|
@@ -145,7 +145,7 @@ export class UserResolver {
|
|
|
145
145
|
*/
|
|
146
146
|
@Subscription(() => User, {
|
|
147
147
|
filter(this: UserResolver, payload, variables, context) {
|
|
148
|
-
return context
|
|
148
|
+
return context?.user?.hasRole?.(RoleEnum.ADMIN);
|
|
149
149
|
},
|
|
150
150
|
resolve: (user) => user,
|
|
151
151
|
})
|
package/src/test/test.helper.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { INestApplication } from '@nestjs/common';
|
|
2
2
|
import { createClient } from 'graphql-ws';
|
|
3
|
-
// import { FastifyInstance } from 'fastify';
|
|
4
3
|
import { jsonToGraphQLQuery } from 'json-to-graphql-query';
|
|
5
4
|
import * as LightMyRequest from 'light-my-request';
|
|
6
5
|
import * as supertest from 'supertest';
|
|
@@ -125,25 +124,21 @@ export class TestHelper {
|
|
|
125
124
|
|
|
126
125
|
/**
|
|
127
126
|
* GraphQL request
|
|
128
|
-
* @param graphql
|
|
129
|
-
* @param options
|
|
130
127
|
*/
|
|
131
128
|
async graphQl(graphql: string | TestGraphQLConfig, options: TestGraphQLOptions = {}): Promise<any> {
|
|
132
129
|
// Default options
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
options
|
|
143
|
-
);
|
|
130
|
+
const config = {
|
|
131
|
+
convertEnums: true,
|
|
132
|
+
countOfSubscriptionMessages: 1,
|
|
133
|
+
token: null,
|
|
134
|
+
statusCode: 200,
|
|
135
|
+
log: false,
|
|
136
|
+
logError: false,
|
|
137
|
+
...options,
|
|
138
|
+
};
|
|
144
139
|
|
|
145
140
|
// Init vars
|
|
146
|
-
const { token, statusCode, log, logError } =
|
|
141
|
+
const { token, statusCode, log, logError } = config;
|
|
147
142
|
|
|
148
143
|
// Init
|
|
149
144
|
let query = '';
|
|
@@ -188,13 +183,13 @@ export class TestHelper {
|
|
|
188
183
|
}
|
|
189
184
|
|
|
190
185
|
if ((graphql as TestGraphQLConfig).type === TestGraphQLType.SUBSCRIPTION) {
|
|
191
|
-
return this.getSubscription(graphql as TestGraphQLConfig, query,
|
|
186
|
+
return this.getSubscription(graphql as TestGraphQLConfig, query, config);
|
|
192
187
|
}
|
|
193
188
|
|
|
194
189
|
// Convert uppercase strings in arguments of query to enums
|
|
195
|
-
if (
|
|
196
|
-
if (Array.isArray(
|
|
197
|
-
for (const key of Object.values(
|
|
190
|
+
if (config.convertEnums) {
|
|
191
|
+
if (Array.isArray(config.convertEnums)) {
|
|
192
|
+
for (const key of Object.values(config.convertEnums)) {
|
|
198
193
|
const regExpStr = '(' + key + ': )\\"([_A-Z][_0-9A-Z]*)\\"';
|
|
199
194
|
const regExp = new RegExp(regExpStr, 'g');
|
|
200
195
|
query = query.replace(regExp, '$1$2');
|
|
@@ -242,28 +237,26 @@ export class TestHelper {
|
|
|
242
237
|
*/
|
|
243
238
|
async rest(url: string, options: TestRestOptions = {}): Promise<any> {
|
|
244
239
|
// Default options
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
options
|
|
255
|
-
);
|
|
240
|
+
const config: TestRestOptions = {
|
|
241
|
+
token: null,
|
|
242
|
+
statusCode: 200,
|
|
243
|
+
log: false,
|
|
244
|
+
logError: false,
|
|
245
|
+
payload: null,
|
|
246
|
+
method: 'GET',
|
|
247
|
+
...options,
|
|
248
|
+
};
|
|
256
249
|
|
|
257
250
|
// Init vars
|
|
258
|
-
const { token, statusCode, log, logError } =
|
|
251
|
+
const { token, statusCode, log, logError } = config;
|
|
259
252
|
|
|
260
253
|
// Request configuration
|
|
261
254
|
const requestConfig: LightMyRequest.InjectOptions = {
|
|
262
|
-
method:
|
|
255
|
+
method: config.method,
|
|
263
256
|
url,
|
|
264
257
|
};
|
|
265
|
-
if (
|
|
266
|
-
requestConfig.payload =
|
|
258
|
+
if (config.payload) {
|
|
259
|
+
requestConfig.payload = config.payload;
|
|
267
260
|
}
|
|
268
261
|
|
|
269
262
|
// Process response
|