add account reset

This commit is contained in:
2025-06-02 16:37:22 +05:30
parent 52b97fe7ad
commit e25c9e5f92
4 changed files with 66 additions and 2 deletions

View File

@@ -4,8 +4,10 @@ import {
deleteUser,
ErrMissingOrdId,
ErrOpNotValid,
ErrUserNotFound,
getUser,
listUsers,
resetUser,
updateUser,
} from "./user.service";
import { CreateUserInput, UpdateUserInput } from "./user.schema";
@@ -30,6 +32,23 @@ export async function createUserHandler(
}
}
export async function resetUserHandler(req: FastifyRequest, res: FastifyReply) {
const { userId } = req.params as { userId: string };
try {
await resetUser(userId, req.user);
return res.code(200).send({ msg: "Account reset mail sent" });
} catch (err) {
if (
err instanceof Error &&
(err.message == ErrOpNotValid.message ||
err.message == ErrUserNotFound.message)
)
return res.code(400).send({ error: err.message });
return err;
}
}
export async function getCurrentUserHandler(
req: FastifyRequest,
res: FastifyReply