summary refs log tree commit diff
path: root/src/api/routes/auth/accountRoutes.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/routes/auth/accountRoutes.js')
-rw-r--r--src/api/routes/auth/accountRoutes.js78
1 files changed, 52 insertions, 26 deletions
diff --git a/src/api/routes/auth/accountRoutes.js b/src/api/routes/auth/accountRoutes.js

index 18c204d..76452e3 100644 --- a/src/api/routes/auth/accountRoutes.js +++ b/src/api/routes/auth/accountRoutes.js
@@ -1,44 +1,70 @@ import { deleteUser, loginUser, registerUser } from '#db/index.js'; import { AuthDto, RegisterDto } from '#dto/index.js'; +import { RouteDescription, RouteMethod } from '#api/RouteDescription.js'; +/** + * @type {RouteDescription} + */ export const registerRoute = { - route: '/auth/register', - async onPost(req, res) { - const data = await RegisterDto.create(req.body); - await registerUser(data); - res.status(204).send(); + path: '/auth/register', + methods: { + post: new RouteMethod({ + async method(req, res) { + const data = await RegisterDto.create(req.body); + await registerUser(data); + res.status(204).send(); + } + }) } }; +/** + * @type {RouteDescription} + */ export const loginRoute = { - route: '/auth/login', - async onPost(req, res) { - const data = await AuthDto.create(req.body); - const loginResult = await loginUser(data, req.headers['user-agent']); - res.send(loginResult); + path: '/auth/login', + methods: { + post: new RouteMethod({ + async method(req, res) { + const data = await AuthDto.create(req.body); + const loginResult = await loginUser( + data, + req.headers['user-agent'] + ); + res.send(loginResult); + } + }) } }; +/** + * @type {RouteDescription} + */ export const logoutRoute = { - route: '/auth/logout', - /** - * - * @param req {Request} - * @param res - * @returns {Promise<WhoAmIDto>} - */ - async onPost(req, res) { - const data = await AuthDto.create(req.body); - // const loginResult = await deleteDevice(data, ); - res.status(204).send(); + path: '/auth/logout', + methods: { + post: new RouteMethod({ + async method(req, res) { + const data = await AuthDto.create(req.body); + // const loginResult = await deleteDevice(data, ); + res.status(204).send(); + } + }) } }; +/** + * @type {RouteDescription} + */ export const deleteRoute = { - route: '/auth/delete', - async onDelete(req, res) { - const data = await AuthDto.create(req.body); - await deleteUser(data); - res.status(204).send(); + path: '/auth/delete', + methods: { + delete: new RouteMethod({ + async method(req, res) { + const data = await AuthDto.create(req.body); + await deleteUser(data); + res.status(204).send(); + } + }) } };