refactor: AuthController

#9
This commit is contained in:
Mathis H (Avnyr) 2024-04-23 15:09:26 +02:00
parent 5130e0a248
commit 750e36e363
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -4,6 +4,7 @@ import JwtService from "@services/jwt.service";
import {Logger} from "tslog"; import {Logger} from "tslog";
import type {Request, Response} from "express"; import type {Request, Response} from "express";
import UserService from "@services/user.service"; import UserService from "@services/user.service";
import {IReqEditUserData} from "@interfaces/IReqEditUserData";
const logger = new Logger({ name: "AuthController" }); const logger = new Logger({ name: "AuthController" });
@ -233,7 +234,7 @@ async function getUser(req: Request, res: Response) {
//TODO - Implement re-auth by current password in case of password change //TODO - Implement re-auth by current password in case of password change
async function editUser(req: Request, res: Response) { async function editUser(req: Request, res: Response) {
const body = req.body; const body: IReqEditUserData | null = req.body;
if (!body) { if (!body) {
return res return res
.type('application/json') .type('application/json')
@ -278,12 +279,16 @@ async function editUser(req: Request, res: Response) {
} }
//TODO Interface //TODO Interface
const modifiedData= {} const modifiedData = {
}
//@ts-ignore
if (body.firstName) modifiedData.firstName = `${body.firstName}`; if (body.firstName) modifiedData.firstName = `${body.firstName}`;
//@ts-ignore
if (body.lastName) modifiedData.lastName = `${body.lastName}`; if (body.lastName) modifiedData.lastName = `${body.lastName}`;
//@ts-ignore
if (body.displayName) modifiedData.displayName = `${body.displayName}`; if (body.displayName) modifiedData.displayName = `${body.displayName}`;
// Case handled with hashing by the service. //TODO Case handled with hashing by the service.
if (body.password) modifiedData.password = `${body.password}`; //if (body.password) modifiedData.password = `${body.password}`;
//Call service //Call service
const EditUserServiceResult = await UserService.edit(`${targetUserId}`, modifiedData); const EditUserServiceResult = await UserService.edit(`${targetUserId}`, modifiedData);