Skip to content

Commit

Permalink
Merge pull request #172 from cap-js/cds.validate
Browse files Browse the repository at this point in the history
Consolidating cds.assert / cds.validate
  • Loading branch information
danjoa authored Jul 8, 2024
2 parents c22305f + f558582 commit 6f33947
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/resolvers/crud/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ module.exports = async ({ req, res }, service, entity, selection) => {
const entries = entriesStructureToEntityStructure(service, entity, astToEntries(input))
query.entries(entries)

if (cds.env.features.cds_assert) {
if (cds.env.features.cds_validate) {
const assertOptions = { mandatories: true }
const errs = cds.assert(entries, entity, assertOptions)
const errs = cds.validate(entries, entity, assertOptions)
if (errs) {
if (errs.length === 1) throw errs[0]
throw Object.assign(new Error('MULTIPLE_ERRORS'), { statusCode: 400, details: errs })
}
}

const result = await service.dispatch(new GraphQLRequest({ req, res, query }))

return formatResult(entity, selection, result, false)
Expand Down
4 changes: 2 additions & 2 deletions lib/resolvers/crud/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module.exports = async ({ req, res }, service, entity, selection) => {
const entries = entriesStructureToEntityStructure(service, entity, astToEntries(input))
query.with(entries)

if (cds.env.features.cds_assert) {
if (cds.env.features.cds_validate) {
const assertOptions = { mandatories: true }
const errs = cds.assert(entries, entity, assertOptions)
const errs = cds.validate(entries, entity, assertOptions)
if (errs) {
if (errs.length === 1) throw errs[0]
throw Object.assign(new Error('MULTIPLE_ERRORS'), { statusCode: 400, details: errs })
Expand Down

0 comments on commit 6f33947

Please sign in to comment.