const UserModel = require('../models/userModel') const { hashPassword } = require('../utils/hashUtils') exports.startTransaction = async () => { const seesion = await UserModel.startSession() seesion.startTransaction() return seesion } exports.commitTransaction = async (session) => { return await session.commitTransaction() } exports.rollbackTransaction = async (session) => { return await session.abortTransaction() } exports.selectAllUser = async () => { return await UserModel.find() } exports.selectUserById = async (id) => { return await UserModel.findById(id) } exports.selectUserByAccount = async (account) => { return await UserModel.findOne({ account: account }) } exports.selectUserByEmail = async (email) => { return await UserModel.findOne({ email: email }) } exports.selectUserByUsername = async (username) => { return await UserModel.findOne({ username: username }) } exports.selectUserByPhone = async (phone) => { return await UserModel.findOne({ phone: phone }) } exports.createUser = async (user) => { return await UserModel.create(user) } exports.updateUserById = async (id, user) => { return await UserModel.findByIdAndUpdate(id, user) } exports.updateUserByLoginDate = async (id, loginDate) => { return await UserModel.findByIdAndUpdate(id, { last_login_date: loginDate }) } exports.deleteUserById = async (id) => { return await UserModel.findByIdAndDelete(id) } exports.deleteAllUser = async () => { return await UserModel.deleteMany() }