Skip to content

Commit

Permalink
feat: Remove ajv-errors and related implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieuka committed Nov 16, 2024
1 parent 821c631 commit 914466a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 51 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@fastify/type-provider-typebox": "^5.0.0",
"@fastify/under-pressure": "^9.0.1",
"@sinclair/typebox": "^0.33.12",
"ajv-errors": "^3.0.0",
"concurrently": "^9.0.1",
"fastify": "^5.0.0",
"fastify-cli": "^7.0.0",
Expand Down
8 changes: 2 additions & 6 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
import path from 'node:path'
import fastifyAutoload from '@fastify/autoload'
import { FastifyInstance, FastifyPluginOptions } from 'fastify'
import AjvErrors from 'ajv-errors'

export const options = {
ajv: {
customOptions: {
coerceTypes: 'array',
removeAdditional: 'all',
strict: false,
allErrors: true
},
plugins: [AjvErrors.default]
removeAdditional: 'all'
}
}
}

Expand Down
46 changes: 2 additions & 44 deletions src/schemas/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,11 @@ const passwordPattern = '^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]

const PasswordSchema = Type.String({
pattern: passwordPattern,
minLength: 8,
errorMessage: {
pattern: 'The password does not meet the required format (at least one uppercase letter, one lowercase letter, one number and one special character)',
minLength: 'Password must contain at least 8 characters'
}
minLength: 8

})

export const UpdateCredentialsSchema = Type.Object({
currentPassword: PasswordSchema,
newPassword: PasswordSchema
}, {
errorMessage: {
required: {
currentPassword: 'Current password is required',
newPassword: 'New password is required'
}
}
})

// same error with vanilla ajv schema
export const AjvUpdateCredentialsSchema = {
type: 'object',
properties: {
currentPassword: {
type: 'string',
pattern: passwordPattern,
minLength: 8,
errorMessage: {
pattern: 'Invalid current password pattern',
minLength: 'Current password is too short'
}
},
newPassword: {
type: 'string',
pattern: passwordPattern,
minLength: 8,
errorMessage: {
pattern: 'Invalid new password pattern',
minLength: 'New password is too short'
}
}
},
required: ['currentPassword', 'newPassword'],
errorMessage: {
required: {
currentPassword: 'Current password is required',
newPassword: 'New password is required'
}
}
}

0 comments on commit 914466a

Please sign in to comment.