express-validate-decorator
Advanced tools
Comparing version 0.0.5 to 0.1.0
@@ -9,3 +9,4 @@ /// <reference types="hapi__joi" /> | ||
query?: Joi.ObjectSchema<JoiModelObject> | JoiModelObject; | ||
params?: Joi.ObjectSchema<JoiModelObject> | JoiModelObject; | ||
} | ||
//# sourceMappingURL=models.d.ts.map |
@@ -12,2 +12,3 @@ "use strict"; | ||
let bodySchema; | ||
let paramsSchema; | ||
if (model.query) | ||
@@ -21,4 +22,10 @@ querySchema = joi_1.default.isSchema(model.query) | ||
: joi_1.default.object(model.body); | ||
if (querySchema === undefined && bodySchema === undefined) | ||
throw Error("Query or Body schema required"); | ||
if (model.params) | ||
paramsSchema = joi_1.default.isSchema(model.params) | ||
? model.params | ||
: joi_1.default.object(model.params); | ||
if (querySchema === undefined && | ||
bodySchema === undefined && | ||
paramsSchema === undefined) | ||
throw Error("Query, Body or Params schema required"); | ||
return function (scope, methodName, descriptor) { | ||
@@ -40,2 +47,9 @@ const original = descriptor.value; | ||
} | ||
if (paramsSchema) { | ||
const paramsResult = paramsSchema.validate(req.params); | ||
if (paramsResult.error) | ||
return res | ||
.status(400) | ||
.send("Params Error " + paramsResult.error.message); | ||
} | ||
return original.apply(this, [req, res, next]); | ||
@@ -42,0 +56,0 @@ }; |
{ | ||
"name": "express-validate-decorator", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"main": "./dist/validate.js", | ||
@@ -5,0 +5,0 @@ "types": "./dist/validate.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10202
92