itlab-internal-services 2.4.3 → 2.4.5

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.
@@ -0,0 +1,3 @@
1
+ import { Document, Model } from 'mongoose';
2
+ import { ErrorException } from './exceptions';
3
+ export declare function createDuplicateChecker<D, T extends Document>(model: Model<T>, criticalKeys: (keyof D & keyof T)[], error?: new () => ErrorException): (dto: D, target?: T) => Promise<void>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createDuplicateChecker = void 0;
13
+ const exceptions_1 = require("./exceptions");
14
+ function createDuplicateChecker(model, criticalKeys, error = exceptions_1.DuplicateException) {
15
+ return (dto, target) => __awaiter(this, void 0, void 0, function* () {
16
+ const fq = {};
17
+ for (const key of criticalKeys) {
18
+ if (dto && key in dto)
19
+ fq[key] = dto[key];
20
+ if (target && key in target)
21
+ fq[key] = target[key];
22
+ }
23
+ const found = yield model.findOne(fq);
24
+ const compareId = target ? String(target._id).toLowerCase() : undefined;
25
+ if (found && String(found._id).toLowerCase() !== compareId)
26
+ throw new error();
27
+ });
28
+ }
29
+ exports.createDuplicateChecker = createDuplicateChecker;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './create-duplicate-checker.function';
1
2
  export * from './exceptions';
2
3
  export * from './favicon.controller';
3
4
  export * from './guards';
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./create-duplicate-checker.function"), exports);
17
18
  __exportStar(require("./exceptions"), exports);
18
19
  __exportStar(require("./favicon.controller"), exports);
19
20
  __exportStar(require("./guards"), exports);
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Represents a MailToken
3
+ */
4
+ export declare class MailToken {
5
+ /** The login token */
6
+ token: string;
7
+ }
1
8
  /**
2
9
  * Represents a MailWeeklyDagoBERTSummary
3
10
  */
@@ -26,3 +33,12 @@ export declare class MailDagoBERTDowntime {
26
33
  /** The end time */
27
34
  end: string;
28
35
  }
36
+ /**
37
+ * Represents a MailPasswordReset
38
+ */
39
+ export declare class MailPasswordReset {
40
+ /** The name of the receiver */
41
+ name: string;
42
+ /** The URL from where to reset the password from */
43
+ url: string;
44
+ }
@@ -9,8 +9,14 @@ 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
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MailDagoBERTDowntime = exports.MailWeeklyDagoBERTSummary = void 0;
12
+ exports.MailPasswordReset = exports.MailDagoBERTDowntime = exports.MailWeeklyDagoBERTSummary = exports.MailToken = void 0;
13
13
  const swagger_1 = require("@nestjs/swagger");
14
+ /**
15
+ * Represents a MailToken
16
+ */
17
+ class MailToken {
18
+ }
19
+ exports.MailToken = MailToken;
14
20
  /**
15
21
  * Represents a MailWeeklyDagoBERTSummary
16
22
  */
@@ -59,3 +65,17 @@ __decorate([
59
65
  __metadata("design:type", String)
60
66
  ], MailDagoBERTDowntime.prototype, "end", void 0);
61
67
  exports.MailDagoBERTDowntime = MailDagoBERTDowntime;
68
+ /**
69
+ * Represents a MailPasswordReset
70
+ */
71
+ class MailPasswordReset {
72
+ }
73
+ __decorate([
74
+ (0, swagger_1.ApiProperty)(),
75
+ __metadata("design:type", String)
76
+ ], MailPasswordReset.prototype, "name", void 0);
77
+ __decorate([
78
+ (0, swagger_1.ApiProperty)(),
79
+ __metadata("design:type", String)
80
+ ], MailPasswordReset.prototype, "url", void 0);
81
+ exports.MailPasswordReset = MailPasswordReset;
@@ -1,5 +1,12 @@
1
1
  import { ConfigService } from '@nestjs/config';
