All files / src/controllers/system-controller changeUserPassword.js

75% Statements 6/8
100% Branches 0/0
100% Functions 1/1
75% Lines 6/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21        3x 3x 3x 3x           3x 3x            
import { hashSync } from "bcrypt";
import UsersModel from "../../models/Users.js";
 
export default async function changeUserPassword({ userId, userEmail }, newPassword) {
    try {
        const newPasswordHashed = hashSync(newPassword, +process.env.HASHING_SALT_ROUNDS);
        const filter = { $or: [{ _id: userId }, { userEmail }] };
        const updateQuery = {
            $set: {
                userPassword: newPasswordHashed,
                lastPasswordChange: new Date().toISOString()
            }
        }
        const { modifiedCount } = await UsersModel.updateOne(filter, updateQuery);
        return !!modifiedCount;
    } catch (error) {
        console.log(error)
        return;
    }
}