itlab-internal-services 2.16.0 → 2.16.1
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/classes/document-merger.class.js +2 -1
- package/dist/classes/index.d.ts +3 -1
- package/dist/classes/index.js +5 -3
- package/dist/classes/schema-builder.class.d.ts +75 -0
- package/dist/classes/schema-builder.class.js +109 -0
- package/dist/classes/task-manager.class.d.ts +71 -0
- package/dist/classes/task-manager.class.js +99 -0
- package/dist/exceptions/bad-parameter.exception.js +2 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/interceptors/attribute-sanitizer.interceptor.d.ts +68 -0
- package/dist/interceptors/attribute-sanitizer.interceptor.js +154 -0
- package/dist/interceptors/index.d.ts +1 -0
- package/dist/interceptors/index.js +17 -0
- package/dist/middleware/http-logging.middleware.d.ts +19 -0
- package/dist/middleware/http-logging.middleware.js +50 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.js +17 -0
- package/dist/modules/authentication/guards/jwt-auth.guard.js +1 -7
- package/dist/modules/authentication/guards/permissions.guard.js +4 -3
- package/dist/modules/authentication/guards/service-auth.guard.js +1 -1
- package/dist/modules/comment/comment-module-options.interface.d.ts +2 -2
- package/dist/modules/comment/comment.controller.d.ts +5 -5
- package/dist/modules/comment/comment.controller.js +3 -3
- package/dist/modules/comment/comment.service.d.ts +3 -3
- package/dist/modules/comment/comment.service.js +1 -1
- package/dist/modules/like/like-module-options.interface.d.ts +2 -2
- package/dist/modules/like/like.controller.d.ts +2 -2
- package/dist/modules/like/like.controller.js +2 -2
- package/dist/modules/services/providers/accounts.service.js +2 -0
- package/dist/modules/services/providers/books.service.js +2 -0
- package/dist/modules/services/providers/changelog.service.js +2 -0
- package/dist/modules/services/providers/comments/comments.service.d.ts +3 -3
- package/dist/modules/services/providers/comments/comments.service.js +2 -1
- package/dist/modules/services/providers/content/{content-types.d.ts → content-return-types.d.ts} +3 -4
- package/dist/modules/services/providers/content/{content-types.js → content-return-types.js} +2 -2
- package/dist/modules/services/providers/content/content.service.d.ts +7 -5
- package/dist/modules/services/providers/content/content.service.js +29 -12
- package/dist/modules/services/providers/content/index.d.ts +1 -0
- package/dist/modules/services/providers/demo-hive.service.js +2 -0
- package/dist/modules/services/providers/events.service.js +2 -0
- package/dist/modules/services/providers/hackschool.service.js +2 -0
- package/dist/modules/services/providers/ideas.service.js +2 -0
- package/dist/modules/services/providers/lunch-roulette.service.js +2 -0
- package/dist/modules/services/providers/mail/mail.service.js +1 -1
- package/dist/modules/services/providers/newletter.service.js +2 -0
- package/dist/modules/services/providers/newsroom.service.js +2 -0
- package/dist/modules/services/providers/podcasts.service.js +2 -0
- package/dist/modules/services/providers/search/search.service.js +1 -1
- package/dist/modules/services/providers/team.service.js +2 -0
- package/dist/modules/services/providers/tech-radar.service.js +2 -0
- package/dist/properties/content-return-type.property.d.ts +7 -0
- package/dist/properties/content-return-type.property.js +22 -0
- package/dist/properties/index.d.ts +3 -0
- package/dist/properties/index.js +7 -1
- package/dist/properties/likeable.properties.d.ts +1 -0
- package/dist/properties/likeable.properties.js +66 -0
- package/dist/properties/viewable.properties.d.ts +1 -0
- package/dist/properties/viewable.properties.js +66 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +18 -0
- package/dist/types/likeable.type.d.ts +15 -0
- package/dist/types/likeable.type.js +2 -0
- package/dist/types/viewable.type.d.ts +15 -0
- package/dist/types/viewable.type.js +2 -0
- package/package.json +2 -2
- package/dist/classes/document-updater.class.d.ts +0 -39
- package/dist/classes/document-updater.class.js +0 -57
- package/dist/http-logger.middleware.d.ts +0 -12
- package/dist/http-logger.middleware.js +0 -43
- package/dist/likeable.interface.d.ts +0 -41
- package/dist/likeable.interface.js +0 -48
- package/dist/viewable.interface.d.ts +0 -41
- package/dist/viewable.interface.js +0 -48
|
@@ -13,6 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.HackschoolService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
16
17
|
const config_1 = require("@nestjs/config");
|
|
17
18
|
const authentication_1 = require("../../authentication");
|
|
18
19
|
const base_http_service_1 = require("../base-http.service");
|
|
@@ -72,6 +73,7 @@ let HackschoolService = class HackschoolService extends base_http_service_1.Base
|
|
|
72
73
|
};
|
|
73
74
|
exports.HackschoolService = HackschoolService;
|
|
74
75
|
exports.HackschoolService = HackschoolService = __decorate([
|
|
76
|
+
(0, common_1.Injectable)(),
|
|
75
77
|
__param(0, (0, authentication_1.InjectAuthenticationOptions)()),
|
|
76
78
|
__metadata("design:paramtypes", [Object, config_1.ConfigService])
|
|
77
79
|
], HackschoolService);
|
|
@@ -13,6 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.IdeasService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
16
17
|
const config_1 = require("@nestjs/config");
|
|
17
18
|
const authentication_1 = require("../../authentication");
|
|
18
19
|
const base_http_service_1 = require("../base-http.service");
|
|
@@ -36,6 +37,7 @@ let IdeasService = class IdeasService extends base_http_service_1.BaseHttpServic
|
|
|
36
37
|
};
|
|
37
38
|
exports.IdeasService = IdeasService;
|
|
38
39
|
exports.IdeasService = IdeasService = __decorate([
|
|
40
|
+
(0, common_1.Injectable)(),
|
|
39
41
|
__param(0, (0, authentication_1.InjectAuthenticationOptions)()),
|
|
40
42
|
__metadata("design:paramtypes", [Object, config_1.ConfigService])
|
|
41
43
|
], IdeasService);
|
|
@@ -13,6 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.LunchRouletteService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
16
17
|
const config_1 = require("@nestjs/config");
|
|
17
18
|
const authentication_1 = require("../../authentication");
|
|
18
19
|
const base_http_service_1 = require("../base-http.service");
|
|
@@ -36,6 +37,7 @@ let LunchRouletteService = class LunchRouletteService extends base_http_service_
|
|
|
36
37
|
};
|
|
37
38
|
exports.LunchRouletteService = LunchRouletteService;
|
|
38
39
|
exports.LunchRouletteService = LunchRouletteService = __decorate([
|
|
40
|
+
(0, common_1.Injectable)(),
|
|
39
41
|
__param(0, (0, authentication_1.InjectAuthenticationOptions)()),
|
|
40
42
|
__metadata("design:paramtypes", [Object, config_1.ConfigService])
|
|
41
43
|
], LunchRouletteService);
|
|
@@ -44,7 +44,7 @@ let MailService = class MailService extends base_http_service_1.BaseHttpService
|
|
|
44
44
|
*/
|
|
45
45
|
sendMail(type, payload) {
|
|
46
46
|
// Email service expects paths like "auth/login-token"
|
|
47
|
-
const endpoint = type.
|
|
47
|
+
const endpoint = type.replace(/\./g, '/');
|
|
48
48
|
this.logger.log(`Dispatching email to endpoint: ${endpoint}`);
|
|
49
49
|
this.client
|
|
50
50
|
.post(`internal/${endpoint}`, payload)
|
|
@@ -13,6 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.NewsletterService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
16
17
|
const config_1 = require("@nestjs/config");
|
|
17
18
|
const authentication_1 = require("../../authentication");
|
|
18
19
|
const base_http_service_1 = require("../base-http.service");
|
|
@@ -48,6 +49,7 @@ let NewsletterService = class NewsletterService extends base_http_service_1.Base
|
|
|
48
49
|
};
|
|
49
50
|
exports.NewsletterService = NewsletterService;
|
|
50
51
|
exports.NewsletterService = NewsletterService = __decorate([
|
|
52
|
+
(0, common_1.Injectable)(),
|
|
51
53
|
__param(0, (0, authentication_1.InjectAuthenticationOptions)()),
|
|
52
54
|
__metadata("design:paramtypes", [Object, config_1.ConfigService])
|
|
53
55
|
], NewsletterService);
|
|
@@ -13,6 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.NewsroomService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
16
17
|
const config_1 = require("@nestjs/config");
|
|
17
18
|
const class_validator_1 = require("class-validator");
|
|
18
19
|
const authentication_1 = require("../../authentication");
|
|
@@ -66,6 +67,7 @@ let NewsroomService = class NewsroomService extends base_http_service_1.BaseHttp
|
|
|
66
67
|
};
|
|
67
68
|
exports.NewsroomService = NewsroomService;
|
|
68
69
|
exports.NewsroomService = NewsroomService = __decorate([
|
|
70
|
+
(0, common_1.Injectable)(),
|
|
69
71
|
__param(0, (0, authentication_1.InjectAuthenticationOptions)()),
|
|
70
72
|
__metadata("design:paramtypes", [Object, config_1.ConfigService])
|
|
71
73
|
], NewsroomService);
|
|
@@ -13,6 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.PodcastsService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
16
17
|
const config_1 = require("@nestjs/config");
|
|
17
18
|
const authentication_1 = require("../../authentication");
|
|
18
19
|
const base_http_service_1 = require("../base-http.service");
|
|
@@ -48,6 +49,7 @@ let PodcastsService = class PodcastsService extends base_http_service_1.BaseHttp
|
|
|
48
49
|
};
|
|
49
50
|
exports.PodcastsService = PodcastsService;
|
|
50
51
|
exports.PodcastsService = PodcastsService = __decorate([
|
|
52
|
+
(0, common_1.Injectable)(),
|
|
51
53
|
__param(0, (0, authentication_1.InjectAuthenticationOptions)()),
|
|
52
54
|
__metadata("design:paramtypes", [Object, config_1.ConfigService])
|
|
53
55
|
], PodcastsService);
|
|
@@ -155,7 +155,7 @@ let SearchService = SearchService_1 = class SearchService extends base_http_serv
|
|
|
155
155
|
const fetchSimilarDocuments = () => this.getSimilarDocuments(resourceId);
|
|
156
156
|
if (this.cacheService) {
|
|
157
157
|
const cacheKey = `${this.options.resource}.${resourceId}.similarDocuments`;
|
|
158
|
-
return this.cacheService.fetchOrStore(cacheKey, fetchSimilarDocuments,
|
|
158
|
+
return this.cacheService.fetchOrStore(cacheKey, fetchSimilarDocuments, 18000000); // 30 Minutes
|
|
159
159
|
}
|
|
160
160
|
return fetchSimilarDocuments();
|
|
161
161
|
}
|
|
@@ -13,6 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.TeamService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
16
17
|
const config_1 = require("@nestjs/config");
|
|
17
18
|
const authentication_1 = require("../../authentication");
|
|
18
19
|
const base_http_service_1 = require("../base-http.service");
|
|
@@ -48,6 +49,7 @@ let TeamService = class TeamService extends base_http_service_1.BaseHttpService
|
|
|
48
49
|
};
|
|
49
50
|
exports.TeamService = TeamService;
|
|
50
51
|
exports.TeamService = TeamService = __decorate([
|
|
52
|
+
(0, common_1.Injectable)(),
|
|
51
53
|
__param(0, (0, authentication_1.InjectAuthenticationOptions)()),
|
|
52
54
|
__metadata("design:paramtypes", [Object, config_1.ConfigService])
|
|
53
55
|
], TeamService);
|
|
@@ -13,6 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.TechRadarService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
16
17
|
const config_1 = require("@nestjs/config");
|
|
17
18
|
const authentication_1 = require("../../authentication");
|
|
18
19
|
const base_http_service_1 = require("../base-http.service");
|
|
@@ -60,6 +61,7 @@ let TechRadarService = class TechRadarService extends base_http_service_1.BaseHt
|
|
|
60
61
|
};
|
|
61
62
|
exports.TechRadarService = TechRadarService;
|
|
62
63
|
exports.TechRadarService = TechRadarService = __decorate([
|
|
64
|
+
(0, common_1.Injectable)(),
|
|
63
65
|
__param(0, (0, authentication_1.InjectAuthenticationOptions)()),
|
|
64
66
|
__metadata("design:paramtypes", [Object, config_1.ConfigService])
|
|
65
67
|
], TechRadarService);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContentReturnType } from '../modules';
|
|
2
|
+
type PropertyContentReturnTypeOptions = {
|
|
3
|
+
optional?: boolean;
|
|
4
|
+
default?: ContentReturnType;
|
|
5
|
+
};
|
|
6
|
+
export declare function PropertyContentReturnType(options?: PropertyContentReturnTypeOptions): PropertyDecorator;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PropertyContentReturnType = PropertyContentReturnType;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
+
const class_transformer_1 = require("class-transformer");
|
|
7
|
+
const class_validator_1 = require("class-validator");
|
|
8
|
+
const content_return_types_1 = require("../modules/services/providers/content/content-return-types");
|
|
9
|
+
function isSupportedContentType(value) {
|
|
10
|
+
return content_return_types_1.supportedContentReturnTypes.some((type) => type === value);
|
|
11
|
+
}
|
|
12
|
+
function PropertyContentReturnType(options = {}) {
|
|
13
|
+
const decorators = [
|
|
14
|
+
(0, swagger_1.ApiProperty)(Object.assign({ description: 'In which format should the content be returned', examples: [...content_return_types_1.supportedContentReturnTypes] }, options)),
|
|
15
|
+
(0, class_transformer_1.Transform)(({ value }) => (isSupportedContentType(value) ? value : options.default)),
|
|
16
|
+
(0, class_validator_1.IsIn)(content_return_types_1.supportedContentReturnTypes, { message: 'Invalid content return type' }),
|
|
17
|
+
];
|
|
18
|
+
if (options.optional) {
|
|
19
|
+
decorators.push(common_1.Optional);
|
|
20
|
+
}
|
|
21
|
+
return (0, common_1.applyDecorators)(...decorators);
|
|
22
|
+
}
|
package/dist/properties/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PropertyContent = void 0;
|
|
3
|
+
exports.PropertiesViewable = exports.PropertiesLikeable = exports.PropertyContent = exports.PropertyContentReturnType = void 0;
|
|
4
|
+
var content_return_type_property_1 = require("./content-return-type.property");
|
|
5
|
+
Object.defineProperty(exports, "PropertyContentReturnType", { enumerable: true, get: function () { return content_return_type_property_1.PropertyContentReturnType; } });
|
|
4
6
|
var content_property_1 = require("./content.property");
|
|
5
7
|
Object.defineProperty(exports, "PropertyContent", { enumerable: true, get: function () { return content_property_1.PropertyContent; } });
|
|
8
|
+
var likeable_properties_1 = require("./likeable.properties");
|
|
9
|
+
Object.defineProperty(exports, "PropertiesLikeable", { enumerable: true, get: function () { return likeable_properties_1.PropertiesLikeable; } });
|
|
10
|
+
var viewable_properties_1 = require("./viewable.properties");
|
|
11
|
+
Object.defineProperty(exports, "PropertiesViewable", { enumerable: true, get: function () { return viewable_properties_1.PropertiesViewable; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function PropertiesLikeable(): ClassDecorator;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PropertiesLikeable = PropertiesLikeable;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
+
const models_1 = require("../models");
|
|
7
|
+
function PropertiesLikeable() {
|
|
8
|
+
return (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({
|
|
9
|
+
name: '_likedBy',
|
|
10
|
+
description: 'Array of user IDs that liked this resource.',
|
|
11
|
+
type: [String],
|
|
12
|
+
default: [],
|
|
13
|
+
}), (0, swagger_1.ApiPropertyOptional)({
|
|
14
|
+
name: 'likes',
|
|
15
|
+
description: 'Total number of likes for this resource.',
|
|
16
|
+
type: Number,
|
|
17
|
+
default: 0,
|
|
18
|
+
}), (0, swagger_1.ApiPropertyOptional)({
|
|
19
|
+
name: 'likedBy',
|
|
20
|
+
description: 'Populated list of User objects who liked this resource.',
|
|
21
|
+
type: [models_1.User],
|
|
22
|
+
default: [],
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
// /**
|
|
26
|
+
// * Decorator for the internal array of user IDs who liked the resource.
|
|
27
|
+
// */
|
|
28
|
+
// export function PropertyLikedBy(): PropertyDecorator {
|
|
29
|
+
// return applyDecorators(
|
|
30
|
+
// ApiPropertyOptional({
|
|
31
|
+
// name: '_likedBy',
|
|
32
|
+
// description: 'Array of user IDs that liked this resource.',
|
|
33
|
+
// type: [String],
|
|
34
|
+
// default: [],
|
|
35
|
+
// }),
|
|
36
|
+
// Prop({ required: true, default: () => [] }),
|
|
37
|
+
// );
|
|
38
|
+
// }
|
|
39
|
+
// /**
|
|
40
|
+
// * Decorator for the total number of likes on the resource.
|
|
41
|
+
// */
|
|
42
|
+
// export function PropertyLikes(): PropertyDecorator {
|
|
43
|
+
// return applyDecorators(
|
|
44
|
+
// ApiPropertyOptional({
|
|
45
|
+
// name: 'likes',
|
|
46
|
+
// description: 'Total number of likes for this resource.',
|
|
47
|
+
// type: Number,
|
|
48
|
+
// default: 0,
|
|
49
|
+
// }),
|
|
50
|
+
// Prop({ required: true, default: 0 }),
|
|
51
|
+
// );
|
|
52
|
+
// }
|
|
53
|
+
// /**
|
|
54
|
+
// * Virtual decorator to expose the populated list of users who liked the resource.
|
|
55
|
+
// */
|
|
56
|
+
// export function VirtualLikedBy(): PropertyDecorator {
|
|
57
|
+
// return applyDecorators(
|
|
58
|
+
// ApiPropertyOptional({
|
|
59
|
+
// name: 'likedBy',
|
|
60
|
+
// description: 'Populated list of User objects who liked this resource.',
|
|
61
|
+
// type: [User],
|
|
62
|
+
// default: [],
|
|
63
|
+
// }),
|
|
64
|
+
// Virtual(),
|
|
65
|
+
// );
|
|
66
|
+
// }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function PropertiesViewable(): ClassDecorator;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PropertiesViewable = PropertiesViewable;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
+
const models_1 = require("../models");
|
|
7
|
+
function PropertiesViewable() {
|
|
8
|
+
return (0, common_1.applyDecorators)((0, swagger_1.ApiPropertyOptional)({
|
|
9
|
+
name: '_viewedBy',
|
|
10
|
+
description: 'Array of user IDs that have viewed this resource.',
|
|
11
|
+
type: [String],
|
|
12
|
+
default: [],
|
|
13
|
+
}), (0, swagger_1.ApiPropertyOptional)({
|
|
14
|
+
name: 'views',
|
|
15
|
+
description: 'Total number of views for this resource.',
|
|
16
|
+
type: Number,
|
|
17
|
+
default: 0,
|
|
18
|
+
}), (0, swagger_1.ApiPropertyOptional)({
|
|
19
|
+
name: 'viewedBy',
|
|
20
|
+
description: 'Populated list of User objects who viewed this resource.',
|
|
21
|
+
type: [models_1.User],
|
|
22
|
+
default: [],
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
// /**
|
|
26
|
+
// * Decorator for the internal array of user IDs who viewed the resource.
|
|
27
|
+
// */
|
|
28
|
+
// export function PropertyViewedBy(): PropertyDecorator {
|
|
29
|
+
// return applyDecorators(
|
|
30
|
+
// ApiPropertyOptional({
|
|
31
|
+
// name: '_viewedBy',
|
|
32
|
+
// description: 'Array of user IDs that have viewed this resource.',
|
|
33
|
+
// type: [String],
|
|
34
|
+
// default: [],
|
|
35
|
+
// }),
|
|
36
|
+
// Prop({ required: true, default: () => [] }),
|
|
37
|
+
// );
|
|
38
|
+
// }
|
|
39
|
+
// /**
|
|
40
|
+
// * Decorator for the total number of views on the resource.
|
|
41
|
+
// */
|
|
42
|
+
// export function PropertyViews(): PropertyDecorator {
|
|
43
|
+
// return applyDecorators(
|
|
44
|
+
// ApiPropertyOptional({
|
|
45
|
+
// name: 'views',
|
|
46
|
+
// description: 'Total number of views for this resource.',
|
|
47
|
+
// type: Number,
|
|
48
|
+
// default: 0,
|
|
49
|
+
// }),
|
|
50
|
+
// Prop({ required: true, default: 0 }),
|
|
51
|
+
// );
|
|
52
|
+
// }
|
|
53
|
+
// /**
|
|
54
|
+
// * Virtual decorator to expose the populated list of users who viewed the resource.
|
|
55
|
+
// */
|
|
56
|
+
// export function VirtualViewedBy(): PropertyDecorator {
|
|
57
|
+
// return applyDecorators(
|
|
58
|
+
// ApiPropertyOptional({
|
|
59
|
+
// name: 'viewedBy',
|
|
60
|
+
// description: 'Populated list of User objects who viewed this resource.',
|
|
61
|
+
// type: [User],
|
|
62
|
+
// default: [],
|
|
63
|
+
// }),
|
|
64
|
+
// Virtual(),
|
|
65
|
+
// );
|
|
66
|
+
// }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./likeable.type"), exports);
|
|
18
|
+
__exportStar(require("./viewable.type"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { User } from '../models';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an entity that can be liked by users.
|
|
4
|
+
*
|
|
5
|
+
* - `_likedBy`: stores IDs of users who liked the entity.
|
|
6
|
+
* - `likes`: computed total number of likes.
|
|
7
|
+
* - `likedBy`: optional populated list of User objects.
|
|
8
|
+
*/
|
|
9
|
+
export type Likeable = {
|
|
10
|
+
_likedBy: string[];
|
|
11
|
+
likes: number;
|
|
12
|
+
likedBy?: User[];
|
|
13
|
+
addLike(accountId: string): Promise<void>;
|
|
14
|
+
removeLike(accountId: string): Promise<void>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { User } from '../models';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an entity that can be viewed by users.
|
|
4
|
+
*
|
|
5
|
+
* - `_viewedBy`: stores IDs of users who viewed the entity.
|
|
6
|
+
* - `views`: computed total number of views.
|
|
7
|
+
* - `viewedBy`: optional populated list of User objects.
|
|
8
|
+
*/
|
|
9
|
+
export type Viewable = {
|
|
10
|
+
_viewedBy: string[];
|
|
11
|
+
views: number;
|
|
12
|
+
viewedBy?: User[];
|
|
13
|
+
addView(accountId: string): Promise<void>;
|
|
14
|
+
removeView(accountId: string): Promise<void>;
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"name": "Timo Scheuermann",
|
|
5
5
|
"email": "timo.scheuermann@sv-informatik.de"
|
|
6
6
|
},
|
|
7
|
-
"version": "2.16.
|
|
7
|
+
"version": "2.16.1",
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"cache-manager": "^7.1.1",
|
|
36
36
|
"class-transformer": "^0.5.1",
|
|
37
37
|
"class-validator": "^0.14.2",
|
|
38
|
-
"itlab-functions": "^1.0.
|
|
38
|
+
"itlab-functions": "^1.0.6",
|
|
39
39
|
"mongoose": "^8.17.1",
|
|
40
40
|
"rxjs": "^7.8.2"
|
|
41
41
|
},
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Document } from 'mongoose';
|
|
2
|
-
import { Viewable } from '../viewable.interface';
|
|
3
|
-
/**
|
|
4
|
-
* Facilitates asynchronous updates to documents by adding unique account IDs to specified
|
|
5
|
-
* array attributes. This prevents duplication of IDs in those arrays, ensuring data integrity.
|
|
6
|
-
*
|
|
7
|
-
* Designed primarily for adding account references such as views or other related IDs.
|
|
8
|
-
*/
|
|
9
|
-
export declare class DocumentUpdater {
|
|
10
|
-
private static readonly logger;
|
|
11
|
-
/**
|
|
12
|
-
* Adds an account ID uniquely to a specified array attribute of a document.
|
|
13
|
-
*
|
|
14
|
-
* This method verifies the presence of an accountId before proceeding.
|
|
15
|
-
* It then performs an atomic MongoDB `$addToSet` update on the document to
|
|
16
|
-
* add the accountId to the given attribute array only if it is not already present,
|
|
17
|
-
* preventing duplicates without needing to fetch the document first.
|
|
18
|
-
*
|
|
19
|
-
* Updates are saved without modifying timestamps to preserve original metadata.
|
|
20
|
-
*
|
|
21
|
-
* @template I - Interface representing the document’s shape.
|
|
22
|
-
* @template T - Mongoose Document type extending `Document`.
|
|
23
|
-
* @param document - The Mongoose document to update.
|
|
24
|
-
* @param attribute - The document attribute (key) representing the array to update.
|
|
25
|
-
* @param accountId - The unique account ID to add.
|
|
26
|
-
*/
|
|
27
|
-
static addUniqueAccountId<I, T extends Document = Document>(document: T, attribute: keyof I, accountId?: string): void;
|
|
28
|
-
/**
|
|
29
|
-
* Adds a view record to a document by associating an account ID with the '_viewedBy' attribute.
|
|
30
|
-
*
|
|
31
|
-
* This method leverages `addUniqueAccountId` to add the given accountId to the '_viewedBy' array,
|
|
32
|
-
* ensuring each viewer is recorded only once.
|
|
33
|
-
*
|
|
34
|
-
* @template T - Mongoose Document type that extends Document and implements Viewable interface.
|
|
35
|
-
* @param target - The target document to record the view.
|
|
36
|
-
* @param accountId - The account ID representing the viewer.
|
|
37
|
-
*/
|
|
38
|
-
static addView<T extends Document & Viewable>(target: T, accountId?: string): void;
|
|
39
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DocumentUpdater = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
/**
|
|
6
|
-
* Facilitates asynchronous updates to documents by adding unique account IDs to specified
|
|
7
|
-
* array attributes. This prevents duplication of IDs in those arrays, ensuring data integrity.
|
|
8
|
-
*
|
|
9
|
-
* Designed primarily for adding account references such as views or other related IDs.
|
|
10
|
-
*/
|
|
11
|
-
class DocumentUpdater {
|
|
12
|
-
/**
|
|
13
|
-
* Adds an account ID uniquely to a specified array attribute of a document.
|
|
14
|
-
*
|
|
15
|
-
* This method verifies the presence of an accountId before proceeding.
|
|
16
|
-
* It then performs an atomic MongoDB `$addToSet` update on the document to
|
|
17
|
-
* add the accountId to the given attribute array only if it is not already present,
|
|
18
|
-
* preventing duplicates without needing to fetch the document first.
|
|
19
|
-
*
|
|
20
|
-
* Updates are saved without modifying timestamps to preserve original metadata.
|
|
21
|
-
*
|
|
22
|
-
* @template I - Interface representing the document’s shape.
|
|
23
|
-
* @template T - Mongoose Document type extending `Document`.
|
|
24
|
-
* @param document - The Mongoose document to update.
|
|
25
|
-
* @param attribute - The document attribute (key) representing the array to update.
|
|
26
|
-
* @param accountId - The unique account ID to add.
|
|
27
|
-
*/
|
|
28
|
-
static addUniqueAccountId(document, attribute, accountId) {
|
|
29
|
-
if (!accountId)
|
|
30
|
-
return; // Exit if no accountId provided, avoiding unnecessary operations.
|
|
31
|
-
// Perform atomic update to add accountId uniquely to the attribute array.
|
|
32
|
-
document
|
|
33
|
-
.updateOne({ $addToSet: { [String(attribute)]: accountId } }, { timestamps: false })
|
|
34
|
-
.then(() => {
|
|
35
|
-
this.logger.log(`Added unique accountId '${accountId}' to attribute '${String(attribute)}' for document ${document._id.toString()}`);
|
|
36
|
-
})
|
|
37
|
-
.catch((error) => {
|
|
38
|
-
// Log any errors during the update operation for debugging and audit.
|
|
39
|
-
this.logger.error(`Failed to add accountId '${accountId}' to attribute '${String(attribute)}' for document ${document._id.toString()}: ${error.stack}`);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Adds a view record to a document by associating an account ID with the '_viewedBy' attribute.
|
|
44
|
-
*
|
|
45
|
-
* This method leverages `addUniqueAccountId` to add the given accountId to the '_viewedBy' array,
|
|
46
|
-
* ensuring each viewer is recorded only once.
|
|
47
|
-
*
|
|
48
|
-
* @template T - Mongoose Document type that extends Document and implements Viewable interface.
|
|
49
|
-
* @param target - The target document to record the view.
|
|
50
|
-
* @param accountId - The account ID representing the viewer.
|
|
51
|
-
*/
|
|
52
|
-
static addView(target, accountId) {
|
|
53
|
-
this.addUniqueAccountId(target, '_viewedBy', accountId);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.DocumentUpdater = DocumentUpdater;
|
|
57
|
-
DocumentUpdater.logger = new common_1.Logger('DocumentUpdater');
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { INestApplication } from '@nestjs/common';
|
|
2
|
-
/**
|
|
3
|
-
* @function setupHttpLoggingMiddleware
|
|
4
|
-
* @description
|
|
5
|
-
* Attaches a middleware to the given NestJS application instance for logging HTTP requests and responses.
|
|
6
|
-
* This middleware logs only non-API and non-internal requests to avoid log clutter from system or Swagger routes.
|
|
7
|
-
* Logs include the HTTP method, original URL, response status code, and message.
|
|
8
|
-
*
|
|
9
|
-
* @param {INestApplication} app - The NestJS application to which the logging middleware will be applied.
|
|
10
|
-
* @returns {void}
|
|
11
|
-
*/
|
|
12
|
-
export declare function setupHttpLoggingMiddleware(app: INestApplication): void;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setupHttpLoggingMiddleware = setupHttpLoggingMiddleware;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
/**
|
|
6
|
-
* @function setupHttpLoggingMiddleware
|
|
7
|
-
* @description
|
|
8
|
-
* Attaches a middleware to the given NestJS application instance for logging HTTP requests and responses.
|
|
9
|
-
* This middleware logs only non-API and non-internal requests to avoid log clutter from system or Swagger routes.
|
|
10
|
-
* Logs include the HTTP method, original URL, response status code, and message.
|
|
11
|
-
*
|
|
12
|
-
* @param {INestApplication} app - The NestJS application to which the logging middleware will be applied.
|
|
13
|
-
* @returns {void}
|
|
14
|
-
*/
|
|
15
|
-
function setupHttpLoggingMiddleware(app) {
|
|
16
|
-
app.use((req, res, next) => {
|
|
17
|
-
const { method, url } = req;
|
|
18
|
-
// Define a list of routes to exclude from logging to prevent unnecessary noise
|
|
19
|
-
const excludedPaths = ['/alive', '/favicon.ico'];
|
|
20
|
-
// Skip logging for known non-critical paths and documentation endpoints
|
|
21
|
-
const isSwagger = url.includes('swagger');
|
|
22
|
-
const isApiInternal = url.startsWith('/api');
|
|
23
|
-
const isExcluded = excludedPaths.includes(url);
|
|
24
|
-
if (isSwagger || isApiInternal || isExcluded) {
|
|
25
|
-
next(); // Skip logging logic for ignored routes
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
// Log response info once the request lifecycle completes
|
|
29
|
-
res.on('finish', () => {
|
|
30
|
-
const { statusCode, statusMessage } = res;
|
|
31
|
-
// Construct log entry using standardized format
|
|
32
|
-
const message = `${method} ${url} - ${statusCode} (${statusMessage})`;
|
|
33
|
-
// Use 'warn' log level for client errors, otherwise use standard 'log'
|
|
34
|
-
const level = statusCode >= 400 && statusCode < 500 ? 'warn' : 'log';
|
|
35
|
-
// Avoid logging again if the path is excluded
|
|
36
|
-
if (!excludedPaths.includes(url)) {
|
|
37
|
-
new common_1.Logger('HTTP')[level](message);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
// Proceed to next middleware or route handler
|
|
41
|
-
next();
|
|
42
|
-
});
|
|
43
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface for entities that can be liked by users. Used to track engagement metrics
|
|
3
|
-
* such as user interest or approval. Fields include a reference to user IDs and a count of total likes.
|
|
4
|
-
*
|
|
5
|
-
* Intended to be implemented or extended by Mongoose documents representing likeable resources.
|
|
6
|
-
*/
|
|
7
|
-
export interface Likeable {
|
|
8
|
-
/**
|
|
9
|
-
* List of account IDs who have liked this entity.
|
|
10
|
-
*/
|
|
11
|
-
_likedBy: string[];
|
|
12
|
-
/**
|
|
13
|
-
* Count of total likes.
|
|
14
|
-
*/
|
|
15
|
-
likes: number;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Mongoose property decorator for defining the `_likedBy` field.
|
|
19
|
-
* This field is required and initialized with an empty array to ensure consistency.
|
|
20
|
-
*
|
|
21
|
-
* Useful for tracking which accounts have liked a particular document.
|
|
22
|
-
*
|
|
23
|
-
* @returns {PropertyDecorator} - Mongoose property configuration for `_likedBy`.
|
|
24
|
-
*/
|
|
25
|
-
export declare function PropertyLikedBy(): PropertyDecorator;
|
|
26
|
-
/**
|
|
27
|
-
* Swagger property decorator for documenting the `_likedBy` field in API specs.
|
|
28
|
-
* Describes the field as an array of `Account` and documents its usage.
|
|
29
|
-
*
|
|
30
|
-
* This improves visibility in auto-generated API docs for consumers of likeable entities.
|
|
31
|
-
*
|
|
32
|
-
* @returns {PropertyDecorator} - Swagger metadata for the `_likedBy` field.
|
|
33
|
-
*/
|
|
34
|
-
export declare function ApiLikedBy(): PropertyDecorator;
|
|
35
|
-
/**
|
|
36
|
-
* Swagger property decorator for documenting the `likes` field in API responses.
|
|
37
|
-
* Represents the total number of likes and helps clarify it is derived/cached.
|
|
38
|
-
*
|
|
39
|
-
* @returns {PropertyDecorator} - Swagger metadata for the `likes` field.
|
|
40
|
-
*/
|
|
41
|
-
export declare function ApiLikes(): PropertyDecorator;
|