Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Chen committed Jun 12, 2024
1 parent c8b7390 commit f7700dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/checkData.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { validate, format } from '@sumor/validator'
import APIError from './i18n/APIError.js'

export default (data, apiInfo) => {
export default (data, apiParameters) => {
let errors = []
for (const key in apiInfo.parameters) {
data[key] = format(apiInfo.parameters[key], data[key])
for (const key in apiParameters) {
data[key] = format(apiParameters[key], data[key])
const fieldErrors = validate(
{
...apiInfo.parameters[key],
...apiParameters[key],
error: true
},
data[key]
Expand Down
14 changes: 5 additions & 9 deletions test/check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ describe('check', () => {
text: ' demo '
},
{
parameters: {
text: {
type: 'string'
}
text: {
type: 'string'
}
}
)
expect(data1.text).toEqual('demo')
})
it('error', () => {
const definition = {
parameters: {
text: {
type: 'string',
length: 4
}
text: {
type: 'string',
length: 4
}
}
let error
Expand Down

0 comments on commit f7700dd

Please sign in to comment.