itlab-internal-services 2.16.1 → 2.16.3
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/commentable-document.class.d.ts +200 -0
- package/dist/classes/document/commentable-document.class.js +24 -0
- package/dist/classes/document/content-document.class.d.ts +200 -0
- package/dist/classes/document/content-document.class.js +24 -0
- package/dist/classes/document/index.d.ts +4 -0
- package/dist/classes/document/index.js +11 -0
- package/dist/classes/document/likeable-document.class.d.ts +205 -0
- package/dist/classes/document/likeable-document.class.js +70 -0
- package/dist/classes/document/viewable-document.class.d.ts +205 -0
- package/dist/classes/document/viewable-document.class.js +67 -0
- package/dist/classes/document-updater.class.d.ts +40 -0
- package/dist/classes/document-updater.class.js +58 -0
- package/dist/classes/fetch-options/base-options.class.d.ts +18 -0
- package/dist/classes/fetch-options/base-options.class.js +81 -0
- package/dist/classes/fetch-options/comments-options.class.d.ts +6 -0
- package/dist/classes/fetch-options/comments-options.class.js +26 -0
- package/dist/classes/fetch-options/content-options.class.d.ts +7 -0
- package/dist/classes/fetch-options/content-options.class.js +32 -0
- package/dist/classes/fetch-options/drafted-options.class.d.ts +9 -0
- package/dist/classes/fetch-options/drafted-options.class.js +34 -0
- package/dist/classes/fetch-options/index.d.ts +6 -0
- package/dist/classes/fetch-options/index.js +15 -0
- package/dist/classes/fetch-options/liked-by-options.class.d.ts +8 -0
- package/dist/classes/fetch-options/liked-by-options.class.js +28 -0
- package/dist/classes/fetch-options/viewed-by-options.class.d.ts +9 -0
- package/dist/classes/fetch-options/viewed-by-options.class.js +28 -0
- package/dist/classes/index.d.ts +2 -2
- package/dist/classes/index.js +17 -3
- package/dist/classes/task-manager.class.d.ts +2 -2
- package/dist/classes/task-manager.class.js +4 -0
- package/dist/decorators/has-permission.decorator.d.ts +3 -0
- package/dist/decorators/has-permission.decorator.js +26 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/jwt.decorator.d.ts +1 -1
- package/dist/decorators/jwt.decorator.js +13 -11
- package/dist/decorators/schema-with-critical-keys.decorator.d.ts +12 -0
- package/dist/decorators/schema-with-critical-keys.decorator.js +16 -0
- package/dist/factories/index.d.ts +1 -0
- package/dist/factories/index.js +5 -0
- package/dist/factories/virtuals.factory.d.ts +80 -0
- package/dist/factories/virtuals.factory.js +172 -0
- package/dist/functions/create-schema.function.d.ts +3 -0
- package/dist/functions/create-schema.function.js +33 -0
- package/dist/functions/index.d.ts +1 -1
- package/dist/functions/index.js +3 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +10 -0
- package/dist/likeable.interface.d.ts +42 -0
- package/dist/likeable.interface.js +48 -0
- package/dist/modules/_old/comment/comment.controller.d.ts +35 -0
- package/dist/modules/_old/comment/comment.controller.js +86 -0
- package/dist/modules/_old/comment/comment.model.d.ts +29 -0
- package/dist/modules/_old/comment/comment.model.js +43 -0
- package/dist/modules/_old/comment/comment.module-definition.d.ts +45 -0
- package/dist/modules/{comment → _old/comment}/comment.module-definition.js +2 -1
- package/dist/modules/_old/comment/comment.module.d.ts +22 -0
- package/dist/modules/_old/comment/comment.module.js +71 -0
- package/dist/modules/_old/comment/comment.service.d.ts +54 -0
- package/dist/modules/_old/comment/comment.service.js +133 -0
- package/dist/modules/_old/comment/index.d.ts +3 -0
- package/dist/modules/_old/comment/index.js +9 -0
- package/dist/modules/_old/content/content.module-definition.d.ts +5 -0
- package/dist/modules/_old/content/content.module-definition.js +8 -0
- package/dist/modules/_old/content/content.module.d.ts +31 -0
- package/dist/modules/_old/content/content.module.js +60 -0
- package/dist/modules/_old/content/content.service.d.ts +50 -0
- package/dist/modules/_old/content/content.service.js +145 -0
- package/dist/modules/_old/content/index.d.ts +2 -0
- package/dist/modules/_old/content/index.js +7 -0
- package/dist/modules/_old/database/database-module-options.interface.d.ts +41 -0
- package/dist/modules/_old/database/database.liveness-controller.d.ts +27 -0
- package/dist/modules/_old/database/database.liveness-controller.js +80 -0
- package/dist/modules/_old/database/database.module.d.ts +41 -0
- package/dist/modules/_old/database/database.module.js +97 -0
- package/dist/modules/_old/database/index.d.ts +6 -0
- package/dist/modules/_old/database/index.js +13 -0
- package/dist/modules/_old/database/lock-service/lock.schema.d.ts +38 -0
- package/dist/modules/_old/database/lock-service/lock.schema.js +51 -0
- package/dist/modules/_old/database/lock-service/lock.service.d.ts +53 -0
- package/dist/modules/_old/database/lock-service/lock.service.js +103 -0
- package/dist/modules/_old/database/model-service/dbs/hub-account.db.d.ts +28 -0
- package/dist/modules/_old/database/model-service/dbs/hub-account.db.js +44 -0
- package/dist/modules/_old/database/model-service/dbs/hub-books.db.d.ts +23 -0
- package/dist/modules/_old/database/model-service/dbs/hub-books.db.js +45 -0
- package/dist/modules/_old/database/model-service/dbs/hub-comments.db.d.ts +29 -0
- package/dist/modules/_old/database/model-service/dbs/hub-comments.db.js +68 -0
- package/dist/modules/_old/database/model-service/dbs/hub-content.db.d.ts +24 -0
- package/dist/modules/_old/database/model-service/dbs/hub-content.db.js +49 -0
- package/dist/modules/_old/database/model-service/dbs/hub-demo-hive.db.d.ts +23 -0
- package/dist/modules/_old/database/model-service/dbs/hub-demo-hive.db.js +45 -0
- package/dist/modules/_old/database/model-service/dbs/hub-events.db.d.ts +24 -0
- package/dist/modules/_old/database/model-service/dbs/hub-events.db.js +49 -0
- package/dist/modules/_old/database/model-service/dbs/hub-hackschool.db.d.ts +60 -0
- package/dist/modules/_old/database/model-service/dbs/hub-hackschool.db.js +106 -0
- package/dist/modules/_old/database/model-service/dbs/hub-newsroom.db.d.ts +25 -0
- package/dist/modules/_old/database/model-service/dbs/hub-newsroom.db.js +53 -0
- package/dist/modules/_old/database/model-service/dbs/hub-podcasts.db.d.ts +23 -0
- package/dist/modules/_old/database/model-service/dbs/hub-podcasts.db.js +45 -0
- package/dist/modules/_old/database/model-service/dbs/hub-team.db.d.ts +22 -0
- package/dist/modules/_old/database/model-service/dbs/hub-team.db.js +41 -0
- package/dist/modules/_old/database/model-service/dbs/hub-tech-radar.db.d.ts +42 -0
- package/dist/modules/_old/database/model-service/dbs/hub-tech-radar.db.js +81 -0
- package/dist/modules/_old/database/model-service/model.service.d.ts +8465 -0
- package/dist/modules/_old/database/model-service/model.service.js +136 -0
- package/dist/modules/_old/database/populate-service/populate.service.d.ts +73 -0
- package/dist/modules/_old/database/populate-service/populate.service.js +163 -0
- package/dist/modules/_old/database/service-mapper-service/service-mapper.service.d.ts +32 -0
- package/dist/modules/_old/database/service-mapper-service/service-mapper.service.js +73 -0
- package/dist/modules/_old/fetch/fetch.module.d.ts +31 -0
- package/dist/modules/_old/fetch/fetch.module.js +60 -0
- package/dist/modules/_old/fetch/fetch.service.d.ts +153 -0
- package/dist/modules/_old/fetch/fetch.service.js +274 -0
- package/dist/modules/_old/fetch/index.d.ts +2 -0
- package/dist/modules/_old/fetch/index.js +7 -0
- package/dist/modules/_old/index.d.ts +5 -0
- package/dist/modules/{comment → _old}/index.js +5 -2
- package/dist/modules/_old/like/index.d.ts +1 -0
- package/dist/modules/_old/like/index.js +5 -0
- package/dist/modules/_old/like/like.controller.d.ts +41 -0
- package/dist/modules/_old/like/like.controller.js +125 -0
- package/dist/modules/_old/like/like.module-definition.d.ts +20 -0
- package/dist/modules/_old/like/like.module-definition.js +8 -0
- package/dist/modules/_old/like/like.module.d.ts +21 -0
- package/dist/modules/_old/like/like.module.js +67 -0
- package/dist/modules/_old/like/like.service.d.ts +61 -0
- package/dist/modules/_old/like/like.service.js +103 -0
- package/dist/modules/authentication/guards/jwt-auth.guard.d.ts +1 -1
- package/dist/modules/authentication/guards/jwt-auth.guard.js +5 -3
- package/dist/modules/authentication/guards/permissions.guard.d.ts +1 -3
- package/dist/modules/authentication/guards/permissions.guard.js +2 -8
- package/dist/modules/authentication/guards/service-auth.guard.d.ts +0 -4
- package/dist/modules/authentication/guards/service-auth.guard.js +10 -13
- package/dist/modules/{comment/comment-module-options.interface.d.ts → comments/comments-module-options.interface.d.ts} +3 -2
- package/dist/modules/comments/comments-module-options.interface.js +2 -0
- package/dist/modules/{comment/comment.controller.d.ts → comments/comments.controller.d.ts} +7 -6
- package/dist/modules/{comment/comment.controller.js → comments/comments.controller.js} +14 -14
- package/dist/modules/comments/comments.module-definition.d.ts +4 -0
- package/dist/modules/comments/comments.module-definition.js +7 -0
- package/dist/modules/{comment/comment.module.d.ts → comments/comments.module.d.ts} +6 -6
- package/dist/modules/{comment/comment.module.js → comments/comments.module.js} +17 -16
- package/dist/modules/{comment/comment.service.d.ts → comments/comments.service.d.ts} +35 -9
- package/dist/modules/comments/comments.service.js +165 -0
- package/dist/modules/comments/index.d.ts +3 -0
- package/dist/modules/{services/providers/comments → comments}/index.js +2 -0
- package/dist/modules/index.d.ts +1 -1
- package/dist/modules/index.js +1 -1
- package/dist/modules/like/like-module-options.interface.d.ts +1 -0
- package/dist/modules/like/like.controller.d.ts +3 -2
- package/dist/modules/like/like.controller.js +4 -4
- package/dist/modules/like/like.module.js +1 -1
- package/dist/modules/like/like.service.d.ts +0 -16
- package/dist/modules/like/like.service.js +9 -28
- package/dist/modules/merge/merge-module-options.interface.d.ts +1 -0
- package/dist/modules/merge/merge.controller.d.ts +3 -2
- package/dist/modules/merge/merge.controller.js +4 -4
- package/dist/modules/merge/merge.module.js +1 -1
- package/dist/modules/services/providers/accounts.service.js +4 -0
- package/dist/modules/services/providers/index.d.ts +0 -1
- package/dist/modules/services/providers/index.js +0 -1
- package/dist/modules/services/services.module.js +0 -1
- package/dist/pipes/index.d.ts +1 -0
- package/dist/pipes/index.js +1 -0
- package/dist/pipes/restricted-fields.pipe.d.ts +35 -0
- package/dist/pipes/restricted-fields.pipe.js +83 -0
- package/dist/properties/content-return-type.property.d.ts +4 -0
- package/dist/properties/content-return-type.property.js +12 -7
- package/dist/properties/content.property.d.ts +7 -2
- package/dist/properties/content.property.js +11 -3
- package/dist/properties/index.d.ts +2 -4
- package/dist/properties/index.js +5 -5
- package/dist/transform/index.d.ts +2 -0
- package/dist/transform/index.js +2 -0
- package/dist/transform/mongo-id.transform.d.ts +4 -0
- package/dist/transform/mongo-id.transform.js +13 -0
- package/dist/transform/mongo-ids.transform.d.ts +4 -0
- package/dist/transform/mongo-ids.transform.js +16 -0
- package/dist/types/duplicable-model.type.d.ts +10 -0
- package/dist/types/duplicable-model.type.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/likeable.type.d.ts +4 -3
- package/dist/types/viewable.type.d.ts +4 -3
- package/dist/viewable.interface.d.ts +42 -0
- package/dist/viewable.interface.js +48 -0
- package/package.json +1 -1
- package/dist/classes/schema-builder.class.d.ts +0 -75
- package/dist/classes/schema-builder.class.js +0 -109
- package/dist/modules/comment/comment.module-definition.d.ts +0 -4
- package/dist/modules/comment/comment.service.js +0 -99
- package/dist/modules/comment/index.d.ts +0 -2
- package/dist/modules/services/providers/comments/comments.service-definition.d.ts +0 -1
- package/dist/modules/services/providers/comments/comments.service-definition.js +0 -4
- package/dist/modules/services/providers/comments/comments.service.d.ts +0 -60
- package/dist/modules/services/providers/comments/comments.service.js +0 -139
- package/dist/modules/services/providers/comments/index.d.ts +0 -1
- package/dist/properties/likeable.properties.d.ts +0 -1
- package/dist/properties/likeable.properties.js +0 -66
- package/dist/properties/viewable.properties.d.ts +0 -1
- package/dist/properties/viewable.properties.js +0 -66
- /package/dist/modules/{comment/comment-module-options.interface.js → _old/database/database-module-options.interface.js} +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { LikeModuleOptions } from './like.module-definition';
|
|
3
|
+
/**
|
|
4
|
+
* LikeModule dynamically registers controllers and services to handle "like" functionality
|
|
5
|
+
* for different resources based on the provided model and optional suffix.
|
|
6
|
+
*
|
|
7
|
+
* This design enables modularity and reuse of like-related logic across various resource types.
|
|
8
|
+
*/
|
|
9
|
+
export declare class LikeModule {
|
|
10
|
+
/**
|
|
11
|
+
* Registers and configures the LikeModule dynamically.
|
|
12
|
+
*
|
|
13
|
+
* - Automatically generates an endpoint path based on provided suffix.
|
|
14
|
+
* - Tags the controller in Swagger docs for better discoverability.
|
|
15
|
+
* - Inherits all business logic from the base LikeController.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Configuration options including the model and route suffix.
|
|
18
|
+
* @returns A fully configured dynamic NestJS module.
|
|
19
|
+
*/
|
|
20
|
+
static register(options: LikeModuleOptions): DynamicModule;
|
|
21
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var LikeModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.LikeModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
13
|
+
const itlab_functions_1 = require("itlab-functions");
|
|
14
|
+
const like_controller_1 = require("./like.controller");
|
|
15
|
+
const like_module_definition_1 = require("./like.module-definition");
|
|
16
|
+
const like_service_1 = require("./like.service");
|
|
17
|
+
/**
|
|
18
|
+
* LikeModule dynamically registers controllers and services to handle "like" functionality
|
|
19
|
+
* for different resources based on the provided model and optional suffix.
|
|
20
|
+
*
|
|
21
|
+
* This design enables modularity and reuse of like-related logic across various resource types.
|
|
22
|
+
*/
|
|
23
|
+
let LikeModule = LikeModule_1 = class LikeModule {
|
|
24
|
+
/**
|
|
25
|
+
* Registers and configures the LikeModule dynamically.
|
|
26
|
+
*
|
|
27
|
+
* - Automatically generates an endpoint path based on provided suffix.
|
|
28
|
+
* - Tags the controller in Swagger docs for better discoverability.
|
|
29
|
+
* - Inherits all business logic from the base LikeController.
|
|
30
|
+
*
|
|
31
|
+
* @param options - Configuration options including the model and route suffix.
|
|
32
|
+
* @returns A fully configured dynamic NestJS module.
|
|
33
|
+
*/
|
|
34
|
+
static register(options) {
|
|
35
|
+
const { routeScope = [] } = options;
|
|
36
|
+
// Transform suffixes into a readable Swagger tag (e.g., "Like Module - Posts")
|
|
37
|
+
const swaggerTag = ['Like Module', ...routeScope.map((scope) => (0, itlab_functions_1.capitalize)(scope))].join(' -');
|
|
38
|
+
// Build the controller route path (e.g., "/like/posts")
|
|
39
|
+
const controllerRoutePath = ['like', ...routeScope].join('/');
|
|
40
|
+
/**
|
|
41
|
+
* A dynamically scoped LikeController for a specific resource.
|
|
42
|
+
*
|
|
43
|
+
* This controller uses a generated route path and custom Swagger tag,
|
|
44
|
+
* but otherwise inherits all base LikeController behavior.
|
|
45
|
+
*/
|
|
46
|
+
let LikeController = class LikeController extends like_controller_1.LikeController {
|
|
47
|
+
};
|
|
48
|
+
LikeController = __decorate([
|
|
49
|
+
(0, swagger_1.ApiTags)(swaggerTag),
|
|
50
|
+
(0, common_1.Controller)(controllerRoutePath)
|
|
51
|
+
], LikeController);
|
|
52
|
+
return {
|
|
53
|
+
module: LikeModule_1,
|
|
54
|
+
controllers: [LikeController],
|
|
55
|
+
providers: [like_service_1.LikeService, { provide: like_module_definition_1.LIKE_MODULE_OPTIONS_TOKEN, useValue: options }],
|
|
56
|
+
exports: [like_service_1.LikeService],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.LikeModule = LikeModule;
|
|
61
|
+
exports.LikeModule = LikeModule = LikeModule_1 = __decorate([
|
|
62
|
+
(0, common_1.Module)({
|
|
63
|
+
controllers: [like_controller_1.LikeController],
|
|
64
|
+
providers: [like_service_1.LikeService],
|
|
65
|
+
exports: [like_service_1.LikeService],
|
|
66
|
+
})
|
|
67
|
+
], LikeModule);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Connection } from 'mongoose';
|
|
2
|
+
import { LikeModuleOptions } from './like.module-definition';
|
|
3
|
+
/**
|
|
4
|
+
* LikeService manages the "like" functionality for resources.
|
|
5
|
+
*
|
|
6
|
+
* It provides methods to add, remove, and verify likes on resource entities,
|
|
7
|
+
* interacting with the underlying MongoDB collection configured by the module options.
|
|
8
|
+
*/
|
|
9
|
+
export declare class LikeService {
|
|
10
|
+
private readonly moduleOptions;
|
|
11
|
+
private readonly connection;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
private readonly likeModel;
|
|
14
|
+
/**
|
|
15
|
+
* Initializes LikeService with database connection and module configuration.
|
|
16
|
+
*
|
|
17
|
+
* @param {LikeModuleOptions} moduleOptions - The module options containing model info.
|
|
18
|
+
* @param {Connection} connection - The active MongoDB connection injected by Mongoose.
|
|
19
|
+
*/
|
|
20
|
+
constructor(moduleOptions: LikeModuleOptions, connection: Connection);
|
|
21
|
+
/**
|
|
22
|
+
* Computes the number of likes for a given resource document.
|
|
23
|
+
*
|
|
24
|
+
* @param {Document & Likeable} [resource] - The resource document which contains _likedBy array.
|
|
25
|
+
* @returns {number} The count of likes, or zero if none exist.
|
|
26
|
+
*/
|
|
27
|
+
private getLikeCount;
|
|
28
|
+
/**
|
|
29
|
+
* Adds a like to the specified resource by the given account.
|
|
30
|
+
*
|
|
31
|
+
* Uses MongoDB's `$addToSet` to avoid duplicate entries efficiently.
|
|
32
|
+
* Returns the updated count of likes after addition.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} resourceId - The identifier of the resource to like.
|
|
35
|
+
* @param {string} accountId - The account identifier that likes the resource.
|
|
36
|
+
* @returns {Promise<number>} The updated like count.
|
|
37
|
+
*/
|
|
38
|
+
addLike(resourceId: string, accountId: string): Promise<number>;
|
|
39
|
+
/**
|
|
40
|
+
* Removes a like from the specified resource by the given account.
|
|
41
|
+
*
|
|
42
|
+
* Uses MongoDB's `$pull` operator to remove the account ID from the liked list.
|
|
43
|
+
* Returns the updated count of likes after removal.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} resourceId - The identifier of the resource to unlike.
|
|
46
|
+
* @param {string} accountId - The account identifier that removes the like.
|
|
47
|
+
* @returns {Promise<number>} The updated like count.
|
|
48
|
+
*/
|
|
49
|
+
removeLike(resourceId: string, accountId: string): Promise<number>;
|
|
50
|
+
/**
|
|
51
|
+
* Checks whether the specified account has liked the resource.
|
|
52
|
+
*
|
|
53
|
+
* This method fetches the resource document and checks if the account ID
|
|
54
|
+
* exists in the `_likedBy` array.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} resourceId - The resource to check.
|
|
57
|
+
* @param {string} accountId - The account to verify.
|
|
58
|
+
* @returns {Promise<boolean>} True if the account has liked the resource; false otherwise.
|
|
59
|
+
*/
|
|
60
|
+
hasLiked(resourceId: string, accountId: string): Promise<boolean>;
|
|
61
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var LikeService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.LikeService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
19
|
+
const mongoose_2 = require("mongoose");
|
|
20
|
+
const like_module_definition_1 = require("./like.module-definition");
|
|
21
|
+
/**
|
|
22
|
+
* LikeService manages the "like" functionality for resources.
|
|
23
|
+
*
|
|
24
|
+
* It provides methods to add, remove, and verify likes on resource entities,
|
|
25
|
+
* interacting with the underlying MongoDB collection configured by the module options.
|
|
26
|
+
*/
|
|
27
|
+
let LikeService = LikeService_1 = class LikeService {
|
|
28
|
+
/**
|
|
29
|
+
* Initializes LikeService with database connection and module configuration.
|
|
30
|
+
*
|
|
31
|
+
* @param {LikeModuleOptions} moduleOptions - The module options containing model info.
|
|
32
|
+
* @param {Connection} connection - The active MongoDB connection injected by Mongoose.
|
|
33
|
+
*/
|
|
34
|
+
constructor(moduleOptions, connection) {
|
|
35
|
+
this.moduleOptions = moduleOptions;
|
|
36
|
+
this.connection = connection;
|
|
37
|
+
this.logger = new common_1.Logger(LikeService_1.name);
|
|
38
|
+
this.likeModel = this.connection.model(this.moduleOptions.model.name, this.moduleOptions.model.schema);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Computes the number of likes for a given resource document.
|
|
42
|
+
*
|
|
43
|
+
* @param {Document & Likeable} [resource] - The resource document which contains _likedBy array.
|
|
44
|
+
* @returns {number} The count of likes, or zero if none exist.
|
|
45
|
+
*/
|
|
46
|
+
getLikeCount(resource) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
return (_b = (_a = resource === null || resource === void 0 ? void 0 : resource._likedBy) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Adds a like to the specified resource by the given account.
|
|
52
|
+
*
|
|
53
|
+
* Uses MongoDB's `$addToSet` to avoid duplicate entries efficiently.
|
|
54
|
+
* Returns the updated count of likes after addition.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} resourceId - The identifier of the resource to like.
|
|
57
|
+
* @param {string} accountId - The account identifier that likes the resource.
|
|
58
|
+
* @returns {Promise<number>} The updated like count.
|
|
59
|
+
*/
|
|
60
|
+
async addLike(resourceId, accountId) {
|
|
61
|
+
this.logger.log(`Adding like to resource ${resourceId} by account ${accountId}`);
|
|
62
|
+
const updatedResource = await this.likeModel.findOneAndUpdate({ _id: resourceId }, { $addToSet: { _likedBy: accountId } }, { new: true, upsert: false, timestamps: false });
|
|
63
|
+
return this.getLikeCount(updatedResource);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Removes a like from the specified resource by the given account.
|
|
67
|
+
*
|
|
68
|
+
* Uses MongoDB's `$pull` operator to remove the account ID from the liked list.
|
|
69
|
+
* Returns the updated count of likes after removal.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} resourceId - The identifier of the resource to unlike.
|
|
72
|
+
* @param {string} accountId - The account identifier that removes the like.
|
|
73
|
+
* @returns {Promise<number>} The updated like count.
|
|
74
|
+
*/
|
|
75
|
+
async removeLike(resourceId, accountId) {
|
|
76
|
+
this.logger.log(`Removing like from resource ${resourceId} by account ${accountId}`);
|
|
77
|
+
const updatedResource = await this.likeModel.findOneAndUpdate({ _id: resourceId }, { $pull: { _likedBy: accountId } }, { new: true, upsert: false, timestamps: false });
|
|
78
|
+
return this.getLikeCount(updatedResource);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Checks whether the specified account has liked the resource.
|
|
82
|
+
*
|
|
83
|
+
* This method fetches the resource document and checks if the account ID
|
|
84
|
+
* exists in the `_likedBy` array.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} resourceId - The resource to check.
|
|
87
|
+
* @param {string} accountId - The account to verify.
|
|
88
|
+
* @returns {Promise<boolean>} True if the account has liked the resource; false otherwise.
|
|
89
|
+
*/
|
|
90
|
+
async hasLiked(resourceId, accountId) {
|
|
91
|
+
var _a;
|
|
92
|
+
this.logger.log(`Checking if account ${accountId} has liked resource ${resourceId}`);
|
|
93
|
+
const resource = await this.likeModel.findOne({ _id: resourceId });
|
|
94
|
+
return !!((_a = resource === null || resource === void 0 ? void 0 : resource._likedBy) === null || _a === void 0 ? void 0 : _a.includes(accountId));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.LikeService = LikeService;
|
|
98
|
+
exports.LikeService = LikeService = LikeService_1 = __decorate([
|
|
99
|
+
(0, common_1.Injectable)(),
|
|
100
|
+
__param(0, (0, common_1.Inject)(like_module_definition_1.LIKE_MODULE_OPTIONS_TOKEN)),
|
|
101
|
+
__param(1, (0, mongoose_1.InjectConnection)()),
|
|
102
|
+
__metadata("design:paramtypes", [Object, mongoose_2.Connection])
|
|
103
|
+
], LikeService);
|
|
@@ -14,4 +14,4 @@ export declare class JwtAuthGuard implements CanActivate {
|
|
|
14
14
|
canActivate(context: ExecutionContext): boolean;
|
|
15
15
|
}
|
|
16
16
|
/** Decorator enforcing JWT authentication on routes/controllers */
|
|
17
|
-
export declare function RequireJwtAuth(): MethodDecorator & ClassDecorator;
|
|
17
|
+
export declare function RequireJwtAuth(...permissions: string[]): MethodDecorator & ClassDecorator;
|
|
@@ -19,6 +19,7 @@ const core_1 = require("@nestjs/core");
|
|
|
19
19
|
const jwt_1 = require("@nestjs/jwt");
|
|
20
20
|
const swagger_1 = require("@nestjs/swagger");
|
|
21
21
|
const authentication_options_parameter_1 = require("../authentication-options.parameter");
|
|
22
|
+
const permissions_guard_1 = require("./permissions.guard");
|
|
22
23
|
const public_guard_1 = require("./public.guard");
|
|
23
24
|
/**
|
|
24
25
|
* Guard implementing JWT authentication for routes.
|
|
@@ -35,8 +36,9 @@ let JwtAuthGuard = class JwtAuthGuard {
|
|
|
35
36
|
return true;
|
|
36
37
|
const request = context.switchToHttp().getRequest();
|
|
37
38
|
const token = extractBearerToken(request);
|
|
38
|
-
if (!token)
|
|
39
|
+
if (!token) {
|
|
39
40
|
throw new common_1.UnauthorizedException('Authorization token not found.');
|
|
41
|
+
}
|
|
40
42
|
try {
|
|
41
43
|
request.account = this.jwtService.verify(token, { secret: this.authenticationOptions.jwtSecret });
|
|
42
44
|
}
|
|
@@ -62,6 +64,6 @@ function extractBearerToken(request) {
|
|
|
62
64
|
return scheme === 'Bearer' && (token === null || token === void 0 ? void 0 : token.trim()) ? token : undefined;
|
|
63
65
|
}
|
|
64
66
|
/** Decorator enforcing JWT authentication on routes/controllers */
|
|
65
|
-
function RequireJwtAuth() {
|
|
66
|
-
return (0, common_1.applyDecorators)((0, common_1.UseGuards)(JwtAuthGuard), (0, swagger_1.ApiBearerAuth)('Auth Token'), (0, swagger_1.ApiUnauthorizedResponse)({ description: 'Unauthorized: Invalid or missing
|
|
67
|
+
function RequireJwtAuth(...permissions) {
|
|
68
|
+
return (0, common_1.applyDecorators)((0, common_1.UseGuards)(JwtAuthGuard), (0, swagger_1.ApiBearerAuth)('Auth Token'), (0, swagger_1.ApiUnauthorizedResponse)({ description: 'Unauthorized: Invalid or missing Json Web Token' }), ...(permissions.length > 0 ? [(0, permissions_guard_1.RequirePermissions)(...permissions)] : []));
|
|
67
69
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
2
|
import { Reflector } from '@nestjs/core';
|
|
3
|
-
import { AuthenticationModuleOptions } from '../authentication-module-options.interface';
|
|
4
3
|
/**
|
|
5
4
|
* Guard enforcing that authenticated users have the necessary permissions.
|
|
6
5
|
*/
|
|
7
6
|
export declare class PermissionsGuard implements CanActivate {
|
|
8
|
-
private readonly authenticationOptions;
|
|
9
7
|
private readonly reflector;
|
|
10
|
-
constructor(
|
|
8
|
+
constructor(reflector: Reflector);
|
|
11
9
|
canActivate(context: ExecutionContext): boolean;
|
|
12
10
|
}
|
|
13
11
|
/** Decorator enforcing permissions on routes/controllers */
|
|
@@ -8,9 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.PermissionsGuard = void 0;
|
|
16
13
|
exports.RequirePermissions = RequirePermissions;
|
|
@@ -19,7 +16,6 @@ const core_1 = require("@nestjs/core");
|
|
|
19
16
|
const swagger_1 = require("@nestjs/swagger");
|
|
20
17
|
const class_validator_1 = require("class-validator");
|
|
21
18
|
const itlab_functions_1 = require("itlab-functions");
|
|
22
|
-
const authentication_options_parameter_1 = require("../authentication-options.parameter");
|
|
23
19
|
const jwt_auth_guard_1 = require("./jwt-auth.guard");
|
|
24
20
|
const public_guard_1 = require("./public.guard");
|
|
25
21
|
/** Metadata key storing required permissions for routes */
|
|
@@ -28,8 +24,7 @@ const PERMISSIONS_METADATA_KEY = Symbol('itlab-permissions-guard');
|
|
|
28
24
|
* Guard enforcing that authenticated users have the necessary permissions.
|
|
29
25
|
*/
|
|
30
26
|
let PermissionsGuard = class PermissionsGuard {
|
|
31
|
-
constructor(
|
|
32
|
-
this.authenticationOptions = authenticationOptions;
|
|
27
|
+
constructor(reflector) {
|
|
33
28
|
this.reflector = reflector;
|
|
34
29
|
}
|
|
35
30
|
canActivate(context) {
|
|
@@ -44,8 +39,7 @@ let PermissionsGuard = class PermissionsGuard {
|
|
|
44
39
|
exports.PermissionsGuard = PermissionsGuard;
|
|
45
40
|
exports.PermissionsGuard = PermissionsGuard = __decorate([
|
|
46
41
|
(0, common_1.Injectable)(),
|
|
47
|
-
|
|
48
|
-
__metadata("design:paramtypes", [Object, core_1.Reflector])
|
|
42
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
49
43
|
], PermissionsGuard);
|
|
50
44
|
/** Check if account has required permissions */
|
|
51
45
|
function hasRequiredPermissions(context, requiredPermissions) {
|
|
@@ -12,10 +12,6 @@ export declare class ServiceAuthGuard implements CanActivate {
|
|
|
12
12
|
constructor(authenticationOptions: AuthenticationModuleOptions, reflector: Reflector);
|
|
13
13
|
canActivate(context: ExecutionContext): boolean;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Check if request contains the required internal service token.
|
|
17
|
-
*/
|
|
18
|
-
export declare function isServiceRequest(context: ExecutionContext, requiredk8sToken: string): boolean;
|
|
19
15
|
/**
|
|
20
16
|
* Decorator for routes/controllers accessible only by internal services.
|
|
21
17
|
*/
|
|
@@ -13,7 +13,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ServiceAuthGuard = exports.SERVICE_AUTH_HEADER_KEY = void 0;
|
|
16
|
-
exports.isServiceRequest = isServiceRequest;
|
|
17
16
|
exports.RequireServiceAuth = RequireServiceAuth;
|
|
18
17
|
const common_1 = require("@nestjs/common");
|
|
19
18
|
const core_1 = require("@nestjs/core");
|
|
@@ -33,9 +32,15 @@ let ServiceAuthGuard = class ServiceAuthGuard {
|
|
|
33
32
|
canActivate(context) {
|
|
34
33
|
if ((0, public_guard_1.isPublicRoute)(context, this.reflector))
|
|
35
34
|
return true;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const request = context.switchToHttp().getRequest();
|
|
36
|
+
const serviceToken = request.header(exports.SERVICE_AUTH_HEADER_KEY);
|
|
37
|
+
if (!serviceToken) {
|
|
38
|
+
throw new common_1.UnauthorizedException('Authorization token not found.');
|
|
39
|
+
}
|
|
40
|
+
if (serviceToken !== this.authenticationOptions.k8sToken) {
|
|
41
|
+
throw new common_1.UnauthorizedException('Invalid or expired token.');
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
39
44
|
}
|
|
40
45
|
};
|
|
41
46
|
exports.ServiceAuthGuard = ServiceAuthGuard;
|
|
@@ -44,14 +49,6 @@ exports.ServiceAuthGuard = ServiceAuthGuard = __decorate([
|
|
|
44
49
|
__param(0, (0, authentication_options_parameter_1.InjectAuthenticationOptions)()),
|
|
45
50
|
__metadata("design:paramtypes", [Object, core_1.Reflector])
|
|
46
51
|
], ServiceAuthGuard);
|
|
47
|
-
/**
|
|
48
|
-
* Check if request contains the required internal service token.
|
|
49
|
-
*/
|
|
50
|
-
function isServiceRequest(context, requiredk8sToken) {
|
|
51
|
-
const request = context.switchToHttp().getRequest();
|
|
52
|
-
const token = request.header(exports.SERVICE_AUTH_HEADER_KEY);
|
|
53
|
-
return token && token === requiredk8sToken;
|
|
54
|
-
}
|
|
55
52
|
/**
|
|
56
53
|
* Decorator for routes/controllers accessible only by internal services.
|
|
57
54
|
*/
|
|
@@ -61,5 +58,5 @@ function RequireServiceAuth() {
|
|
|
61
58
|
description: 'Token for service authentication',
|
|
62
59
|
allowEmptyValue: true,
|
|
63
60
|
required: true,
|
|
64
|
-
}), (0, swagger_1.ApiUnauthorizedResponse)({ description: '
|
|
61
|
+
}), (0, swagger_1.ApiUnauthorizedResponse)({ description: 'Unauthorized: Invalid or missing Service Header Token' }));
|
|
65
62
|
}
|
|
@@ -2,14 +2,14 @@ import { ModelDefinition } from '@nestjs/mongoose';
|
|
|
2
2
|
import { Document } from 'mongoose';
|
|
3
3
|
import { HubResource } from '../../hub-resource.enum';
|
|
4
4
|
/**
|
|
5
|
-
* Module options for configuring and dynamically registering the
|
|
5
|
+
* Module options for configuring and dynamically registering the CommentsModule.
|
|
6
6
|
*
|
|
7
7
|
* This allows developers to specify the resource model that supports "commenting"
|
|
8
8
|
* and optionally provide a custom route suffix. The modular design ensures
|
|
9
9
|
* consistent, reusable comment functionality across multiple resource types
|
|
10
10
|
* (e.g. News, Events, Demos).
|
|
11
11
|
*/
|
|
12
|
-
export type
|
|
12
|
+
export type CommentsModuleOptions<T extends Document> = {
|
|
13
13
|
/**
|
|
14
14
|
* The enum value identifying the resource type this comment module relates to.
|
|
15
15
|
* Used internally for routing and tagging.
|
|
@@ -25,6 +25,7 @@ export type CommentModuleOptions<T extends Document> = {
|
|
|
25
25
|
* For example, setting this to "news" will expose routes comment `/comment/news/:id`.
|
|
26
26
|
*/
|
|
27
27
|
routeSuffix: string;
|
|
28
|
+
version: string;
|
|
28
29
|
/**
|
|
29
30
|
* Field name on the resource document representing a single owner's ID.
|
|
30
31
|
* Enables access control and filtering of comments by ownership.
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { LabComment, LabContentRichtext } from 'itlab-functions';
|
|
2
|
-
import {
|
|
2
|
+
import { CommentsModuleOptions } from './comments-module-options.interface';
|
|
3
|
+
import { CommentsService } from './comments.service';
|
|
3
4
|
/**
|
|
4
|
-
* Factory function for creating a
|
|
5
|
+
* Factory function for creating a CommentsController bound to a specific route suffix.
|
|
5
6
|
*
|
|
6
7
|
* Why: Instead of writing separate controllers for each resource type,
|
|
7
8
|
* we generate one dynamically. This ensures DRY principles while still
|
|
8
9
|
* supporting custom routes (e.g. `/comment/news` or `/comment/event`).
|
|
9
10
|
*
|
|
10
|
-
* @param {
|
|
11
|
+
* @param {CommentsModuleOptions} options -
|
|
11
12
|
* @returns A dynamically generated controller class.
|
|
12
13
|
*/
|
|
13
|
-
export declare function
|
|
14
|
-
new (commentService:
|
|
15
|
-
readonly commentService:
|
|
14
|
+
export declare function createCommentsController(options: CommentsModuleOptions<any>): {
|
|
15
|
+
new (commentService: CommentsService): {
|
|
16
|
+
readonly commentService: CommentsService;
|
|
16
17
|
/**
|
|
17
18
|
* Creates a new comment on a specific resource.
|
|
18
19
|
*
|
|
@@ -12,28 +12,28 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.createCommentsController = createCommentsController;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const swagger_1 = require("@nestjs/swagger");
|
|
18
18
|
const decorators_1 = require("../../decorators");
|
|
19
19
|
const exceptions_1 = require("../../exceptions");
|
|
20
20
|
const pipes_1 = require("../../pipes");
|
|
21
21
|
const authentication_1 = require("../authentication");
|
|
22
|
-
const
|
|
22
|
+
const comments_service_1 = require("./comments.service");
|
|
23
23
|
/**
|
|
24
|
-
* Factory function for creating a
|
|
24
|
+
* Factory function for creating a CommentsController bound to a specific route suffix.
|
|
25
25
|
*
|
|
26
26
|
* Why: Instead of writing separate controllers for each resource type,
|
|
27
27
|
* we generate one dynamically. This ensures DRY principles while still
|
|
28
28
|
* supporting custom routes (e.g. `/comment/news` or `/comment/event`).
|
|
29
29
|
*
|
|
30
|
-
* @param {
|
|
30
|
+
* @param {CommentsModuleOptions} options -
|
|
31
31
|
* @returns A dynamically generated controller class.
|
|
32
32
|
*/
|
|
33
|
-
function
|
|
33
|
+
function createCommentsController(options) {
|
|
34
34
|
// Normalize route path, removing duplicate/trailing slashes
|
|
35
|
-
const normalizedRoute = `
|
|
36
|
-
let
|
|
35
|
+
const normalizedRoute = `comments/${options.routeSuffix}`.replace(/\/{2,}/g, '/').replace(/\/$/, '');
|
|
36
|
+
let CommentsController = class CommentsController {
|
|
37
37
|
constructor(commentService) {
|
|
38
38
|
this.commentService = commentService;
|
|
39
39
|
}
|
|
@@ -73,12 +73,12 @@ function createCommentController(routeSuffix) {
|
|
|
73
73
|
__metadata("design:type", Function),
|
|
74
74
|
__metadata("design:paramtypes", [String, String, Object]),
|
|
75
75
|
__metadata("design:returntype", Promise)
|
|
76
|
-
],
|
|
77
|
-
|
|
76
|
+
], CommentsController.prototype, "postComment", null);
|
|
77
|
+
CommentsController = __decorate([
|
|
78
78
|
(0, authentication_1.RequireJwtAuth)(),
|
|
79
|
-
(0, swagger_1.ApiTags)('
|
|
80
|
-
(0, common_1.Controller)(normalizedRoute),
|
|
81
|
-
__metadata("design:paramtypes", [
|
|
82
|
-
],
|
|
83
|
-
return
|
|
79
|
+
(0, swagger_1.ApiTags)('Comments'),
|
|
80
|
+
(0, common_1.Controller)({ path: normalizedRoute, version: options.version }),
|
|
81
|
+
__metadata("design:paramtypes", [comments_service_1.CommentsService])
|
|
82
|
+
], CommentsController);
|
|
83
|
+
return CommentsController;
|
|
84
84
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMMENTS_MODULE_OPTIONS_TOKEN = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Dependency injection token for CommentsModule options.
|
|
6
|
+
*/
|
|
7
|
+
exports.COMMENTS_MODULE_OPTIONS_TOKEN = Symbol('COMMENTS_MODULE_OPTIONS_TOKEN');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
2
|
import { Document } from 'mongoose';
|
|
3
|
-
import {
|
|
3
|
+
import { CommentsModuleOptions } from './comments-module-options.interface';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* CommentsModule dynamically registers controllers and services
|
|
6
6
|
* to handle "commenting" functionality for a given resource model.
|
|
7
7
|
*
|
|
8
8
|
* Why: Many resources (e.g. blogposts, events, demos) can be commented,
|
|
@@ -10,13 +10,13 @@ import { CommentModuleOptions } from './comment-module-options.interface';
|
|
|
10
10
|
* Instead, this module centralizes the commenting-related logic, keeping it
|
|
11
11
|
* consistent while still allowing customization via options.
|
|
12
12
|
*/
|
|
13
|
-
export declare class
|
|
13
|
+
export declare class CommentsModule {
|
|
14
14
|
/**
|
|
15
|
-
* Dynamically registers a
|
|
15
|
+
* Dynamically registers a CommentsController bound to the provided model
|
|
16
16
|
* and optional route suffix.
|
|
17
17
|
*
|
|
18
|
-
* @param {
|
|
18
|
+
* @param {CommentsModuleOptions} options - Configuration for the resource model and route.
|
|
19
19
|
* @returns {DynamicModule} The dynamically created module definition.
|
|
20
20
|
*/
|
|
21
|
-
static forFeature<T extends Document>(options:
|
|
21
|
+
static forFeature<T extends Document>(options: CommentsModuleOptions<T>): DynamicModule;
|
|
22
22
|
}
|
|
@@ -5,15 +5,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
-
var
|
|
8
|
+
var CommentsModule_1;
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
10
|
+
exports.CommentsModule = void 0;
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
12
|
+
const comments_controller_1 = require("./comments.controller");
|
|
13
|
+
const comments_module_definition_1 = require("./comments.module-definition");
|
|
14
|
+
const comments_service_1 = require("./comments.service");
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* CommentsModule dynamically registers controllers and services
|
|
17
17
|
* to handle "commenting" functionality for a given resource model.
|
|
18
18
|
*
|
|
19
19
|
* Why: Many resources (e.g. blogposts, events, demos) can be commented,
|
|
@@ -21,24 +21,25 @@ const comment_service_1 = require("./comment.service");
|
|
|
21
21
|
* Instead, this module centralizes the commenting-related logic, keeping it
|
|
22
22
|
* consistent while still allowing customization via options.
|
|
23
23
|
*/
|
|
24
|
-
let
|
|
24
|
+
let CommentsModule = CommentsModule_1 = class CommentsModule {
|
|
25
25
|
/**
|
|
26
|
-
* Dynamically registers a
|
|
26
|
+
* Dynamically registers a CommentsController bound to the provided model
|
|
27
27
|
* and optional route suffix.
|
|
28
28
|
*
|
|
29
|
-
* @param {
|
|
29
|
+
* @param {CommentsModuleOptions} options - Configuration for the resource model and route.
|
|
30
30
|
* @returns {DynamicModule} The dynamically created module definition.
|
|
31
31
|
*/
|
|
32
32
|
static forFeature(options) {
|
|
33
|
-
const
|
|
33
|
+
const CommentsController = (0, comments_controller_1.createCommentsController)(options);
|
|
34
34
|
return {
|
|
35
|
-
module:
|
|
36
|
-
providers: [
|
|
37
|
-
controllers: [
|
|
35
|
+
module: CommentsModule_1,
|
|
36
|
+
providers: [comments_service_1.CommentsService, { provide: comments_module_definition_1.COMMENTS_MODULE_OPTIONS_TOKEN, useValue: options }],
|
|
37
|
+
controllers: [CommentsController],
|
|
38
|
+
exports: [comments_service_1.CommentsService],
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
|
-
exports.
|
|
42
|
-
exports.
|
|
42
|
+
exports.CommentsModule = CommentsModule;
|
|
43
|
+
exports.CommentsModule = CommentsModule = CommentsModule_1 = __decorate([
|
|
43
44
|
(0, common_1.Module)({})
|
|
44
|
-
],
|
|
45
|
+
], CommentsModule);
|