UNPKG

994 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const decorators_1 = require("../decorators");
5const index_1 = require("../index");
6const is_uuid_1 = require("../utils/is-uuid");
7let 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};
21ParseUUIDPipe = tslib_1.__decorate([
22 index_1.Injectable(),
23 tslib_1.__param(0, decorators_1.Optional()),
24 tslib_1.__metadata("design:paramtypes", [Object])
25], ParseUUIDPipe);
26exports.ParseUUIDPipe = ParseUUIDPipe;