itlab-internal-services 2.16.14 → 2.16.15

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.
@@ -3,7 +3,7 @@ import { Document } from 'mongoose';
3
3
  export declare function CommentableDocument<TBase extends new (...args: any[]) => Document>(Base: TBase): {
4
4
  new (...args: any[]): {
5
5
  comments?: LabComment[];
6
- _id: unknown;
6
+ _id: import("mongoose").Types.ObjectId;
7
7
  $assertPopulated<Paths = {}>(path: string | string[], values?: Partial<Paths>): Omit</*elided*/ any, keyof Paths> & Paths;
8
8
  $clearModifiedPaths(): /*elided*/ any;
9
9
  $clone(): /*elided*/ any;
@@ -37,7 +37,7 @@ export declare function CommentableDocument<TBase extends new (...args: any[]) =
37
37
  deleteOne(options?: import("mongoose").QueryOptions): any;
38
38
  depopulate<Paths = {}>(path?: string | string[]): import("mongoose").MergeType</*elided*/ any, Paths>;
39
39
  directModifiedPaths(): Array<string>;
40
- equals(doc: Document<unknown, any, any, Record<string, any>, {}>): boolean;
40
+ equals(doc: Document<import("mongoose").Types.ObjectId, any, any, Record<string, any>, {}>): boolean;
41
41
  errors?: import("mongoose").Error.ValidationError;
42
42
  get<T extends string | number | symbol>(path: T, type?: any, options?: any): any;
43
43
  get(path: string, type?: any, options?: any): any;
@@ -85,6 +85,7 @@ export declare function CommentableDocument<TBase extends new (...args: any[]) =
85
85
  set(path: string | Record<string, any>, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
86
86
  set(path: string | Record<string, any>, val: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
87
87
  set(value: string | Record<string, any>): /*elided*/ any;
88
+ toBSON(): any;
88
89
  toJSON(options: import("mongoose").ToObjectOptions & {
89
90
  versionKey: false;
90
91
  virtuals: true;
@@ -3,7 +3,7 @@ import { Document } from 'mongoose';
3
3
  export declare function ContentDocument<TBase extends new (...args: any[]) => Document>(Base: TBase): {
4
4
  new (...args: any[]): {
5
5
  content?: LabJsonContent | LabHtmlContent | LabTextContent;
6
- _id: unknown;
6
+ _id: import("mongoose").Types.ObjectId;
7
7
  $assertPopulated<Paths = {}>(path: string | string[], values?: Partial<Paths>): Omit</*elided*/ any, keyof Paths> & Paths;
8
8
  $clearModifiedPaths(): /*elided*/ any;
9
9
  $clone(): /*elided*/ any;
@@ -37,7 +37,7 @@ export declare function ContentDocument<TBase extends new (...args: any[]) => Do
37
37
  deleteOne(options?: import("mongoose").QueryOptions): any;
38
38
  depopulate<Paths = {}>(path?: string | string[]): import("mongoose").MergeType</*elided*/ any, Paths>;
39
39
  directModifiedPaths(): Array<string>;
40
- equals(doc: Document<unknown, any, any, Record<string, any>, {}>): boolean;
40
+ equals(doc: Document<import("mongoose").Types.ObjectId, any, any, Record<string, any>, {}>): boolean;
41
41
  errors?: import("mongoose").Error.ValidationError;
42
42
  get<T extends string | number | symbol>(path: T, type?: any, options?: any): any;
43
43
  get(path: string, type?: any, options?: any): any;
@@ -85,6 +85,7 @@ export declare function ContentDocument<TBase extends new (...args: any[]) => Do
85
85
  set(path: string | Record<string, any>, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
86
86
  set(path: string | Record<string, any>, val: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
87
87
  set(value: string | Record<string, any>): /*elided*/ any;
88
+ toBSON(): any;
88
89
  toJSON(options: import("mongoose").ToObjectOptions & {
89
90
  versionKey: false;
90
91
  virtuals: true;
@@ -10,7 +10,7 @@ export declare function LikeableDocument<TBase extends new (...args: any[]) => D
10
10
  hasLiked(accountId: string): boolean;
11
11
  addLike(accountId: string): Promise<number>;
12
12
  removeLike(accountId: string): Promise<number>;
13
- _id: unknown;
13
+ _id: import("mongoose").Types.ObjectId;
14
14
  $assertPopulated<Paths = {}>(path: string | string[], values?: Partial<Paths>): Omit</*elided*/ any, keyof Paths> & Paths;
15
15
  $clearModifiedPaths(): /*elided*/ any;
16
16
  $clone(): /*elided*/ any;
@@ -44,7 +44,7 @@ export declare function LikeableDocument<TBase extends new (...args: any[]) => D
44
44
  deleteOne(options?: import("mongoose").QueryOptions): any;
45
45
  depopulate<Paths = {}>(path?: string | string[]): import("mongoose").MergeType</*elided*/ any, Paths>;
46
46
  directModifiedPaths(): Array<string>;
47
- equals(doc: Document<unknown, any, any, Record<string, any>, {}>): boolean;
47
+ equals(doc: Document<import("mongoose").Types.ObjectId, any, any, Record<string, any>, {}>): boolean;
48
48
  errors?: import("mongoose").Error.ValidationError;
49
49
  get<T extends string | number | symbol>(path: T, type?: any, options?: any): any;
50
50
  get(path: string, type?: any, options?: any): any;
@@ -92,6 +92,7 @@ export declare function LikeableDocument<TBase extends new (...args: any[]) => D
92
92
  set(path: string | Record<string, any>, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
93
93
  set(path: string | Record<string, any>, val: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
94
94
  set(value: string | Record<string, any>): /*elided*/ any;
95
+ toBSON(): any;
95
96
  toJSON(options: import("mongoose").ToObjectOptions & {
96
97
  versionKey: false;
97
98
  virtuals: true;
@@ -10,11 +10,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.LikeableDocument = LikeableDocument;
13
+ const common_1 = require("@nestjs/common");
13
14
  const mongoose_1 = require("@nestjs/mongoose");
14
15
  const swagger_1 = require("@nestjs/swagger");
15
16
  const class_validator_1 = require("class-validator");
16
17
  const models_1 = require("../../models");
17
18
  const pipes_1 = require("../../pipes");
19
+ const logger = new common_1.Logger('MongooseModule');
18
20
  function LikeableDocument(Base, options) {
19
21
  class LikeableDocument extends Base {
20
22
  hasLiked(accountId) {
@@ -22,21 +24,33 @@ function LikeableDocument(Base, options) {
22
24
  return ((_a = this._likedBy) !== null && _a !== void 0 ? _a : []).includes(accountId);
23
25
  }
24
26
  async addLike(accountId) {
25
- var _a;
26
- if (!(0, class_validator_1.isMongoId)(accountId))
27
- return this.likes;
28
- this._likedBy = Array.from(new Set([...((_a = this._likedBy) !== null && _a !== void 0 ? _a : []), accountId]));
27
+ var _a, _b;
28
+ if (!(0, class_validator_1.isMongoId)(accountId) || this.hasLiked(accountId))
29
+ return (_a = this.likes) !== null && _a !== void 0 ? _a : 0;
30
+ // Update the DB atomically
31
+ await this.updateOne({
32
+ $addToSet: { _likedBy: accountId },
33
+ $inc: { likes: 1 },
34
+ }, { timestamps: false });
35
+ logger.debug(`Account ${accountId} liked ${this.collection.name} resource ${this._id.toString()}`);
36
+ // Update the local instance state so the return value is accurate
37
+ this._likedBy = [...((_b = this._likedBy) !== null && _b !== void 0 ? _b : []), accountId];
29
38
  this.likes = this._likedBy.length;
30
- await this.save({ timestamps: false });
31
39
  return this.likes;
32
40
  }
33
41
  async removeLike(accountId) {
34
42
  var _a;
35
- if (!(0, class_validator_1.isMongoId)(accountId))
43
+ if (!(0, class_validator_1.isMongoId)(accountId) || !this.hasLiked(accountId))
36
44
  return this.likes;
45
+ // Update the DB atomically
46
+ await this.updateOne({
47
+ $pull: { _likedBy: accountId },
48
+ $inc: { likes: -1 },
49
+ }, { timestamps: false });
50
+ logger.debug(`Account ${accountId} unliked ${this.collection.name} resource ${this._id.toString()}`);
51
+ // Update the local instance state so the return value is accurate
37
52
  this._likedBy = ((_a = this._likedBy) !== null && _a !== void 0 ? _a : []).filter((id) => id !== accountId);
38
53
  this.likes = this._likedBy.length;
39
- await this.save({ timestamps: false });
40
54
  return this.likes;
41
55
  }
42
56
  }
@@ -1,9 +1,9 @@
1
1
  import { Document } from 'mongoose';
2
2
  export declare function TimestampsDocument<TBase extends new (...args: any[]) => Document>(Base: TBase): {
3
3
  new (...args: any[]): {
4
- createdAt: Date;
5
- updatedAt: Date;
6
- _id: unknown;
4
+ createdAt: string;
5
+ updatedAt: string;
6
+ _id: import("mongoose").Types.ObjectId;
7
7
  $assertPopulated<Paths = {}>(path: string | string[], values?: Partial<Paths>): Omit</*elided*/ any, keyof Paths> & Paths;
8
8
  $clearModifiedPaths(): /*elided*/ any;
9
9
  $clone(): /*elided*/ any;
@@ -37,7 +37,7 @@ export declare function TimestampsDocument<TBase extends new (...args: any[]) =>
37
37
  deleteOne(options?: import("mongoose").QueryOptions): any;
38
38
  depopulate<Paths = {}>(path?: string | string[]): import("mongoose").MergeType</*elided*/ any, Paths>;
39
39
  directModifiedPaths(): Array<string>;
40
- equals(doc: Document<unknown, any, any, Record<string, any>, {}>): boolean;
40
+ equals(doc: Document<import("mongoose").Types.ObjectId, any, any, Record<string, any>, {}>): boolean;
41
41
  errors?: import("mongoose").Error.ValidationError;
42
42
  get<T extends string | number | symbol>(path: T, type?: any, options?: any): any;
43
43
  get(path: string, type?: any, options?: any): any;
@@ -85,6 +85,7 @@ export declare function TimestampsDocument<TBase extends new (...args: any[]) =>
85
85
  set(path: string | Record<string, any>, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
86
86
  set(path: string | Record<string, any>, val: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
87
87
  set(value: string | Record<string, any>): /*elided*/ any;
88
+ toBSON(): any;
88
89
  toJSON(options: import("mongoose").ToObjectOptions & {
89
90
  versionKey: false;
90
91
  virtuals: true;
@@ -10,18 +10,20 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TimestampsDocument = TimestampsDocument;
13
+ const mongoose_1 = require("@nestjs/mongoose");
13
14
  const swagger_1 = require("@nestjs/swagger");
14
15
  function TimestampsDocument(Base) {
15
16
  class TimestampsDocument extends Base {
16
17
  }
17
18
  __decorate([
18
- (0, swagger_1.ApiPropertyOptional)({ description: 'Timestamps' }),
19
- (0, swagger_1.ApiPropertyOptional)(),
20
- __metadata("design:type", Date)
19
+ (0, swagger_1.ApiPropertyOptional)({ description: 'Timestamp the item was created at' }),
20
+ (0, mongoose_1.Prop)({ required: true, type: String }),
21
+ __metadata("design:type", String)
21
22
  ], TimestampsDocument.prototype, "createdAt", void 0);
22
23
  __decorate([
23
- (0, swagger_1.ApiPropertyOptional)(),
24
- __metadata("design:type", Date)
24
+ (0, swagger_1.ApiPropertyOptional)({ description: 'Timestamp the item was last updated at' }),
25
+ (0, mongoose_1.Prop)({ required: true, type: String }),
26
+ __metadata("design:type", String)
25
27
  ], TimestampsDocument.prototype, "updatedAt", void 0);
26
28
  return TimestampsDocument;
27
29
  }
@@ -10,7 +10,7 @@ export declare function ViewableDocument<TBase extends new (...args: any[]) => D
10
10
  hasViewed(accountId: string): boolean;
11
11
  addView(accountId: string): Promise<number>;
12
12
  removeView(accountId: string): Promise<number>;
13
- _id: unknown;
13
+ _id: import("mongoose").Types.ObjectId;
14
14
  $assertPopulated<Paths = {}>(path: string | string[], values?: Partial<Paths>): Omit</*elided*/ any, keyof Paths> & Paths;
15
15
  $clearModifiedPaths(): /*elided*/ any;
16
16
  $clone(): /*elided*/ any;
@@ -44,7 +44,7 @@ export declare function ViewableDocument<TBase extends new (...args: any[]) => D
44
44
  deleteOne(options?: import("mongoose").QueryOptions): any;
45
45
  depopulate<Paths = {}>(path?: string | string[]): import("mongoose").MergeType</*elided*/ any, Paths>;
46
46
  directModifiedPaths(): Array<string>;
47
- equals(doc: Document<unknown, any, any, Record<string, any>, {}>): boolean;
47
+ equals(doc: Document<import("mongoose").Types.ObjectId, any, any, Record<string, any>, {}>): boolean;
48
48
  errors?: import("mongoose").Error.ValidationError;
49
49
  get<T extends string | number | symbol>(path: T, type?: any, options?: any): any;
50
50
  get(path: string, type?: any, options?: any): any;
@@ -92,6 +92,7 @@ export declare function ViewableDocument<TBase extends new (...args: any[]) => D
92
92
  set(path: string | Record<string, any>, val: any, type: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
93
93
  set(path: string | Record<string, any>, val: any, options?: import("mongoose").DocumentSetOptions): /*elided*/ any;
94
94
  set(value: string | Record<string, any>): /*elided*/ any;
95
+ toBSON(): any;
95
96
  toJSON(options: import("mongoose").ToObjectOptions & {
96
97
  versionKey: false;
97
98
  virtuals: true;
@@ -10,11 +10,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ViewableDocument = ViewableDocument;
13
+ const common_1 = require("@nestjs/common");
13
14
  const mongoose_1 = require("@nestjs/mongoose");
14
15
  const swagger_1 = require("@nestjs/swagger");
15
16
  const class_validator_1 = require("class-validator");
16
17
  const models_1 = require("../../models");
17
18
  const pipes_1 = require("../../pipes");
19
+ const logger = new common_1.Logger('MongooseModule');
18
20
  function ViewableDocument(Base, options) {
19
21
  class ViewableDocument extends Base {
20
22
  hasViewed(accountId) {
@@ -23,20 +25,32 @@ function ViewableDocument(Base, options) {
23
25
  }
24
26
  async addView(accountId) {
25
27
  var _a;
26
- if (!(0, class_validator_1.isMongoId)(accountId))
28
+ if (!(0, class_validator_1.isMongoId)(accountId) || this.hasViewed(accountId))
27
29
  return this.views;
28
- this._viewedBy = Array.from(new Set([...((_a = this._viewedBy) !== null && _a !== void 0 ? _a : []), accountId]));
30
+ // Update the DB atomically
31
+ await this.updateOne({
32
+ $addToSet: { _viewedBy: accountId },
33
+ $inc: { views: 1 },
34
+ }, { timestamps: false });
35
+ logger.debug(`Account ${accountId} viewed ${this.collection.name} resource ${this._id.toString()}`);
36
+ // Update the local instance state so the return value is accurate
37
+ this._viewedBy = [...((_a = this._viewedBy) !== null && _a !== void 0 ? _a : []), accountId];
29
38
  this.views = this._viewedBy.length;
30
- await this.save({ timestamps: false });
31
39
  return this.views;
32
40
  }
33
41
  async removeView(accountId) {
34
42
  var _a;
35
- if (!(0, class_validator_1.isMongoId)(accountId))
43
+ if (!(0, class_validator_1.isMongoId)(accountId) || !this.hasViewed(accountId))
36
44
  return this.views;
45
+ // Update the DB atomically
46
+ await this.updateOne({
47
+ $pull: { _viewedBy: accountId },
48
+ $inc: { views: -1 },
49
+ }, { timestamps: false });
50
+ logger.debug(`Account ${accountId} unviewed ${this.collection.name} resource ${this._id.toString()}`);
51
+ // Update the local instance state so the return value is accurate
37
52
  this._viewedBy = ((_a = this._viewedBy) !== null && _a !== void 0 ? _a : []).filter((id) => id !== accountId);
38
53
  this.views = this._viewedBy.length;
39
- await this.save({ timestamps: false });
40
54
  return this.views;
41
55
  }
42
56
  }
@@ -11,7 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ViewedByOptions = ViewedByOptions;
13
13
  exports.populateViewedBy = populateViewedBy;
14
- const common_1 = require("@nestjs/common");
15
14
  const swagger_1 = require("@nestjs/swagger");
16
15
  const class_validator_1 = require("class-validator");
17
16
  const pipes_1 = require("../../pipes");
@@ -37,17 +36,9 @@ function ViewedByOptions(Base, options) {
37
36
  }
38
37
  async function populateViewedBy(options, items, accountsService) {
39
38
  if (options.viewedBy) {
40
- const logger = new common_1.Logger('MongooseModule');
41
39
  items.forEach((item) => {
42
- var _a;
43
- const viewedBy = Array.from(new Set([...((_a = item._viewedBy) !== null && _a !== void 0 ? _a : []), options.viewedBy]));
44
- item
45
- .updateOne({ $set: { _viewedBy: viewedBy, views: viewedBy.length } }, { timestamps: false })
46
- .then(() => {
47
- logger.log(`Added unique accountId '${options.viewedBy}' to '_viewedBy' for document ${item._id.toString()}`);
48
- })
49
- .catch((error) => {
50
- logger.error(`Failed to add accountId '${options.viewedBy}' to attribute '_viewedBy' for document ${item._id.toString()}: ${error.stack}`);
40
+ item.addView(options.viewedBy).then(() => {
41
+ /* noop */
51
42
  });
52
43
  });
53
44
  }
@@ -10,7 +10,6 @@ import { LikeModuleOptions } from './like-module-options.interface';
10
10
  export declare class LikeService {
11
11
  private readonly moduleOptions;
12
12
  private readonly connection;
13
- private readonly logger;
14
13
  private readonly likeableModel;
15
14
  /**
16
15
  * Constructs the LikeService with a configured model instance.
@@ -11,7 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var LikeService_1;
15
14
  Object.defineProperty(exports, "__esModule", { value: true });
16
15
  exports.LikeService = void 0;
17
16
  const common_1 = require("@nestjs/common");
@@ -25,7 +24,7 @@ const like_module_definition_1 = require("./like.module-definition");
25
24
  * Why: Encapsulates MongoDB operations and ensures consistent handling
26
25
  * of like-related behavior across all resources that support likes.
27
26
  */
28
- let LikeService = LikeService_1 = class LikeService {
27
+ let LikeService = class LikeService {
29
28
  /**
30
29
  * Constructs the LikeService with a configured model instance.
31
30
  *
@@ -38,7 +37,6 @@ let LikeService = LikeService_1 = class LikeService {
38
37
  constructor(moduleOptions, connection) {
39
38
  this.moduleOptions = moduleOptions;
40
39
  this.connection = connection;
41
- this.logger = new common_1.Logger(LikeService_1.name);
42
40
  const { name, schema } = this.moduleOptions.model;
43
41
  this.likeableModel = this.connection.model(name, schema);
44
42
  }
@@ -51,7 +49,6 @@ let LikeService = LikeService_1 = class LikeService {
51
49
  */
52
50
  async addLike(resourceId, accountId) {
53
51
  var _a;
54
- this.logger.debug(`Account ${accountId} liked ${this.likeableModel.name.toLowerCase()} resource ${resourceId}`);
55
52
  const resource = await this.likeableModel.findOne({ _id: resourceId });
56
53
  return (_a = resource === null || resource === void 0 ? void 0 : resource.addLike(accountId)) !== null && _a !== void 0 ? _a : 0;
57
54
  }
@@ -64,7 +61,6 @@ let LikeService = LikeService_1 = class LikeService {
64
61
  */
65
62
  async removeLike(resourceId, accountId) {
66
63
  var _a;
67
- this.logger.debug(`Account ${accountId} unliked ${this.likeableModel.name.toLowerCase()} resource ${resourceId}`);
68
64
  const resource = await this.likeableModel.findOne({ _id: resourceId });
69
65
  return (_a = resource === null || resource === void 0 ? void 0 : resource.removeLike(accountId)) !== null && _a !== void 0 ? _a : 0;
70
66
  }
@@ -77,13 +73,12 @@ let LikeService = LikeService_1 = class LikeService {
77
73
  */
78
74
  async hasLiked(resourceId, accountId) {
79
75
  var _a;
80
- this.logger.log(`Checking like status for account ${accountId} on ${this.likeableModel.name.toLowerCase()} resource ${resourceId}`);
81
76
  const resource = await this.likeableModel.findOne({ _id: resourceId });
82
77
  return (_a = resource === null || resource === void 0 ? void 0 : resource.hasLiked(accountId)) !== null && _a !== void 0 ? _a : false;
83
78
  }
84
79
  };
85
80
  exports.LikeService = LikeService;
86
- exports.LikeService = LikeService = LikeService_1 = __decorate([
81
+ exports.LikeService = LikeService = __decorate([
87
82
  (0, common_1.Injectable)(),
88
83
  __param(0, (0, common_1.Inject)(like_module_definition_1.LIKE_MODULE_OPTIONS_TOKEN)),
89
84
  __param(1, (0, mongoose_1.InjectConnection)()),
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringArrayTransform = StringArrayTransform;
4
4
  const class_transformer_1 = require("class-transformer");
5
- const class_validator_1 = require("class-validator");
6
5
  /**
7
6
  * Property decorator to normalize and sanitize an array of strings.
8
7
  * Applies trimming, lowercasing, and deduplication as configured.
@@ -12,9 +11,7 @@ const class_validator_1 = require("class-validator");
12
11
  */
13
12
  function StringArrayTransform(opts = {}) {
14
13
  return (0, class_transformer_1.Transform)(({ value }) => {
15
- if (!(0, class_validator_1.isArray)(value))
16
- return undefined;
17
- const transformed = value.map((item) => {
14
+ const transformed = [value].flat().map((item) => {
18
15
  let str = String(item);
19
16
  if (opts.trim)
20
17
  str = str.trim();
@@ -1,4 +1,4 @@
1
1
  export type HasTimestamps = {
2
- createdAt: Date;
3
- updatedAt: Date;
2
+ createdAt: string;
3
+ updatedAt: string;
4
4
  };
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.14",
7
+ "version": "2.16.15",
8
8
  "type": "commonjs",
9
9
  "files": [
10
10
  "dist"