2
- import { MailDagoBERTDowntime, MailWeeklyDagoBERTSummary } from './mail.models';
2
+ import { MailDagoBERTDowntime, MailPasswordReset, MailToken, MailWeeklyDagoBERTSummary } from './mail.models';
3
+ declare type Data = MailToken | MailPasswordReset | MailWeeklyDagoBERTSummary | MailDagoBERTDowntime | Record<string, string>;
4
+ export declare enum Endpoint {
5
+ Token = "token",
6
+ PasswordReset = "password-reset",
7
+ WeeklyDagoBERTSummary = "weekly-dagobert-summary",
8
+ DagoBERTDowntime = "dagobert-downtime"
9
+ }
3
10
  /**
4
11
  * Mail service
5
12
  * @class MailService
@@ -16,27 +23,12 @@ export declare class MailService {
16
23
  /** The axios instance */
17
24
  private axios;
18
25
  /**
19
- * Sends a signin token to a specified address.
20
- *
21
- * @param {string} token - the token to be sent
22
- * @param {string} address - the address where the token will be sent to
23
- * @return {void}
24
- */
25
- sendToken(token: string, address: string): void;
26
- /**
27
- * Sends the weekly DagoBERT summary via email.
28
- *
29
- * @param {MailWeeklyDagoBERTSummary} data - the data for the weekly summary
30
- * @param {string} address - the email address to send the summary to
31
- * @return {void}
32
- */
33
- sendWeeklyDagoBERTSummary(data: MailWeeklyDagoBERTSummary, address: string): void;
34
- /**
35
- * Send DagoBERT downtime data to the specified address.
26
+ * Send data to a specified address.
36
27
  *
37
- * @param {MailDagoBERTDowntime} data - the data to send
38
- * @param {string} address - the address to send the data to
39
- * @return {void}
28
+ * @param {string} endpoint - the endpoint of the mail service
29
+ * @param {Data} data - the data to sent
30
+ * @param address - the addess where the data will be sent to
40
31
  */
41
- sendDagoBERTDowntime(data: MailDagoBERTDowntime, address: string): void;
32
+ send<T = Data>(endpoint: string, data: T, address: string): void;
42
33
  }
34
+ export {};
@@ -10,11 +10,18 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  var MailService_1;
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.MailService = void 0;
13
+ exports.MailService = exports.Endpoint = void 0;
14
14
  const common_1 = require("@nestjs/common");
15
15
  const config_1 = require("@nestjs/config");
16
16
  const axios_1 = require("../../axios");
17
17
  const env_1 = require("../../env");
18
+ var Endpoint;
19
+ (function (Endpoint) {
20
+ Endpoint["Token"] = "token";
21
+ Endpoint["PasswordReset"] = "password-reset";
22
+ Endpoint["WeeklyDagoBERTSummary"] = "weekly-dagobert-summary";
23
+ Endpoint["DagoBERTDowntime"] = "dagobert-downtime";
24
+ })(Endpoint = exports.Endpoint || (exports.Endpoint = {}));
18
25
  /**
19
26
  * Mail service
20
27
  * @class MailService
@@ -35,46 +42,18 @@ let MailService = MailService_1 = class MailService {
35
42
  });
36
43
  }
37
44
  /**
38
- * Sends a signin token to a specified address.
45
+ * Send data to a specified address.
39
46
  *
40
- * @param {string} token - the token to be sent
41
- * @param {string} address - the address where the token will be sent to
42
- * @return {void}
47
+ * @param {string} endpoint - the endpoint of the mail service
48
+ * @param {Data} data - the data to sent
49
+ * @param address - the addess where the data will be sent to
43
50
  */
