-
Notifications
You must be signed in to change notification settings - Fork 21
/
herbsValidator.js
43 lines (33 loc) · 1.04 KB
/
herbsValidator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const { validate, checker } = require('@herbsjs/suma')
const useCaseValidator = (useCase) => {
let output = {}
const defaultValidator = {
presence: true,
allowNull: false
}
const withTypeValidator = {
presence: true,
allowNull: false,
type: String
}
const responseValidation = validate(useCase.responseSchema, defaultValidator)
const nameValidation = validate(useCase.description, withTypeValidator)
if (!checker.isEmpty(nameValidation.errors))
output.useCaseName = nameValidation.errors
if (!checker.isEmpty(responseValidation.errors))
output.response = responseValidation.errors
return output
}
const entityValidator = (entity) => {
let output = {}
const validations = {
presence: true,
allowNull: false,
type: String
}
const { errors } = validate(entity.name, validations)
if (!checker.isEmpty(errors))
output.entityName = errors
return output
}
module.exports = { useCaseValidator, entityValidator }