Skip to content
Snippets Groups Projects
userService.js 749 B
Newer Older
root's avatar
root committed
import User from '../models/user.js';

const userService = {
  async createUser(userData) {
    try {
      const user = new User(userData);
      await user.save();
      return user;
    } catch (err) {
      throw err;
    }
  },

Gwangbin's avatar
Gwangbin committed
  async findUserById(userId) {
    try {
      const user = await User.findById(userId);
      return user;
    } catch (err) {
      throw err;
    }
  },

  async findUserByEmail(email) {
    try {
      const user = await User.findOne({ email });
      return user;
    } catch (err) {
      throw err;
    }
  },
Gwangbin's avatar
Gwangbin committed

  async existsByEmail(email) {
    try {
      const user = await User.exists({ email });
      return user !== null;
    } catch (err) {
      throw err;
    }
  }
root's avatar
root committed
export default userService;