44
- sendToken(token, address) {
45
- this.logger.log('Sending token');
51
+ send(endpoint, data, address) {
52
+ this.logger.log('Sending E-Mail');
46
53
  this.axios
47
- .post(`token`, { token, address })
48
- .then(() => this.logger.log('Token sent'))
49
- .catch(({ response }) => this.logger.error("Couldn't send token...", response.data));
50
- }
51
- /**
52
- * Sends the weekly DagoBERT summary via email.
53
- *
54
- * @param {MailWeeklyDagoBERTSummary} data - the data for the weekly summary
55
- * @param {string} address - the email address to send the summary to
56
- * @return {void}
57
- */
58
- sendWeeklyDagoBERTSummary(data, address) {
59
- this.logger.log('Sending weekly DagoBERT summary');
60
- this.axios
61
- .post(`weekly-dagobert-summary`, Object.assign(Object.assign({}, data), { address }))
62
- .then(() => this.logger.log('Weekly DagoBERT summary sent'))
63
- .catch(({ response }) => this.logger.error("Couldnt't send weekly DagoBERT summary...", response.data));
64
- }
65
- /**
66
- * Send DagoBERT downtime data to the specified address.
67
- *
68
- * @param {MailDagoBERTDowntime} data - the data to send
69
- * @param {string} address - the address to send the data to
70
- * @return {void}
71
- */
72
- sendDagoBERTDowntime(data, address) {
73
- this.logger.log('Sending DagoBERT downtime');
74
- this.axios
75
- .post(`dagobert-downtime`, Object.assign(Object.assign({}, data), { address }))
76
- .then(() => this.logger.log('DagoBERT downtime sent'))
77
- .catch(({ response }) => this.logger.error("Couldnt't send DagoBERT downtime...", response.data));
54
+ .post(endpoint, Object.assign(Object.assign({}, data), { address }))
55
+ .then(() => this.logger.log('E-Mail sent'))
56
+ .catch(({ response }) => this.logger.error("Couldn't send E-Mail...", response.data));
78
57
  }
79
58
  };
80
59
  MailService = MailService_1 = __decorate([
@@ -1,3 +1,3 @@
1
- export { SearchableDocument } from './search.models';
1
+ export { SearchableDocument, SearchDocument } from './search.models';
2
2
  export { SearchModule } from './search.module';
3
3
  export { SearchService } from './search.service';
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SearchService = exports.SearchModule = exports.SearchableDocument = void 0;
3
+ exports.SearchService = exports.SearchModule = exports.SearchDocument = exports.SearchableDocument = void 0;
4
4
  var search_models_1 = require("./search.models");
5
5
  Object.defineProperty(exports, "SearchableDocument", { enumerable: true, get: function () { return search_models_1.SearchableDocument; } });
6
+ Object.defineProperty(exports, "SearchDocument", { enumerable: true, get: function () { return search_models_1.SearchDocument; } });
6
7
  var search_module_1 = require("./search.module");
7
8
  Object.defineProperty(exports, "SearchModule", { enumerable: true, get: function () { return search_module_1.SearchModule; } });
8
9
  var search_service_1 = require("./search.service");
@@ -17,3 +17,10 @@ export declare class SearchableDocument {
17
17
  /** The data of the searchable document. */
18
18
  data: object;
19
19
  }
20
+ export declare class SearchDocument {
21
+ id: string;
22
+ type: string;
23
+ label: string;
24
+ url: string;
25
+ highlight?: string;
26
+ }
@@ -9,8 +9,9 @@ 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
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SearchableDocument = void 0;
12
+ exports.SearchDocument = exports.SearchableDocument = void 0;
13
13
  const swagger_1 = require("@nestjs/swagger");
14
+ const pipes_1 = require("../../pipes");
14
15
  /**
15
16
  * Represents a searchable document.
16
17
  *
@@ -39,3 +40,26 @@ __decorate([
39
40
  __metadata("design:type", Object)
40
41
  ], SearchableDocument.prototype, "data", void 0);
41
42
  exports.SearchableDocument = SearchableDocument;
43
+ class SearchDocument {
44
+ }
45
+ __decorate([
46
+ (0, swagger_1.ApiProperty)({ description: 'Id des Ergebnisses' }),
47
+ __metadata("design:type", String)
48
+ ], SearchDocument.prototype, "id", void 0);
49
+ __decorate([
50
+ (0, swagger_1.ApiProperty)({ description: 'Typ des Ergebnisses', enum: pipes_1.Targets }),
51
+ __metadata("design:type", String)
52
+ ], SearchDocument.prototype, "type", void 0);
53
+ __decorate([
54
+ (0, swagger_1.ApiProperty)({ description: 'Anzeigename des Ergebnisses' }),
55
+ __metadata("design:type", String)
56
+ ], SearchDocument.prototype, "label", void 0);
57
+ __decorate([
58
+ (0, swagger_1.ApiProperty)({ description: 'Link zum Ergebnis' }),
59
+ __metadata("design:type", String)
60
+ ], SearchDocument.prototype, "url", void 0);
61
+ __decorate([
62
+ (0, swagger_1.ApiProperty)({ description: 'Anzeigename des Ergebnisses mit Highlights (<mark>)' }),
63
+ __metadata("design:type", String)
64
+ ], SearchDocument.prototype, "highlight", void 0);
65
+ exports.SearchDocument = SearchDocument;
@@ -1,6 +1,6 @@
1
1
  import { ConfigService } from '@nestjs/config';
2
2
  import { Targets } from '../../pipes';
3
- import { SearchableDocument } from './search.models';
3
+ import { SearchableDocument, SearchDocument } from './search.models';
4
4
  /**
5
5
  * Search service
6
6
  * @class SearchService
@@ -32,4 +32,11 @@ export declare class SearchService {
32
32
  * @return {void}
33
33
  */
34
34
  remove(targetId: string): void;
35
+ /**
36
+ * Find similar documents from elasticsaech
37
+ *
38
+ * @param {string} targetId - the ID of the target to find similar documents of
39
+ * @returns {Promise<SearchDocument[]>} Promise containing similar documents
40
+ */
41
+ similar(targetId: string): Promise<SearchDocument[]>;
35
42
  }
@@ -11,6 +11,15 @@ 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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
14
23
  var SearchService_1;
15
24
  Object.defineProperty(exports, "__esModule", { value: true });
16
25
  exports.SearchService = void 0;
@@ -66,6 +75,19 @@ let SearchService = SearchService_1 = class SearchService {
66
75
  .then(() => this.logger.log(`Sucessfully removed ${this.target} (${targetId})`))
67
76
  .catch(({ response }) => this.logger.error(`Couldn't remove ${this.target} (${targetId})`, response.data));
68
77
  }
78
+ /**
79
+ * Find similar documents from elasticsaech
80
+ *
81
+ * @param {string} targetId - the ID of the target to find similar documents of
82
+ * @returns {Promise<SearchDocument[]>} Promise containing similar documents
83
+ */
84
+ similar(targetId) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ this.logger.log(`Finding similar documents for ${this.target} (${targetId})`);
87
+ const response = yield this.axios.get(`${this.target}/${targetId}/similar`);
88
+ return response.data;
89
+ });
90
+ }
69
91
  };
