fix(models): update user and token operations to use centralized functions

This commit is contained in:
Danny Avila 2025-05-30 13:59:30 -04:00
parent 6e278f6932
commit 3831ad8202
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
10 changed files with 48 additions and 58 deletions

View file

@ -9,12 +9,10 @@ const {
requestPasswordReset,
setOpenIDAuthTokens,
} = require('~/server/services/AuthService');
const { findUser, getUserById } = require('~/models');
const { findUser, getUserById, deleteAllUserSessions, findSession } = require('~/models');
const { getOpenIdConfig } = require('~/strategies');
const { isEnabled } = require('~/server/utils');
const Session = require('~/db/models').Session;
const registrationController = async (req, res) => {
try {
const response = await registerUser(req.body);
@ -50,7 +48,7 @@ const resetPasswordController = async (req, res) => {
if (resetPasswordService instanceof Error) {
return res.status(400).json(resetPasswordService);
} else {
await Session.deleteAllUserSessions({ userId: req.body.userId });
await deleteAllUserSessions({ userId: req.body.userId });
return res.status(200).json(resetPasswordService);
}
} catch (e) {
@ -98,7 +96,7 @@ const refreshController = async (req, res) => {
}
// Find the session with the hashed refresh token
const session = await Session.findSession({
const session = await findSession({
userId: userId,
refreshToken: refreshToken,
});