itlab-internal-services 2.8.0 → 2.9.0

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.
@@ -18,6 +18,7 @@ export declare enum HubResource {
18
18
  HUB_COMMENT = "hub-comment",
19
19
  HUB_CONFLICT = "hub-conflict",
20
20
  HUB_IDEA = "hub-idea",
21
+ HUB_CHANGELOG = "hub-changelog",
21
22
  ANY = "any"
22
23
  }
23
24
  export declare enum FetchableHubResource {
@@ -22,6 +22,7 @@ var HubResource;
22
22
  HubResource["HUB_COMMENT"] = "hub-comment";
23
23
  HubResource["HUB_CONFLICT"] = "hub-conflict";
24
24
  HubResource["HUB_IDEA"] = "hub-idea";
25
+ HubResource["HUB_CHANGELOG"] = "hub-changelog";
25
26
  HubResource["ANY"] = "any";
26
27
  })(HubResource || (exports.HubResource = HubResource = {}));
27
28
  var FetchableHubResource;
@@ -61,5 +62,6 @@ exports.HUB_RESOURCES = [
61
62
  HubResource.HUB_COMMENT,
62
63
  HubResource.HUB_CONFLICT,
63
64
  HubResource.HUB_IDEA,
65
+ HubResource.HUB_CHANGELOG,
64
66
  HubResource.ANY,
65
67
  ];
