-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
on_insert
becomes self_check
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ local _M = {} | |
-- `is_update` For an entity update, check immutable fields. Set to true. | ||
-- @return `valid` Success of validation. True or false. | ||
-- @return `errors` A list of encountered errors during the validation. | ||
function _M.validate_fields(t, schema, options) | ||
function _M.validate_entity(t, schema, options) | ||
if not options then options = {} end | ||
local errors | ||
|
||
|
@@ -151,7 +151,7 @@ function _M.validate_fields(t, schema, options) | |
|
||
if t[column] and type(t[column]) == "table" then | ||
-- Actually validating the sub-schema | ||
local s_ok, s_errors = _M.validate_fields(t[column], sub_schema, options) | ||
local s_ok, s_errors = _M.validate_entity(t[column], sub_schema, options) | ||
if not s_ok then | ||
for s_k, s_v in pairs(s_errors) do | ||
errors = utils.add_error(errors, column.."."..s_k, s_v) | ||
|
@@ -190,29 +190,14 @@ function _M.validate_fields(t, schema, options) | |
end | ||
end | ||
|
||
return errors == nil, errors | ||
end | ||
|
||
function _M.on_insert(t, schema, dao) | ||
if schema.on_insert and type(schema.on_insert) == "function" then | ||
local valid, err = schema.on_insert(t, dao, schema) | ||
if not valid or err then | ||
return false, err | ||
else | ||
return true | ||
if errors == nil and type(schema.self_check) == "function" then | ||
local ok, err = schema.self_check(schema, t, options.dao, (options.partial_update or options.full_update)) | ||
if ok == false then | ||
return false, nil, err | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
thibaultcha
Author
Member
|
||
end | ||
else | ||
return true | ||
end | ||
end | ||
|
||
function _M.validate(t, dao, options) | ||
local ok, errors | ||
|
||
ok, errors = _M.validate_fields(t, dao._schema, options) | ||
if not ok then | ||
return DaoError(errors, error_types.SCHEMA) | ||
end | ||
return errors == nil, errors | ||
end | ||
|
||
local digit = "[0-9a-f]" | ||
|
@thibaultcha can this be
return false, err
?This function is supposed to return
ok, err
everywhere else, why is there an exception here?