File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
src/http/controllers/users Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import type { FastifyReply , FastifyRequest } from 'fastify'
2+ import { z } from 'zod'
3+
4+ import { InvalidCredentialsError } from '@/services/errors/invalid-credentials-error'
5+ import { makeResetPasswordService } from '@/services/factories/users/make-reset-password-service'
6+
7+ export async function resetPassword (
8+ request : FastifyRequest ,
9+ reply : FastifyReply ,
10+ ) {
11+ const resetPasswordBodySchema = z . object ( {
12+ code : z . number ( ) . int ( ) . min ( 100000 ) . max ( 999999 ) ,
13+ password : z . string ( ) . min ( 6 ) ,
14+ userId : z . string ( ) . cuid ( ) ,
15+ } )
16+
17+ const { code, password, userId } = resetPasswordBodySchema . parse ( request . body )
18+
19+ try {
20+ const resetPasswordService = makeResetPasswordService ( )
21+
22+ await resetPasswordService . execute ( { code, password, userId } )
23+ } catch ( err ) {
24+ if ( err instanceof InvalidCredentialsError ) {
25+ return reply . status ( 404 ) . send ( { message : err . message } )
26+ }
27+
28+ throw err
29+ }
30+
31+ return reply . status ( 204 ) . send ( )
32+ }
You can’t perform that action at this time.
0 commit comments