1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const decorators_1 = require("../decorators");
|
5 | const index_1 = require("../index");
|
6 | const is_uuid_1 = require("../utils/is-uuid");
|
7 | let ParseUUIDPipe = class ParseUUIDPipe {
|
8 | constructor(options) {
|
9 | options = options || {};
|
10 | this.version = options.version;
|
11 | this.exceptionFactory =
|
12 | options.exceptionFactory || (error => new index_1.BadRequestException(error));
|
13 | }
|
14 | async transform(value, metadata) {
|
15 | if (!is_uuid_1.isUUID(value, this.version)) {
|
16 | throw this.exceptionFactory(`Validation failed (uuid ${this.version ? 'v' + this.version : ''} is expected)`);
|
17 | }
|
18 | return value;
|
19 | }
|
20 | };
|
21 | ParseUUIDPipe = tslib_1.__decorate([
|
22 | index_1.Injectable(),
|
23 | tslib_1.__param(0, decorators_1.Optional()),
|
24 | tslib_1.__metadata("design:paramtypes", [Object])
|
25 | ], ParseUUIDPipe);
|
26 | exports.ParseUUIDPipe = ParseUUIDPipe;
|