70
92
  SearchService = SearchService_1 = __decorate([
71
93
  (0, common_1.Injectable)(),
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This function casts the input value to an array if it's not an
3
+ * array, otherwise it returns the original value.
4
+ */
5
+ export declare function CastToArray(): PropertyDecorator;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CastToArray = void 0;
4
+ const class_transformer_1 = require("class-transformer");
5
+ /**
6
+ * This function casts the input value to an array if it's not an
7
+ * array, otherwise it returns the original value.
8
+ */
9
+ function CastToArray() {
10
+ return (0, class_transformer_1.Transform)(({ value }) => (Array.isArray(value) ? value : [value]));
11
+ }
12
+ exports.CastToArray = CastToArray;
@@ -1,3 +1,4 @@
1
+ export { CastToArray } from './castToArray';
1
2
  export { TransformBoolean } from './transformBoolean';
2
3
  export { TransformImage } from './transformImage';
3
4
  export { TransformNumber } from './transformNumber';
@@ -6,3 +7,4 @@ export { TransformStringArray } from './transformStringArray';
6
7
  export { isStringLike, isStringLikeMin, TransformStringLike } from './transformStringLike';
7
8
  export { TransformStringLowerCase } from './transformStringLowerCase';
8
9
  export { TransformStringSet } from './transformStringSet';
10
+ export { TransformTimestamp } from './transformTimestamp';
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransformStringSet = exports.TransformStringLowerCase = exports.TransformStringLike = exports.isStringLikeMin = exports.isStringLike = exports.TransformStringArray = exports.TransformString = exports.TransformNumber = exports.TransformImage = exports.TransformBoolean = void 0;
3
+ exports.TransformTimestamp = exports.TransformStringSet = exports.TransformStringLowerCase = exports.TransformStringLike = exports.isStringLikeMin = exports.isStringLike = exports.TransformStringArray = exports.TransformString = exports.TransformNumber = exports.TransformImage = exports.TransformBoolean = exports.CastToArray = void 0;
4
+ var castToArray_1 = require("./castToArray");
5
+ Object.defineProperty(exports, "CastToArray", { enumerable: true, get: function () { return castToArray_1.CastToArray; } });
4
6
  var transformBoolean_1 = require("./transformBoolean");
5
7
  Object.defineProperty(exports, "TransformBoolean", { enumerable: true, get: function () { return transformBoolean_1.TransformBoolean; } });
6
8
  var transformImage_1 = require("./transformImage");
@@ -19,3 +21,5 @@ var transformStringLowerCase_1 = require("./transformStringLowerCase");
19
21
  Object.defineProperty(exports, "TransformStringLowerCase", { enumerable: true, get: function () { return transformStringLowerCase_1.TransformStringLowerCase; } });
20
22
  var transformStringSet_1 = require("./transformStringSet");
21
23
  Object.defineProperty(exports, "TransformStringSet", { enumerable: true, get: function () { return transformStringSet_1.TransformStringSet; } });
24
+ var transformTimestamp_1 = require("./transformTimestamp");
25
+ Object.defineProperty(exports, "TransformTimestamp", { enumerable: true, get: function () { return transformTimestamp_1.TransformTimestamp; } });
@@ -1,6 +1,9 @@
1
1
  interface NumberOptions {
2
+ /** Default value if value isnt a number */
2
3
  default?: number;
4
+ /** Maximum value */
3
5
  min?: number;
6
+ /** Minimum value */
4
7
  max?: number;
5
8
  }
6
9
  /**
@@ -0,0 +1,16 @@
1
+ interface NumberOptions {
2
+ /** Default value if value isnt a number */
3
+ default?: number;
4
+ /** Maximum value */
5
+ min?: number;
6
+ /** Minimum value */
7
+ max?: number;
8
+ /** Round the timestamp to the nearest <unit> */
9
+ roundTo?: 'ms' | 's' | 'm' | 'h';
10
+ }
11
+ /**
12
+ * This function transforms the input value to a trimmed number if it's a string
13
+ * or a number, otherwise it returns the original value.
14
+ */
15
+ export declare function TransformTimestamp(opts?: NumberOptions): PropertyDecorator;
16
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformTimestamp = void 0;
4
+ const class_transformer_1 = require("class-transformer");
5
+ /**
6
+ * This function transforms the input value to a trimmed number if it's a string
7
+ * or a number, otherwise it returns the original value.
8
+ */
9
+ function TransformTimestamp(opts = {}) {
10
+ return (0, class_transformer_1.Transform)(({ value }) => {
11
+ let number = Number.parseInt(value || String(opts.default), 10);
12
+ if (Number.isNaN(number) && !opts.default)
13
+ return value;
14
+ if (Number.isNaN(number))
15
+ number = opts.default;
16
+ if (opts.min && number < opts.min)
17
+ number = opts.min;
18
+ if (opts.max && number > opts.max)
19
+ number = opts.max;
20
+ if (opts.roundTo === 'h')
21
+ return new Date(number).setHours(0, 0, 0, 0);
22
+ if (opts.roundTo === 'm')
23
+ return new Date(number).setMinutes(0, 0, 0);
24
+ if (opts.roundTo === 's')
25
+ return new Date(number).setSeconds(0, 0);
26
+ if (opts.roundTo === 'ms')
27
+ return new Date(number).setMilliseconds(0);
28
+ return number;
29
+ });
30
+ }
31
+ exports.TransformTimestamp = TransformTimestamp;
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.4.3",
8
+ "version": "2.4.5",
9
9
  "type": "commonjs",
10
10
  "files": [
11
11
  "dist"
@@ -70,5 +70,6 @@
70
70
  },
71
71
  "lint-staged": {
72
72
  "**/*.{ts,json}": []
73
- }
73
+ },
74
+ "packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
74
75
  }