@lenne.tech/nest-server 8.6.10 → 8.6.13
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/db.helper.d.ts +1 -1
- package/dist/core/common/helpers/db.helper.js +6 -2
- package/dist/core/common/helpers/db.helper.js.map +1 -1
- package/dist/core/common/interfaces/service-options.interface.d.ts +1 -1
- package/dist/core/common/types/field-selection.type.d.ts +1 -1
- package/dist/core/common/types/maybe-promise.type.d.ts +1 -0
- package/dist/core/common/types/maybe-promise.type.js +3 -0
- package/dist/core/common/types/maybe-promise.type.js.map +1 -0
- package/dist/core/modules/auth/core-auth.model.d.ts +1 -0
- package/dist/core/modules/auth/core-auth.model.js +4 -0
- package/dist/core/modules/auth/core-auth.model.js.map +1 -1
- package/dist/core/modules/file/{file-info.output.d.ts → core-file-info.model.d.ts} +4 -3
- package/dist/core/modules/file/{file-info.output.js → core-file-info.model.js} +35 -20
- package/dist/core/modules/file/core-file-info.model.js.map +1 -0
- package/dist/core/modules/file/core-file.controller.d.ts +7 -0
- package/dist/core/modules/file/core-file.controller.js +52 -0
- package/dist/core/modules/file/core-file.controller.js.map +1 -0
- package/dist/core/modules/file/core-file.resolver.d.ts +10 -0
- package/dist/core/modules/file/core-file.resolver.js +70 -0
- package/dist/core/modules/file/core-file.resolver.js.map +1 -0
- package/dist/core/modules/file/core-file.service.d.ts +20 -15
- package/dist/core/modules/file/core-file.service.js +59 -22
- package/dist/core/modules/file/core-file.service.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 +4 -0
- package/dist/core/modules/user/core-user.model.js.map +1 -1
- package/dist/core.module.js +1 -1
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/server/common/models/persistence.model.d.ts +3 -3
- package/dist/server/common/models/persistence.model.js +8 -4
- package/dist/server/common/models/persistence.model.js.map +1 -1
- package/dist/server/modules/auth/auth.model.d.ts +1 -0
- package/dist/server/modules/auth/auth.model.js +5 -0
- package/dist/server/modules/auth/auth.model.js.map +1 -1
- package/dist/server/modules/file/file-info.model.d.ts +26 -0
- package/dist/server/modules/file/file-info.model.js +21 -0
- package/dist/server/modules/file/file-info.model.js.map +1 -0
- package/dist/server/modules/file/file.controller.d.ts +2 -3
- package/dist/server/modules/file/file.controller.js +4 -26
- package/dist/server/modules/file/file.controller.js.map +1 -1
- package/dist/server/modules/file/file.module.d.ts +2 -0
- package/dist/server/modules/file/file.module.js +27 -0
- package/dist/server/modules/file/file.module.js.map +1 -0
- package/dist/server/modules/file/file.resolver.d.ts +3 -4
- 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/file/file.service.js +1 -1
- package/dist/server/modules/file/file.service.js.map +1 -1
- package/dist/server/modules/user/inputs/user-create.input.js.map +1 -1
- package/dist/server/modules/user/inputs/user.input.js.map +1 -1
- package/dist/server/modules/user/user.model.d.ts +3 -3
- package/dist/server/modules/user/user.model.js +4 -4
- package/dist/server/modules/user/user.model.js.map +1 -1
- package/dist/server/server.module.js +4 -6
- package/dist/server/server.module.js.map +1 -1
- package/dist/test/test.helper.js +1 -1
- package/dist/test/test.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/common/helpers/db.helper.ts +7 -3
- package/src/core/common/interfaces/service-options.interface.ts +1 -1
- package/src/core/common/types/field-selection.type.ts +6 -1
- package/src/core/common/types/maybe-promise.type.ts +4 -0
- package/src/core/modules/auth/core-auth.model.ts +11 -1
- package/src/core/modules/file/core-file-info.model.ts +40 -0
- package/src/core/modules/file/core-file.controller.ts +34 -0
- package/src/core/modules/file/core-file.resolver.ts +56 -0
- package/src/core/modules/file/core-file.service.ts +81 -27
- package/src/core/modules/user/core-user.model.ts +10 -0
- package/src/core.module.ts +1 -2
- package/src/index.ts +4 -1
- package/src/server/common/models/persistence.model.ts +25 -11
- package/src/server/modules/auth/auth.model.ts +9 -0
- package/src/server/modules/file/file-info.model.ts +15 -0
- package/src/server/modules/file/file.controller.ts +8 -37
- package/src/server/modules/file/file.module.ts +17 -0
- package/src/server/modules/file/file.resolver.ts +1 -4
- package/src/server/modules/file/file.service.ts +4 -1
- package/src/server/modules/user/inputs/user-create.input.ts +0 -4
- package/src/server/modules/user/inputs/user.input.ts +0 -4
- package/src/server/modules/user/user.model.ts +8 -8
- package/src/server/server.module.ts +6 -8
- package/src/test/test.helper.ts +1 -1
- package/dist/core/modules/file/file-info.output.js.map +0 -1
- package/src/core/modules/file/file-info.output.ts +0 -26
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { MongooseModule } from '@nestjs/mongoose';
|
|
3
|
+
import { FileInfo, FileInfoSchema } from './file-info.model';
|
|
4
|
+
import { FileController } from './file.controller';
|
|
5
|
+
import { FileResolver } from './file.resolver';
|
|
6
|
+
import { FileService } from './file.service';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* File module
|
|
10
|
+
*/
|
|
11
|
+
@Module({
|
|
12
|
+
imports: [MongooseModule.forFeature([{ name: FileInfo.name, schema: FileInfoSchema }])],
|
|
13
|
+
controllers: [FileController],
|
|
14
|
+
providers: [FileService, FileResolver],
|
|
15
|
+
exports: [MongooseModule, FileService],
|
|
16
|
+
})
|
|
17
|
+
export class FileModule {}
|
|
@@ -3,8 +3,8 @@ import { createWriteStream } from 'fs';
|
|
|
3
3
|
import * as GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
|
|
4
4
|
import { Roles } from '../../../core/common/decorators/roles.decorator';
|
|
5
5
|
import { RoleEnum } from '../../../core/common/enums/role.enum';
|
|
6
|
-
import { FileInfo } from '../../../core/modules/file/file-info.output';
|
|
7
6
|
import { FileUpload } from '../../../core/modules/file/interfaces/file-upload.interface';
|
|
7
|
+
import { FileInfo } from './file-info.model';
|
|
8
8
|
import { FileService } from './file.service';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -49,9 +49,6 @@ export class FileResolver {
|
|
|
49
49
|
@Roles(RoleEnum.ADMIN)
|
|
50
50
|
@Mutation(() => FileInfo)
|
|
51
51
|
async uploadFile(@Args({ name: 'file', type: () => GraphQLUpload }) file: FileUpload) {
|
|
52
|
-
const { filename, mimetype, encoding, createReadStream } = file;
|
|
53
|
-
|
|
54
|
-
// Save file in DB
|
|
55
52
|
return await this.fileService.createFile(file);
|
|
56
53
|
}
|
|
57
54
|
|
|
@@ -3,9 +3,12 @@ import { InjectConnection } from '@nestjs/mongoose';
|
|
|
3
3
|
import { Connection } from 'mongoose';
|
|
4
4
|
import { CoreFileService } from '../../../core/modules/file/core-file.service';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* File service
|
|
8
|
+
*/
|
|
6
9
|
@Injectable()
|
|
7
10
|
export class FileService extends CoreFileService {
|
|
8
11
|
constructor(@InjectConnection() protected readonly connection: Connection) {
|
|
9
|
-
super(connection, '
|
|
12
|
+
super(connection, 'fs');
|
|
10
13
|
}
|
|
11
14
|
}
|
|
@@ -3,10 +3,6 @@ import { CoreUserCreateInput } from '../../../../core/modules/user/inputs/core-u
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* User input to create a new user
|
|
6
|
-
*
|
|
7
|
-
* HINT: All properties (in this class and all classes that extend this class) must be initialized with undefined,
|
|
8
|
-
* otherwise the property will not be recognized via Object.keys (this is necessary for mapping) or will be initialized
|
|
9
|
-
* with a default value that may overwrite an existing value in the DB.
|
|
10
6
|
*/
|
|
11
7
|
@InputType({ description: 'User input to create a new user' })
|
|
12
8
|
export class UserCreateInput extends CoreUserCreateInput {
|
|
@@ -3,10 +3,6 @@ import { CoreUserInput } from '../../../../core/modules/user/inputs/core-user.in
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* User input to update a user
|
|
6
|
-
*
|
|
7
|
-
* HINT: All properties (in this class and all classes that extend this class) must be initialized with undefined,
|
|
8
|
-
* otherwise the property will not be recognized via Object.keys (this is necessary for mapping) or will be initialized
|
|
9
|
-
* with a default value that may overwrite an existing value in the DB.
|
|
10
6
|
*/
|
|
11
7
|
@InputType({ description: 'User input' })
|
|
12
8
|
export class UserInput extends CoreUserInput {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Field, ObjectType } from '@nestjs/graphql';
|
|
2
2
|
import { Prop, Schema as MongooseSchema, SchemaFactory } from '@nestjs/mongoose';
|
|
3
|
-
import { Document, Schema } from 'mongoose';
|
|
3
|
+
import { Document, Schema, Types } from 'mongoose';
|
|
4
4
|
import { mapClasses } from '../../../core/common/helpers/model.helper';
|
|
5
5
|
import { CoreUserModel } from '../../../core/modules/user/core-user.model';
|
|
6
6
|
import { PersistenceModel } from '../../common/models/persistence.model';
|
|
@@ -8,7 +8,7 @@ import { PersistenceModel } from '../../common/models/persistence.model';
|
|
|
8
8
|
export type UserDocument = User & Document;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* User
|
|
11
|
+
* User model
|
|
12
12
|
*/
|
|
13
13
|
@ObjectType({ description: 'User' })
|
|
14
14
|
@MongooseSchema({ timestamps: true })
|
|
@@ -25,28 +25,28 @@ export class User extends CoreUserModel implements PersistenceModel {
|
|
|
25
25
|
avatar: string = undefined;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* ID of the user who created the object
|
|
29
29
|
*
|
|
30
30
|
* Not set when created by system
|
|
31
31
|
*/
|
|
32
|
-
@Field((
|
|
32
|
+
@Field(() => String, {
|
|
33
33
|
description: 'ID of the user who created the object',
|
|
34
34
|
nullable: true,
|
|
35
35
|
})
|
|
36
36
|
@Prop({ type: Schema.Types.ObjectId, ref: 'User' })
|
|
37
|
-
createdBy:
|
|
37
|
+
createdBy: Types.ObjectId | string = undefined;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* ID of the user who updated the object
|
|
41
41
|
*
|
|
42
42
|
* Not set when updated by system
|
|
43
43
|
*/
|
|
44
|
-
@Field((
|
|
44
|
+
@Field(() => String, {
|
|
45
45
|
description: 'ID of the user who last updated the object',
|
|
46
46
|
nullable: true,
|
|
47
47
|
})
|
|
48
48
|
@Prop({ type: Schema.Types.ObjectId, ref: 'User' })
|
|
49
|
-
updatedBy:
|
|
49
|
+
updatedBy: Types.ObjectId | string = undefined;
|
|
50
50
|
|
|
51
51
|
// ===================================================================================================================
|
|
52
52
|
// Methods
|
|
@@ -3,9 +3,7 @@ import envConfig from '../config.env';
|
|
|
3
3
|
import { CoreModule } from '../core.module';
|
|
4
4
|
import { CoreAuthService } from '../core/modules/auth/services/core-auth.service';
|
|
5
5
|
import { AuthModule } from './modules/auth/auth.module';
|
|
6
|
-
import {
|
|
7
|
-
import { FileResolver } from './modules/file/file.resolver';
|
|
8
|
-
import { FileService } from './modules/file/file.service';
|
|
6
|
+
import { FileModule } from './modules/file/file.module';
|
|
9
7
|
import { ServerController } from './server.controller';
|
|
10
8
|
|
|
11
9
|
/**
|
|
@@ -23,15 +21,15 @@ import { ServerController } from './server.controller';
|
|
|
23
21
|
// Include AuthModule for authorization handling,
|
|
24
22
|
// which will also include UserModule
|
|
25
23
|
AuthModule.forRoot(envConfig.jwt),
|
|
24
|
+
|
|
25
|
+
// Include FileModule for file handling
|
|
26
|
+
FileModule,
|
|
26
27
|
],
|
|
27
28
|
|
|
28
29
|
// Include REST controllers
|
|
29
|
-
controllers: [
|
|
30
|
-
|
|
31
|
-
// Include resolvers, services and other providers
|
|
32
|
-
providers: [FileService, FileResolver],
|
|
30
|
+
controllers: [ServerController],
|
|
33
31
|
|
|
34
32
|
// Export modules for reuse in other modules
|
|
35
|
-
exports: [CoreModule, AuthModule],
|
|
33
|
+
exports: [CoreModule, AuthModule, FileModule],
|
|
36
34
|
})
|
|
37
35
|
export class ServerModule {}
|
package/src/test/test.helper.ts
CHANGED
|
@@ -169,7 +169,7 @@ export class TestHelper {
|
|
|
169
169
|
});
|
|
170
170
|
})
|
|
171
171
|
.end((err, res: superagent.Response) => {
|
|
172
|
-
(res as superagent.Response & { data: string }).data =
|
|
172
|
+
(res as superagent.Response & { data: string }).data = Buffer.from(data, 'binary').toString();
|
|
173
173
|
err ? reject(err) : resolve(res as superagent.Response & { data: string });
|
|
174
174
|
});
|
|
175
175
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-info.output.js","sourceRoot":"","sources":["../../../../src/core/modules/file/file-info.output.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAoD;AAEpD,2EAAiE;AAMjE,IAAa,QAAQ,GAArB,MAAa,QAAS,SAAQ,4BAAS;IAAvC;;QAIE,OAAE,GAAW,SAAS,CAAC;QAGvB,WAAM,GAAW,SAAS,CAAC;QAG3B,cAAS,GAAW,SAAS,CAAC;QAG9B,aAAQ,GAAY,SAAS,CAAC;QAG9B,gBAAW,GAAY,SAAS,CAAC;IACnC,CAAC;CAAA,CAAA;AAbC;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;;oCACzC;AAGvB;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,6BAA6B,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;wCACzD;AAG3B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,mBAAmB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;2CAC5C;AAG9B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;0CAC3C;AAG9B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;6CACpC;AAhBtB,QAAQ;IADpB,IAAA,oBAAU,EAAC,EAAE,WAAW,EAAE,mCAAmC,EAAE,CAAC;GACpD,QAAQ,CAiBpB;AAjBY,4BAAQ"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Field, ObjectType } from '@nestjs/graphql';
|
|
2
|
-
import { Types } from 'mongoose';
|
|
3
|
-
import { CoreModel } from '../../common/models/core-model.model';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* File info (output)
|
|
7
|
-
*/
|
|
8
|
-
@ObjectType({ description: 'Information about attachment file' })
|
|
9
|
-
export class FileInfo extends CoreModel {
|
|
10
|
-
_id: Types.ObjectId;
|
|
11
|
-
|
|
12
|
-
@Field(() => String, { description: 'ID of the file in bytes' })
|
|
13
|
-
id: string = undefined;
|
|
14
|
-
|
|
15
|
-
@Field(() => Number, { description: 'Length of the file in bytes', nullable: true })
|
|
16
|
-
length: number = undefined;
|
|
17
|
-
|
|
18
|
-
@Field(() => Number, { description: 'Size of the chunk', nullable: true })
|
|
19
|
-
chunkSize: number = undefined;
|
|
20
|
-
|
|
21
|
-
@Field(() => String, { description: 'Name of the file', nullable: true })
|
|
22
|
-
filename?: string = undefined;
|
|
23
|
-
|
|
24
|
-
@Field(() => String, { description: 'Content type', nullable: true })
|
|
25
|
-
contentType?: string = undefined;
|
|
26
|
-
}
|