polishing
This commit is contained in:
@@ -14,18 +14,19 @@ cds.validate = function (x, pk, ...columns) {
|
||||
if (x?.ref) [ x, pk ] = [ x.ref +'.constraints', pk.ID||pk ]
|
||||
|
||||
// Run the constraints check query
|
||||
const constraints = cds.model.definitions[x] || cds.error `No such constraints view: ${x}`
|
||||
return SELECT.one.from (constraints, pk, columns.length && columns)
|
||||
const constraints = typeof x === 'string' ? cds.model.definitions[x] || cds.error `No such constraints view: ${x}` : x
|
||||
return SELECT.from (constraints, pk, columns.length && columns)
|
||||
|
||||
// Collect and throw errors, if any
|
||||
.then (checks => {
|
||||
.then (rows => (rows.map ? rows : [rows]).map (checks => {
|
||||
const failed = {}; for (let c in checks) {
|
||||
if (c in constraints.keys) continue
|
||||
if (c[0] == '_') continue
|
||||
if (checks[c]) failed[c] = checks[c]
|
||||
}
|
||||
if (Object.keys(failed).length) throw cds.error `Invalid input: ${failed}`
|
||||
})
|
||||
return checks
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user