11import { status as httpStatus } from 'http-status'
22
3- import type { Collection } from '../../collections/config/types.js'
3+ import type { Collection , DataFromCollectionSlug } from '../../collections/config/types.js'
4+ import type { CollectionSlug } from '../../index.js'
45import type { PayloadRequest } from '../../types/index.js'
56
7+ import { buildAfterOperation } from '../../collections/operations/utils.js'
68import { APIError , Forbidden } from '../../errors/index.js'
79import { commitTransaction } from '../../utilities/commitTransaction.js'
810import { initTransaction } from '../../utilities/initTransaction.js'
@@ -28,7 +30,9 @@ export type Arguments = {
2830 req : PayloadRequest
2931}
3032
31- export const resetPasswordOperation = async ( args : Arguments ) : Promise < Result > => {
33+ export const resetPasswordOperation = async < TSlug extends CollectionSlug > (
34+ args : Arguments ,
35+ ) : Promise < Result > => {
3236 const {
3337 collection : { config : collectionConfig } ,
3438 data,
@@ -55,6 +59,19 @@ export const resetPasswordOperation = async (args: Arguments): Promise<Result> =
5559 try {
5660 const shouldCommit = await initTransaction ( req )
5761
62+ if ( args . collection . config . hooks ?. beforeOperation ?. length ) {
63+ for ( const hook of args . collection . config . hooks . beforeOperation ) {
64+ args =
65+ ( await hook ( {
66+ args,
67+ collection : args . collection ?. config ,
68+ context : args . req . context ,
69+ operation : 'resetPassword' ,
70+ req : args . req ,
71+ } ) ) || args
72+ }
73+ }
74+
5875 // /////////////////////////////////////
5976 // Reset Password
6077 // /////////////////////////////////////
@@ -135,6 +152,7 @@ export const resetPasswordOperation = async (args: Arguments): Promise<Result> =
135152 overrideAccess,
136153 req,
137154 } )
155+
138156 if ( shouldCommit ) {
139157 await commitTransaction ( req )
140158 }
@@ -144,11 +162,22 @@ export const resetPasswordOperation = async (args: Arguments): Promise<Result> =
144162 fullUser . _strategy = 'local-jwt'
145163 }
146164
147- const result = {
165+ let result : { user : DataFromCollectionSlug < TSlug > } & Result = {
148166 token,
149167 user : fullUser ,
150168 }
151169
170+ // /////////////////////////////////////
171+ // afterOperation - Collection
172+ // /////////////////////////////////////
173+
174+ result = await buildAfterOperation ( {
175+ args,
176+ collection : args . collection ?. config ,
177+ operation : 'resetPassword' ,
178+ result,
179+ } )
180+
152181 return result
153182 } catch ( error : unknown ) {
154183 await killTransaction ( req )
0 commit comments