-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow.ts
50 lines (44 loc) · 1.2 KB
/
workflow.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Request, AuthRequest, Response, NextFunction } from 'express'
import Joi from 'joi'
import { fullMessagesResponse, passwordSchema } from '../utils/joiSchemas'
import runner from './runner'
import { MESSAGE_TYPE } from '../utils/enums'
import { customTFunction } from '../utils/translations'
/**
* Password reset request schema - password in the body
*/
export const requestSchema = Joi.object({
body: Joi.object({
password: passwordSchema
}),
query: Joi.object(),
params: Joi.object()
})
/**
* Password reset response schema - full message
*/
export const responseSchema = fullMessagesResponse
/**
* Password reset endpoint.
* Usage: `router.post('/password-reset', PasswordReset.guard, schemaMiddleware(PasswordReset.requestSchema), PasswordReset.endpoint)`
* @param req
* @param res
* @param next
*/
export async function workflow(req: Request, res: Response, next: NextFunction) {
try {
const { body, user } = req as AuthRequest
await runner(body.password, user.id)
const t = req.t ?? customTFunction
return res.json({
messages: [
{
message: t('Password was successfully changed'),
type: MESSAGE_TYPE.SUCCESS
}
]
})
} catch (err) {
return next(err)
}
}