@@ -0,0 +1,42 @@
1
+ /// <reference types="mongoose/types/aggregate" />
2
+ /// <reference types="mongoose/types/callback" />
3
+ /// <reference types="mongoose/types/collection" />
4
+ /// <reference types="mongoose/types/connection" />
5
+ /// <reference types="mongoose/types/cursor" />
6
+ /// <reference types="mongoose/types/document" />
7
+ /// <reference types="mongoose/types/error" />
8
+ /// <reference types="mongoose/types/expressions" />
9
+ /// <reference types="mongoose/types/helpers" />
10
+ /// <reference types="mongoose/types/middlewares" />
11
+ /// <reference types="mongoose/types/indexes" />
12
+ /// <reference types="mongoose/types/models" />
13
+ /// <reference types="mongoose/types/mongooseoptions" />
14
+ /// <reference types="mongoose/types/pipelinestage" />
15
+ /// <reference types="mongoose/types/populate" />
16
+ /// <reference types="mongoose/types/query" />
17
+ /// <reference types="mongoose/types/schemaoptions" />
18
+ /// <reference types="mongoose/types/schematypes" />
19
+ /// <reference types="mongoose/types/session" />
20
+ /// <reference types="mongoose/types/types" />
21
+ /// <reference types="mongoose/types/utility" />
22
+ /// <reference types="mongoose/types/validation" />
23
+ /// <reference types="mongoose/types/virtuals" />
24
+ /// <reference types="mongoose/types/inferschematype" />
25
+ /// <reference types="mongoose/types/inferrawdoctype" />
26
+ import { Document } from 'mongoose';
27
+ /**
28
+ * Represents something viewable
29
+ *
30
+ * @interface Viewable
31
+ * @property {string[]} _viewedBy - Array of user IDs who have viewed the document
32
+ */
33
+ export interface Viewable {
34
+ /** Array of user IDs who have viewed the document. */
35
+ _viewedBy: string[];
36
+ /** The number of views */
37
+ views: number;
38
+ }
39
+ export declare function incrementViews<T extends Document & Viewable>(target: T, accountId?: string): void;
40
+ export declare const PropViewedBy: () => PropertyDecorator;
41
+ export declare const ApiViewedBy: () => PropertyDecorator;
42
+ export declare const ApiViews: () => PropertyDecorator;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiViews = exports.ApiViewedBy = exports.PropViewedBy = exports.incrementViews = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const mongoose_1 = require("@nestjs/mongoose");
6
+ const swagger_1 = require("@nestjs/swagger");
7
+ const increment_function_1 = require("./increment.function");
8
+ const modules_1 = require("./modules");
9
+ function incrementViews(target, accountId) {
10
+ if (!accountId)
11
+ return;
12
+ new common_1.Logger('ViewService').log(`Adding view to ${target._id} by ${accountId}`);
13
+ (0, increment_function_1.incrementAttr)(target, '_viewedBy', accountId);
14
+ }
15
+ exports.incrementViews = incrementViews;
16
+ const PropViewedBy = () => (0, mongoose_1.Prop)({ required: true, default: () => [] });
17
+ exports.PropViewedBy = PropViewedBy;
18
+ const ApiViewedBy = () => (0, swagger_1.ApiProperty)({ default: [], name: 'viewedBy', type: [modules_1.LabAccount] });
19
+ exports.ApiViewedBy = ApiViewedBy;
20
+ const ApiViews = () => (0, swagger_1.ApiProperty)({ default: 0 });
21
+ exports.ApiViews = ApiViews;
@@ -0,0 +1,27 @@
1
+ /// <reference types="mongoose/types/aggregate" />
2
+ /// <reference types="mongoose/types/callback" />
3
+ /// <reference types="mongoose/types/collection" />
4
+ /// <reference types="mongoose/types/connection" />
5
+ /// <reference types="mongoose/types/cursor" />
6
+ /// <reference types="mongoose/types/document" />
7
+ /// <reference types="mongoose/types/error" />
8
+ /// <reference types="mongoose/types/expressions" />
9
+ /// <reference types="mongoose/types/helpers" />
10
+ /// <reference types="mongoose/types/middlewares" />
11
+ /// <reference types="mongoose/types/indexes" />
12
+ /// <reference types="mongoose/types/models" />
13
+ /// <reference types="mongoose/types/mongooseoptions" />
14
+ /// <reference types="mongoose/types/pipelinestage" />
15
+ /// <reference types="mongoose/types/populate" />
16
+ /// <reference types="mongoose/types/query" />
17
+ /// <reference types="mongoose/types/schemaoptions" />
18
+ /// <reference types="mongoose/types/schematypes" />
19
+ /// <reference types="mongoose/types/session" />
20
+ /// <reference types="mongoose/types/types" />
21
+ /// <reference types="mongoose/types/utility" />
22
+ /// <reference types="mongoose/types/validation" />
23
+ /// <reference types="mongoose/types/virtuals" />
24
+ /// <reference types="mongoose/types/inferschematype" />
25
+ /// <reference types="mongoose/types/inferrawdoctype" />
26
+ import { Document } from 'mongoose';
27
+ export declare function incrementAttr<I, T extends Document = Document>(target: T, attr: keyof I, accountId?: string): void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.incrementAttr = void 0;
4
+ function incrementAttr(target, attr, accountId) {
5
+ if (!accountId)
6
+ return;
7
+ target.updateOne({ $addToSet: { [attr]: accountId } }, { timestamps: false }).then(() => {
8
+ /* noop */
9
+ });
10
+ }
11
+ exports.incrementAttr = incrementAttr;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ export * from './favicon.controller';
4
4
  export * from './guards';
5
5
  export * from './http.logger';
6
6
  export * from './hub-resource.enum';
7
+ export * from './increment-views';
8
+ export * from './increment.function';
7
9
  export * from './interceptors';
8
10
  export * from './liveness.probe';
9
11
  export * from './models';
package/dist/index.js CHANGED
@@ -20,6 +20,8 @@ __exportStar(require("./favicon.controller"), exports);
20
20
  __exportStar(require("./guards"), exports);
21
21
  __exportStar(require("./http.logger"), exports);
22
22
  __exportStar(require("./hub-resource.enum"), exports);
23
+ __exportStar(require("./increment-views"), exports);
24
+ __exportStar(require("./increment.function"), exports);
23
25
  __exportStar(require("./interceptors"), exports);
24
26
  __exportStar(require("./liveness.probe"), exports);
25
27
  __exportStar(require("./models"), exports);
