1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ParseBoolPipe = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const injectable_decorator_1 = require("../decorators/core/injectable.decorator");
|
6 | const optional_decorator_1 = require("../decorators/core/optional.decorator");
|
7 | const http_status_enum_1 = require("../enums/http-status.enum");
|
8 | const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | let ParseBoolPipe = class ParseBoolPipe {
|
17 | constructor(options) {
|
18 | options = options || {};
|
19 | const { exceptionFactory, errorHttpStatusCode = http_status_enum_1.HttpStatus.BAD_REQUEST, } = options;
|
20 | this.exceptionFactory =
|
21 | exceptionFactory ||
|
22 | (error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
23 | }
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | async transform(value, metadata) {
|
32 | if (value === true || value === 'true') {
|
33 | return true;
|
34 | }
|
35 | if (value === false || value === 'false') {
|
36 | return false;
|
37 | }
|
38 | throw this.exceptionFactory('Validation failed (boolean string is expected)');
|
39 | }
|
40 | };
|
41 | ParseBoolPipe = tslib_1.__decorate([
|
42 | injectable_decorator_1.Injectable(),
|
43 | tslib_1.__param(0, optional_decorator_1.Optional()),
|
44 | tslib_1.__metadata("design:paramtypes", [Object])
|
45 | ], ParseBoolPipe);
|
46 | exports.ParseBoolPipe = ParseBoolPipe;
|