-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(validator): add validation to update route
- Loading branch information
Showing
7 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Middleware, type Context } from '@athenna/http' | ||
import { BaseValidator } from '#src/validators/base.validator' | ||
|
||
@Middleware({ name: 'update:validator' }) | ||
export class UpdateValidator extends BaseValidator { | ||
public schema = this.validator.object({ | ||
name: this.validator.string().optional(), | ||
email: this.validator | ||
.string() | ||
.email() | ||
.unique({ table: 'users', max: 1 }) | ||
.optional(), | ||
password: this.validator | ||
.string() | ||
.minLength(8) | ||
.maxLength(32) | ||
.confirmed() | ||
.optional() | ||
}) | ||
|
||
public async handle({ request }: Context) { | ||
const data = request.only([ | ||
'name', | ||
'email', | ||
'password', | ||
'password_confirmation' | ||
]) | ||
|
||
await this.validate(data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"default":[],"deadletter":[],"user:email":[],"user:password":[{"user":{"name":"João Lenon","email":"Darlene.Wilkinson@gmail.com"},"password":"$2b$10$gTXEZsXmkLJhOvvge3t/IO99RUw1AD6NmddfQ3mPByHweP3hWJdoO"}],"user:email:password":[],"user:confirm":[]} | ||
{"default":[],"deadletter":[],"user:email":[],"user:password":[{"user":{"name":"João Lenon","email":"Monique_Johnson@yahoo.com"},"password":"$2b$10$utsMOdfjDFKeEdD6UKgXieeGgzh/KtoLPq0Q7il4Qlsvr7/IC23Qi"}],"user:email:password":[],"user:confirm":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,7 +170,7 @@ export default class UserControllerTest extends BaseHttpTest { | |
const user = await User.find({ email: '[email protected]' }) | ||
const token = await ioc.use('authService').login('[email protected]', '12345') | ||
const response = await request.put(`/api/v1/users/${user.id}`, { | ||
body: { name: 'Customer Updated', password: '123456' }, | ||
body: { name: 'Customer Updated', password: '12345678', password_confirmation: '12345678' }, | ||
headers: { authorization: token } | ||
}) | ||
|
||
|
@@ -192,7 +192,12 @@ export default class UserControllerTest extends BaseHttpTest { | |
const user = await User.find({ email: '[email protected]' }) | ||
const token = await ioc.use('authService').login('[email protected]', '12345') | ||
const response = await request.put(`/api/v1/users/${user.id}`, { | ||
body: { name: 'Customer Updated', email: '[email protected]', password: '123456' }, | ||
body: { | ||
name: 'Customer Updated', | ||
email: '[email protected]', | ||
password: '12345678', | ||
password_confirmation: '12345678' | ||
}, | ||
headers: { authorization: token } | ||
}) | ||
|
||
|