itlab-internal-services 2.14.3 → 2.14.4
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/models/account-entity.model.d.ts +4 -4
- package/dist/models/account-entity.model.js +7 -7
- package/dist/modules/comment/comment-module-options.interface.d.ts +5 -2
- package/dist/modules/comment/comment.module.d.ts +2 -1
- package/dist/modules/comment/comment.module.js +3 -1
- package/dist/modules/comment/comment.service.d.ts +10 -9
- package/dist/modules/comment/comment.service.js +28 -20
- package/dist/modules/like/like.service.d.ts +1 -1
- package/dist/modules/like/like.service.js +4 -6
- package/package.json +1 -1
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
export declare class AccountEntity {
|
|
5
5
|
/** Unique identifier for the account */
|
|
6
6
|
id: string;
|
|
7
|
-
/** Array of permissions for the account */
|
|
8
|
-
perms: string[];
|
|
9
|
-
/** Username of the account */
|
|
10
|
-
username: string;
|
|
11
7
|
/** Email of the account */
|
|
12
8
|
email: string;
|
|
9
|
+
/** Username of the account */
|
|
10
|
+
username: string;
|
|
13
11
|
/** Optional: Avatar of the account */
|
|
14
12
|
avatar?: string;
|
|
13
|
+
/** Array of permissions for the account */
|
|
14
|
+
perms: string[];
|
|
15
15
|
}
|
|
@@ -22,18 +22,18 @@ __decorate([
|
|
|
22
22
|
__metadata("design:type", String)
|
|
23
23
|
], AccountEntity.prototype, "id", void 0);
|
|
24
24
|
__decorate([
|
|
25
|
-
(0, swagger_1.ApiProperty)({ description: '
|
|
26
|
-
__metadata("design:type",
|
|
27
|
-
], AccountEntity.prototype, "
|
|
25
|
+
(0, swagger_1.ApiProperty)({ description: 'Email of the account', example: 'timo@example.com' }),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], AccountEntity.prototype, "email", void 0);
|
|
28
28
|
__decorate([
|
|
29
29
|
(0, swagger_1.ApiProperty)({ description: 'Username of the account', example: 'Timo S.' }),
|
|
30
30
|
__metadata("design:type", String)
|
|
31
31
|
], AccountEntity.prototype, "username", void 0);
|
|
32
|
-
__decorate([
|
|
33
|
-
(0, swagger_1.ApiProperty)({ description: 'Email of the account', example: 'timo@example.com' }),
|
|
34
|
-
__metadata("design:type", String)
|
|
35
|
-
], AccountEntity.prototype, "email", void 0);
|
|
36
32
|
__decorate([
|
|
37
33
|
(0, swagger_1.ApiPropertyOptional)({ description: 'Avatar of the account', example: 'https://example.com/avatar.jpg' }),
|
|
38
34
|
__metadata("design:type", String)
|
|
39
35
|
], AccountEntity.prototype, "avatar", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, swagger_1.ApiProperty)({ description: 'Array of permissions for the account', example: ['news.publish'] }),
|
|
38
|
+
__metadata("design:type", Array)
|
|
39
|
+
], AccountEntity.prototype, "perms", void 0);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ModelDefinition } from '@nestjs/mongoose';
|
|
2
|
+
import { Document } from 'mongoose';
|
|
2
3
|
import { HubResource } from '../../hub-resource.enum';
|
|
3
|
-
export interface CommentModuleOptions {
|
|
4
|
+
export interface CommentModuleOptions<T extends Document = any> {
|
|
4
5
|
resource: HubResource;
|
|
5
|
-
model?: ModelDefinition;
|
|
6
6
|
suffix?: string[];
|
|
7
|
+
model?: ModelDefinition;
|
|
8
|
+
ownerIdField?: keyof Omit<T, keyof Document>;
|
|
9
|
+
ownerIdsField?: keyof Omit<T, keyof Document>;
|
|
7
10
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { Document } from 'mongoose';
|
|
2
3
|
import { CommentModuleOptions } from './comment-module-options.interface';
|
|
3
4
|
/**
|
|
4
5
|
* @class CommentModule
|
|
@@ -6,5 +7,5 @@ import { CommentModuleOptions } from './comment-module-options.interface';
|
|
|
6
7
|
* @author Timo Scheuermann
|
|
7
8
|
*/
|
|
8
9
|
export declare class CommentModule {
|
|
9
|
-
static register(options: CommentModuleOptions): DynamicModule;
|
|
10
|
+
static register<T extends Document = any>(options: CommentModuleOptions<T>): DynamicModule;
|
|
10
11
|
}
|
|
@@ -39,9 +39,11 @@ let CommentModule = CommentModule_1 = class CommentModule {
|
|
|
39
39
|
controllers: [CommentController],
|
|
40
40
|
providers: [
|
|
41
41
|
comment_service_1.CommentService,
|
|
42
|
-
{ provide: 'COMMENT_RESOURCE', useValue: options.resource },
|
|
43
42
|
{ provide: 'COMMENT_MODEL', useValue: options.model.name },
|
|
44
43
|
{ provide: 'COMMENT_SCHEMA', useValue: options.model.schema },
|
|
44
|
+
{ provide: 'COMMENT_RESOURCE', useValue: options.resource },
|
|
45
|
+
{ provide: 'COMMENT_RESOURCE_OWNER_ID_FIELD', useValue: options.ownerIdField },
|
|
46
|
+
{ provide: 'COMMENT_RESOURCE_OWNER_IDS_FIELD', useValue: options.ownerIdsField },
|
|
45
47
|
],
|
|
46
48
|
exports: [comment_service_1.CommentService],
|
|
47
49
|
};
|
|
@@ -10,25 +10,26 @@ import { AuthOptions } from '../authentication';
|
|
|
10
10
|
* @author Timo Scheuermann
|
|
11
11
|
*/
|
|
12
12
|
export declare class CommentService {
|
|
13
|
+
private readonly configService;
|
|
13
14
|
private readonly authOptions;
|
|
14
15
|
private readonly connection;
|
|
16
|
+
private readonly resource;
|
|
15
17
|
private readonly model;
|
|
16
18
|
private readonly schema;
|
|
17
|
-
private readonly
|
|
18
|
-
private readonly
|
|
19
|
+
private readonly ownerIdField;
|
|
20
|
+
private readonly ownerIdsField;
|
|
19
21
|
/** The CommentService logger */
|
|
20
22
|
private readonly logger;
|
|
21
23
|
/**
|
|
22
24
|
* @constructor Constructor for the CommentService class
|
|
23
|
-
* @param {
|
|
25
|
+
* @param {ConfigService} configService - the config service
|
|
26
|
+
* @param {HubResource} resource - the resource used
|
|
24
27
|
* @param {string} model - the model name
|
|
25
28
|
* @param {string} schema - the schema
|
|
26
|
-
* @param {
|
|
27
|
-
* @param {
|
|
29
|
+
* @param {string} ownerId - the ownerId attr of the resource
|
|
30
|
+
* @param {string} ownerIds - the ownerIds attr of the resource
|
|
28
31
|
*/
|
|
29
|
-
constructor(authOptions: AuthOptions, connection: Connection, model: string | undefined, schema: Schema<
|
|
30
|
-
_url: string;
|
|
31
|
-
}> | undefined, resource: HubResource, configService: ConfigService);
|
|
32
|
+
constructor(configService: ConfigService, authOptions: AuthOptions, connection: Connection | undefined, resource: HubResource, model: string | undefined, schema: Schema<any> | undefined, ownerIdField: string | undefined, ownerIdsField: string | undefined);
|
|
32
33
|
private get baseUrl();
|
|
33
34
|
/** The axios instance */
|
|
34
35
|
private axios;
|
|
@@ -37,7 +38,7 @@ export declare class CommentService {
|
|
|
37
38
|
*
|
|
38
39
|
* @return {Model<{}> | undefined} The model retrieved from the connection.
|
|
39
40
|
*/
|
|
40
|
-
private
|
|
41
|
+
private get resourceModel();
|
|
41
42
|
/**
|
|
42
43
|
* Post a comment to a specific resource.
|
|
43
44
|
*
|
|
@@ -39,19 +39,22 @@ const authentication_1 = require("../authentication");
|
|
|
39
39
|
let CommentService = CommentService_1 = class CommentService {
|
|
40
40
|
/**
|
|
41
41
|
* @constructor Constructor for the CommentService class
|
|
42
|
-
* @param {
|
|
42
|
+
* @param {ConfigService} configService - the config service
|
|
43
|
+
* @param {HubResource} resource - the resource used
|
|
43
44
|
* @param {string} model - the model name
|
|
44
45
|
* @param {string} schema - the schema
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {
|
|
46
|
+
* @param {string} ownerId - the ownerId attr of the resource
|
|
47
|
+
* @param {string} ownerIds - the ownerIds attr of the resource
|
|
47
48
|
*/
|
|
48
|
-
constructor(authOptions, connection, model, schema,
|
|
49
|
+
constructor(configService, authOptions, connection, resource, model, schema, ownerIdField, ownerIdsField) {
|
|
50
|
+
this.configService = configService;
|
|
49
51
|
this.authOptions = authOptions;
|
|
50
52
|
this.connection = connection;
|
|
53
|
+
this.resource = resource;
|
|
51
54
|
this.model = model;
|
|
52
55
|
this.schema = schema;
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
56
|
+
this.ownerIdField = ownerIdField;
|
|
57
|
+
this.ownerIdsField = ownerIdsField;
|
|
55
58
|
/** The CommentService logger */
|
|
56
59
|
this.logger = new common_1.Logger(CommentService_1.name);
|
|
57
60
|
/** The axios instance */
|
|
@@ -71,10 +74,9 @@ let CommentService = CommentService_1 = class CommentService {
|
|
|
71
74
|
*
|
|
72
75
|
* @return {Model<{}> | undefined} The model retrieved from the connection.
|
|
73
76
|
*/
|
|
74
|
-
|
|
77
|
+
get resourceModel() {
|
|
75
78
|
if (!(this.model && this.schema))
|
|
76
79
|
return undefined;
|
|
77
|
-
this.logger.debug('Current DB', this.connection.db.databaseName);
|
|
78
80
|
return this.connection.model(this.model, this.schema);
|
|
79
81
|
}
|
|
80
82
|
/**
|
|
@@ -88,17 +90,19 @@ let CommentService = CommentService_1 = class CommentService {
|
|
|
88
90
|
postComment(resourceId, accountId, comment) {
|
|
89
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
92
|
// CommentModel is null inside manager modules
|
|
91
|
-
if (!(0, class_validator_1.isDefined)(this.
|
|
93
|
+
if (!(0, class_validator_1.isDefined)(this.resourceModel)) {
|
|
92
94
|
this.logger.error('Kommentare können nicht vom Management aus erstellt werden');
|
|
93
95
|
return;
|
|
94
96
|
}
|
|
95
|
-
const
|
|
96
|
-
if (!
|
|
97
|
+
const resource = yield this.resourceModel.findOne({ _id: resourceId });
|
|
98
|
+
if (!resource)
|
|
97
99
|
throw new common_1.NotFoundException('Kommentar konnte nicht erstellt werden');
|
|
100
|
+
const ownerId = this.ownerIdField ? resource[this.ownerIdField] : undefined;
|
|
101
|
+
const ownerIds = this.ownerIdsField ? resource[this.ownerIdsField] : undefined;
|
|
98
102
|
this.logger.log(`Posting comment for ${this.resource} (${resourceId}) by ${accountId}`);
|
|
99
103
|
return new Promise((resolve, reject) => {
|
|
100
104
|
this.axios
|
|
101
|
-
.post(`${this.resource}/${resourceId}/${accountId}`, comment)
|
|
105
|
+
.post(`${this.resource}/${resourceId}/${accountId}`, comment, { params: { ownerId, ownerIds } })
|
|
102
106
|
.then(({ data }) => {
|
|
103
107
|
this.logger.log(`Comment for ${this.resource} (${resourceId}) posted`);
|
|
104
108
|
resolve(data);
|
|
@@ -127,12 +131,16 @@ let CommentService = CommentService_1 = class CommentService {
|
|
|
127
131
|
exports.CommentService = CommentService;
|
|
128
132
|
exports.CommentService = CommentService = CommentService_1 = __decorate([
|
|
129
133
|
(0, common_1.Injectable)(),
|
|
130
|
-
__param(
|
|
131
|
-
__param(
|
|
132
|
-
__param(
|
|
133
|
-
__param(
|
|
134
|
-
__param(
|
|
135
|
-
__param(
|
|
136
|
-
__param(
|
|
137
|
-
|
|
134
|
+
__param(1, (0, authentication_1.InjectAuthOptions)()),
|
|
135
|
+
__param(2, (0, mongoose_1.InjectConnection)()),
|
|
136
|
+
__param(3, (0, common_1.Inject)('COMMENT_RESOURCE')),
|
|
137
|
+
__param(4, (0, common_1.Optional)()),
|
|
138
|
+
__param(4, (0, common_1.Inject)('COMMENT_MODEL')),
|
|
139
|
+
__param(5, (0, common_1.Optional)()),
|
|
140
|
+
__param(5, (0, common_1.Inject)('COMMENT_SCHEMA')),
|
|
141
|
+
__param(6, (0, common_1.Optional)()),
|
|
142
|
+
__param(6, (0, common_1.Inject)('COMMENT_RESOURCE_OWNER_ID_FIELD')),
|
|
143
|
+
__param(7, (0, common_1.Optional)()),
|
|
144
|
+
__param(7, (0, common_1.Inject)('COMMENT_RESOURCE_OWNER_IDS_FIELD')),
|
|
145
|
+
__metadata("design:paramtypes", [config_1.ConfigService, Object, mongoose_2.Connection, String, String, mongoose_2.Schema, String, String])
|
|
138
146
|
], CommentService);
|
|
@@ -50,9 +50,7 @@ let LikeService = LikeService_1 = class LikeService {
|
|
|
50
50
|
*
|
|
51
51
|
* @return {Model<{}>} The model retrieved from the connection.
|
|
52
52
|
*/
|
|
53
|
-
|
|
54
|
-
if (!this.model)
|
|
55
|
-
return undefined;
|
|
53
|
+
get resourceModel() {
|
|
56
54
|
return this.connection.model(this.model, this.schema);
|
|
57
55
|
}
|
|
58
56
|
/**
|
|
@@ -76,7 +74,7 @@ let LikeService = LikeService_1 = class LikeService {
|
|
|
76
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
75
|
this.logger.log(`Adding like to ${resourceId} by ${accountId}`);
|
|
78
76
|
// Find the resource and update the likedBy array by adding the accountId
|
|
79
|
-
const resource = yield this.
|
|
77
|
+
const resource = yield this.resourceModel.findOneAndUpdate({ _id: resourceId }, { $addToSet: { _likedBy: accountId } }, { upsert: false, new: true, timestamps: false });
|
|
80
78
|
// Return the like count after the addition
|
|
81
79
|
return this.likeCount(resource);
|
|
82
80
|
});
|
|
@@ -92,7 +90,7 @@ let LikeService = LikeService_1 = class LikeService {
|
|
|
92
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
91
|
this.logger.log(`Removing like from ${resourceId} by ${accountId}`);
|
|
94
92
|
// Find the resource and update the _likedBy array by removing the accountId
|
|
95
|
-
const resource = yield this.
|
|
93
|
+
const resource = yield this.resourceModel.findOneAndUpdate({ _id: resourceId }, { $pull: { _likedBy: { $in: [accountId] } } }, { upsert: false, new: true, timestamps: false });
|
|
96
94
|
// Return the like count after the removal
|
|
97
95
|
return this.likeCount(resource);
|
|
98
96
|
});
|
|
@@ -108,7 +106,7 @@ let LikeService = LikeService_1 = class LikeService {
|
|
|
108
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
107
|
this.logger.log(`Check if ${accountId} has liked ${resourceId}`);
|
|
110
108
|
// Find the resource in the likeModel with the provided resourceId.
|
|
111
|
-
const resource = yield this.
|
|
109
|
+
const resource = yield this.resourceModel.findOne({ _id: resourceId });
|
|
112
110
|
// Return true if the resource exists and has the account in its _likedBy array, otherwise return false.
|
|
113
111
|
return resource && resource._likedBy ? resource._likedBy.includes(accountId) : false;
|
|
114
112
|
});
|