edit my details
This commit is contained in:
parent
ba3c763a09
commit
f87c7b4a7c
2 changed files with 56 additions and 7 deletions
|
@ -4,14 +4,30 @@ import QRCode from "qrcode";
|
||||||
import InternalException from "../exceptions/internalException";
|
import InternalException from "../exceptions/internalException";
|
||||||
import { CLUB_NAME } from "../env.defaults";
|
import { CLUB_NAME } from "../env.defaults";
|
||||||
import UserService from "../service/userService";
|
import UserService from "../service/userService";
|
||||||
|
import UserFactory from "../factory/admin/user";
|
||||||
|
import { UpdateUserCommand } from "../command/userCommand";
|
||||||
|
import UserCommandHandler from "../command/userCommandHandler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description get user totp
|
* @description get my by id
|
||||||
* @param req {Request} Express req object
|
* @param req {Request} Express req object
|
||||||
* @param res {Response} Express res object
|
* @param res {Response} Express res object
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export async function getUserTotp(req: Request, res: Response): Promise<any> {
|
export async function getMeById(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.userId);
|
||||||
|
let user = await UserService.getById(id);
|
||||||
|
|
||||||
|
res.json(UserFactory.mapToSingle(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description get my totp
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function getMyTotp(req: Request, res: Response): Promise<any> {
|
||||||
const userId = parseInt(req.userId);
|
const userId = parseInt(req.userId);
|
||||||
|
|
||||||
let { secret } = await UserService.getById(userId);
|
let { secret } = await UserService.getById(userId);
|
||||||
|
@ -31,12 +47,12 @@ export async function getUserTotp(req: Request, res: Response): Promise<any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description verify user totp
|
* @description verify my totp
|
||||||
* @param req {Request} Express req object
|
* @param req {Request} Express req object
|
||||||
* @param res {Response} Express res object
|
* @param res {Response} Express res object
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export async function verifyUserTotp(req: Request, res: Response): Promise<any> {
|
export async function verifyMyTotp(req: Request, res: Response): Promise<any> {
|
||||||
const userId = parseInt(req.userId);
|
const userId = parseInt(req.userId);
|
||||||
let totp = req.body.totp;
|
let totp = req.body.totp;
|
||||||
|
|
||||||
|
@ -53,3 +69,28 @@ export async function verifyUserTotp(req: Request, res: Response): Promise<any>
|
||||||
}
|
}
|
||||||
res.sendStatus(204);
|
res.sendStatus(204);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description update my data
|
||||||
|
* @param req {Request} Express req object
|
||||||
|
* @param res {Response} Express res object
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export async function updateMe(req: Request, res: Response): Promise<any> {
|
||||||
|
const id = parseInt(req.userId);
|
||||||
|
let mail = req.body.mail;
|
||||||
|
let firstname = req.body.firstname;
|
||||||
|
let lastname = req.body.lastname;
|
||||||
|
let username = req.body.username;
|
||||||
|
|
||||||
|
let updateUser: UpdateUserCommand = {
|
||||||
|
id: id,
|
||||||
|
mail: mail,
|
||||||
|
firstname: firstname,
|
||||||
|
lastname: lastname,
|
||||||
|
username: username,
|
||||||
|
};
|
||||||
|
await UserCommandHandler.update(updateUser);
|
||||||
|
|
||||||
|
res.sendStatus(204);
|
||||||
|
}
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import { getUserTotp, verifyUserTotp } from "../controller/userController";
|
import { getMeById, getMyTotp, updateMe, verifyMyTotp } from "../controller/userController";
|
||||||
|
|
||||||
var router = express.Router({ mergeParams: true });
|
var router = express.Router({ mergeParams: true });
|
||||||
|
|
||||||
|
router.get("/me", async (req, res) => {
|
||||||
|
await getMeById(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
router.get("/totp", async (req, res) => {
|
router.get("/totp", async (req, res) => {
|
||||||
await getUserTotp(req, res);
|
await getMyTotp(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/verify", async (req, res) => {
|
router.post("/verify", async (req, res) => {
|
||||||
await verifyUserTotp(req, res);
|
await verifyMyTotp(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
|
router.patch("/me", async (req, res) => {
|
||||||
|
await updateMe(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
Loading…
Reference in a new issue