@@ -42,12 +42,32 @@ export declare class PopulateService {
42
42
  * @returns {PopulateOptions} the populate options
43
43
  */
44
44
  account: (path: string) => PopulateOptions;
45
+ /**
46
+ * Populates an author
47
+ * @returns {PopulateOptions} the populate options
48
+ */
49
+ author: () => PopulateOptions;
50
+ /**
51
+ * Populates a contact
52
+ * @returns {PopulateOptions} the populate options
53
+ */
54
+ contact: () => PopulateOptions;
45
55
  /**
46
56
  * Populates an array of accounts
47
57
  * @param path - the path to populate
48
58
  * @returns {PopulateOptions} the populate options
49
59
  */
50
60
  accounts: (path: string) => PopulateOptions;
61
+ /**
62
+ * Populates the _viewedBy array
63
+ * @returns {PopulateOptions} the populate options
64
+ */
65
+ viewedBy: () => PopulateOptions;
66
+ /**
67
+ * Populates the _likedBy array
68
+ * @returns {PopulateOptions} the populate options
69
+ */
70
+ likedBy: () => PopulateOptions;
51
71
  /**
52
72
  * Populates the comments field of a document with its comments but without replies
53
73
  * @returns {PopulateOptions} the populate options
@@ -33,6 +33,16 @@ let PopulateService = class PopulateService {
33
33
  justOne: true,
34
34
  model: this.modelService.accountModel(),
35
35
  });
36
+ /**
37
+ * Populates an author
38
+ * @returns {PopulateOptions} the populate options
39
+ */
40
+ this.author = () => this.account('author');
41
+ /**
42
+ * Populates a contact
43
+ * @returns {PopulateOptions} the populate options
44
+ */
45
+ this.contact = () => this.account('contact');
36
46
  /**
37
47
  * Populates an array of accounts
38
48
  * @param path - the path to populate
@@ -43,6 +53,16 @@ let PopulateService = class PopulateService {
43
53
  justOne: false,
44
54
  model: this.modelService.accountModel(),
45
55
  });
56
+ /**
57
+ * Populates the _viewedBy array
58
+ * @returns {PopulateOptions} the populate options
59
+ */
60
+ this.viewedBy = () => this.accounts('viewedBy');
61
+ /**
62
+ * Populates the _likedBy array
63
+ * @returns {PopulateOptions} the populate options
64
+ */
65
+ this.likedBy = () => this.accounts('likedBy');
46
66
  /**
47
67
  * Populates the comments field of a document with its comments but without replies
48
68
  * @returns {PopulateOptions} the populate options
@@ -1 +1,2 @@
1
1
  export { LikeModule } from './like.module';
2
+ export { ApiLikedBy, ApiLikes, Likeable } from './like.module-options';
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LikeModule = void 0;
3
+ exports.ApiLikes = exports.ApiLikedBy = exports.LikeModule = void 0;
4
4
  /*
5
5
  * Like Module
6
6
  */
7
7
  var like_module_1 = require("./like.module");
8
8
  Object.defineProperty(exports, "LikeModule", { enumerable: true, get: function () { return like_module_1.LikeModule; } });
9
+ /*
10
+ * Like Module options
11
+ */
12
+ var like_module_options_1 = require("./like.module-options");
13
+ Object.defineProperty(exports, "ApiLikedBy", { enumerable: true, get: function () { return like_module_options_1.ApiLikedBy; } });
14
+ Object.defineProperty(exports, "ApiLikes", { enumerable: true, get: function () { return like_module_options_1.ApiLikes; } });
@@ -1,42 +1,15 @@
1
- /// <reference types="mongoose/types/aggregate" />
2
- /// <reference types="mongoose/types/callback" />
3
- /// <reference types="mongoose/types/collection" />
4
- /// <reference types="mongoose/types/connection" />
5
- /// <reference types="mongoose/types/cursor" />
6
- /// <reference types="mongoose/types/document" />
7
- /// <reference types="mongoose/types/error" />
8
- /// <reference types="mongoose/types/expressions" />
9
- /// <reference types="mongoose/types/helpers" />
10
- /// <reference types="mongoose/types/middlewares" />
11
- /// <reference types="mongoose/types/indexes" />
12
- /// <reference types="mongoose/types/models" />
13
- /// <reference types="mongoose/types/mongooseoptions" />
14
- /// <reference types="mongoose/types/pipelinestage" />
15
- /// <reference types="mongoose/types/populate" />
16
- /// <reference types="mongoose/types/query" />
17
- /// <reference types="mongoose/types/schemaoptions" />
18
- /// <reference types="mongoose/types/schematypes" />
19
- /// <reference types="mongoose/types/session" />
20
- /// <reference types="mongoose/types/types" />
21
- /// <reference types="mongoose/types/utility" />
22
- /// <reference types="mongoose/types/validation" />
23
- /// <reference types="mongoose/types/virtuals" />
24
- /// <reference types="mongoose/types/inferschematype" />
25
- /// <reference types="mongoose/types/inferrawdoctype" />
26
- import { Document } from 'mongoose';
27
1
  /**
28
- * Represents a likeable document.
29
- *
30
- * @class LikeableDocument
31
- * @extends {Document}
32
- * @author Timo Scheuermann
2
+ * Represents something likeable
33
3
  *
4
+ * @interface Likeable
34
5
  * @property {string[]} _likedBy - Array of user IDs who have liked the document
35
- * @property {boolean} draft - Indicates if the document is a draft
36
6
  */
37
- export declare class LikeableDocument extends Document {
7
+ export interface Likeable {
38
8
  /** Array of user IDs who have liked the document. */
39
9
  _likedBy: string[];
40
- /** Indicates if the document is a draft. */
41
- draft?: boolean;
10
+ /** The number of likes */
11
+ likes: number;
42
12
  }
13
+ export declare const PropLikedBy: () => PropertyDecorator;
14
+ export declare const ApiLikedBy: () => PropertyDecorator;
15
+ export declare const ApiLikes: () => PropertyDecorator;
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LikeableDocument = void 0;
4
- const mongoose_1 = require("mongoose");
5
- /**
6
- * Represents a likeable document.
7
- *
8
- * @class LikeableDocument
9
- * @extends {Document}
10
- * @author Timo Scheuermann
11
- *
12
- * @property {string[]} _likedBy - Array of user IDs who have liked the document
13
- * @property {boolean} draft - Indicates if the document is a draft
14
- */
15
- class LikeableDocument extends mongoose_1.Document {
16
- }
17
- exports.LikeableDocument = LikeableDocument;
3
+ exports.ApiLikes = exports.ApiLikedBy = exports.PropLikedBy = void 0;
4
+ const mongoose_1 = require("@nestjs/mongoose");
5
+ const swagger_1 = require("@nestjs/swagger");
6
+ const authentication_1 = require("../authentication");
7
+ const PropLikedBy = () => (0, mongoose_1.Prop)({ required: true, default: () => [] });
8
+ exports.PropLikedBy = PropLikedBy;
9
+ const ApiLikedBy = () => (0, swagger_1.ApiProperty)({ default: [], name: 'likedBy', type: [authentication_1.LabAccount] });
10
+ exports.ApiLikedBy = ApiLikedBy;
11
+ const ApiLikes = () => (0, swagger_1.ApiProperty)({ default: 0 });
12
+ exports.ApiLikes = ApiLikes;
@@ -23,7 +23,8 @@
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  /// <reference types="mongoose/types/inferrawdoctype" />
26
- import { Connection, Schema } from 'mongoose';
26
+ import { Connection, Document, Schema } from 'mongoose';
27
+ import { Likeable } from './like.module-options';
27
28
  /**
28
29
  * @class LikeService
29
30
  * @description The LikeService class is responsible for handling likes for a specified resource. It provides methods to add, remove, and check likes of a resource.
@@ -41,10 +42,7 @@ export declare class LikeService {
41
42
  * @param {string} model - the model name
42
43
  * @param {Schema} schema - the schema
43
44
  */
44
- constructor(connection: Connection, model: string, schema: Schema<{
45
- _likedBy: string[];
46
- _id: string;
47
- }>);
45
+ constructor(connection: Connection, model: string, schema: Schema<Document & Likeable>);
48
46
  /**
49
47
  * Retrieve the model from the connection based on the schema name.
50
48
  *
@@ -54,7 +52,7 @@ export declare class LikeService {
54
52
  /**
55
53
  * Get the number of likes for the specified resource
56
54
  *
57
- * @param {LikeableDocument} resource - optional parameter for the resource
55
+ * @param {Document & Likeable} resource - optional parameter for the resource
58
56
  * @return {number} the number of likes for the resource
59
57
  */
60
58
  private likeCount;
@@ -58,7 +58,7 @@ let LikeService = LikeService_1 = class LikeService {
58
58
  /**
59
59
  * Get the number of likes for the specified resource
60
60
  *
61
- * @param {LikeableDocument} resource - optional parameter for the resource
61
+ * @param {Document & Likeable} resource - optional parameter for the resource
62
62
  * @return {number} the number of likes for the resource
63
63
  */
64
64
  likeCount(resource) {
@@ -76,7 +76,7 @@ let LikeService = LikeService_1 = class LikeService {
76
76
  return __awaiter(this, void 0, void 0, function* () {
77
77
  this.logger.log(`Adding like to ${resourceId} by ${accountId}`);
78
78
  // Find the resource and update the likedBy array by adding the accountId
79
- const resource = yield this.getModel().findOneAndUpdate({ _id: resourceId, draft: false }, { $addToSet: { _likedBy: accountId } }, { upsert: false, new: true });
79
+ const resource = yield this.getModel().findOneAndUpdate({ _id: resourceId }, { $addToSet: { _likedBy: accountId } }, { upsert: false, new: true, timestamps: false });
80
80
  // Return the like count after the addition
81
81
  return this.likeCount(resource);
82
82
  });
@@ -92,7 +92,7 @@ let LikeService = LikeService_1 = class LikeService {
92
92
  return __awaiter(this, void 0, void 0, function* () {
93
93
  this.logger.log(`Removing like from ${resourceId} by ${accountId}`);
94
94
  // Find the resource and update the _likedBy array by removing the accountId
95
- const resource = yield this.getModel().findOneAndUpdate({ _id: resourceId, draft: false }, { $pull: { _likedBy: { $in: [accountId] } } }, { upsert: false, new: true });
95
+ const resource = yield this.getModel().findOneAndUpdate({ _id: resourceId }, { $pull: { _likedBy: { $in: [accountId] } } }, { upsert: false, new: true, timestamps: false });
96
96
  // Return the like count after the removal
97
97
  return this.likeCount(resource);
98
98
  });
@@ -107,8 +107,8 @@ let LikeService = LikeService_1 = class LikeService {
107
107
  hasLiked(resourceId, accountId) {
108
108
  return __awaiter(this, void 0, void 0, function* () {
109
109
  this.logger.log(`Check if ${accountId} has liked ${resourceId}`);
110
- // Find the resource in the likeModel with the provided resourceId and ensure it's not a draft.
111
- const resource = yield this.getModel().findOne({ _id: resourceId, draft: false });
110
+ // Find the resource in the likeModel with the provided resourceId.
111
+ const resource = yield this.getModel().findOne({ _id: resourceId });
112
112
  // Return true if the resource exists and has the account in its _likedBy array, otherwise return false.
113
113
  return resource && resource._likedBy ? resource._likedBy.includes(accountId) : false;
114
114
  });
@@ -47,6 +47,18 @@ export declare class VirtualsFactory {
47
47
  * @return {VirtualsFactory} the VirtualsFactory
48
48
  */
49
49
  account(name: string, localField: string): VirtualsFactory;
50
+ /**
51
+ * Creates a virtual author field on the given schema, linking it to the 'accounts' collection.
52
+ *
53
+ * @return {VirtualsFactory} the VirtualsFactory
54
+ */
55
+ author: () => VirtualsFactory;
56
+ /**
57
+ * Creates a virtual contact field on the given schema, linking it to the 'accounts' collection.
58
+ *
59
+ * @return {VirtualsFactory} the VirtualsFactory
60
+ */
61
+ contact: () => VirtualsFactory;
50
62
  /**
51
63
  * Creates a virtual accounts field on the given schema, linking it to the 'accounts' collection.
52
64
  *
@@ -55,6 +67,18 @@ export declare class VirtualsFactory {
55
67
  * @return {VirtualsFactory} the VirtualsFactory
56
68
  */
57
69
  accounts(name: string, localField: string): VirtualsFactory;
70
+ /**
71
+ * Creates a virtual viewedBy field on the given schema, linking it to the 'accounts' collection.
72
+ *
73
+ * @return {VirtualsFactory} the VirtualsFactory
74
+ */
75
+ views(): VirtualsFactory;
76
+ /**
77
+ * Creates a virtual likedBy field on the given schema, linking it to the 'accounts' collection.
78
+ *
79
+ * @return {VirtualsFactory} the VirtualsFactory
80
+ */
81
+ likes(): VirtualsFactory;
58
82
  /**
59
83
  * Creates virtual comments field on the given schema, linking it to the 'comments' collection.
60
84
  *
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VirtualsFactory = void 0;
4
+ const class_validator_1 = require("class-validator");
4
5
  const hub_resource_enum_1 = require("./hub-resource.enum");
5
6
  /**
6
7
  * Creates virtual fields on a schema.
@@ -16,6 +17,18 @@ class VirtualsFactory {
16
17
  constructor(schema, resource) {
17
18
  this.schema = schema;
18
19
  this.resource = resource;
20
+ /**
21
+ * Creates a virtual author field on the given schema, linking it to the 'accounts' collection.
22
+ *
23
+ * @return {VirtualsFactory} the VirtualsFactory
24
+ */
25
+ this.author = () => this.account('author', 'authorId');
26
+ /**
27
+ * Creates a virtual contact field on the given schema, linking it to the 'accounts' collection.
28
+ *
29
+ * @return {VirtualsFactory} the VirtualsFactory
30
+ */
31
+ this.contact = () => this.account('contact', 'contactId');
19
32
  }
20
33
  /**
21
34
  * Creates a virtual account field on the given schema, linking it to the 'accounts' collection.
@@ -49,6 +62,30 @@ class VirtualsFactory {
49
62
  });
50
63
  return this;
51
64
  }
65
+ /**
66
+ * Creates a virtual viewedBy field on the given schema, linking it to the 'accounts' collection.
67
+ *
68
+ * @return {VirtualsFactory} the VirtualsFactory
69
+ */
70
+ views() {
71
+ this.accounts('viewedBy', '_viewedBy');
72
+ this.schema.virtual('views').get(function () {
73
+ return (0, class_validator_1.isArray)(this._viewedBy) ? this._viewedBy.length : 0;
74
+ });
75
+ return this;
76
+ }
77
+ /**
78
+ * Creates a virtual likedBy field on the given schema, linking it to the 'accounts' collection.
79
+ *
80
+ * @return {VirtualsFactory} the VirtualsFactory
81
+ */
82
+ likes() {
83
+ this.accounts('likedBy', '_likedBy');
84
+ this.schema.virtual('likes').get(function () {
85
+ return (0, class_validator_1.isArray)(this._likedBy) ? this._likedBy.length : 0;
86
+ });
87
+ return this;
88
+ }
52
89
  /**
53
90
  * Creates virtual comments field on the given schema, linking it to the 'comments' collection.
54
91
  *
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "timo.scheuermann@sv-informatik.de",
6
6
  "url": "https://timos.design"
7
7
  },
8
- "version": "2.8.0",
8
+ "version": "2.9.0",
9
9
  "type": "commonjs",
10
10
  "files": [
11
11
  "dist"